Skip to content

Commit cc18a5d

Browse files
author
Alexey Botchkov
committed
MDEV-5313 Improving audit API.
json_locate_key() implemented. get rid of 'key_len' argument in functions.
1 parent dd03cb3 commit cc18a5d

File tree

10 files changed

+185
-66
lines changed

10 files changed

+185
-66
lines changed

include/json_lib.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,11 @@ int json_path_compare(const json_path_t *a, const json_path_t *b,
425425

426426
int json_valid(const char *js, size_t js_len, CHARSET_INFO *cs);
427427

428+
int json_locate_key(const char *js, const char *js_end,
429+
const char *kname,
430+
const char **key_start, const char **key_end,
431+
int *comma_pos);
432+
428433
#ifdef __cplusplus
429434
}
430435
#endif

include/mysql/plugin_audit.h.pp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@
393393
int n_item,
394394
const char **value, int *value_len);
395395
enum json_types (*json_get_object_key)(const char *js, const char *js_end,
396-
const char *key, const char *key_end,
396+
const char *key,
397397
const char **value, int *value_len);
398398
enum json_types (*json_get_object_nkey)(const char *js,const char *js_end,
399399
int nkey,
@@ -410,7 +410,7 @@
410410
int n_item,
411411
const char **value, int *value_len);
412412
enum json_types json_get_object_key(const char *js, const char *js_end,
413-
const char *key, const char *key_end,
413+
const char *key,
414414
const char **value, int *value_len);
415415
enum json_types json_get_object_nkey(const char *js,const char *js_end, int nkey,
416416
const char **keyname, const char **keyname_end,

include/mysql/plugin_auth.h.pp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@
393393
int n_item,
394394
const char **value, int *value_len);
395395
enum json_types (*json_get_object_key)(const char *js, const char *js_end,
396-
const char *key, const char *key_end,
396+
const char *key,
397397
const char **value, int *value_len);
398398
enum json_types (*json_get_object_nkey)(const char *js,const char *js_end,
399399
int nkey,
@@ -410,7 +410,7 @@
410410
int n_item,
411411
const char **value, int *value_len);
412412
enum json_types json_get_object_key(const char *js, const char *js_end,
413-
const char *key, const char *key_end,
413+
const char *key,
414414
const char **value, int *value_len);
415415
enum json_types json_get_object_nkey(const char *js,const char *js_end, int nkey,
416416
const char **keyname, const char **keyname_end,

include/mysql/plugin_encryption.h.pp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@
393393
int n_item,
394394
const char **value, int *value_len);
395395
enum json_types (*json_get_object_key)(const char *js, const char *js_end,
396-
const char *key, const char *key_end,
396+
const char *key,
397397
const char **value, int *value_len);
398398
enum json_types (*json_get_object_nkey)(const char *js,const char *js_end,
399399
int nkey,
@@ -410,7 +410,7 @@
410410
int n_item,
411411
const char **value, int *value_len);
412412
enum json_types json_get_object_key(const char *js, const char *js_end,
413-
const char *key, const char *key_end,
413+
const char *key,
414414
const char **value, int *value_len);
415415
enum json_types json_get_object_nkey(const char *js,const char *js_end, int nkey,
416416
const char **keyname, const char **keyname_end,

include/mysql/plugin_ftparser.h.pp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@
393393
int n_item,
394394
const char **value, int *value_len);
395395
enum json_types (*json_get_object_key)(const char *js, const char *js_end,
396-
const char *key, const char *key_end,
396+
const char *key,
397397
const char **value, int *value_len);
398398
enum json_types (*json_get_object_nkey)(const char *js,const char *js_end,
399399
int nkey,
@@ -410,7 +410,7 @@
410410
int n_item,
411411
const char **value, int *value_len);
412412
enum json_types json_get_object_key(const char *js, const char *js_end,
413-
const char *key, const char *key_end,
413+
const char *key,
414414
const char **value, int *value_len);
415415
enum json_types json_get_object_nkey(const char *js,const char *js_end, int nkey,
416416
const char **keyname, const char **keyname_end,

include/mysql/plugin_password_validation.h.pp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@
393393
int n_item,
394394
const char **value, int *value_len);
395395
enum json_types (*json_get_object_key)(const char *js, const char *js_end,
396-
const char *key, const char *key_end,
396+
const char *key,
397397
const char **value, int *value_len);
398398
enum json_types (*json_get_object_nkey)(const char *js,const char *js_end,
399399
int nkey,
@@ -410,7 +410,7 @@
410410
int n_item,
411411
const char **value, int *value_len);
412412
enum json_types json_get_object_key(const char *js, const char *js_end,
413-
const char *key, const char *key_end,
413+
const char *key,
414414
const char **value, int *value_len);
415415
enum json_types json_get_object_nkey(const char *js,const char *js_end, int nkey,
416416
const char **keyname, const char **keyname_end,

include/mysql/service_json.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ extern struct json_service_st {
6666
int n_item,
6767
const char **value, int *value_len);
6868
enum json_types (*json_get_object_key)(const char *js, const char *js_end,
69-
const char *key, const char *key_end,
69+
const char *key,
7070
const char **value, int *value_len);
7171
enum json_types (*json_get_object_nkey)(const char *js,const char *js_end,
7272
int nkey,
@@ -95,7 +95,7 @@ enum json_types json_get_array_item(const char *js, const char *js_end,
9595
int n_item,
9696
const char **value, int *value_len);
9797
enum json_types json_get_object_key(const char *js, const char *js_end,
98-
const char *key, const char *key_end,
98+
const char *key,
9999
const char **value, int *value_len);
100100
enum json_types json_get_object_nkey(const char *js,const char *js_end, int nkey,
101101
const char **keyname, const char **keyname_end,

sql/sql_acl.cc

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,16 +1204,16 @@ class User_table_json: public User_table
12041204

12051205
int get_auth(THD *thd, MEM_ROOT *root, const char **plugin, const char **authstr) const
12061206
{
1207-
*plugin= get_str_value(root, STRING_WITH_LEN("plugin"));
1207+
*plugin= get_str_value(root, "plugin");
12081208
if (!**plugin)
12091209
*plugin= native_password_plugin_name.str;
1210-
*authstr= get_str_value(root, STRING_WITH_LEN("authentication_string"));
1210+
*authstr= get_str_value(root, "authentication_string");
12111211
return *plugin == NULL || *authstr == NULL;
12121212
}
12131213
void set_auth(const char *p, size_t pl, const char *as, size_t asl) const
12141214
{
1215-
set_str_value(STRING_WITH_LEN("plugin"), p, pl);
1216-
set_str_value(STRING_WITH_LEN("authentication_string"), as, asl);
1215+
set_str_value("plugin", p, pl);
1216+
set_str_value("authentication_string", as, asl);
12171217
}
12181218
ulong get_access() const
12191219
{
@@ -1222,7 +1222,7 @@ class User_table_json: public User_table
12221222
(or, for example, my_count_bits(GLOBAL_ACLS))
12231223
in the json too, and it'll allow us to do privilege upgrades
12241224
*/
1225-
return get_int_value(STRING_WITH_LEN("access")) & GLOBAL_ACLS;
1225+
return get_int_value("access") & GLOBAL_ACLS;
12261226
}
12271227
void set_access(ulong rights, bool revoke) const
12281228
{
@@ -1231,53 +1231,53 @@ class User_table_json: public User_table
12311231
access&= ~rights;
12321232
else
12331233
access|= rights;
1234-
set_int_value(STRING_WITH_LEN("access"), access & GLOBAL_ACLS);
1234+
set_int_value("access", access & GLOBAL_ACLS);
12351235
}
12361236

12371237
SSL_type get_ssl_type () const
1238-
{ return (SSL_type)get_int_value(STRING_WITH_LEN("ssl_type")); }
1238+
{ return (SSL_type)get_int_value("ssl_type"); }
12391239
int set_ssl_type (SSL_type x) const
1240-
{ return set_int_value(STRING_WITH_LEN("ssl_type"), x); }
1240+
{ return set_int_value("ssl_type", x); }
12411241
const char* get_ssl_cipher (MEM_ROOT *root) const
1242-
{ return get_str_value(root, STRING_WITH_LEN("ssl_cipher")); }
1242+
{ return get_str_value(root, "ssl_cipher"); }
12431243
int set_ssl_cipher (const char *s, size_t l) const
1244-
{ return set_str_value(STRING_WITH_LEN("ssl_cipher"), s, l); }
1244+
{ return set_str_value("ssl_cipher", s, l); }
12451245
const char* get_x509_issuer (MEM_ROOT *root) const
1246-
{ return get_str_value(root, STRING_WITH_LEN("x509_issuer")); }
1246+
{ return get_str_value(root, "x509_issuer"); }
12471247
int set_x509_issuer (const char *s, size_t l) const
1248-
{ return set_str_value(STRING_WITH_LEN("x509_issuer"), s, l); }
1248+
{ return set_str_value("x509_issuer", s, l); }
12491249
const char* get_x509_subject (MEM_ROOT *root) const
1250-
{ return get_str_value(root, STRING_WITH_LEN("x509_subject")); }
1250+
{ return get_str_value(root, "x509_subject"); }
12511251
int set_x509_subject (const char *s, size_t l) const
1252-
{ return set_str_value(STRING_WITH_LEN("x509_subject"), s, l); }
1252+
{ return set_str_value("x509_subject", s, l); }
12531253
longlong get_max_questions () const
1254-
{ return get_int_value(STRING_WITH_LEN("max_questions")); }
1254+
{ return get_int_value("max_questions"); }
12551255
int set_max_questions (longlong x) const
1256-
{ return set_int_value(STRING_WITH_LEN("max_questions"), x); }
1256+
{ return set_int_value("max_questions", x); }
12571257
longlong get_max_updates () const
1258-
{ return get_int_value(STRING_WITH_LEN("max_updates")); }
1258+
{ return get_int_value("max_updates"); }
12591259
int set_max_updates (longlong x) const
1260-
{ return set_int_value(STRING_WITH_LEN("max_updates"), x); }
1260+
{ return set_int_value("max_updates", x); }
12611261
longlong get_max_connections () const
1262-
{ return get_int_value(STRING_WITH_LEN("max_connections")); }
1262+
{ return get_int_value("max_connections"); }
12631263
int set_max_connections (longlong x) const
1264-
{ return set_int_value(STRING_WITH_LEN("max_connections"), x); }
1264+
{ return set_int_value("max_connections", x); }
12651265
longlong get_max_user_connections () const
1266-
{ return get_int_value(STRING_WITH_LEN("max_user_connections")); }
1266+
{ return get_int_value("max_user_connections"); }
12671267
int set_max_user_connections (longlong x) const
1268-
{ return set_int_value(STRING_WITH_LEN("max_user_connections"), x); }
1268+
{ return set_int_value("max_user_connections", x); }
12691269
double get_max_statement_time () const
1270-
{ return get_double_value(STRING_WITH_LEN("max_statement_time")); }
1270+
{ return get_double_value("max_statement_time"); }
12711271
int set_max_statement_time (double x) const
1272-
{ return set_double_value(STRING_WITH_LEN("max_statement_time"), x); }
1272+
{ return set_double_value("max_statement_time", x); }
12731273
bool get_is_role () const
1274-
{ return get_bool_value(STRING_WITH_LEN("is_role")); }
1274+
{ return get_bool_value("is_role"); }
12751275
int set_is_role (bool x) const
1276-
{ return set_bool_value(STRING_WITH_LEN("is_role"), x); }
1276+
{ return set_bool_value("is_role", x); }
12771277
const char* get_default_role (MEM_ROOT *root) const
1278-
{ return get_str_value(root, STRING_WITH_LEN("default_role")); }
1278+
{ return get_str_value(root, "default_role"); }
12791279
int set_default_role (const char *s, size_t l) const
1280-
{ return set_str_value(STRING_WITH_LEN("default_role"), s, l); }
1280+
{ return set_str_value("default_role", s, l); }
12811281

12821282
~User_table_json() {}
12831283
private:
@@ -1290,24 +1290,24 @@ class User_table_json: public User_table
12901290
USERNAME_CHAR_LENGTH);
12911291
return 0;
12921292
}
1293-
bool get_value(const char *key, size_t klen,
1293+
bool get_value(const char *key,
12941294
enum json_types vt, const char **v, size_t *vl) const
12951295
{
12961296
enum json_types value_type;
12971297
int int_vl;
12981298
String str, *res= m_table->field[2]->val_str(&str);
12991299
if (!res ||
1300-
(value_type= json_get_object_key(res->ptr(), res->end(),
1301-
key, key+klen, v, &int_vl)) == JSV_BAD_JSON)
1300+
(value_type= json_get_object_key(res->ptr(), res->end(), key,
1301+
v, &int_vl)) == JSV_BAD_JSON)
13021302
return 1; // invalid
13031303
*vl= int_vl;
13041304
return value_type != vt;
13051305
}
1306-
const char *get_str_value(MEM_ROOT *root, const char *key, size_t klen) const
1306+
const char *get_str_value(MEM_ROOT *root, const char *key) const
13071307
{
13081308
size_t value_len;
13091309
const char *value_start;
1310-
if (get_value(key, klen, JSV_STRING, &value_start, &value_len))
1310+
if (get_value(key, JSV_STRING, &value_start, &value_len))
13111311
return "";
13121312
char *ptr= (char*)alloca(value_len);
13131313
int len= json_unescape(m_table->field[2]->charset(),
@@ -1319,35 +1319,35 @@ class User_table_json: public User_table
13191319
return NULL;
13201320
return strmake_root(root, ptr, len);
13211321
}
1322-
longlong get_int_value(const char *key, size_t klen) const
1322+
longlong get_int_value(const char *key) const
13231323
{
13241324
int err;
13251325
size_t value_len;
13261326
const char *value_start;
1327-
if (get_value(key, klen, JSV_NUMBER, &value_start, &value_len))
1327+
if (get_value(key, JSV_NUMBER, &value_start, &value_len))
13281328
return 0;
13291329
const char *value_end= value_start + value_len;
13301330
return my_strtoll10(value_start, (char**)&value_end, &err);
13311331
}
1332-
double get_double_value(const char *key, size_t klen) const
1332+
double get_double_value(const char *key) const
13331333
{
13341334
int err;
13351335
size_t value_len;
13361336
const char *value_start;
1337-
if (get_value(key, klen, JSV_NUMBER, &value_start, &value_len))
1337+
if (get_value(key, JSV_NUMBER, &value_start, &value_len))
13381338
return 0;
13391339
const char *value_end= value_start + value_len;
13401340
return my_strtod(value_start, (char**)&value_end, &err);
13411341
}
1342-
bool get_bool_value(const char *key, size_t klen) const
1342+
bool get_bool_value(const char *key) const
13431343
{
13441344
size_t value_len;
13451345
const char *value_start;
1346-
if (get_value(key, klen, JSV_TRUE, &value_start, &value_len))
1346+
if (get_value(key, JSV_TRUE, &value_start, &value_len))
13471347
return false;
13481348
return true;
13491349
}
1350-
bool set_value(const char *key, size_t klen,
1350+
bool set_value(const char *key,
13511351
const char *val, size_t vlen, bool string) const
13521352
{
13531353
int value_len;
@@ -1356,7 +1356,7 @@ class User_table_json: public User_table
13561356
String str, *res= m_table->field[2]->val_str(&str);
13571357
if (!res || !res->length())
13581358
(res= &str)->set(STRING_WITH_LEN("{}"), m_table->field[2]->charset());
1359-
value_type= json_get_object_key(res->ptr(), res->end(), key, key+klen,
1359+
value_type= json_get_object_key(res->ptr(), res->end(), key,
13601360
&value_start, &value_len);
13611361
if (value_type == JSV_BAD_JSON)
13621362
return 1; // invalid
@@ -1367,7 +1367,7 @@ class User_table_json: public User_table
13671367
if (value_len)
13681368
json.append(',');
13691369
json.append('"');
1370-
json.append(key, klen);
1370+
json.append(STRING_WITH_LEN(key));
13711371
json.append(STRING_WITH_LEN("\":"));
13721372
if (string)
13731373
json.append('"');
@@ -1382,7 +1382,7 @@ class User_table_json: public User_table
13821382
m_table->field[2]->store(json.ptr(), json.length(), json.charset());
13831383
return 0;
13841384
}
1385-
bool set_str_value(const char *key, size_t klen, const char *val, size_t vlen) const
1385+
bool set_str_value(const char *key, const char *val, size_t vlen) const
13861386
{
13871387
char buf[JSON_SIZE];
13881388
int blen= json_escape(system_charset_info,
@@ -1391,22 +1391,22 @@ class User_table_json: public User_table
13911391
(uchar*)buf, (uchar*)buf+sizeof(buf));
13921392
if (blen < 0)
13931393
return 1;
1394-
return set_value(key, klen, buf, blen, true);
1394+
return set_value(key, buf, blen, true);
13951395
}
1396-
bool set_int_value(const char *key, size_t klen, longlong val) const
1396+
bool set_int_value(const char *key, longlong val) const
13971397
{
13981398
char v[MY_INT64_NUM_DECIMAL_DIGITS+1];
13991399
size_t vlen= longlong10_to_str(val, v, -10) - v;
1400-
return set_value(key, klen, v, vlen, false);
1400+
return set_value(key, v, vlen, false);
14011401
}
1402-
bool set_double_value(const char *key, size_t klen, double val) const
1402+
bool set_double_value(const char *key, double val) const
14031403
{
14041404
char v[FLOATING_POINT_BUFFER+1];
14051405
size_t vlen= my_fcvt(val, TIME_SECOND_PART_DIGITS, v, NULL);
1406-
return set_value(key, klen, v, vlen, false);
1406+
return set_value(key, v, vlen, false);
14071407
}
1408-
bool set_bool_value(const char *key, size_t klen, bool val) const
1409-
{ return set_value(key, klen, val ? "true" : "false", val ? 4 : 5, false); }
1408+
bool set_bool_value(const char *key, bool val) const
1409+
{ return set_value(key, val ? "true" : "false", val ? 4 : 5, false); }
14101410
};
14111411

14121412
class Db_table: public Grant_table_base

0 commit comments

Comments
 (0)