13#include <boost/lexical_cast.hpp>
50 int64_t lfc_interval = 0;
51 int64_t connect_timeout = 0;
52 int64_t read_timeout = 0;
53 int64_t write_timeout = 0;
54 int64_t tcp_user_timeout = 0;
56 int64_t max_reconnect_tries = 0;
57 int64_t reconnect_wait_time = 0;
58 int64_t max_row_errors = 0;
61 for (std::pair<std::string, ConstElementPtr> param : database_config->mapValue()) {
63 if ((param.first ==
"persist") ||
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 connect_timeout = param.second->intValue();
75 values_copy[param.first] =
76 boost::lexical_cast<std::string>(connect_timeout);
78 }
else if (param.first ==
"read-timeout") {
79 read_timeout = param.second->intValue();
80 values_copy[param.first] =
81 boost::lexical_cast<std::string>(read_timeout);
83 }
else if (param.first ==
"write-timeout") {
84 write_timeout = param.second->intValue();
85 values_copy[param.first] =
86 boost::lexical_cast<std::string>(write_timeout);
88 }
else if (param.first ==
"tcp-user-timeout") {
89 tcp_user_timeout = param.second->intValue();
90 values_copy[param.first] =
91 boost::lexical_cast<std::string>(tcp_user_timeout);
93 }
else if (param.first ==
"max-reconnect-tries") {
94 max_reconnect_tries = param.second->intValue();
95 values_copy[param.first] =
96 boost::lexical_cast<std::string>(max_reconnect_tries);
98 }
else if (param.first ==
"reconnect-wait-time") {
99 reconnect_wait_time = param.second->intValue();
100 values_copy[param.first] =
101 boost::lexical_cast<std::string>(reconnect_wait_time);
103 }
else if (param.first ==
"port") {
104 port = param.second->intValue();
105 values_copy[param.first] =
106 boost::lexical_cast<std::string>(port);
108 }
else if (param.first ==
"max-row-errors") {
109 max_row_errors = param.second->intValue();
110 values_copy[param.first] =
111 boost::lexical_cast<std::string>(max_row_errors);
125 values_copy[param.first] = param.second->stringValue();
130 "parameter '" << param.first <<
"' ("
131 << param.second->getPosition() <<
")");
138 auto type_ptr = values_copy.find(
"type");
139 if (type_ptr == values_copy.end()) {
141 "database access parameters must "
142 "include the keyword 'type' to determine type of database "
143 "to be accessed (" << database_config->getPosition() <<
")");
150 string dbtype = type_ptr->second;
151 if ((dbtype !=
"memfile") &&
152 (dbtype !=
"mysql") &&
153 (dbtype !=
"postgresql")) {
156 <<
" (" << value->getPosition() <<
")");
160 if ((lfc_interval < 0) ||
161 (lfc_interval > std::numeric_limits<uint32_t>::max())) {
164 <<
" is out of range, expected value: 0.."
165 << std::numeric_limits<uint32_t>::max()
166 <<
" (" << value->getPosition() <<
")");
170 if ((connect_timeout < 0) ||
171 (connect_timeout > std::numeric_limits<uint32_t>::max())) {
174 <<
" is out of range, expected value: 0.."
175 << std::numeric_limits<uint32_t>::max()
176 <<
" (" << value->getPosition() <<
")");
178 if ((read_timeout < 0) ||
179 (read_timeout > std::numeric_limits<uint32_t>::max())) {
182 <<
" is out of range, expected value: 0.."
183 << std::numeric_limits<uint32_t>::max()
184 <<
" (" << value->getPosition() <<
")");
186 if (read_timeout > 0 && (dbtype !=
"mysql")) {
189 <<
" (" << value->getPosition() <<
")");
191 if ((write_timeout < 0) ||
192 (write_timeout > std::numeric_limits<uint32_t>::max())) {
195 <<
" is out of range, expected value: 0.."
196 << std::numeric_limits<uint32_t>::max()
197 <<
" (" << value->getPosition() <<
")");
199 if (write_timeout > 0 && (dbtype !=
"mysql")) {
202 <<
" (" << value->getPosition() <<
")");
204 if ((tcp_user_timeout < 0) ||
205 (tcp_user_timeout > std::numeric_limits<uint32_t>::max())) {
208 <<
" is out of range, expected value: 0.."
209 << std::numeric_limits<uint32_t>::max()
210 <<
" (" << value->getPosition() <<
")");
212 if (tcp_user_timeout > 0 && (dbtype !=
"postgresql")) {
215 <<
" (" << value->getPosition() <<
")");
220 (port > std::numeric_limits<uint16_t>::max())) {
223 <<
" is out of range, expected value: 0.."
224 << std::numeric_limits<uint16_t>::max()
225 <<
" (" << value->getPosition() <<
")");
229 if ((max_row_errors < 0) ||
230 (max_row_errors > std::numeric_limits<uint32_t>::max())) {
233 <<
" is out of range, expected value: 0.."
234 << std::numeric_limits<uint32_t>::max()
235 <<
" (" << value->getPosition() <<
")");
239 if (max_reconnect_tries < 0) {
242 "max-reconnect-tries cannot be less than zero: ("
243 << value->getPosition() <<
")");
247 if ((reconnect_wait_time < 0) ||
248 (reconnect_wait_time > std::numeric_limits<uint32_t>::max())) {
251 <<
" must be in range 0...MAX_UINT32 (4294967295) "
252 <<
"(" << value->getPosition() <<
")");
259 values_.swap(values_copy);
272 for (
auto keyval : values_) {
273 if (!keyval.second.empty()) {
276 if (!dbaccess.empty()) {
277 dbaccess += std::string(
" ");
281 auto val = keyval.second;
282 if (val.find_first_of(
"\t ") != string::npos){
283 val =
"'" + val +
"'";
285 dbaccess += (keyval.first + std::string(
"=") + val);
A standard Data module exception that is thrown if a function is called for an Element that has a wro...
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.
DbAccessParser()
Constructor.
std::string getDbAccessString() const
Construct database access string.
Error detected in the database configuration.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
boost::shared_ptr< const Element > ConstElementPtr
Defines the logger used by the top-level component of kea-lfc.