[Commits] 07f5d03: MDEV-5313 Improving merge audit api.
revision-id: 07f5d036fbb5bdcb011a84f5c882a062d9e609e7 (mariadb-10.4.0-54-g07f5d03) parent(s): 3afae13b548c903d86a55530d59fbf7d8666281f committer: Alexey Botchkov timestamp: 2018-12-03 02:35:52 +0400 message: MDEV-5313 Improving merge audit api. service_json and service_cfg_table interfaces added. --- include/mysql/plugin.h | 2 +- include/mysql/service_cfg_table.h | 109 ++++++++++++++++++++++++++++++++++++++ include/mysql/service_json.h | 109 ++++++++++++++++++++++++++++++++++++++ include/mysql/services.h | 2 + include/service_versions.h | 2 + libservices/CMakeLists.txt | 2 + libservices/cfg_table_service.c | 18 +++++++ libservices/json_service.c | 19 +++++++ sql/sql_plugin_services.ic | 20 ++++++- 9 files changed, 281 insertions(+), 2 deletions(-) diff --git a/include/mysql/plugin.h b/include/mysql/plugin.h index b122d88..02a87c6 100644 --- a/include/mysql/plugin.h +++ b/include/mysql/plugin.h @@ -75,7 +75,7 @@ typedef struct st_mysql_xid MYSQL_XID; #define MYSQL_PLUGIN_INTERFACE_VERSION 0x0104 /* MariaDB plugin interface version */ -#define MARIA_PLUGIN_INTERFACE_VERSION 0x010d +#define MARIA_PLUGIN_INTERFACE_VERSION 0x010e /* The allowable types of plugins diff --git a/include/mysql/service_cfg_table.h b/include/mysql/service_cfg_table.h new file mode 100644 index 0000000..36660ff --- /dev/null +++ b/include/mysql/service_cfg_table.h @@ -0,0 +1,109 @@ +/* Copyright (C) 2018 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_CFG_TABLE +#define MYSQL_SERVICE_CFG_TABLE + +/** + @file + cfg table service + + Reading plugin settings from the server table. + + This service lets the plugin to read it's settings + from the server table. + This 'cfg' table has two VARCHAR fields per row + which are + 'id' - the name of the setting + 'value' - the value of the respective 'id' setting + The structure 'cfg_table_row' reflects this format for + the data interchange with the service. + Fuctions of the service: + cfg_table_check_exists + checks if the table exists. + cfg_table_create - creates the table + parameers: + table_name - the name of the table + int id_len, int value_len - the length of the 'id' and 'value' + fields. + const struct cfg_table_row *defaults - table will be filled + with these default rows. + The list of rows is ended by {0,0} row + + cfg_table_set - replaces (inserts if not exists) the setting + parameters: + table_name - the name of the table + const char *id, const char *value - the 'id' and the new value + + cfg_table_get - reads the cft tale content + It return the number of rows in the table or -1 if error. + parameters: + table_name, + struct cfg_table_row *data_buf - buffer to store the records + int n_buf_row - the size of the buffer +*/ + + +#ifdef __cplusplus +extern "C" { +#endif + + +struct cfg_table_row +{ + const char *id; + const char *value; +}; + + +extern struct cfg_table_service_st { + int (*cfg_table_check_exists)(const char *table_name); + int (*cfg_table_create)(const char *table_name, + int id_len, int value_len, + const struct cfg_table_row *defaults); + int (*cfg_table_set)(const char *table_name, + const char *id, const char *value); + int (*cfg_table_get)(const char *table_name, + struct cfg_table_row *data_buf, int n_buf_row); +} *cfg_table_service; + +#ifdef MYSQL_DYNAMIC_PLUGIN + +#define cfg_table_check_exists cfg_table_service->cfg_table_check_exists +#define cfg_table_create cfg_table_service->cfg_table_create +#define cfg_table_set cfg_table_service->cfg_table_set +#define cfg_table_get cfg_table_service->cfg_table_get + +#else + +int cfg_table_check_exists(const char *table_name); +int cfg_table_create(const char *table_name, + int id_len, int value_len, + const struct cfg_table_row *defaults); +int cfg_table_set(const char *table_name, + const char *id, const char *value); +int cfg_table_get(const char *table_name, + struct cfg_table_row *data_buf, int n_buf_row); + +#endif + + +#ifdef __cplusplus +} +#endif + +#endif /*MYSQL_SERVICE_CFG_TABLE */ + + diff --git a/include/mysql/service_json.h b/include/mysql/service_json.h new file mode 100644 index 0000000..5d0e260 --- /dev/null +++ b/include/mysql/service_json.h @@ -0,0 +1,109 @@ +/* Copyright (C) 2018 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_JSON +#define MYSQL_SERVICE_JSON + +/** + @file + json service + + Esports JSON parsing methods for plugins to use. + + Fuctions of the service: + js_type - returns the type of the JSON argument, + and the parsed value if it's scalar (not object or array) + + js_get_array_item - expecs JSON array as an argument, + and returns the n_item's item's type and value + Returns JSV_NOTHING type if the array is shorter + than n_item and the actual length of the array in v_len. + + js_get_object_key - expects JSON object as an argument, + searches for a key in the object, return it's type and value. + JSV_NOTHING if no such key found, the number of keys + in v_len. + + js_get_object_nkey - expects JSON object as an argument. + finds n_key's key in the object, returns it's name, type and value. + JSV_NOTHING if object has less keys than n_key. +*/ + + +#ifdef __cplusplus +extern "C" { +#endif + +enum js_value_types +{ + JSV_NOTTHING=0, + JSV_OBJECT=1, + JSV_ARRAY=2, + JSV_STRING=3, + JSV_NUMBER=4, + JSV_TRUE=5, + JSV_FALSE=6, + JSV_NULL=7 +}; + +extern struct json_service_st { + int (*js_type)(const char *js, const char *js_end, + enum js_value_types *vt, + const char **v, int *vlen); + int (*js_get_array_item)(const char *js, const char *js_end, int n_item, + enum js_value_types *vt, + const char **v, int *vlen); + int (*js_get_object_key)(const char *js, const char *js_end, const char *key, + enum js_value_types *vt, + const char **v, int *vlen); + int (*js_get_object_nkey)(const char *js,const char *js_end, int nkey, + const char **keyname, const char **keyname_end, + enum js_value_types *vt, + const char **v, int *vlen); +} *json_service; + +#ifdef MYSQL_DYNAMIC_PLUGIN + +#define js_type json_service->js_type +#define js_get_array_item json_service->js_get_array_item +#define js_get_object_key json_service->js_get_object_key +#define js_get_object_nkey json_service->js_get_object_nkey + +#else + +int js_type(const char *js, const char *js_end, + enum js_value_types *vt, + const char **v, int *vlen); +int js_get_array_item(const char *js, const char *js_end, int n_item, + enum js_value_types *vt, + const char **v, int *vlen); +int js_get_object_key(const char *js, const char *js_end, const char *key, + enum js_value_types *vt, + const char **v, int *vlen); +int js_get_object_nkey(const char *js,const char *js_end, int nkey, + const char **keyname, const char **keyname_end, + enum js_value_types *vt, + const char **v, int *vlen); + +#endif + + +#ifdef __cplusplus +} +#endif + +#endif /*MYSQL_SERVICE_JSON */ + + diff --git a/include/mysql/services.h b/include/mysql/services.h index 6168c5e..2e1879c 100644 --- a/include/mysql/services.h +++ b/include/mysql/services.h @@ -39,6 +39,8 @@ extern "C" { #include <mysql/service_thd_specifics.h> #include <mysql/service_thd_timezone.h> #include <mysql/service_thd_wait.h> +#include <mysql/service_cfg_table.h> +#include <mysql/service_json.h> /*#include <mysql/service_wsrep.h>*/ #ifdef __cplusplus diff --git a/include/service_versions.h b/include/service_versions.h index 753d644..0ea0c3a 100644 --- a/include/service_versions.h +++ b/include/service_versions.h @@ -42,3 +42,5 @@ #define VERSION_thd_timezone 0x0100 #define VERSION_thd_wait 0x0100 #define VERSION_wsrep 0x0202 +#define VERSION_cfg_table 0x0100 +#define VERSION_json 0x0100 diff --git a/libservices/CMakeLists.txt b/libservices/CMakeLists.txt index e20be6d..ac66295 100644 --- a/libservices/CMakeLists.txt +++ b/libservices/CMakeLists.txt @@ -37,6 +37,8 @@ SET(MYSQLSERVICES_SOURCES thd_timezone_service.c thd_wait_service.c wsrep_service.c + cfg_table_service.c + json_service.c ) ADD_CONVENIENCE_LIBRARY(mysqlservices ${MYSQLSERVICES_SOURCES}) diff --git a/libservices/cfg_table_service.c b/libservices/cfg_table_service.c new file mode 100644 index 0000000..8b5bd6f --- /dev/null +++ b/libservices/cfg_table_service.c @@ -0,0 +1,18 @@ +/* Copyright (c) 2018, 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 cfg_table_service= (void*)VERSION_cfg_table; diff --git a/libservices/json_service.c b/libservices/json_service.c new file mode 100644 index 0000000..96b3b3f --- /dev/null +++ b/libservices/json_service.c @@ -0,0 +1,19 @@ + +/* Copyright (c) 2018, 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 json_service= (void*)VERSION_json; diff --git a/sql/sql_plugin_services.ic b/sql/sql_plugin_services.ic index 8de53aa..9aaadb3 100644 --- a/sql/sql_plugin_services.ic +++ b/sql/sql_plugin_services.ic @@ -217,6 +217,22 @@ static struct my_print_error_service_st my_print_error_handler= my_printv_error }; +struct cfg_table_service_st cfg_table_handler= +{ + cfg_table_check_exists, + cfg_table_create, + cfg_table_set, + cfg_table_get +}; + +struct json_service_st json_handler= +{ + js_type, + js_get_array_item, + js_get_object_key, + js_get_object_nkey +}; + static struct st_service_ref list_of_services[]= { { "base64_service", VERSION_base64, &base64_handler }, @@ -239,6 +255,8 @@ static struct st_service_ref list_of_services[]= { "thd_specifics_service", VERSION_thd_specifics, &thd_specifics_handler }, { "thd_timezone_service", VERSION_thd_timezone, &thd_timezone_handler }, { "thd_wait_service", VERSION_thd_wait, &thd_wait_handler }, - { "wsrep_service", VERSION_wsrep, &wsrep_handler } + { "wsrep_service", VERSION_wsrep, &wsrep_handler }, + { "cfg_table_service", VERSION_cfg_table, &cfg_table_handler }, + { "json_service", VERSION_json, &json_handler } };
participants (1)
-
holyfoot@askmonty.org