13#include <boost/lexical_cast.hpp>
50 int64_t lfc_interval = 0;
53 int64_t max_reconnect_tries = 0;
54 int64_t reconnect_wait_time = 0;
55 int64_t max_row_errors = 0;
58 for (std::pair<std::string, ConstElementPtr> param : database_config->mapValue()) {
60 if ((param.first ==
"persist") ||
61 (param.first ==
"readonly")) {
62 values_copy[param.first] = (param.second->boolValue() ?
65 }
else if (param.first ==
"lfc-interval") {
66 lfc_interval = param.second->intValue();
67 values_copy[param.first] =
68 boost::lexical_cast<std::string>(lfc_interval);
70 }
else if (param.first ==
"connect-timeout") {
71 timeout = param.second->intValue();
72 values_copy[param.first] =
73 boost::lexical_cast<std::string>(timeout);
75 }
else if (param.first ==
"max-reconnect-tries") {
76 max_reconnect_tries = param.second->intValue();
77 values_copy[param.first] =
78 boost::lexical_cast<std::string>(max_reconnect_tries);
80 }
else if (param.first ==
"reconnect-wait-time") {
81 reconnect_wait_time = param.second->intValue();
82 values_copy[param.first] =
83 boost::lexical_cast<std::string>(reconnect_wait_time);
85 }
else if (param.first ==
"port") {
86 port = param.second->intValue();
87 values_copy[param.first] =
88 boost::lexical_cast<std::string>(port);
90 }
else if (param.first ==
"max-row-errors") {
91 max_row_errors = param.second->intValue();
92 values_copy[param.first] =
93 boost::lexical_cast<std::string>(max_row_errors);
107 values_copy[param.first] = param.second->stringValue();
112 "parameter '" << param.first <<
"' ("
113 << param.second->getPosition() <<
")");
120 auto type_ptr = values_copy.find(
"type");
121 if (type_ptr == values_copy.end()) {
123 "database access parameters must "
124 "include the keyword 'type' to determine type of database "
125 "to be accessed (" << database_config->getPosition() <<
")");
132 string dbtype = type_ptr->second;
133 if ((dbtype !=
"memfile") &&
134 (dbtype !=
"mysql") &&
135 (dbtype !=
"postgresql")) {
138 <<
" (" << value->getPosition() <<
")");
142 if ((lfc_interval < 0) ||
143 (lfc_interval > std::numeric_limits<uint32_t>::max())) {
146 <<
" is out of range, expected value: 0.."
147 << std::numeric_limits<uint32_t>::max()
148 <<
" (" << value->getPosition() <<
")");
153 (timeout > std::numeric_limits<uint32_t>::max())) {
156 <<
" is out of range, expected value: 0.."
157 << std::numeric_limits<uint32_t>::max()
158 <<
" (" << value->getPosition() <<
")");
163 (port > std::numeric_limits<uint16_t>::max())) {
166 <<
" is out of range, expected value: 0.."
167 << std::numeric_limits<uint16_t>::max()
168 <<
" (" << value->getPosition() <<
")");
172 if ((max_row_errors < 0) ||
173 (max_row_errors > std::numeric_limits<uint32_t>::max())) {
176 <<
" is out of range, expected value: 0.."
177 << std::numeric_limits<uint32_t>::max()
178 <<
" (" << value->getPosition() <<
")");
182 if (max_reconnect_tries < 0) {
185 "max-reconnect-tries cannot be less than zero: ("
186 << value->getPosition() <<
")");
190 if ((reconnect_wait_time < 0) ||
191 (reconnect_wait_time > std::numeric_limits<uint32_t>::max())) {
194 <<
" must be in range 0...MAX_UINT32 (4294967295) "
195 <<
"(" << value->getPosition() <<
")");
202 values_.swap(values_copy);
215 for (
auto keyval : values_) {
216 if (!keyval.second.empty()) {
219 if (!dbaccess.empty()) {
220 dbaccess += std::string(
" ");
224 auto val = keyval.second;
225 if (val.find_first_of(
"\t ") != string::npos){
226 val =
"'" + val +
"'";
228 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.