// Please move at the end when migration will be finished.
if (config_pair.first == "lease-database") {
- DbAccessParser parser(DBType::LEASE_DB);
+ DbAccessParser parser;
+ std::string access_string;
+ parser.parse(access_string, config_pair.second);
CfgDbAccessPtr cfg_db_access = srv_cfg->getCfgDbAccess();
- parser.parse(cfg_db_access, config_pair.second);
+ cfg_db_access->setLeaseDbAccessString(access_string);
continue;
}
if (config_pair.first == "hosts-database") {
- DbAccessParser parser(DBType::HOSTS_DB);
+ DbAccessParser parser;
+ std::string access_string;
+ parser.parse(access_string, config_pair.second);
CfgDbAccessPtr cfg_db_access = srv_cfg->getCfgDbAccess();
- parser.parse(cfg_db_access, config_pair.second);
+ cfg_db_access->setHostDbAccessString(access_string);
continue;
}
if (config_pair.first == "hosts-databases") {
CfgDbAccessPtr cfg_db_access = srv_cfg->getCfgDbAccess();
- DbAccessParser parser(DBType::HOSTS_DB);
+ DbAccessParser parser;
auto list = config_pair.second->listValue();
for (auto it : list) {
- parser.parse(cfg_db_access, it);
+ std::string access_string;
+ parser.parse(access_string, it);
+ cfg_db_access->setHostDbAccessString(access_string);
}
continue;
}
// Please move at the end when migration will be finished.
if (config_pair.first == "lease-database") {
- DbAccessParser parser(DBType::LEASE_DB);
+ DbAccessParser parser;
+ std::string access_string;
+ parser.parse(access_string, config_pair.second);
CfgDbAccessPtr cfg_db_access = srv_config->getCfgDbAccess();
- parser.parse(cfg_db_access, config_pair.second);
+ cfg_db_access->setLeaseDbAccessString(access_string);
continue;
}
if (config_pair.first == "hosts-database") {
- DbAccessParser parser(DBType::HOSTS_DB);
+ DbAccessParser parser;
+ std::string access_string;
+ parser.parse(access_string, config_pair.second);
CfgDbAccessPtr cfg_db_access = srv_config->getCfgDbAccess();
- parser.parse(cfg_db_access, config_pair.second);
+ cfg_db_access->setHostDbAccessString(access_string);
continue;
}
if (config_pair.first == "hosts-databases") {
CfgDbAccessPtr cfg_db_access = srv_config->getCfgDbAccess();
- DbAccessParser parser(DBType::HOSTS_DB);
+ DbAccessParser parser;
auto list = config_pair.second->listValue();
for (auto it : list) {
- parser.parse(cfg_db_access, it);
+ std::string access_string;
+ parser.parse(access_string, it);
+ cfg_db_access->setHostDbAccessString(access_string);
}
continue;
}
// Factory function to build the parser
-DbAccessParser::DbAccessParser(DBType db_type)
- : values_(), type_(db_type) {
+DbAccessParser::DbAccessParser()
+ : values_() {
}
// Parse the configuration and check that the various keywords are consistent.
void
-DbAccessParser::parse(CfgDbAccessPtr& cfg_db,
+DbAccessParser::parse(std::string& access_string,
ConstElementPtr database_config) {
// To cope with incremental updates, the strategy is:
StringPairMap::const_iterator type_ptr = values_copy.find("type");
if (type_ptr == values_copy.end()) {
isc_throw(DhcpConfigError,
- (type_ == DBType::LEASE_DB ? "lease" : "host")
- << " database access parameters must "
+ "database access parameters must "
"include the keyword 'type' to determine type of database "
"to be accessed (" << database_config->getPosition() << ")");
}
values_.swap(values_copy);
// 5. Save the database access string in the Configuration Manager.
- if (type_ == DBType::LEASE_DB) {
- cfg_db->setLeaseDbAccessString(getDbAccessString());
- } else if (type_ == DBType::HOSTS_DB) {
- cfg_db->setHostDbAccessString(getDbAccessString(), false);
- }
+ access_string = getDbAccessString();
}
// Create the database access string
namespace isc {
namespace dhcp {
-/// @brief Parse Lease Database Parameters
+/// @brief Parse Database Parameters
///
-/// This class is the parser for the lease database configuration. This is a
-/// map under the top-level "lease-database" element, and comprises a map of
-/// strings.
+/// This class is the parser for the database configuration. This is a
+/// map under the top-level "lease-database", "host-database" and
+/// "config-database" elements, and comprises a map of strings.
///
-/// Only the "type" sub-element is mandatory: the remaining sub-elements
-/// depend on the database chosen.
class DbAccessParser: public isc::data::SimpleParser {
public:
typedef std::map<std::string, std::string> StringPairMap;
/// @brief Constructor
- ///
- /// @param db_type Specifies database type (lease or hosts)
- explicit DbAccessParser(DBType db_type);
+ DbAccessParser();
/// The destructor.
virtual ~DbAccessParser()
/// - "connect-timeout" is a number from the range of 0 to 4294967295.
/// - "port" is a number from the range of 0 to 65535.
///
- /// Once all has been validated, constructs the database access string
- /// expected by the lease manager.
+ /// Once all has been validated, constructs the database access string.
///
- /// @param cfg_db The configuration where the access string will be set
+ /// @param [out] access_string Generated database access string.
/// @param database_config The configuration value for the "*-database"
/// identifier.
///
/// @throw isc::dhcp::DhcpConfigError The 'type' keyword contains an
/// unknown database type or is missing from the list of
/// database access keywords.
- void parse(isc::dhcp::CfgDbAccessPtr& cfg_db,
+ void parse(std::string& access_string,
isc::data::ConstElementPtr database_config);
private:
std::map<std::string, std::string> values_; ///< Stored parameter values
-
- DBType type_; ///< Database type (leases or hosts)
};
}; // namespace dhcp
///
/// @brief Keyword/value collection of database access parameters
TestDbAccessParser(DBType type)
- : DbAccessParser(type)
+ : DbAccessParser(), type_(type)
{}
/// @brief Destructor
{}
/// @brief Parse configuration value
+ ///
+ /// @param database_config Configuration to be parsed.
void parse(ConstElementPtr database_config) {
CfgDbAccessPtr cfg_db(new CfgDbAccess());
- DbAccessParser::parse(cfg_db, database_config);
+ std::string db_access_string;
+ DbAccessParser::parse(db_access_string, database_config);
+
+ if (type_ == DBType::LEASE_DB) {
+ cfg_db->setLeaseDbAccessString(db_access_string);
+ } else {
+ cfg_db->setHostDbAccessString(db_access_string);
+ }
}
/// Allow use of superclass's protected functions.
std::string getDbAccessString() const {
return (DbAccessParser::getDbAccessString());
}
+
+ DBType type_;
};
// Check that the parser works with a simple configuration.