[Commits] 81768c1: MDEV-5313 Improving audit plugin API.
revision-id: 81768c1a878ee11e39d2b4d1ed0d52a35a00c6dc (mariadb-10.4.1-102-g81768c1) parent(s): 4edb29380c98058a28e49c826bacee9c83473579 committer: Alexey Botchkov timestamp: 2019-01-20 02:45:58 +0400 message: MDEV-5313 Improving audit plugin API. service_sql added. --- include/mysql/service_sql.h | 101 ++++++++++++++++++++++++++++++++++++++++++++ include/mysql/services.h | 1 + include/service_versions.h | 1 + libservices/CMakeLists.txt | 1 + libservices/sql_service.c | 19 +++++++++ sql/sql_plugin_services.ic | 22 +++++++++- 6 files changed, 143 insertions(+), 2 deletions(-) diff --git a/include/mysql/service_sql.h b/include/mysql/service_sql.h new file mode 100644 index 0000000..2af5177 --- /dev/null +++ b/include/mysql/service_sql.h @@ -0,0 +1,101 @@ +/* Copyright (C) 2019 MariaDB Corporation + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA */ + +#ifndef MYSQL_SERVICE_SQL +#define MYSQL_SERVICE_SQL + +/** + @file + sql service + + Provides interface for plugins to execute SQL queries. + +*/ + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct st_mysql MYSQL; +typedef struct st_mysql_res MYSQL_RES; +typedef char **MYSQL_ROW; + + +extern struct sql_service_st { + MYSQL *(*sqls_init)(MYSQL *mysql); + void (*sqls_close)(MYSQL *mysql); + int (*sqls_real_query)(MYSQL *mysql, const char *q, + unsigned long length); + unsigned long (*sqls_affected_rows)(MYSQL *mysql); + uint (*sqls_errno)(MYSQL *mysql); + const char *(*sqls_error)(MYSQL *mysql); + MYSQL_RES *(*sqls_store_result)(MYSQL *mysql); + void (*sqls_free_result)(MYSQL_RES *result); + unsigned long (*sqls_num_rows)(MYSQL_RES *res); + unsigned int (*sqls_num_fields)(MYSQL_RES *res); + MYSQL_ROW (*sqls_fetch_row)(MYSQL_RES *result); + unsigned long * (*sqls_fetch_lengths)(MYSQL_RES *result); +} *sql_service; + +#ifdef MYSQL_DYNAMIC_PLUGIN + +#define sqls_init sql_service->sqls_init +#define sqls_close sql_service->sqls_close +#define sqls_real_query sql_service->sqls_real_query +#define sqls_affected_rows sql_service->sqls_affected_rows +#define sqls_warning_count sql_service->sqls_warning_count +#define sqls_errno sql_service->sqls_errno +#define sqls_sqlstate sql_service->sqls_sqlstate +#define sqls_error sql_service->sqls_error +#define sqls_store_result sql_service->sqls_store_result +#define sqls_free_result sql_service->sqls_free_result +#define sqls_num_rows sql_service->sqls_num_rows +#define sqls_num_fields sql_service->sqls_num_fields +#define sqls_fetch_field sql_service->sqls_fetch_field +#define sqls_field_seek sql_service->sqls_field_seek +#define sqls_fetch_row sql_service->sqls_fetch_row +#define sqls_fetch_lengths sql_service->sqls_fetch_lengths + +#else + +MYSQL *sqls_init(MYSQL *mysql); +void sqls_close(MYSQL *mysql); +int sqls_real_query(MYSQL *mysql, const char *q, + unsigned long length); + +unsigned long sqls_affected_rows(MYSQL *mysql); +#define sqls_errno mysql_errno +#define sqls_error mysql_error +#define sqls_store_result mysql_store_result +#define sqls_free_result mysql_free_result +unsigned long sqls_num_rows(MYSQL_RES *res); +#define sqls_num_fields mysql_num_fields +#define sqls_fetch_field mysql_fetch_field +#define sqls_field_seek mysql_field_seek +#define sqls_fetch_row mysql_fetch_row +#define sqls_fetch_lengths mysql_fetch_lengths + +#endif /*MYSQL_DYNAMIC_PLUGIN*/ + + +#ifdef __cplusplus +} +#endif + +//#undef MYSQL_SERVER + +#endif /*MYSQL_SERVICE_SQL */ + + diff --git a/include/mysql/services.h b/include/mysql/services.h index 6dc970d..1ad5ae1 100644 --- a/include/mysql/services.h +++ b/include/mysql/services.h @@ -40,6 +40,7 @@ extern "C" { #include <mysql/service_thd_timezone.h> #include <mysql/service_thd_wait.h> #include <mysql/service_json.h> +#include <mysql/service_sql.h> /*#include <mysql/service_wsrep.h>*/ #ifdef __cplusplus diff --git a/include/service_versions.h b/include/service_versions.h index 050012d..4cb4725 100644 --- a/include/service_versions.h +++ b/include/service_versions.h @@ -43,3 +43,4 @@ #define VERSION_thd_wait 0x0100 #define VERSION_wsrep 0x0202 #define VERSION_json 0x0100 +#define VERSION_sql 0x0100 diff --git a/libservices/CMakeLists.txt b/libservices/CMakeLists.txt index b99be71..0120648 100644 --- a/libservices/CMakeLists.txt +++ b/libservices/CMakeLists.txt @@ -38,6 +38,7 @@ SET(MYSQLSERVICES_SOURCES thd_wait_service.c wsrep_service.c json_service.c + sql_service.c ) ADD_CONVENIENCE_LIBRARY(mysqlservices ${MYSQLSERVICES_SOURCES}) diff --git a/libservices/sql_service.c b/libservices/sql_service.c new file mode 100644 index 0000000..39a9d0a --- /dev/null +++ b/libservices/sql_service.c @@ -0,0 +1,19 @@ + +/* Copyright (c) 2019, Monty Program Ab + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include <service_versions.h> +SERVICE_VERSION sql_service= (void*)VERSION_sql; diff --git a/sql/sql_plugin_services.ic b/sql/sql_plugin_services.ic index c730490..fd0dba4 100644 --- a/sql/sql_plugin_services.ic +++ b/sql/sql_plugin_services.ic @@ -17,6 +17,7 @@ /* support for Services */ #include <service_versions.h> #include <mysql/service_wsrep.h> +#include <mysql.h> struct st_service_ref { const char *name; @@ -217,7 +218,7 @@ static struct my_print_error_service_st my_print_error_handler= my_printv_error }; -struct json_service_st json_handler= +static struct json_service_st json_handler= { json_type, json_get_array_item, @@ -227,6 +228,22 @@ struct json_service_st json_handler= json_unescape_json }; +static struct sql_service_st sql_handler= +{ + sqls_init, + sqls_close, + sqls_real_query, + sqls_affected_rows, + mysql_errno, + mysql_error, + mysql_store_result, + mysql_free_result, + sqls_num_rows, + mysql_num_fields, + mysql_fetch_row, + mysql_fetch_lengths +}; + static struct st_service_ref list_of_services[]= { { "base64_service", VERSION_base64, &base64_handler }, @@ -250,6 +267,7 @@ static struct st_service_ref list_of_services[]= { "thd_timezone_service", VERSION_thd_timezone, &thd_timezone_handler }, { "thd_wait_service", VERSION_thd_wait, &thd_wait_handler }, { "wsrep_service", VERSION_wsrep, &wsrep_handler }, - { "json_service", VERSION_json, &json_handler } + { "json_service", VERSION_json, &json_handler }, + { "sql_service", VERSION_sql, &sql_handler } };
participants (1)
-
holyfoot@askmonty.org