summaryrefslogtreecommitdiffstats
path: root/src/lib/dhcpsrv/cfg_db_access.cc
diff options
context:
space:
mode:
authorAndrei Pavel <andrei.pavel@qualitance.com>2017-08-17 20:04:29 +0200
committerAndrei Pavel <andrei.pavel@qualitance.com>2017-08-17 20:04:29 +0200
commit529d15326887b3513413567e497118b3db2c24f3 (patch)
tree8b66b262349433802bd52e920bb4783baac57cb3 /src/lib/dhcpsrv/cfg_db_access.cc
parentAdded mysql_execute_script (diff)
parent[master] Added ChangeLog 1288 for trac 5315. (diff)
downloadkea-529d15326887b3513413567e497118b3db2c24f3.tar.xz
kea-529d15326887b3513413567e497118b3db2c24f3.zip
Merge branch 'isc-master' into minor-changes
Diffstat (limited to 'src/lib/dhcpsrv/cfg_db_access.cc')
-rw-r--r--src/lib/dhcpsrv/cfg_db_access.cc66
1 files changed, 64 insertions, 2 deletions
diff --git a/src/lib/dhcpsrv/cfg_db_access.cc b/src/lib/dhcpsrv/cfg_db_access.cc
index 4601dc93e6..e93631dc7b 100644
--- a/src/lib/dhcpsrv/cfg_db_access.cc
+++ b/src/lib/dhcpsrv/cfg_db_access.cc
@@ -1,4 +1,4 @@
-// Copyright (C) 2016 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2016-2017 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -9,7 +9,13 @@
#include <dhcpsrv/host_data_source_factory.h>
#include <dhcpsrv/host_mgr.h>
#include <dhcpsrv/lease_mgr_factory.h>
+#include <boost/algorithm/string.hpp>
+#include <boost/foreach.hpp>
+#include <boost/lexical_cast.hpp>
#include <sstream>
+#include <vector>
+
+using namespace isc::data;
namespace isc {
namespace dhcp {
@@ -59,7 +65,63 @@ CfgDbAccess::getAccessString(const std::string& access_string) const {
return (s.str());
}
-
+ElementPtr
+CfgDbAccess::toElementDbAccessString(const std::string& dbaccess) {
+ ElementPtr result = Element::createMap();
+ // Code from DatabaseConnection::parse
+ if (dbaccess.empty()) {
+ return (result);
+ }
+ std::vector<std::string> tokens;
+ boost::split(tokens, dbaccess, boost::is_any_of(std::string("\t ")));
+ BOOST_FOREACH(std::string token, tokens) {
+ size_t pos = token.find("=");
+ if (pos != std::string::npos) {
+ std::string keyword = token.substr(0, pos);
+ std::string value = token.substr(pos + 1);
+ if ((keyword == "lfc-interval") ||
+ (keyword == "connect-timeout") ||
+ (keyword == "port")) {
+ // integer parameters
+ int64_t int_value;
+ try {
+ int_value = boost::lexical_cast<int64_t>(value);
+ result->set(keyword, Element::create(int_value));
+ } catch (...) {
+ isc_throw(ToElementError, "invalid DB access "
+ << "integer parameter: "
+ << keyword << "=" << value);
+ }
+ } else if ((keyword == "persist") ||
+ (keyword == "readonly")) {
+ if (value == "true") {
+ result->set(keyword, Element::create(true));
+ } else if (value == "false") {
+ result->set(keyword, Element::create(false));
+ } else {
+ isc_throw(ToElementError, "invalid DB access "
+ << "boolean parameter: "
+ << keyword << "=" << value);
+ }
+ } else if ((keyword == "type") ||
+ (keyword == "user") ||
+ (keyword == "password") ||
+ (keyword == "host") ||
+ (keyword == "name") ||
+ (keyword == "contact_points") ||
+ (keyword == "keyspace")) {
+ result->set(keyword, Element::create(value));
+ } else {
+ isc_throw(ToElementError, "unknown DB access parameter: "
+ << keyword << "=" << value);
+ }
+ } else {
+ isc_throw(ToElementError, "Cannot unparse " << token
+ << ", expected format is name=value");
+ }
+ }
+ return (result);
+}
} // end of isc::dhcp namespace
} // end of isc namespace