13 #include <boost/lexical_cast.hpp>
27 DbAccessParser::DbAccessParser()
50 int64_t lfc_interval = 0;
53 int64_t max_reconnect_tries = 0;
54 int64_t reconnect_wait_time = 0;
55 int64_t request_timeout = 0;
56 int64_t tcp_keepalive = 0;
57 int64_t max_row_errors = 0;
60 for (std::pair<std::string, ConstElementPtr> param : database_config->mapValue()) {
62 if ((param.first ==
"persist") ||
63 (param.first ==
"tcp-nodelay") ||
64 (param.first ==
"readonly")) {
65 values_copy[param.first] = (param.second->boolValue() ?
68 }
else if (param.first ==
"lfc-interval") {
69 lfc_interval = param.second->intValue();
70 values_copy[param.first] =
71 boost::lexical_cast<std::string>(lfc_interval);
73 }
else if (param.first ==
"connect-timeout") {
74 timeout = param.second->intValue();
75 values_copy[param.first] =
76 boost::lexical_cast<std::string>(timeout);
78 }
else if (param.first ==
"max-reconnect-tries") {
79 max_reconnect_tries = param.second->intValue();
80 values_copy[param.first] =
81 boost::lexical_cast<std::string>(max_reconnect_tries);
83 }
else if (param.first ==
"reconnect-wait-time") {
84 reconnect_wait_time = param.second->intValue();
85 values_copy[param.first] =
86 boost::lexical_cast<std::string>(reconnect_wait_time);
88 }
else if (param.first ==
"request-timeout") {
89 request_timeout = param.second->intValue();
90 values_copy[param.first] =
91 boost::lexical_cast<std::string>(request_timeout);
93 }
else if (param.first ==
"tcp-keepalive") {
94 tcp_keepalive = param.second->intValue();
95 values_copy[param.first] =
96 boost::lexical_cast<std::string>(tcp_keepalive);
98 }
else if (param.first ==
"port") {
99 port = param.second->intValue();
100 values_copy[param.first] =
101 boost::lexical_cast<std::string>(port);
103 }
else if (param.first ==
"max-row-errors") {
104 max_row_errors = param.second->intValue();
105 values_copy[param.first] =
106 boost::lexical_cast<std::string>(max_row_errors);
120 values_copy[param.first] = param.second->stringValue();
125 "parameter '" << param.first <<
"' ("
126 << param.second->getPosition() <<
")");
133 auto type_ptr = values_copy.find(
"type");
134 if (type_ptr == values_copy.end()) {
136 "database access parameters must "
137 "include the keyword 'type' to determine type of database "
138 "to be accessed (" << database_config->getPosition() <<
")");
145 string dbtype = type_ptr->second;
146 if ((dbtype !=
"memfile") &&
147 (dbtype !=
"mysql") &&
148 (dbtype !=
"postgresql") &&
152 <<
" (" << value->getPosition() <<
")");
156 if ((lfc_interval < 0) ||
157 (lfc_interval > std::numeric_limits<uint32_t>::max())) {
160 <<
" is out of range, expected value: 0.."
161 << std::numeric_limits<uint32_t>::max()
162 <<
" (" << value->getPosition() <<
")");
167 (timeout > std::numeric_limits<uint32_t>::max())) {
170 <<
" is out of range, expected value: 0.."
171 << std::numeric_limits<uint32_t>::max()
172 <<
" (" << value->getPosition() <<
")");
177 (port > std::numeric_limits<uint16_t>::max())) {
180 <<
" is out of range, expected value: 0.."
181 << std::numeric_limits<uint16_t>::max()
182 <<
" (" << value->getPosition() <<
")");
186 if ((max_row_errors < 0) ||
187 (max_row_errors > std::numeric_limits<uint32_t>::max())) {
190 <<
" is out of range, expected value: 0.."
191 << std::numeric_limits<uint32_t>::max()
192 <<
" (" << value->getPosition() <<
")");
196 if (max_reconnect_tries < 0) {
199 "max-reconnect-tries cannot be less than zero: ("
200 << value->getPosition() <<
")");
204 if ((reconnect_wait_time < 0) ||
205 (reconnect_wait_time > std::numeric_limits<uint32_t>::max())) {
208 <<
" must be in range 0...MAX_UINT32 (4294967295) "
209 <<
"(" << value->getPosition() <<
")");
213 if ((request_timeout < 0) ||
214 (request_timeout > std::numeric_limits<uint32_t>::max())) {
217 <<
" must be in range 0...MAX_UINT32 (4294967295) "
218 <<
"(" << value->getPosition() <<
")");
222 if ((tcp_keepalive < 0) ||
223 (tcp_keepalive > std::numeric_limits<uint32_t>::max())) {
226 <<
" must be in range 0...MAX_UINT32 (4294967295) "
227 <<
"(" << value->getPosition() <<
")");
234 values_.swap(values_copy);
247 for (
auto keyval : values_) {
248 if (!keyval.second.empty()) {
251 if (!dbaccess.empty()) {
252 dbaccess += std::string(
" ");
256 auto val = keyval.second;
257 if (val.find_first_of(
"\t ") != string::npos){
258 val =
"'" + val +
"'";
260 dbaccess += (keyval.first + std::string(
"=") + val);
std::string getDbAccessString() const
Construct database access string.
#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::map< std::string, std::string > ParameterMap
Database configuration parameter map.
void parse(std::string &access_string, isc::data::ConstElementPtr database_config)
Parse configuration value.