diff options
Diffstat (limited to '')
-rw-r--r-- | lib/mysql_shim/CMakeLists.txt | 31 | ||||
-rw-r--r-- | lib/mysql_shim/mysql_shim.def | 3 | ||||
-rw-r--r-- | lib/mysql_shim/mysqlinterface.cpp | 119 | ||||
-rw-r--r-- | lib/mysql_shim/mysqlinterface.hpp | 65 |
4 files changed, 218 insertions, 0 deletions
diff --git a/lib/mysql_shim/CMakeLists.txt b/lib/mysql_shim/CMakeLists.txt new file mode 100644 index 0000000..fc7dbee --- /dev/null +++ b/lib/mysql_shim/CMakeLists.txt @@ -0,0 +1,31 @@ +# Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ + +include_directories(${MYSQL_INCLUDE_DIR}) + +set(mysql_shim_SOURCES + mysql_shim.def + mysqlinterface.cpp mysqlinterface.hpp +) + +if(ICINGA2_UNITY_BUILD) + mkunity_target(mysql_shim mysql_shim mysql_shim_SOURCES) +endif() + +add_library(mysql_shim SHARED ${mysql_shim_SOURCES}) + +include(GenerateExportHeader) +generate_export_header(mysql_shim) + +target_link_libraries(mysql_shim ${MYSQL_LIB}) + +set_target_properties ( + mysql_shim PROPERTIES + FOLDER Lib + VERSION ${SPEC_VERSION} +) + +install( + TARGETS mysql_shim + RUNTIME DESTINATION ${CMAKE_INSTALL_SBINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}/icinga2 +) diff --git a/lib/mysql_shim/mysql_shim.def b/lib/mysql_shim/mysql_shim.def new file mode 100644 index 0000000..ae36765 --- /dev/null +++ b/lib/mysql_shim/mysql_shim.def @@ -0,0 +1,3 @@ +LIBRARY mysql_shim +EXPORTS + create_mysql_shim diff --git a/lib/mysql_shim/mysqlinterface.cpp b/lib/mysql_shim/mysqlinterface.cpp new file mode 100644 index 0000000..43e50e8 --- /dev/null +++ b/lib/mysql_shim/mysqlinterface.cpp @@ -0,0 +1,119 @@ +/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */ + +#include "mysql_shim/mysqlinterface.hpp" + +using namespace icinga; + +struct MysqlInterfaceImpl final : public MysqlInterface +{ + void Destroy() override + { + delete this; + } + + my_ulonglong affected_rows(MYSQL *mysql) const override + { + return mysql_affected_rows(mysql); + } + + void close(MYSQL *sock) const override + { + return mysql_close(sock); + } + + const char *error(MYSQL *mysql) const override + { + return mysql_error(mysql); + } + + MYSQL_FIELD *fetch_field(MYSQL_RES *result) const override + { + return mysql_fetch_field(result); + } + + unsigned long *fetch_lengths(MYSQL_RES *result) const override + { + return mysql_fetch_lengths(result); + } + + MYSQL_ROW fetch_row(MYSQL_RES *result) const override + { + return mysql_fetch_row(result); + } + + unsigned int field_count(MYSQL *mysql) const override + { + return mysql_field_count(mysql); + } + + MYSQL_FIELD_OFFSET field_seek(MYSQL_RES *result, MYSQL_FIELD_OFFSET offset) const override + { + return mysql_field_seek(result, offset); + } + + void free_result(MYSQL_RES *result) const override + { + mysql_free_result(result); + } + + MYSQL *init(MYSQL *mysql) const override + { + return mysql_init(mysql); + } + + my_ulonglong insert_id(MYSQL *mysql) const override + { + return mysql_insert_id(mysql); + } + + int next_result(MYSQL *mysql) const override + { + return mysql_next_result(mysql); + } + + int ping(MYSQL *mysql) const override + { + return mysql_ping(mysql); + } + + int query(MYSQL *mysql, const char *q) const override + { + return mysql_query(mysql, q); + } + + MYSQL *real_connect(MYSQL *mysql, const char *host, const char *user, const char *passwd, + const char *db, unsigned int port, const char *unix_socket, unsigned long clientflag) const override + { + return mysql_real_connect(mysql, host, user, passwd, db, port, unix_socket, clientflag); + } + + unsigned long real_escape_string(MYSQL *mysql, char *to, const char *from, unsigned long length) const override + { + return mysql_real_escape_string(mysql, to, from, length); + } + + int options(MYSQL *mysql, mysql_option option, const void *arg) const override + { + return mysql_options(mysql, option, arg); + } + + bool ssl_set(MYSQL *mysql, const char *key, const char *cert, const char *ca, const char *capath, const char *cipher) const override + { + return mysql_ssl_set(mysql, key, cert, ca, capath, cipher); + } + + MYSQL_RES *store_result(MYSQL *mysql) const override + { + return mysql_store_result(mysql); + } + + unsigned int thread_safe() const override + { + return mysql_thread_safe(); + } +}; + +MysqlInterface *create_mysql_shim() +{ + return new MysqlInterfaceImpl(); +} diff --git a/lib/mysql_shim/mysqlinterface.hpp b/lib/mysql_shim/mysqlinterface.hpp new file mode 100644 index 0000000..04dfc30 --- /dev/null +++ b/lib/mysql_shim/mysqlinterface.hpp @@ -0,0 +1,65 @@ +/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */ + +#ifndef MYSQLINTERFACE_H +#define MYSQLINTERFACE_H + +#include "mysql_shim/mysql_shim_export.h" +#include <memory> +#include <mysql.h> + +namespace icinga +{ + +struct MysqlInterface +{ + MysqlInterface(const MysqlInterface&) = delete; + MysqlInterface& operator=(MysqlInterface&) = delete; + + virtual void Destroy() = 0; + + virtual my_ulonglong affected_rows(MYSQL *mysql) const = 0; + virtual void close(MYSQL *sock) const = 0; + virtual const char *error(MYSQL *mysql) const = 0; + virtual MYSQL_FIELD *fetch_field(MYSQL_RES *result) const = 0; + virtual unsigned long *fetch_lengths(MYSQL_RES *result) const = 0; + virtual MYSQL_ROW fetch_row(MYSQL_RES *result) const = 0; + virtual unsigned int field_count(MYSQL *mysql) const = 0; + virtual MYSQL_FIELD_OFFSET field_seek(MYSQL_RES *result, + MYSQL_FIELD_OFFSET offset) const = 0; + virtual void free_result(MYSQL_RES *result) const = 0; + virtual MYSQL *init(MYSQL *mysql) const = 0; + virtual my_ulonglong insert_id(MYSQL *mysql) const = 0; + virtual int next_result(MYSQL *mysql) const = 0; + virtual int ping(MYSQL *mysql) const = 0; + virtual int query(MYSQL *mysql, const char *q) const = 0; + virtual MYSQL *real_connect(MYSQL *mysql, const char *host, const char *user, const char *passwd, + const char *db, unsigned int port, const char *unix_socket, unsigned long clientflag) const = 0; + virtual unsigned long real_escape_string(MYSQL *mysql, char *to, const char *from, unsigned long length) const = 0; + virtual int options(MYSQL *mysql, mysql_option option, const void *arg) const = 0; + virtual bool ssl_set(MYSQL *mysql, const char *key, const char *cert, const char *ca, const char *capath, const char *cipher) const = 0; + virtual MYSQL_RES *store_result(MYSQL *mysql) const = 0; + virtual unsigned int thread_safe() const = 0; + +protected: + MysqlInterface() = default; + ~MysqlInterface() = default; +}; + +struct MysqlInterfaceDeleter +{ + void operator()(MysqlInterface *ifc) const + { + ifc->Destroy(); + } +}; + +} + +extern "C" +{ + MYSQL_SHIM_EXPORT icinga::MysqlInterface *create_mysql_shim(); +} + +typedef icinga::MysqlInterface *(*create_mysql_shim_ptr)(); + +#endif /* MYSQLINTERFACE_H */ |