17#include <boost/algorithm/string.hpp>
31 ParameterMap::const_iterator param = parameters_.find(name);
32 if (param == parameters_.end()) {
35 return (param->second);
41 std::string dba = dbaccess;
45 vector<string> tokens;
49 std::string password_prefix =
"password='";
50 auto password_pos = dba.find(password_prefix);
51 if (password_pos != string::npos) {
53 auto password_end_pos = dba.find(
'\'', password_pos + password_prefix.length());
54 if (password_end_pos == string::npos) {
60 auto password = dba.substr(password_pos + password_prefix.length(),
61 password_end_pos - password_pos - password_prefix.length());
62 mapped_tokens.insert(make_pair(
"password", password));
67 dba.erase(password_pos, password_prefix.length() + password.length() + 2);
73 return (mapped_tokens);
81 boost::split(tokens, dba, boost::is_any_of(
string(
"\t ")));
82 for (
auto const& token : tokens) {
83 size_t pos = token.find(
"=");
84 if (pos != string::npos) {
85 string name = token.substr(0, pos);
86 string value = token.substr(pos + 1);
87 mapped_tokens.insert(make_pair(name, value));
90 <<
", expected format is name=value");
93 }
catch (
const std::exception& ex) {
100 return (mapped_tokens);
108 for (
auto const& i : parameters) {
111 if (!access.empty()) {
121 if (i.first == std::string(
"password")) {
133 std::string readonly_value =
"false";
136 boost::algorithm::to_lower(readonly_value);
142 if ((readonly_value !=
"false") && (readonly_value !=
"true")) {
144 <<
"' specified for boolean parameter 'readonly'");
147 return (readonly_value ==
"true");
152 string type =
"unknown";
153 unsigned int retries = 0;
154 unsigned int interval = 0;
163 std::string parm_str;
166 retries = boost::lexical_cast<unsigned int>(parm_str);
173 interval = boost::lexical_cast<unsigned int>(parm_str);
186 reconnect_ctl_ = boost::make_shared<ReconnectCtl>(type, timer_name, retries,
221 for (
auto const& param : params) {
222 std::string keyword = param.first;
223 std::string value = param.second;
225 if ((keyword ==
"lfc-interval") ||
226 (keyword ==
"connect-timeout") ||
227 (keyword ==
"read-timeout") ||
228 (keyword ==
"write-timeout") ||
229 (keyword ==
"tcp-user-timeout") ||
230 (keyword ==
"reconnect-wait-time") ||
231 (keyword ==
"max-reconnect-tries") ||
232 (keyword ==
"port") ||
233 (keyword ==
"max-row-errors")) {
237 int_value = boost::lexical_cast<int64_t>(value);
241 .arg(keyword).arg(value);
243 }
else if ((keyword ==
"persist") ||
244 (keyword ==
"readonly") ||
245 (keyword ==
"retry-on-startup")) {
246 if (value ==
"true") {
248 }
else if (value ==
"false") {
252 .arg(keyword).arg(value);
254 }
else if ((keyword ==
"type") ||
255 (keyword ==
"user") ||
256 (keyword ==
"password") ||
257 (keyword ==
"host") ||
258 (keyword ==
"name") ||
259 (keyword ==
"on-fail") ||
260 (keyword ==
"trust-anchor") ||
261 (keyword ==
"cert-file") ||
262 (keyword ==
"key-file") ||
263 (keyword ==
"cipher-list")) {
267 .arg(keyword).arg(value);
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
A generic exception that is thrown if a parameter given to a method or function is considered invalid...
static ElementPtr create(const Position &pos=ZERO_POSITION())
static ElementPtr createMap(const Position &pos=ZERO_POSITION())
Creates an empty MapElement type ElementPtr.
bool configuredReadOnly() const
Convenience method checking if database should be opened with read only access.
std::string getParameter(const std::string &name) const
Returns value of a connection parameter.
static bool invokeDbLostCallback(const util::ReconnectCtlPtr &db_reconnect_ctl)
Invokes the connection's lost connectivity callback.
static std::string redactedAccessString(const ParameterMap ¶meters)
Redact database access string.
static bool invokeDbFailedCallback(const util::ReconnectCtlPtr &db_reconnect_ctl)
Invokes the connection's restore failed connectivity callback.
std::map< std::string, std::string > ParameterMap
Database configuration parameter map.
static isc::data::ElementPtr toElement(const ParameterMap ¶ms)
Unparse a parameter map.
static isc::data::ElementPtr toElementDbAccessString(const std::string &dbaccess)
Unparse an access string.
static DbCallback db_recovered_callback_
Optional callback function to invoke if an opened connection recovery succeeded.
virtual void makeReconnectCtl(const std::string &timer_name)
Instantiates a ReconnectCtl based on the connection's reconnect parameters.
static ParameterMap parse(const std::string &dbaccess)
Parse database access string.
static bool test_mode_
Test mode flag (default false).
static bool retry_
Flag which indicates if the database connection should be retried on fail.
static bool invokeDbRecoveredCallback(const util::ReconnectCtlPtr &db_reconnect_ctl)
Invokes the connection's restored connectivity callback.
static DbCallback db_failed_callback_
Optional callback function to invoke if an opened connection recovery failed.
static DbCallback db_lost_callback_
Optional callback function to invoke if an opened connection is lost.
static const time_t MAX_DB_TIME
Defines maximum value for time that can be reliably stored.
Invalid 'readonly' value specification.
static OnFailAction onFailActionFromText(const std::string &text)
Convert string to action.
We want to reuse the database backend connection and exchange code for other uses,...
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
#define LOG_ERROR(LOGGER, MESSAGE)
Macro to conveniently test error output and log it.
boost::shared_ptr< IOService > IOServicePtr
Defines a smart pointer to an IOService instance.
boost::shared_ptr< Element > ElementPtr
isc::log::Logger database_logger("database")
Common database library logger.
const isc::log::MessageID DATABASE_TO_JSON_UNKNOWN_TYPE_ERROR
const isc::log::MessageID DATABASE_TO_JSON_INTEGER_ERROR
std::function< bool(util::ReconnectCtlPtr db_reconnect_ctl)> DbCallback
Defines a callback prototype for propagating events upward.
const isc::log::MessageID DATABASE_TO_JSON_BOOLEAN_ERROR
string trim(const string &input)
Trim leading and trailing spaces.
OnFailAction
Type of action to take on connection loss.
boost::shared_ptr< ReconnectCtl > ReconnectCtlPtr
Pointer to an instance of ReconnectCtl.
Defines the logger used by the top-level component of kea-lfc.
DB_LOG & arg(T first, Args... args)
Pass parameters to replace logger placeholders.