24 const Factory& factory,
26 DBVersion db_version) {
27 if (
map_.count(db_type)) {
31 static auto default_db_version = []() ->
string {
36 db_version = default_db_version;
39 map_.insert(pair<
string, pair<Factory, DBVersion>>(db_type, pair<Factory, DBVersion>(factory, db_version)));
55 auto index =
map_.find(db_type);
58 if (index !=
map_.end()) {
74 auto it = parameters.find(
"type");
75 if (it == parameters.end()) {
80 string db_type = it->second;
81 auto index =
map_.find(db_type);
84 if (index ==
map_.end()) {
85 if ((db_type ==
"mysql") || (db_type ==
"postgresql")) {
86 string with = (db_type ==
"postgresql" ?
"pgsql" : db_type);
88 "support for configuration database type: " << db_type
89 <<
". Did you forget to use --with-"
90 << with <<
" during compilation or to load libdhcp_"
91 << with <<
" hook library?");
94 db_type <<
"' is not supported");
98 auto backend = index->second.first(parameters);
101 " factory returned NULL");
105 pool_[id] = pair<DatabaseConnection::ParameterMap, LegalLogMgrPtr>(parameters,
LegalLogMgrPtr());
110 if (parameters.find(
"request-parser-format") != parameters.end()) {
111 backend->setRequestFormatExpression(parameters[
"request-parser-format"]);
113 if (parameters.find(
"response-parser-format") != parameters.end()) {
114 backend->setResponseFormatExpression(parameters[
"response-parser-format"]);
116 if (parameters.find(
"timestamp-format") != parameters.end()) {
117 backend->setTimestampFormat(parameters[
"timestamp-format"]);
121 pool_[id] = pair<DatabaseConnection::ParameterMap, LegalLogMgrPtr>(parameters, backend);
131 auto it =
pool_.begin();
133 while (it !=
pool_.end()) {
134 if (it->second.second && it->second.second->getType() == db_type) {
135 it =
pool_.erase(it);
144 auto it =
pool_.find(
id);
145 if (it !=
pool_.end()) {
146 return (it->second.second);
155 pool_[id] = pair<DatabaseConnection::ParameterMap, LegalLogMgrPtr>(parameters, backend);
156 return (
pool_[
id].second);
166 auto it =
pool_.find(
id);
167 if (it !=
pool_.end()) {
168 it->second.first = parameters;
175 auto it =
pool_.find(
id);
176 if (it !=
pool_.end()) {
177 return (it->second.first);
186 bool deleted =
false;
191 for (
auto it =
pool_.begin(); it !=
pool_.end(); ++it) {
192 if (!it->second.second || it->second.second->getType() != db_type || it->second.first != parameters) {
195 if (if_unusable && (!(it->second.second->isUnusable()))) {
208 bool deleted =
false;
213 auto it =
pool_.find(
id);
214 if (it !=
pool_.end()) {
215 if (if_unusable && it->second.second && !it->second.second->isUnusable()) {
226 auto index =
map_.find(db_type);
227 return (index !=
map_.end());
234 for (
auto const& x :
map_) {
235 if (!txt.str().empty()) {
248 for (
auto const& x :
map_) {
249 auto version = x.second.second();
260 for (
auto const& backend :
pool_) {
261 if (backend.second.second && backend.second.second->getType() == type) {
int version()
returns Kea hooks version.
A generic exception that is thrown if a parameter given to a method or function is considered invalid...
A generic exception that is thrown when an unexpected error condition occurs.
std::map< std::string, std::string > ParameterMap
Database configuration parameter map.
static std::map< std::string, std::pair< LegalLogMgrFactory::Factory, LegalLogMgrFactory::DBVersion > > map_
A map holding registered backend factory functions.
static bool unregisterBackendFactory(const std::string &db_type, bool no_log=false)
Unregisters the backend factory function for a given backend type.
static void addBackend(db::DatabaseConnection::ParameterMap ¶meters, ManagerID id=0)
Create an instance of a forensic log backend.
static void delAllBackends()
Removes all backends from the pool.
static bool registerBackendFactory(const std::string &db_type, const Factory &factory, bool no_log=false, DBVersion db_version=DBVersion())
Registers new backend factory function for a given backend type.
static LegalLogMgrPool pool_
Pointer to the forensic log backends pool.
static isc::db::DatabaseConnection::ParameterMap getParameters(ManagerID id=0)
Gets the forensic backend manager parameters.
static void logRegistered()
Logs out all registered backends.
static bool delBackend(const std::string &db_type, db::DatabaseConnection::ParameterMap ¶meters, bool if_unusable=false)
Delete a forensic backend manager.
static bool registeredFactory(const std::string &db_type)
Check if a backend store factory was registered.
static LegalLogMgrPtr & instance(ManagerID id=0)
Returns the forensic backend manager with specified ID.
static std::list< std::string > getDBVersions()
Return extended version info for registered backends.
static bool haveInstance(std::string type)
Returns true is respective backend store is present, false otherwise.
static void setParameters(isc::db::DatabaseConnection::ParameterMap parameters, ManagerID id=0)
Sets the forensic backend manager parameters.
static isc::asiolink::IOServicePtr io_service_
The hook I/O service.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
#define LOG_INFO(LOGGER, MESSAGE)
Macro to conveniently test info output and log it.
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
boost::shared_ptr< IOService > IOServicePtr
Defines a smart pointer to an IOService instance.
isc::log::Logger dhcpsrv_logger("dhcpsrv")
DHCP server library Logger.
const isc::log::MessageID DHCPSRV_FORENSIC_BACKEND_REGISTER
const isc::log::MessageID DHCPSRV_FORENSIC_BACKENDS_REGISTERED
boost::shared_ptr< LegalLogMgr > LegalLogMgrPtr
Defines a smart pointer to a LegalLogMgr.
const isc::log::MessageID DHCPSRV_FORENSIC_BACKEND_DEREGISTER
std::map< ManagerID, std::pair< isc::db::DatabaseConnection::ParameterMap, LegalLogMgrPtr > > LegalLogMgrPool
LegalLogMgr pool.
uint64_t ManagerID
Manger ID used by hook libraries to retrieve respective LegalLogMgr instance.
const int DHCPSRV_DBG_TRACE
DHCP server library logging levels.
Defines the logger used by the top-level component of kea-lfc.