// CnnectionResolver.h #ifndef ConnectionResolver_H #define ConnectionResolver_H // Vinay Sambamurthy // August 2004 // Modified by D. Adams // November 2004 // // Class to resolve and provide other manipulations for the connection // string used to specify catalogs. // // A connection string is of the form // LOCATION or LOCATION@ACCESSOR // where LOCATION and ACCESSOR is of the form // NAME:PARAMS // where PARAMS is a colon delimited list of parameters. // // LOCATION specifies the location of the catalog and ACCESSOR is an // optional means to access that service. Commonly the location is // a database table and the accessor is a web service providing access // to that table. // // The name in each case is a string that specifies the technology, // e.g. FILE, MYSQL or AMI for locations and WS for the accessor. // // A configuration file, be default located at $DIAL_CATALOG_CONF // lists all the allowed connection strings in order of preference for // each type of catalog (DatasetRepository, DatasetSelectionCatalog, // TaskRepository, ...). This class provides means to resolve a // user request for a connection string, i.e to find the first // connection matching the request. All the fields in the user request // must match the first fields in the connection. // // The number and meaning of the parameters in the location or accessor // depend on the respective type. // // If requested, the password is resolved before returning the // connection string using the following algorithm: // If the connection ends with the string "", then that field // is replaced with the contents of the file at $HOME/.dial/pw // where PREFIX is the part of the connection string preceding that field. // E.g. MYTECH:MyDb:Server:my_table:myname: becomes // MYTECH:MyDb:Server:my_table:myname:1234 if 1234 is the content of // $HOME/.dial/pwMYTECH:MyDb:Server:my_table:myname . // WARNING: the connection string most likely cannot be resolved again // once the password is resolved. #include #include "dataset_util/Text.h" namespace dset { class ConnectionResolver { private: // data Text m_txt; public: // static member functions // Set the name for the configuration file. // Default is $DIAL_CATALOG_CONF. static void set_configuration_file(std::string cfile); // Get the name for the configuration file. static std::string get_configuration_file(); // Return the name from a location in a connection string. // If blank, the connection is not valid. static std::string location_name(std::string conn); // Return the name from the last accssor in a connection string. // IF blank, the connection does not have an accessor. static std::string accessor_name(std::string conn); public: // member functions // Constructor from the file at DIAL_CATALOG_CONF. ConnectionResolver(); // Destructor. ~ConnectionResolver(); // Validity. // True if the file is not empty. bool is_valid() const; // Return the connection string with the longest match in the // specified catalog. // Returns blank if no match is found. // type = catalog type (e.g. DatasetRepository) // conn = connection string // findpass = flag indicating that password should be resolved std::string resolve(std::string type, std::string conn, bool findpass =false) const; }; } // end namespace dset #endif