Commit 11f9193e authored by Marcin Siodelski's avatar Marcin Siodelski
Browse files

[#92,!13] Moved DbAccessParser to libkea-database.

parent 4b2ea5f1
......@@ -429,25 +429,31 @@ configureDhcp4Server(Dhcpv4Srv& server, isc::data::ConstElementPtr config_set,
// 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;
}
......
......@@ -542,25 +542,31 @@ configureDhcp6Server(Dhcpv6Srv& server, isc::data::ConstElementPtr config_set,
// 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;
}
......
......@@ -31,13 +31,13 @@ namespace dhcp {
// 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:
......@@ -122,8 +122,7 @@ DbAccessParser::parse(CfgDbAccessPtr& cfg_db,
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() << ")");
}
......@@ -212,11 +211,7 @@ DbAccessParser::parse(CfgDbAccessPtr& cfg_db,
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
......
......@@ -17,14 +17,12 @@
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:
......@@ -35,9 +33,7 @@ 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()
......@@ -53,17 +49,16 @@ public:
/// - "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);
......@@ -91,8 +86,6 @@ protected:
private:
std::map<std::string, std::string> values_; ///< Stored parameter values
DBType type_; ///< Database type (leases or hosts)
};
}; // namespace dhcp
......
......@@ -198,7 +198,7 @@ public:
///
/// @brief Keyword/value collection of database access parameters
TestDbAccessParser(DBType type)
: DbAccessParser(type)
: DbAccessParser(), type_(type)
{}
/// @brief Destructor
......@@ -206,9 +206,18 @@ public:
{}
/// @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.
......@@ -234,6 +243,8 @@ public:
std::string getDbAccessString() const {
return (DbAccessParser::getDbAccessString());
}
DBType type_;
};
// Check that the parser works with a simple configuration.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment