14 #include <boost/lexical_cast.hpp> 28 DbAccessParser::DbAccessParser()
51 int64_t lfc_interval = 0;
54 int64_t max_reconnect_tries = 0;
55 int64_t reconnect_wait_time = 0;
56 int64_t request_timeout = 0;
57 int64_t tcp_keepalive = 0;
60 for (std::pair<std::string, ConstElementPtr> param : database_config->mapValue()) {
62 if ((param.first ==
"persist") || (param.first ==
"readonly") ||
63 (param.first ==
"tcp-nodelay")) {
64 values_copy[param.first] = (param.second->boolValue() ?
67 }
else if (param.first ==
"lfc-interval") {
68 lfc_interval = param.second->intValue();
69 values_copy[param.first] =
70 boost::lexical_cast<std::string>(lfc_interval);
72 }
else if (param.first ==
"connect-timeout") {
73 timeout = param.second->intValue();
74 values_copy[param.first] =
75 boost::lexical_cast<std::string>(timeout);
77 }
else if (param.first ==
"max-reconnect-tries") {
78 max_reconnect_tries = param.second->intValue();
79 values_copy[param.first] =
80 boost::lexical_cast<std::string>(max_reconnect_tries);
82 }
else if (param.first ==
"reconnect-wait-time") {
83 reconnect_wait_time = param.second->intValue();
84 values_copy[param.first] =
85 boost::lexical_cast<std::string>(reconnect_wait_time);
87 }
else if (param.first ==
"request-timeout") {
88 request_timeout = param.second->intValue();
89 values_copy[param.first] =
90 boost::lexical_cast<std::string>(request_timeout);
92 }
else if (param.first ==
"tcp-keepalive") {
93 tcp_keepalive = param.second->intValue();
94 values_copy[param.first] =
95 boost::lexical_cast<std::string>(tcp_keepalive);
97 }
else if (param.first ==
"port") {
98 port = param.second->intValue();
99 values_copy[param.first] =
100 boost::lexical_cast<std::string>(port);
103 values_copy[param.first] = param.second->stringValue();
108 "parameter '" << param.first <<
"' (" 109 << param.second->getPosition() <<
")");
116 auto type_ptr = values_copy.find(
"type");
117 if (type_ptr == values_copy.end()) {
119 "database access parameters must " 120 "include the keyword 'type' to determine type of database " 121 "to be accessed (" << database_config->getPosition() <<
")");
128 string dbtype = type_ptr->second;
129 if ((dbtype !=
"memfile") &&
130 (dbtype !=
"mysql") &&
131 (dbtype !=
"postgresql") &&
135 <<
" (" << value->getPosition() <<
")");
139 if ((lfc_interval < 0) ||
140 (lfc_interval > std::numeric_limits<uint32_t>::max())) {
143 <<
" is out of range, expected value: 0.." 144 << std::numeric_limits<uint32_t>::max()
145 <<
" (" << value->getPosition() <<
")");
150 (timeout > std::numeric_limits<uint32_t>::max())) {
153 <<
" is out of range, expected value: 0.." 154 << std::numeric_limits<uint32_t>::max()
155 <<
" (" << value->getPosition() <<
")");
160 (port > std::numeric_limits<uint16_t>::max())) {
163 <<
" is out of range, expected value: 0.." 164 << std::numeric_limits<uint16_t>::max()
165 <<
" (" << value->getPosition() <<
")");
169 if (max_reconnect_tries < 0) {
172 <<
" (" << value->getPosition() <<
")");
176 if ((reconnect_wait_time < 0) ||
177 (reconnect_wait_time > std::numeric_limits<uint32_t>::max())) {
180 <<
" must be in range 0...MAX_UINT32 (4294967295) " 181 <<
" (" << value->getPosition() <<
")");
185 if ((reconnect_wait_time < 0) ||
186 (reconnect_wait_time > std::numeric_limits<uint32_t>::max())) {
189 <<
" must be in range 0...MAX_UINT32 (4294967295) " 190 <<
" (" << value->getPosition() <<
")");
193 if ((tcp_keepalive < 0) ||
194 (tcp_keepalive > std::numeric_limits<uint32_t>::max())) {
197 <<
" must be in range 0...MAX_UINT32 (4294967295) " 198 <<
" (" << value->getPosition() <<
")");
205 values_.swap(values_copy);
218 for (
auto keyval : values_) {
219 if (!keyval.second.empty()) {
222 if (!dbaccess.empty()) {
223 dbaccess += std::string(
" ");
227 dbaccess += (keyval.first + std::string(
"=") + keyval.second);
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
Error detected in the database configuration.
boost::shared_ptr< const Element > ConstElementPtr
A standard Data module exception that is thrown if a function is called for an Element that has a wro...
Defines the logger used by the top-level component of kea-dhcp-ddns.
std::string getDbAccessString() const
Construct database access string.
std::map< std::string, std::string > ParameterMap
Database configuration parameter map.
void parse(std::string &access_string, isc::data::ConstElementPtr database_config)
Parse configuration value.