18#include <boost/algorithm/string.hpp>
33 ParameterMap::const_iterator param = parameters_.find(name);
34 if (param == parameters_.end()) {
37 return (param->second);
43 std::string dba = dbaccess;
47 vector<string> tokens;
51 std::string password_prefix =
"password='";
52 auto password_pos = dba.find(password_prefix);
53 if (password_pos != string::npos) {
55 auto password_end_pos = dba.find(
'\'', password_pos + password_prefix.length());
56 if (password_end_pos == string::npos) {
62 auto password = dba.substr(password_pos + password_prefix.length(),
63 password_end_pos - password_pos - password_prefix.length());
66 mapped_tokens.insert(make_pair(
"password", password));
71 dba.erase(password_pos, password_prefix.length() + password.length() + 2);
77 return (mapped_tokens);
85 boost::split(tokens, dba, boost::is_any_of(
string(
"\t ")));
86 for (
auto const& token : tokens) {
87 size_t pos = token.find(
"=");
88 if (pos != string::npos) {
89 string name = token.substr(0, pos);
90 string value = token.substr(pos + 1);
91 mapped_tokens.insert(make_pair(name, value));
94 <<
", expected format is name=value");
97 }
catch (
const std::exception& ex) {
104 return (mapped_tokens);
112 for (
auto const& i : parameters) {
115 if (!access.empty()) {
125 if (i.first == std::string(
"password")) {
137 std::string readonly_value =
"false";
140 boost::algorithm::to_lower(readonly_value);
146 if ((readonly_value !=
"false") && (readonly_value !=
"true")) {
148 <<
"' specified for boolean parameter 'readonly'");
151 return (readonly_value ==
"true");
156 string type =
"unknown";
157 unsigned int retries = 0;
158 unsigned int interval = 0;
167 std::string parm_str;
170 retries = boost::lexical_cast<unsigned int>(parm_str);
177 interval = boost::lexical_cast<unsigned int>(parm_str);
190 reconnect_ctl_ = boost::make_shared<ReconnectCtl>(type, timer_name, retries,
191 interval, action,
id);
225 for (
auto const& param : params) {
226 std::string keyword = param.first;
227 std::string value = param.second;
229 if ((keyword ==
"lfc-interval") ||
230 (keyword ==
"connect-timeout") ||
231 (keyword ==
"read-timeout") ||
232 (keyword ==
"write-timeout") ||
233 (keyword ==
"tcp-user-timeout") ||
234 (keyword ==
"reconnect-wait-time") ||
235 (keyword ==
"max-reconnect-tries") ||
236 (keyword ==
"port") ||
237 (keyword ==
"max-row-errors")) {
241 int_value = boost::lexical_cast<int64_t>(value);
245 .arg(keyword).arg(value);
247 }
else if ((keyword ==
"persist") ||
248 (keyword ==
"readonly") ||
249 (keyword ==
"retry-on-startup")) {
250 if (value ==
"true") {
252 }
else if (value ==
"false") {
256 .arg(keyword).arg(value);
258 }
else if ((keyword ==
"type") ||
259 (keyword ==
"user") ||
260 (keyword ==
"password") ||
261 (keyword ==
"host") ||
262 (keyword ==
"name") ||
263 (keyword ==
"on-fail") ||
264 (keyword ==
"trust-anchor") ||
265 (keyword ==
"cert-file") ||
266 (keyword ==
"key-file") ||
267 (keyword ==
"cipher-list")) {
271 .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.
virtual void makeReconnectCtl(const std::string &timer_name, unsigned int id)
Instantiates a ReconnectCtl based on the connection's reconnect parameters.
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.
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.
static void check(const std::string &value)
Check if the value is a default credential.
DB_LOG & arg(T first, Args... args)
Pass parameters to replace logger placeholders.