diff options
author | Alexey Botchkov <holyfoot@askmonty.org> | 2018-12-12 01:49:39 +0400 |
---|---|---|
committer | Alexey Botchkov <holyfoot@askmonty.org> | 2018-12-12 01:49:39 +0400 |
commit | b1527ef51ccf5c4d7a4a3847c542ef9a81a97240 (patch) | |
tree | 3d4ff816a77e34be669b21d4c44171d1b18f456d /include | |
parent | dc6ad597656e8173dd73edb58a967152df70dc9e (diff) | |
download | mariadb-git-b1527ef51ccf5c4d7a4a3847c542ef9a81a97240.tar.gz |
MDEV-5313 Improving audit api.
Service added to handle json.
Diffstat (limited to 'include')
-rw-r--r-- | include/json_lib.h | 10 | ||||
-rw-r--r-- | include/mysql/plugin.h | 2 | ||||
-rw-r--r-- | include/mysql/plugin_audit.h.pp | 45 | ||||
-rw-r--r-- | include/mysql/plugin_auth.h.pp | 45 | ||||
-rw-r--r-- | include/mysql/plugin_encryption.h.pp | 45 | ||||
-rw-r--r-- | include/mysql/plugin_ftparser.h.pp | 45 | ||||
-rw-r--r-- | include/mysql/plugin_password_validation.h.pp | 45 | ||||
-rw-r--r-- | include/mysql/service_json.h | 117 | ||||
-rw-r--r-- | include/mysql/services.h | 1 | ||||
-rw-r--r-- | include/service_versions.h | 1 |
10 files changed, 350 insertions, 6 deletions
diff --git a/include/json_lib.h b/include/json_lib.h index fed85b516d9..87b2688c850 100644 --- a/include/json_lib.h +++ b/include/json_lib.h @@ -174,11 +174,11 @@ enum json_value_types { JSON_VALUE_OBJECT=1, JSON_VALUE_ARRAY=2, - JSON_VALUE_STRING, - JSON_VALUE_NUMBER, - JSON_VALUE_TRUE, - JSON_VALUE_FALSE, - JSON_VALUE_NULL + JSON_VALUE_STRING=3, + JSON_VALUE_NUMBER=4, + JSON_VALUE_TRUE=5, + JSON_VALUE_FALSE=6, + JSON_VALUE_NULL=7 }; diff --git a/include/mysql/plugin.h b/include/mysql/plugin.h index b122d888c6d..02a87c6db71 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/plugin_audit.h.pp b/include/mysql/plugin_audit.h.pp index 89f7dcc36c4..0588b211b81 100644 --- a/include/mysql/plugin_audit.h.pp +++ b/include/mysql/plugin_audit.h.pp @@ -374,6 +374,51 @@ extern struct thd_wait_service_st { } *thd_wait_service; void thd_wait_begin(void* thd, int wait_type); void thd_wait_end(void* thd); +enum json_types +{ + JSV_BAD_JSON=-1, + JSV_NOTHING=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 { + enum json_types (*json_type)(const char *js, const char *js_end, + const char **v, int *vlen); + enum json_types (*json_get_array_item)(const char *js, const char *js_end, + int n_item, + const char **v, int *vlen); + enum json_types (*json_get_object_key)(const char *js, const char *js_end, + const char *key, + const char **v, int *vlen); + enum json_types (*json_get_object_nkey)(const char *js,const char *js_end, + int nkey, + const char **keyname, const char **keyname_end, + const char **v, int *vlen); + int (*json_escape_string)(const char *str,const char *str_end, + char *json, char *json_end); + int (*json_unescape_json)(const char *json_str, const char *json_end, + char *res, char *res_end); +} *json_service; +enum json_types json_type(const char *js, const char *js_end, + const char **v, int *vlen); +enum json_types json_get_array_item(const char *js, const char *js_end, + int n_item, + const char **v, int *vlen); +enum json_types json_get_object_key(const char *js, const char *js_end, + const char *key, + const char **v, int *vlen); +enum json_types json_get_object_nkey(const char *js,const char *js_end, int nkey, + const char **keyname, const char **keyname_end, + const char **v, int *vlen); +int json_escape_string(const char *str,const char *str_end, + char *json, char *json_end); +int json_unescape_json(const char *json_str, const char *json_end, + char *res, char *res_end); struct st_mysql_xid { long formatID; long gtrid_length; diff --git a/include/mysql/plugin_auth.h.pp b/include/mysql/plugin_auth.h.pp index 7ed786cc1ab..cfb9201bb1e 100644 --- a/include/mysql/plugin_auth.h.pp +++ b/include/mysql/plugin_auth.h.pp @@ -374,6 +374,51 @@ extern struct thd_wait_service_st { } *thd_wait_service; void thd_wait_begin(void* thd, int wait_type); void thd_wait_end(void* thd); +enum json_types +{ + JSV_BAD_JSON=-1, + JSV_NOTHING=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 { + enum json_types (*json_type)(const char *js, const char *js_end, + const char **v, int *vlen); + enum json_types (*json_get_array_item)(const char *js, const char *js_end, + int n_item, + const char **v, int *vlen); + enum json_types (*json_get_object_key)(const char *js, const char *js_end, + const char *key, + const char **v, int *vlen); + enum json_types (*json_get_object_nkey)(const char *js,const char *js_end, + int nkey, + const char **keyname, const char **keyname_end, + const char **v, int *vlen); + int (*json_escape_string)(const char *str,const char *str_end, + char *json, char *json_end); + int (*json_unescape_json)(const char *json_str, const char *json_end, + char *res, char *res_end); +} *json_service; +enum json_types json_type(const char *js, const char *js_end, + const char **v, int *vlen); +enum json_types json_get_array_item(const char *js, const char *js_end, + int n_item, + const char **v, int *vlen); +enum json_types json_get_object_key(const char *js, const char *js_end, + const char *key, + const char **v, int *vlen); +enum json_types json_get_object_nkey(const char *js,const char *js_end, int nkey, + const char **keyname, const char **keyname_end, + const char **v, int *vlen); +int json_escape_string(const char *str,const char *str_end, + char *json, char *json_end); +int json_unescape_json(const char *json_str, const char *json_end, + char *res, char *res_end); struct st_mysql_xid { long formatID; long gtrid_length; diff --git a/include/mysql/plugin_encryption.h.pp b/include/mysql/plugin_encryption.h.pp index 7defe0aec2c..7761a3e600d 100644 --- a/include/mysql/plugin_encryption.h.pp +++ b/include/mysql/plugin_encryption.h.pp @@ -374,6 +374,51 @@ extern struct thd_wait_service_st { } *thd_wait_service; void thd_wait_begin(void* thd, int wait_type); void thd_wait_end(void* thd); +enum json_types +{ + JSV_BAD_JSON=-1, + JSV_NOTHING=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 { + enum json_types (*json_type)(const char *js, const char *js_end, + const char **v, int *vlen); + enum json_types (*json_get_array_item)(const char *js, const char *js_end, + int n_item, + const char **v, int *vlen); + enum json_types (*json_get_object_key)(const char *js, const char *js_end, + const char *key, + const char **v, int *vlen); + enum json_types (*json_get_object_nkey)(const char *js,const char *js_end, + int nkey, + const char **keyname, const char **keyname_end, + const char **v, int *vlen); + int (*json_escape_string)(const char *str,const char *str_end, + char *json, char *json_end); + int (*json_unescape_json)(const char *json_str, const char *json_end, + char *res, char *res_end); +} *json_service; +enum json_types json_type(const char *js, const char *js_end, + const char **v, int *vlen); +enum json_types json_get_array_item(const char *js, const char *js_end, + int n_item, + const char **v, int *vlen); +enum json_types json_get_object_key(const char *js, const char *js_end, + const char *key, + const char **v, int *vlen); +enum json_types json_get_object_nkey(const char *js,const char *js_end, int nkey, + const char **keyname, const char **keyname_end, + const char **v, int *vlen); +int json_escape_string(const char *str,const char *str_end, + char *json, char *json_end); +int json_unescape_json(const char *json_str, const char *json_end, + char *res, char *res_end); struct st_mysql_xid { long formatID; long gtrid_length; diff --git a/include/mysql/plugin_ftparser.h.pp b/include/mysql/plugin_ftparser.h.pp index a36f51e74e1..2e775976015 100644 --- a/include/mysql/plugin_ftparser.h.pp +++ b/include/mysql/plugin_ftparser.h.pp @@ -374,6 +374,51 @@ extern struct thd_wait_service_st { } *thd_wait_service; void thd_wait_begin(void* thd, int wait_type); void thd_wait_end(void* thd); +enum json_types +{ + JSV_BAD_JSON=-1, + JSV_NOTHING=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 { + enum json_types (*json_type)(const char *js, const char *js_end, + const char **v, int *vlen); + enum json_types (*json_get_array_item)(const char *js, const char *js_end, + int n_item, + const char **v, int *vlen); + enum json_types (*json_get_object_key)(const char *js, const char *js_end, + const char *key, + const char **v, int *vlen); + enum json_types (*json_get_object_nkey)(const char *js,const char *js_end, + int nkey, + const char **keyname, const char **keyname_end, + const char **v, int *vlen); + int (*json_escape_string)(const char *str,const char *str_end, + char *json, char *json_end); + int (*json_unescape_json)(const char *json_str, const char *json_end, + char *res, char *res_end); +} *json_service; +enum json_types json_type(const char *js, const char *js_end, + const char **v, int *vlen); +enum json_types json_get_array_item(const char *js, const char *js_end, + int n_item, + const char **v, int *vlen); +enum json_types json_get_object_key(const char *js, const char *js_end, + const char *key, + const char **v, int *vlen); +enum json_types json_get_object_nkey(const char *js,const char *js_end, int nkey, + const char **keyname, const char **keyname_end, + const char **v, int *vlen); +int json_escape_string(const char *str,const char *str_end, + char *json, char *json_end); +int json_unescape_json(const char *json_str, const char *json_end, + char *res, char *res_end); struct st_mysql_xid { long formatID; long gtrid_length; diff --git a/include/mysql/plugin_password_validation.h.pp b/include/mysql/plugin_password_validation.h.pp index b13f8cc9afb..7492642a3ee 100644 --- a/include/mysql/plugin_password_validation.h.pp +++ b/include/mysql/plugin_password_validation.h.pp @@ -374,6 +374,51 @@ extern struct thd_wait_service_st { } *thd_wait_service; void thd_wait_begin(void* thd, int wait_type); void thd_wait_end(void* thd); +enum json_types +{ + JSV_BAD_JSON=-1, + JSV_NOTHING=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 { + enum json_types (*json_type)(const char *js, const char *js_end, + const char **v, int *vlen); + enum json_types (*json_get_array_item)(const char *js, const char *js_end, + int n_item, + const char **v, int *vlen); + enum json_types (*json_get_object_key)(const char *js, const char *js_end, + const char *key, + const char **v, int *vlen); + enum json_types (*json_get_object_nkey)(const char *js,const char *js_end, + int nkey, + const char **keyname, const char **keyname_end, + const char **v, int *vlen); + int (*json_escape_string)(const char *str,const char *str_end, + char *json, char *json_end); + int (*json_unescape_json)(const char *json_str, const char *json_end, + char *res, char *res_end); +} *json_service; +enum json_types json_type(const char *js, const char *js_end, + const char **v, int *vlen); +enum json_types json_get_array_item(const char *js, const char *js_end, + int n_item, + const char **v, int *vlen); +enum json_types json_get_object_key(const char *js, const char *js_end, + const char *key, + const char **v, int *vlen); +enum json_types json_get_object_nkey(const char *js,const char *js_end, int nkey, + const char **keyname, const char **keyname_end, + const char **v, int *vlen); +int json_escape_string(const char *str,const char *str_end, + char *json, char *json_end); +int json_unescape_json(const char *json_str, const char *json_end, + char *res, char *res_end); struct st_mysql_xid { long formatID; long gtrid_length; diff --git a/include/mysql/service_json.h b/include/mysql/service_json.h new file mode 100644 index 00000000000..204417248c6 --- /dev/null +++ b/include/mysql/service_json.h @@ -0,0 +1,117 @@ +/* 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 json_types +{ + JSV_BAD_JSON=-1, + JSV_NOTHING=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 { + enum json_types (*json_type)(const char *js, const char *js_end, + const char **v, int *vlen); + enum json_types (*json_get_array_item)(const char *js, const char *js_end, + int n_item, + const char **v, int *vlen); + enum json_types (*json_get_object_key)(const char *js, const char *js_end, + const char *key, + const char **v, int *vlen); + enum json_types (*json_get_object_nkey)(const char *js,const char *js_end, + int nkey, + const char **keyname, const char **keyname_end, + const char **v, int *vlen); + int (*json_escape_string)(const char *str,const char *str_end, + char *json, char *json_end); + int (*json_unescape_json)(const char *json_str, const char *json_end, + char *res, char *res_end); +} *json_service; + +#ifdef MYSQL_DYNAMIC_PLUGIN + +#define json_type json_service->json_type +#define json_get_array_item json_service->json_get_array_item +#define json_get_object_key json_service->json_get_object_key +#define json_get_object_nkey json_service->json_get_object_nkey +#define json_escape_string json_service->json_escape_string +#define json_unescape_json json_service->json_unescape_json + +#else + +enum json_types json_type(const char *js, const char *js_end, + const char **v, int *vlen); +enum json_types json_get_array_item(const char *js, const char *js_end, + int n_item, + const char **v, int *vlen); +enum json_types json_get_object_key(const char *js, const char *js_end, + const char *key, + const char **v, int *vlen); +enum json_types json_get_object_nkey(const char *js,const char *js_end, int nkey, + const char **keyname, const char **keyname_end, + const char **v, int *vlen); +int json_escape_string(const char *str,const char *str_end, + char *json, char *json_end); +int json_unescape_json(const char *json_str, const char *json_end, + char *res, char *res_end); + +#endif /*MYSQL_DYNAMIC_PLUGIN*/ + + +#ifdef __cplusplus +} +#endif + +#endif /*MYSQL_SERVICE_JSON */ + + diff --git a/include/mysql/services.h b/include/mysql/services.h index 6168c5ed8dc..6dc970df1e6 100644 --- a/include/mysql/services.h +++ b/include/mysql/services.h @@ -39,6 +39,7 @@ extern "C" { #include <mysql/service_thd_specifics.h> #include <mysql/service_thd_timezone.h> #include <mysql/service_thd_wait.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 753d6444475..050012d30b9 100644 --- a/include/service_versions.h +++ b/include/service_versions.h @@ -42,3 +42,4 @@ #define VERSION_thd_timezone 0x0100 #define VERSION_thd_wait 0x0100 #define VERSION_wsrep 0x0202 +#define VERSION_json 0x0100 |