CMS 3D CMS Logo

DbConnectionString.cc
Go to the documentation of this file.
3 #include "DbConnectionString.h"
4 //
8 
9 namespace cond {
10 
11  namespace persistency {
12 
13  unsigned int countslash(const std::string& input) {
14  unsigned int count = 0;
15  std::string::size_type slashpos(0);
16  while (slashpos != std::string::npos) {
17  slashpos = input.find('/', slashpos);
18  if (slashpos != std::string::npos) {
19  ++count;
20  // start next search after this word
21  slashpos += 1;
22  }
23  }
24  return count;
25  }
26 
28  std::string connect("sqlite_file:");
29  std::string::size_type pos = fipConnect.find(':');
30  std::string fipLocation = fipConnect.substr(pos + 1);
31  edm::FileInPath fip(fipLocation);
32  connect.append(fip.fullPath());
33  return connect;
34  }
35 
36  //FIXME: sdg this function does not support frontier connections strings like
37  //frontier://cmsfrontier.cern.ch:8000/FrontierPrep/CMS_CONDITIONS
38  //as http://cmsfrontier.cern.ch:8000/FrontierPrep(freshkey=foo) is an invalid URI.
39  std::pair<std::string, std::string> getConnectionParams(const std::string& connectionString,
40  const std::string& transactionId,
41  const std::string& signature) {
42  if (connectionString.empty())
43  cond::throwException("The connection string is empty.", "getConnectionParams");
45  std::string finalConn = connectionString;
46  std::string refreshConn("");
47  if (protocol == "frontier") {
48  std::string protocol("frontier://");
50  unsigned int nslash = countslash(connectionString.substr(protocol.size(), connectionString.size() - fpos));
51  if (nslash == 1) {
52  edm::Service<edm::SiteLocalConfig> localconfservice;
53  if (!localconfservice.isAvailable()) {
54  cond::throwException("edm::SiteLocalConfigService is not available", "getConnectionParams");
55  }
56  finalConn = localconfservice->lookupCalibConnect(connectionString);
57  }
58  if (!transactionId.empty()) {
59  size_t l = finalConn.rfind('/');
60  finalConn.insert(l, "(freshkey=" + transactionId + ')');
61  }
62 
63  //When the signature parameter is set to sig, FroNTier requests that the server sends digital signatures on every response.
64  //We test here that the signature string, if defined, is actually set to sig, otherwise we throw an exception
65  std::string signatureParameter("sig");
66  if (!signature.empty()) {
67  if (signature == signatureParameter) {
68  std::string::size_type s = finalConn.rfind('/');
69  finalConn.insert(s, "(security=" + signature + ')');
70  } else {
71  cond::throwException("The FroNTier security option is invalid.", "getConnectionParams");
72  }
73  }
74 
75  std::string::size_type startRefresh = finalConn.find("://");
76  if (startRefresh != std::string::npos) {
77  startRefresh += 3;
78  }
79  std::string::size_type endRefresh = finalConn.rfind('/', std::string::npos);
80  if (endRefresh == std::string::npos) {
81  refreshConn = finalConn;
82  } else {
83  refreshConn = finalConn.substr(startRefresh, endRefresh - startRefresh);
84  if (refreshConn.substr(0, 1) != "(") {
85  //if the connect string is not a complicated parenthesized string,
86  // an http:// needs to be at the beginning of it
87  refreshConn.insert(0, "http://");
88  }
89  }
90  } else if (protocol == "sqlite_fip") {
92  }
93  return std::make_pair(finalConn, refreshConn);
94  }
95 
96  } // namespace persistency
97 } // namespace cond
std::string fullPath() const
Definition: FileInPath.cc:161
std::string getConnectionProtocol(const std::string &connectionString)
Definition: Utils.h:86
std::string parseFipConnectionString(const std::string &fipConnect)
virtual std::string const lookupCalibConnect(std::string const &input) const =0
uint16_t size_type
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:18
static std::string const input
Definition: EdmProvDump.cc:50
std::pair< std::string, std::string > getConnectionParams(const std::string &connectionString, const std::string &transactionId, const std::string &signature)
bool isAvailable() const
Definition: Service.h:40
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined signature
Definition: Activities.doc:4
unsigned int countslash(const std::string &input)