summaryrefslogtreecommitdiffstats
path: root/src/lib/dhcpsrv
diff options
context:
space:
mode:
authorMarcin Siodelski <marcin@isc.org>2018-08-28 11:56:19 +0200
committerMarcin Siodelski <marcin@isc.org>2018-09-03 09:31:33 +0200
commit7b2555aa662c828ed2cc94e99d2957426fd24ad3 (patch)
treeb08b05ddf2d5246984fe0c59eeee52582c982faf /src/lib/dhcpsrv
parent[19-move-address-utilities] Moved address utilities (diff)
downloadkea-7b2555aa662c828ed2cc94e99d2957426fd24ad3.tar.xz
kea-7b2555aa662c828ed2cc94e99d2957426fd24ad3.zip
[#92,!13] New libkea-database library created.
Diffstat (limited to 'src/lib/dhcpsrv')
-rw-r--r--src/lib/dhcpsrv/Makefile.am4
-rw-r--r--src/lib/dhcpsrv/db_exceptions.h80
-rw-r--r--src/lib/dhcpsrv/db_log.cc36
-rw-r--r--src/lib/dhcpsrv/db_log.h152
-rw-r--r--src/lib/dhcpsrv/dhcpsrv_db_log.cc4
-rw-r--r--src/lib/dhcpsrv/dhcpsrv_db_log.h6
-rw-r--r--src/lib/dhcpsrv/lease_mgr.h2
-rw-r--r--src/lib/dhcpsrv/mysql_connection.cc2
-rw-r--r--src/lib/dhcpsrv/mysql_connection.h8
-rw-r--r--src/lib/dhcpsrv/mysql_host_data_source.h2
-rw-r--r--src/lib/dhcpsrv/pgsql_connection.h2
11 files changed, 15 insertions, 283 deletions
diff --git a/src/lib/dhcpsrv/Makefile.am b/src/lib/dhcpsrv/Makefile.am
index 8432c7265a..77817aef12 100644
--- a/src/lib/dhcpsrv/Makefile.am
+++ b/src/lib/dhcpsrv/Makefile.am
@@ -115,9 +115,6 @@ libkea_dhcpsrv_la_SOURCES += csv_lease_file6.cc csv_lease_file6.h
libkea_dhcpsrv_la_SOURCES += d2_client_cfg.cc d2_client_cfg.h
libkea_dhcpsrv_la_SOURCES += d2_client_mgr.cc d2_client_mgr.h
libkea_dhcpsrv_la_SOURCES += daemon.cc daemon.h
-libkea_dhcpsrv_la_SOURCES += database_connection.cc database_connection.h
-libkea_dhcpsrv_la_SOURCES += db_exceptions.h
-libkea_dhcpsrv_la_SOURCES += db_log.cc db_log.h
libkea_dhcpsrv_la_SOURCES += db_type.h
libkea_dhcpsrv_la_SOURCES += dhcp4o6_ipc.cc dhcp4o6_ipc.h
libkea_dhcpsrv_la_SOURCES += dhcpsrv_log.cc dhcpsrv_log.h
@@ -220,6 +217,7 @@ libkea_dhcpsrv_la_LIBADD += $(top_builddir)/src/lib/cc/libkea-cc.la
libkea_dhcpsrv_la_LIBADD += $(top_builddir)/src/lib/dns/libkea-dns++.la
libkea_dhcpsrv_la_LIBADD += $(top_builddir)/src/lib/cryptolink/libkea-cryptolink.la
libkea_dhcpsrv_la_LIBADD += $(top_builddir)/src/lib/hooks/libkea-hooks.la
+libkea_dhcpsrv_la_LIBADD += $(top_builddir)/src/lib/database/libkea-database.la
libkea_dhcpsrv_la_LIBADD += $(top_builddir)/src/lib/log/libkea-log.la
libkea_dhcpsrv_la_LIBADD += $(top_builddir)/src/lib/util/threads/libkea-threads.la
libkea_dhcpsrv_la_LIBADD += $(top_builddir)/src/lib/util/libkea-util.la
diff --git a/src/lib/dhcpsrv/db_exceptions.h b/src/lib/dhcpsrv/db_exceptions.h
deleted file mode 100644
index 1bf92a38bf..0000000000
--- a/src/lib/dhcpsrv/db_exceptions.h
+++ /dev/null
@@ -1,80 +0,0 @@
-// Copyright (C) 2015-2018 Internet Systems Consortium, Inc. ("ISC")
-//
-// This Source Code Form is subject to the terms of the Mozilla Public
-// License, v. 2.0. If a copy of the MPL was not distributed with this
-// file, You can obtain one at http://mozilla.org/MPL/2.0/.
-
-#ifndef DB_EXCEPTIONS_H
-#define DB_EXCEPTIONS_H
-
-#include <exceptions/exceptions.h>
-
-namespace isc {
-namespace dhcp {
-
-/// @brief Database statement not applied
-///
-/// Cassandra have a concept of mutation (any statement that does change the
-/// data, like INSERT, UPDATE or DELETE). Under certain conditions it may be
-/// possible that those statesments may fail to apply.
-class StatementNotApplied : public Exception {
-public:
- StatementNotApplied(const char* file, size_t line, const char* what)
- : isc::Exception(file, line, what) {
- }
-};
-
-/// @brief Multiple lease records found where one expected
-class MultipleRecords : public Exception {
-public:
- MultipleRecords(const char* file, size_t line, const char* what) :
- isc::Exception(file, line, what) {}
-};
-
-/// @brief Attempt to update lease that was not there
-class NoSuchLease : public Exception {
-public:
- NoSuchLease(const char* file, size_t line, const char* what) :
- isc::Exception(file, line, what) {}
-};
-
-/// @brief Data is truncated
-class DataTruncated : public Exception {
-public:
- DataTruncated(const char* file, size_t line, const char* what) :
- isc::Exception(file, line, what) {}
-};
-
-/// @brief Database duplicate entry error
-class DuplicateEntry : public Exception {
-public:
- DuplicateEntry(const char* file, size_t line, const char* what) :
- isc::Exception(file, line, what) {}
-};
-
-/// @brief Attempt to modify data in read-only database.
-class ReadOnlyDb : public Exception {
-public:
- ReadOnlyDb(const char* file, size_t line, const char* what) :
- isc::Exception(file, line, what) {}
-};
-
-/// @brief Upper bound address is lower than lower bound address while
-/// retrieving a range of leases.
-class InvalidRange : public Exception {
-public:
- InvalidRange(const char* file, size_t line, const char* what) :
- isc::Exception(file, line, what) {}
-};
-
-/// @brief Invalid address family used as input to Lease Manager.
-class InvalidAddressFamily : public Exception {
-public:
- InvalidAddressFamily(const char* file, size_t line, const char* what) :
- isc::Exception(file, line, what) {}
-};
-
-} // namespace isc
-} // namespace dhcp
-
-#endif
diff --git a/src/lib/dhcpsrv/db_log.cc b/src/lib/dhcpsrv/db_log.cc
deleted file mode 100644
index f2e3cd0a42..0000000000
--- a/src/lib/dhcpsrv/db_log.cc
+++ /dev/null
@@ -1,36 +0,0 @@
-// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC")
-//
-// This Source Code Form is subject to the terms of the Mozilla Public
-// License, v. 2.0. If a copy of the MPL was not distributed with this
-// file, You can obtain one at http://mozilla.org/MPL/2.0/.
-
-/// Defines the logger used by the NSAS
-
-#include <config.h>
-
-#include <exceptions/exceptions.h>
-#include <dhcpsrv/db_log.h>
-#include <dhcpsrv/dhcpsrv_db_log.h>
-
-using namespace isc::log;
-
-namespace isc {
-namespace dhcp {
-
-const MessageID&
-DbLogger::translateMessage(const DbMessageID& id) const {
- try {
- return (map_.at(id));
- } catch (const std::out_of_range&) {
- isc_throw(isc::Unexpected, "can't map message: " << id);
- }
-}
-
-void checkDbLoggerStack() {
- if (db_logger_stack.empty()) {
- isc_throw(isc::Unexpected, "database logger stack is empty");
- }
-}
-
-} // namespace dhcp
-} // namespace isc
diff --git a/src/lib/dhcpsrv/db_log.h b/src/lib/dhcpsrv/db_log.h
deleted file mode 100644
index 4eb76d6a0a..0000000000
--- a/src/lib/dhcpsrv/db_log.h
+++ /dev/null
@@ -1,152 +0,0 @@
-// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC")
-//
-// This Source Code Form is subject to the terms of the Mozilla Public
-// License, v. 2.0. If a copy of the MPL was not distributed with this
-// file, You can obtain one at http://mozilla.org/MPL/2.0/.
-
-#ifndef DB_LOG_H
-#define DB_LOG_H
-
-#include <log/macros.h>
-
-#include <map>
-#include <list>
-
-/// @file db_log.h
-///
-/// We want to reuse the database backend connection and exchange code
-/// for other uses, in particular for hook libraries. But this code
-/// includes some calls to the system logger for debug and uncommon
-/// cases and of course we do not want to get log messages from
-/// a hook library to seem to come from DHCP server core.
-///
-/// The solution is to use a database logger which calls the right
-/// logger with mapped messages.
-
-namespace isc {
-namespace dhcp {
-
-///@{
-/// @brief Database logging levels
-///
-/// Defines the levels used to output debug messages in the database
-/// support. Note that higher numbers equate to more verbose (and detailed)
-/// output.
-
-/// @brief Additional information
-///
-/// Record detailed tracing. This is generally reserved for tracing access to
-/// the lease database.
-const int DB_DBG_TRACE_DETAIL = isc::log::DBGLVL_TRACE_DETAIL;
-
-///@}
-
-///@{
-/// @brief Database messages
-///
-enum DbMessageID {
- DB_INVALID_ACCESS,
-
- PGSQL_DEALLOC_ERROR,
- PGSQL_FATAL_ERROR,
- PGSQL_START_TRANSACTION,
- PGSQL_COMMIT,
- PGSQL_ROLLBACK,
-
- MYSQL_FATAL_ERROR,
- MYSQL_START_TRANSACTION,
- MYSQL_COMMIT,
- MYSQL_ROLLBACK,
-
- CQL_DEALLOC_ERROR,
- CQL_CONNECTION_BEGIN_TRANSACTION,
- CQL_CONNECTION_COMMIT,
- CQL_CONNECTION_ROLLBACK
-};
-///@}
-
-/// @brief Database logger class
-///
-class DbLogger {
-public:
- /// @brief Translation map type
- typedef std::map<DbMessageID, isc::log::MessageID> MessageMap;
-
- /// @brief Constructor
- ///
- /// @param logger logger which will be called
- /// @param map message id translation map
- DbLogger(isc::log::Logger& logger, const MessageMap& map)
- : logger_(logger), map_(map) {
- }
-
- /// @brief Translate message
- ///
- /// @param id database message id
- /// @return logger message
- /// @throw Unexpected if the id is not in the message map
- const isc::log::MessageID& translateMessage(const DbMessageID& id) const;
-
- /// @brief The logger
- isc::log::Logger& logger_;
-
- /// @brief The translation map
- const MessageMap& map_;
-};
-
-/// @brief Database logger stack
-typedef std::list<DbLogger> DbLoggerStack;
-
-/// @brief Global database logger stack (initialized to dhcpsrv logger)
-extern DbLoggerStack db_logger_stack;
-
-/// @brief Check database logger stack
-///
-/// @throw Unexpected if the stack is empty
-void checkDbLoggerStack();
-
-///@{
-/// @brief Macros
-
-#define DB_LOG_DEBUG(LEVEL, MESSAGE) \
- checkDbLoggerStack(); \
- if (!db_logger_stack.back().logger_.isDebugEnabled((LEVEL))) { \
- } else \
- db_logger_stack.back().logger_.debug((LEVEL), \
- db_logger_stack.back().translateMessage((MESSAGE)))
-
-
-#define DB_LOG_INFO(MESSAGE) \
- checkDbLoggerStack(); \
- if (!db_logger_stack.back().logger_.isInfoEnabled()) { \
- } else \
- db_logger_stack.back().logger_.info( \
- db_logger_stack.back().translateMessage((MESSAGE)))
-
-#define DB_LOG_WARN(MESSAGE) \
- checkDbLoggerStack(); \
- if (!db_logger_stack.back().logger_.isWarnEnabled()) { \
- } else \
- db_logger_stack.back().logger_.warn( \
- db_logger_stack.back().translateMessage((MESSAGE)))
-
-#define DB_LOG_ERROR(MESSAGE) \
- checkDbLoggerStack(); \
- if (!db_logger_stack.back().logger_.isErrorEnabled()) { \
- } else \
- db_logger_stack.back().logger_.error( \
- db_logger_stack.back().translateMessage((MESSAGE)))
-
-#define DB_LOG_FATAL(MESSAGE) \
- checkDbLoggerStack(); \
- if (!db_logger_stack.back().logger_.isFatalEnabled()) { \
- } else \
- db_logger_stack.back().logger_.fatal( \
- db_logger_stack.back().translateMessage((MESSAGE)))
-
-///@}
-
-} // namespace dhcp
-} // namespace isc
-
-#endif // DB_LOG_H
diff --git a/src/lib/dhcpsrv/dhcpsrv_db_log.cc b/src/lib/dhcpsrv/dhcpsrv_db_log.cc
index 013d8c469d..4afff06545 100644
--- a/src/lib/dhcpsrv/dhcpsrv_db_log.cc
+++ b/src/lib/dhcpsrv/dhcpsrv_db_log.cc
@@ -11,6 +11,8 @@
#include <dhcpsrv/dhcpsrv_db_log.h>
#include <dhcpsrv/dhcpsrv_log.h>
+using namespace isc::db;
+
namespace isc {
namespace dhcp {
@@ -38,7 +40,7 @@ const DbLogger::MessageMap dhcpsrv_db_message_map = {
DbLogger dhcpsrv_db_logger(dhcpsrv_logger, dhcpsrv_db_message_map);
// Do this initialization here!
-DbLoggerStack db_logger_stack = { dhcpsrv_db_logger };
+//DbLoggerStack db_logger_stack = { dhcpsrv_db_logger };
} // namespace dhcp
diff --git a/src/lib/dhcpsrv/dhcpsrv_db_log.h b/src/lib/dhcpsrv/dhcpsrv_db_log.h
index 5965350cfe..d5056243fd 100644
--- a/src/lib/dhcpsrv/dhcpsrv_db_log.h
+++ b/src/lib/dhcpsrv/dhcpsrv_db_log.h
@@ -7,18 +7,18 @@
#ifndef DHCPSRV_DB_LOG_H
#define DHCPSRV_DB_LOG_H
-#include <dhcpsrv/db_log.h>
+#include <database/db_log.h>
namespace isc {
namespace dhcp {
/// @brief DHCP server database message map
-extern const DbLogger::MessageMap dhcpsrv_db_message_map;
+extern const db::DbLogger::MessageMap dhcpsrv_db_message_map;
/// @brief DHCP server database Logger
///
/// It is the default database logger.
-extern DbLogger dhcpsrv_db_logger;
+extern db::DbLogger dhcpsrv_db_logger;
} // namespace dhcp
} // namespace isc
diff --git a/src/lib/dhcpsrv/lease_mgr.h b/src/lib/dhcpsrv/lease_mgr.h
index e5759973fd..167645ee32 100644
--- a/src/lib/dhcpsrv/lease_mgr.h
+++ b/src/lib/dhcpsrv/lease_mgr.h
@@ -9,12 +9,12 @@
#include <asiolink/io_address.h>
#include <asiolink/io_service.h>
+#include <database/db_exceptions.h>
#include <dhcp/duid.h>
#include <dhcp/option.h>
#include <dhcp/hwaddr.h>
#include <dhcpsrv/lease.h>
#include <dhcpsrv/subnet.h>
-#include <dhcpsrv/db_exceptions.h>
#include <dhcpsrv/sql_common.h>
#include <boost/noncopyable.hpp>
diff --git a/src/lib/dhcpsrv/mysql_connection.cc b/src/lib/dhcpsrv/mysql_connection.cc
index a4de082a5f..7929aa3924 100644
--- a/src/lib/dhcpsrv/mysql_connection.cc
+++ b/src/lib/dhcpsrv/mysql_connection.cc
@@ -7,7 +7,7 @@
#include <config.h>
-#include <dhcpsrv/db_log.h>
+#include <database/db_log.h>
#include <dhcpsrv/mysql_connection.h>
#include <exceptions/exceptions.h>
diff --git a/src/lib/dhcpsrv/mysql_connection.h b/src/lib/dhcpsrv/mysql_connection.h
index 88716d26cd..5ad549d61d 100644
--- a/src/lib/dhcpsrv/mysql_connection.h
+++ b/src/lib/dhcpsrv/mysql_connection.h
@@ -7,8 +7,8 @@
#ifndef MYSQL_CONNECTION_H
#define MYSQL_CONNECTION_H
-#include <dhcpsrv/database_connection.h>
-#include <dhcpsrv/db_log.h>
+#include <database/database_connection.h>
+#include <database/db_log.h>
#include <exceptions/exceptions.h>
#include <boost/scoped_ptr.hpp>
#include <mysql.h>
@@ -117,7 +117,7 @@ public:
/// @throw DbOpenError Unable to initialize MySql handle.
MySqlHolder() : mysql_(mysql_init(NULL)) {
if (mysql_ == NULL) {
- isc_throw(DbOpenError, "unable to initialize MySQL");
+ isc_throw(db::DbOpenError, "unable to initialize MySQL");
}
}
@@ -208,7 +208,7 @@ private:
/// to the database and preparing compiled statements. Its fields are
/// public, because they are used (both set and retrieved) in classes
/// that use instances of MySqlConnection.
-class MySqlConnection : public DatabaseConnection {
+class MySqlConnection : public db::DatabaseConnection {
public:
/// @brief Constructor
diff --git a/src/lib/dhcpsrv/mysql_host_data_source.h b/src/lib/dhcpsrv/mysql_host_data_source.h
index fb6e8274a4..5e47c1dc12 100644
--- a/src/lib/dhcpsrv/mysql_host_data_source.h
+++ b/src/lib/dhcpsrv/mysql_host_data_source.h
@@ -7,8 +7,8 @@
#ifndef MYSQL_HOST_DATA_SOURCE_H
#define MYSQL_HOST_DATA_SOURCE_H
+#include <database/db_exceptions.h>
#include <dhcpsrv/base_host_data_source.h>
-#include <dhcpsrv/db_exceptions.h>
#include <dhcpsrv/mysql_connection.h>
#include <stdint.h>
diff --git a/src/lib/dhcpsrv/pgsql_connection.h b/src/lib/dhcpsrv/pgsql_connection.h
index 49fda1444e..081aeedd49 100644
--- a/src/lib/dhcpsrv/pgsql_connection.h
+++ b/src/lib/dhcpsrv/pgsql_connection.h
@@ -6,7 +6,7 @@
#ifndef PGSQL_CONNECTION_H
#define PGSQL_CONNECTION_H
-#include <dhcpsrv/database_connection.h>
+#include <database/database_connection.h>
#include <libpq-fe.h>
#include <boost/scoped_ptr.hpp>