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() ) cond::throwException( "The connection string is empty.", "getConnectionParams" );
43  std::string protocol = getConnectionProtocol( connectionString );
44  std::string finalConn = connectionString;
45  std::string refreshConn( "" );
46  if( protocol == "frontier" ) {
47  std::string protocol( "frontier://" );
48  std::string::size_type fpos = connectionString.find( protocol );
49  unsigned int nslash = countslash( connectionString.substr( protocol.size(), connectionString.size() - fpos ) );
50  if( nslash==1 ) {
51  edm::Service<edm::SiteLocalConfig> localconfservice;
52  if( !localconfservice.isAvailable() ) {
53  cond::throwException( "edm::SiteLocalConfigService is not available", "getConnectionParams" );
54  }
55  finalConn = localconfservice->lookupCalibConnect( connectionString );
56  }
57  if( !transactionId.empty() ) {
58  size_t l = finalConn.rfind('/');
59  finalConn.insert( l, "(freshkey="+transactionId+')' );
60  }
61 
62  //When the signature parameter is set to sig, FroNTier requests that the server sends digital signatures on every response.
63  //We test here that the signature string, if defined, is actually set to sig, otherwise we throw an exception
64  std::string signatureParameter( "sig" );
65  if( !signature.empty() ) {
66  if( signature == signatureParameter ) {
67  std::string::size_type s = finalConn.rfind('/');
68  finalConn.insert( s, "(security="+signature+')' );
69  } else {
70  cond::throwException( "The FroNTier security option is invalid.", "getConnectionParams" );
71  }
72  }
73 
74  std::string::size_type startRefresh = finalConn.find( "://" );
75  if( startRefresh != std::string::npos ) {
76  startRefresh += 3;
77  }
78  std::string::size_type endRefresh=finalConn.rfind( "/", std::string::npos );
79  if( endRefresh == std::string::npos ) {
80  refreshConn = finalConn;
81  } else {
82  refreshConn = finalConn.substr( startRefresh, endRefresh - startRefresh );
83  if( refreshConn.substr( 0, 1 ) != "(" ) {
84  //if the connect string is not a complicated parenthesized string,
85  // an http:// needs to be at the beginning of it
86  refreshConn.insert( 0, "http://" );
87  }
88  }
89  } else if( protocol == "sqlite_fip" ) {
90  finalConn = parseFipConnectionString( connectionString );
91  }
92  return std::make_pair( finalConn, refreshConn );
93  }
94 
95  }
96 }
virtual std::string const lookupCalibConnect(std::string const &input) const =0
std::string getConnectionProtocol(const std::string &connectionString)
Definition: Utils.h:85
std::string parseFipConnectionString(const std::string &fipConnect)
uint16_t size_type
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:21
static std::string const input
Definition: EdmProvDump.cc:45
bool isAvailable() const
Definition: Service.h:46
std::pair< std::string, std::string > getConnectionParams(const std::string &connectionString, const std::string &transactionId, const std::string &signature)
Definition: plugin.cc:24
std::string fullPath() const
Definition: FileInPath.cc:197
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)