503
611
global_variables_dynamic_size= 0;
614
/****************************************************************************
615
Internal type declarations for variables support
616
****************************************************************************/
618
#undef DRIZZLE_SYSVAR_NAME
619
#define DRIZZLE_SYSVAR_NAME(name) name
620
#define PLUGIN_VAR_TYPEMASK 0x007f
622
static const uint32_t EXTRA_OPTIONS= 1; /* handle the NULL option */
624
typedef DECLARE_DRIZZLE_SYSVAR_BOOL(sysvar_bool_t);
625
typedef DECLARE_DRIZZLE_SessionVAR_BOOL(sessionvar_bool_t);
626
typedef DECLARE_DRIZZLE_SYSVAR_BASIC(sysvar_str_t, char *);
627
typedef DECLARE_DRIZZLE_SessionVAR_BASIC(sessionvar_str_t, char *);
629
typedef DECLARE_DRIZZLE_SessionVAR_TYPELIB(sessionvar_enum_t, unsigned long);
630
typedef DECLARE_DRIZZLE_SessionVAR_TYPELIB(sessionvar_set_t, uint64_t);
632
typedef DECLARE_DRIZZLE_SYSVAR_SIMPLE(sysvar_int_t, int);
633
typedef DECLARE_DRIZZLE_SYSVAR_SIMPLE(sysvar_long_t, long);
634
typedef DECLARE_DRIZZLE_SYSVAR_SIMPLE(sysvar_int64_t_t, int64_t);
635
typedef DECLARE_DRIZZLE_SYSVAR_SIMPLE(sysvar_uint_t, uint);
636
typedef DECLARE_DRIZZLE_SYSVAR_SIMPLE(sysvar_ulong_t, ulong);
637
typedef DECLARE_DRIZZLE_SYSVAR_SIMPLE(sysvar_uint64_t_t, uint64_t);
639
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_int_t, int);
640
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_long_t, long);
641
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_int64_t_t, int64_t);
642
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_uint_t, uint);
643
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_ulong_t, ulong);
644
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_uint64_t_t, uint64_t);
646
typedef bool *(*mysql_sys_var_ptr_p)(Session* a_session, int offset);
649
/****************************************************************************
650
default variable data check and update functions
651
****************************************************************************/
653
static int check_func_bool(Session *, drizzle_sys_var *var,
654
void *save, drizzle_value *value)
656
char buff[STRING_BUFFER_USUAL_SIZE];
657
const char *strvalue= "NULL", *str;
661
if (value->value_type(value) == DRIZZLE_VALUE_TYPE_STRING)
663
length= sizeof(buff);
664
if (!(str= value->val_str(value, buff, &length)) ||
665
(result= find_type(&bool_typelib, str, length, 1)-1) < 0)
674
if (value->val_int(value, &tmp) < 0)
678
internal::llstr(tmp, buff);
684
*(int*)save= -result;
687
my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), var->name, strvalue);
692
static int check_func_int(Session *session, drizzle_sys_var *var,
693
void *save, drizzle_value *value)
697
struct option options;
698
value->val_int(value, &tmp);
699
plugin_opt_set_limits(&options, var);
701
if (var->flags & PLUGIN_VAR_UNSIGNED)
702
*(uint32_t *)save= (uint32_t) getopt_ull_limit_value((uint64_t) tmp, &options,
705
*(int *)save= (int) getopt_ll_limit_value(tmp, &options, &fixed);
707
return throw_bounds_warning(session, fixed, var->flags & PLUGIN_VAR_UNSIGNED,
708
var->name, (int64_t) tmp);
712
static int check_func_long(Session *session, drizzle_sys_var *var,
713
void *save, drizzle_value *value)
717
struct option options;
718
value->val_int(value, &tmp);
719
plugin_opt_set_limits(&options, var);
721
if (var->flags & PLUGIN_VAR_UNSIGNED)
722
*(ulong *)save= (ulong) getopt_ull_limit_value((uint64_t) tmp, &options,
725
*(long *)save= (long) getopt_ll_limit_value(tmp, &options, &fixed);
727
return throw_bounds_warning(session, fixed, var->flags & PLUGIN_VAR_UNSIGNED,
728
var->name, (int64_t) tmp);
732
static int check_func_int64_t(Session *session, drizzle_sys_var *var,
733
void *save, drizzle_value *value)
737
struct option options;
738
value->val_int(value, &tmp);
739
plugin_opt_set_limits(&options, var);
741
if (var->flags & PLUGIN_VAR_UNSIGNED)
742
*(uint64_t *)save= getopt_ull_limit_value((uint64_t) tmp, &options,
745
*(int64_t *)save= getopt_ll_limit_value(tmp, &options, &fixed);
747
return throw_bounds_warning(session, fixed, var->flags & PLUGIN_VAR_UNSIGNED,
748
var->name, (int64_t) tmp);
751
static int check_func_str(Session *session, drizzle_sys_var *,
752
void *save, drizzle_value *value)
754
char buff[STRING_BUFFER_USUAL_SIZE];
758
length= sizeof(buff);
759
if ((str= value->val_str(value, buff, &length)))
760
str= session->strmake(str, length);
761
*(const char**)save= str;
766
static void update_func_bool(Session *, drizzle_sys_var *,
767
void *tgt, const void *save)
769
*(bool *) tgt= *(int *) save ? 1 : 0;
773
static void update_func_int(Session *, drizzle_sys_var *,
774
void *tgt, const void *save)
776
*(int *)tgt= *(int *) save;
780
static void update_func_long(Session *, drizzle_sys_var *,
781
void *tgt, const void *save)
783
*(long *)tgt= *(long *) save;
787
static void update_func_int64_t(Session *, drizzle_sys_var *,
788
void *tgt, const void *save)
790
*(int64_t *)tgt= *(uint64_t *) save;
794
static void update_func_str(Session *, drizzle_sys_var *var,
795
void *tgt, const void *save)
797
char *old= *(char **) tgt;
798
*(char **)tgt= *(char **) save;
799
if (var->flags & PLUGIN_VAR_MEMALLOC)
801
*(char **)tgt= strdup(*(char **) save);
804
* There isn't a _really_ good thing to do here until this whole set_var
805
* mess gets redesigned
808
errmsg_printf(ERRMSG_LVL_ERROR, _("Out of memory."));
507
814
/****************************************************************************
508
815
System Variables support
509
816
****************************************************************************/
819
sys_var *find_sys_var(Session *, const char *str, uint32_t length)
822
sys_var_pluginvar *pi= NULL;
823
module::Module *module;
825
if ((var= intern_find_sys_var(str, length, false)) &&
826
(pi= var->cast_pluginvar()))
828
if (!(module= pi->plugin))
829
var= NULL; /* failed to lock it, it must be uninstalling */
830
else if (module->isInited == false)
837
If the variable exists but the plugin it is associated with is not ready
838
then the intern_plugin_lock did not raise an error, so we do it here.
842
my_error(ER_UNKNOWN_SYSTEM_VARIABLE, MYF(0), (char*) str);
848
static const string make_bookmark_name(const string &plugin, const char *name)
850
string varname(plugin);
851
varname.push_back('_');
852
varname.append(name);
854
dashes_to_underscores(varname);
859
called by register_var, construct_options and test_plugin_options.
860
Returns the 'bookmark' for the named variable.
861
LOCK_system_variables_hash should be at least read locked
863
static Bookmark *find_bookmark(const string &plugin, const char *name, int flags)
865
if (!(flags & PLUGIN_VAR_SessionLOCAL))
868
const string varname(make_bookmark_name(plugin, name));
870
bookmark_unordered_map::iterator iter= bookmark_hash.find(varname);
871
if (iter != bookmark_hash.end())
873
return &((*iter).second);
880
returns a bookmark for session-local variables, creating if neccessary.
881
returns null for non session-local variables.
882
Requires that a write lock is obtained on LOCK_system_variables_hash
884
static Bookmark *register_var(const string &plugin, const char *name,
887
if (!(flags & PLUGIN_VAR_SessionLOCAL))
890
uint32_t size= 0, offset, new_size;
891
Bookmark *result= NULL;
893
switch (flags & PLUGIN_VAR_TYPEMASK) {
894
case PLUGIN_VAR_BOOL:
895
size= ALIGN_SIZE(sizeof(bool));
898
size= ALIGN_SIZE(sizeof(int));
900
case PLUGIN_VAR_LONG:
901
size= ALIGN_SIZE(sizeof(long));
903
case PLUGIN_VAR_LONGLONG:
904
size= ALIGN_SIZE(sizeof(uint64_t));
907
size= ALIGN_SIZE(sizeof(char*));
915
if (!(result= find_bookmark(plugin, name, flags)))
917
const string varname(make_bookmark_name(plugin, name));
919
Bookmark new_bookmark;
920
new_bookmark.key= varname;
921
new_bookmark.offset= -1;
923
assert(size && !(size & (size-1))); /* must be power of 2 */
925
offset= global_system_variables.dynamic_variables_size;
926
offset= (offset + size - 1) & ~(size - 1);
927
new_bookmark.offset= (int) offset;
929
new_size= (offset + size + 63) & ~63;
931
if (new_size > global_variables_dynamic_size)
935
(char *)realloc(global_system_variables.dynamic_variables_ptr,
938
global_system_variables.dynamic_variables_ptr= tmpptr;
941
(char *)realloc(max_system_variables.dynamic_variables_ptr,
944
max_system_variables.dynamic_variables_ptr= tmpptr;
947
Clear the new variable value space. This is required for string
948
variables. If their value is non-NULL, it must point to a valid
951
memset(global_system_variables.dynamic_variables_ptr +
952
global_variables_dynamic_size, 0,
953
new_size - global_variables_dynamic_size);
954
memset(max_system_variables.dynamic_variables_ptr +
955
global_variables_dynamic_size, 0,
956
new_size - global_variables_dynamic_size);
957
global_variables_dynamic_size= new_size;
960
global_system_variables.dynamic_variables_head= offset;
961
max_system_variables.dynamic_variables_head= offset;
962
global_system_variables.dynamic_variables_size= offset + size;
963
max_system_variables.dynamic_variables_size= offset + size;
964
global_system_variables.dynamic_variables_version++;
965
max_system_variables.dynamic_variables_version++;
967
new_bookmark.version= global_system_variables.dynamic_variables_version;
968
new_bookmark.type_code= flags;
970
/* this should succeed because we have already checked if a dup exists */
971
bookmark_hash.insert(make_pair(varname, new_bookmark));
972
result= find_bookmark(plugin, name, flags);
979
returns a pointer to the memory which holds the session-local variable or
980
a pointer to the global variable if session==null.
981
If required, will sync with global variables if the requested variable
982
has not yet been allocated in the current thread.
984
static unsigned char *intern_sys_var_ptr(Session* session, int offset, bool global_lock)
987
assert((uint32_t)offset <= global_system_variables.dynamic_variables_head);
990
return (unsigned char*) global_system_variables.dynamic_variables_ptr + offset;
993
dynamic_variables_head points to the largest valid offset
995
if (!session->variables.dynamic_variables_ptr ||
996
(uint32_t)offset > session->variables.dynamic_variables_head)
999
if (!(tmpptr= (char *)realloc(session->variables.dynamic_variables_ptr,
1000
global_variables_dynamic_size)))
1002
session->variables.dynamic_variables_ptr= tmpptr;
1005
LOCK_global_system_variables.lock();
1007
//safe_mutex_assert_owner(&LOCK_global_system_variables);
1009
memcpy(session->variables.dynamic_variables_ptr +
1010
session->variables.dynamic_variables_size,
1011
global_system_variables.dynamic_variables_ptr +
1012
session->variables.dynamic_variables_size,
1013
global_system_variables.dynamic_variables_size -
1014
session->variables.dynamic_variables_size);
1017
now we need to iterate through any newly copied 'defaults'
1018
and if it is a string type with MEMALLOC flag, we need to strdup
1020
bookmark_unordered_map::iterator iter= bookmark_hash.begin();
1021
for (; iter != bookmark_hash.end() ; ++iter)
1023
sys_var_pluginvar *pi;
1025
const Bookmark &v= (*iter).second;
1026
const string var_name((*iter).first);
1028
if (v.version <= session->variables.dynamic_variables_version ||
1029
!(var= intern_find_sys_var(var_name.c_str(), var_name.size(), true)) ||
1030
!(pi= var->cast_pluginvar()) ||
1031
v.type_code != (pi->plugin_var->flags & PLUGIN_VAR_TYPEMASK))
1034
/* Here we do anything special that may be required of the data types */
1036
if ((pi->plugin_var->flags & PLUGIN_VAR_TYPEMASK) == PLUGIN_VAR_STR &&
1037
pi->plugin_var->flags & PLUGIN_VAR_MEMALLOC)
1039
char **pp= (char**) (session->variables.dynamic_variables_ptr +
1040
*(int*)(pi->plugin_var + 1));
1041
if ((*pp= *(char**) (global_system_variables.dynamic_variables_ptr +
1042
*(int*)(pi->plugin_var + 1))))
1050
LOCK_global_system_variables.unlock();
1052
session->variables.dynamic_variables_version=
1053
global_system_variables.dynamic_variables_version;
1054
session->variables.dynamic_variables_head=
1055
global_system_variables.dynamic_variables_head;
1056
session->variables.dynamic_variables_size=
1057
global_system_variables.dynamic_variables_size;
1059
return (unsigned char*)session->variables.dynamic_variables_ptr + offset;
1062
static bool *mysql_sys_var_ptr_bool(Session* a_session, int offset)
1064
return (bool *)intern_sys_var_ptr(a_session, offset, true);
1067
static int *mysql_sys_var_ptr_int(Session* a_session, int offset)
1069
return (int *)intern_sys_var_ptr(a_session, offset, true);
1072
static long *mysql_sys_var_ptr_long(Session* a_session, int offset)
1074
return (long *)intern_sys_var_ptr(a_session, offset, true);
1077
static int64_t *mysql_sys_var_ptr_int64_t(Session* a_session, int offset)
1079
return (int64_t *)intern_sys_var_ptr(a_session, offset, true);
1082
static char **mysql_sys_var_ptr_str(Session* a_session, int offset)
1084
return (char **)intern_sys_var_ptr(a_session, offset, true);
513
1087
void plugin_sessionvar_init(Session *session)
1138
@brief Free values of thread variables of a plugin.
1140
This must be called before a plugin is deleted. Otherwise its
1141
variables are no longer accessible and the value space is lost. Note
1142
that only string values with PLUGIN_VAR_MEMALLOC are allocated and
1145
@param[in] vars Chain of system variables of a plugin
1148
static void plugin_vars_free_values(module::Module::Variables &vars)
1151
for (module::Module::Variables::iterator iter= vars.begin();
1155
sys_var_pluginvar *piv= (*iter)->cast_pluginvar();
1157
((piv->plugin_var->flags & PLUGIN_VAR_TYPEMASK) == PLUGIN_VAR_STR) &&
1158
(piv->plugin_var->flags & PLUGIN_VAR_MEMALLOC))
1160
/* Free the string from global_system_variables. */
1161
char **valptr= (char**) piv->real_value_ptr(NULL, OPT_GLOBAL);
1170
bool sys_var_pluginvar::check_update_type(Item_result type)
1174
switch (plugin_var->flags & PLUGIN_VAR_TYPEMASK) {
1175
case PLUGIN_VAR_INT:
1176
case PLUGIN_VAR_LONG:
1177
case PLUGIN_VAR_LONGLONG:
1178
return type != INT_RESULT;
1179
case PLUGIN_VAR_STR:
1180
return type != STRING_RESULT;
1187
SHOW_TYPE sys_var_pluginvar::show_type()
1189
switch (plugin_var->flags & PLUGIN_VAR_TYPEMASK) {
1190
case PLUGIN_VAR_BOOL:
1191
return SHOW_MY_BOOL;
1192
case PLUGIN_VAR_INT:
1194
case PLUGIN_VAR_LONG:
1196
case PLUGIN_VAR_LONGLONG:
1197
return SHOW_LONGLONG;
1198
case PLUGIN_VAR_STR:
1199
return SHOW_CHAR_PTR;
1207
unsigned char* sys_var_pluginvar::real_value_ptr(Session *session, sql_var_t type)
1209
assert(session || (type == OPT_GLOBAL));
1210
if (plugin_var->flags & PLUGIN_VAR_SessionLOCAL)
1212
if (type == OPT_GLOBAL)
1215
return intern_sys_var_ptr(session, *(int*) (plugin_var+1), false);
1217
return *(unsigned char**) (plugin_var+1);
1221
TYPELIB* sys_var_pluginvar::plugin_var_typelib(void)
1223
switch (plugin_var->flags & (PLUGIN_VAR_TYPEMASK | PLUGIN_VAR_SessionLOCAL)) {
1224
case PLUGIN_VAR_SessionLOCAL:
1225
return ((sessionvar_enum_t *)plugin_var)->typelib;
1233
unsigned char* sys_var_pluginvar::value_ptr(Session *session, sql_var_t type, const LEX_STRING *)
1235
unsigned char* result;
1237
result= real_value_ptr(session, type);
1243
bool sys_var_pluginvar::check(Session *session, set_var *var)
1245
st_item_value_holder value;
1246
assert(is_readonly() || plugin_var->check);
1248
value.value_type= item_value_type;
1249
value.val_str= item_val_str;
1250
value.val_int= item_val_int;
1251
value.val_real= item_val_real;
1252
value.item= var->value;
1254
return is_readonly() ||
1255
plugin_var->check(session, plugin_var, &var->save_result, &value);
1259
void sys_var_pluginvar::set_default(Session *session, sql_var_t type)
1264
assert(is_readonly() || plugin_var->update);
1269
LOCK_global_system_variables.lock();
1270
tgt= real_value_ptr(session, type);
1271
src= ((void **) (plugin_var + 1) + 1);
1273
if (plugin_var->flags & PLUGIN_VAR_SessionLOCAL)
1275
if (type != OPT_GLOBAL)
1276
src= real_value_ptr(session, OPT_GLOBAL);
1278
switch (plugin_var->flags & PLUGIN_VAR_TYPEMASK) {
1279
case PLUGIN_VAR_INT:
1280
src= &((sessionvar_uint_t*) plugin_var)->def_val;
1282
case PLUGIN_VAR_LONG:
1283
src= &((sessionvar_ulong_t*) plugin_var)->def_val;
1285
case PLUGIN_VAR_LONGLONG:
1286
src= &((sessionvar_uint64_t_t*) plugin_var)->def_val;
1288
case PLUGIN_VAR_BOOL:
1289
src= &((sessionvar_bool_t*) plugin_var)->def_val;
1291
case PLUGIN_VAR_STR:
1292
src= &((sessionvar_str_t*) plugin_var)->def_val;
1299
/* session must equal current_session if PLUGIN_VAR_SessionLOCAL flag is set */
1300
assert(!(plugin_var->flags & PLUGIN_VAR_SessionLOCAL) ||
1301
session == current_session);
1303
if (!(plugin_var->flags & PLUGIN_VAR_SessionLOCAL) || type == OPT_GLOBAL)
1305
plugin_var->update(session, plugin_var, tgt, src);
1306
LOCK_global_system_variables.unlock();
1310
LOCK_global_system_variables.unlock();
1311
plugin_var->update(session, plugin_var, tgt, src);
1316
bool sys_var_pluginvar::update(Session *session, set_var *var)
1320
assert(is_readonly() || plugin_var->update);
1322
/* session must equal current_session if PLUGIN_VAR_SessionLOCAL flag is set */
1323
assert(!(plugin_var->flags & PLUGIN_VAR_SessionLOCAL) ||
1324
session == current_session);
1329
LOCK_global_system_variables.lock();
1330
tgt= real_value_ptr(session, var->type);
1332
if (!(plugin_var->flags & PLUGIN_VAR_SessionLOCAL) || var->type == OPT_GLOBAL)
1334
/* variable we are updating has global scope, so we unlock after updating */
1335
plugin_var->update(session, plugin_var, tgt, &var->save_result);
1336
LOCK_global_system_variables.unlock();
1340
LOCK_global_system_variables.unlock();
1341
plugin_var->update(session, plugin_var, tgt, &var->save_result);
1347
#define OPTION_SET_LIMITS(type, options, opt) \
1348
options->var_type= type; \
1349
options->def_value= (opt)->def_val; \
1350
options->min_value= (opt)->min_val; \
1351
options->max_value= (opt)->max_val; \
1352
options->block_size= (long) (opt)->blk_sz
1355
void plugin_opt_set_limits(struct option *options,
1356
const drizzle_sys_var *opt)
1358
options->sub_size= 0;
1360
switch (opt->flags & (PLUGIN_VAR_TYPEMASK |
1361
PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_SessionLOCAL)) {
1362
/* global system variables */
1363
case PLUGIN_VAR_INT:
1364
OPTION_SET_LIMITS(GET_INT, options, (sysvar_int_t*) opt);
1366
case PLUGIN_VAR_INT | PLUGIN_VAR_UNSIGNED:
1367
OPTION_SET_LIMITS(GET_UINT, options, (sysvar_uint_t*) opt);
1369
case PLUGIN_VAR_LONG:
1370
OPTION_SET_LIMITS(GET_LONG, options, (sysvar_long_t*) opt);
1372
case PLUGIN_VAR_LONG | PLUGIN_VAR_UNSIGNED:
1373
OPTION_SET_LIMITS(GET_ULONG_IS_FAIL, options, (sysvar_ulong_t*) opt);
1375
case PLUGIN_VAR_LONGLONG:
1376
OPTION_SET_LIMITS(GET_LL, options, (sysvar_int64_t_t*) opt);
1378
case PLUGIN_VAR_LONGLONG | PLUGIN_VAR_UNSIGNED:
1379
OPTION_SET_LIMITS(GET_ULL, options, (sysvar_uint64_t_t*) opt);
1381
case PLUGIN_VAR_BOOL:
1382
options->var_type= GET_BOOL;
1383
options->def_value= ((sysvar_bool_t*) opt)->def_val;
1385
case PLUGIN_VAR_STR:
1386
options->var_type= ((opt->flags & PLUGIN_VAR_MEMALLOC) ?
1387
GET_STR_ALLOC : GET_STR);
1388
options->def_value= (intptr_t) ((sysvar_str_t*) opt)->def_val;
1390
/* threadlocal variables */
1391
case PLUGIN_VAR_INT | PLUGIN_VAR_SessionLOCAL:
1392
OPTION_SET_LIMITS(GET_INT, options, (sessionvar_int_t*) opt);
1394
case PLUGIN_VAR_INT | PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_SessionLOCAL:
1395
OPTION_SET_LIMITS(GET_UINT, options, (sessionvar_uint_t*) opt);
1397
case PLUGIN_VAR_LONG | PLUGIN_VAR_SessionLOCAL:
1398
OPTION_SET_LIMITS(GET_LONG, options, (sessionvar_long_t*) opt);
1400
case PLUGIN_VAR_LONG | PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_SessionLOCAL:
1401
OPTION_SET_LIMITS(GET_ULONG_IS_FAIL, options, (sessionvar_ulong_t*) opt);
1403
case PLUGIN_VAR_LONGLONG | PLUGIN_VAR_SessionLOCAL:
1404
OPTION_SET_LIMITS(GET_LL, options, (sessionvar_int64_t_t*) opt);
1406
case PLUGIN_VAR_LONGLONG | PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_SessionLOCAL:
1407
OPTION_SET_LIMITS(GET_ULL, options, (sessionvar_uint64_t_t*) opt);
1409
case PLUGIN_VAR_BOOL | PLUGIN_VAR_SessionLOCAL:
1410
options->var_type= GET_BOOL;
1411
options->def_value= ((sessionvar_bool_t*) opt)->def_val;
1413
case PLUGIN_VAR_STR | PLUGIN_VAR_SessionLOCAL:
1414
options->var_type= ((opt->flags & PLUGIN_VAR_MEMALLOC) ?
1415
GET_STR_ALLOC : GET_STR);
1416
options->def_value= (intptr_t) ((sessionvar_str_t*) opt)->def_val;
1421
options->arg_type= REQUIRED_ARG;
1422
if (opt->flags & PLUGIN_VAR_NOCMDARG)
1423
options->arg_type= NO_ARG;
1424
if (opt->flags & PLUGIN_VAR_OPCMDARG)
1425
options->arg_type= OPT_ARG;
1428
static int construct_options(memory::Root *mem_root, module::Module *tmp,
1432
int localoptionid= 256;
1433
const string plugin_name(tmp->getManifest().name);
1435
size_t namelen= plugin_name.size(), optnamelen;
1438
int index= 0, offset= 0;
1439
drizzle_sys_var *opt, **plugin_option;
1442
string name(plugin_name);
1443
transform(name.begin(), name.end(), name.begin(), ::tolower);
1445
underscores_to_dashes(name);
1448
Two passes as the 2nd pass will take pointer addresses for use
1449
by my_getopt and register_var() in the first pass uses realloc
1452
for (plugin_option= tmp->getManifest().system_vars;
1453
plugin_option && *plugin_option; plugin_option++, index++)
1455
opt= *plugin_option;
1456
if (!(opt->flags & PLUGIN_VAR_SessionLOCAL))
1458
if (!(register_var(name, opt->name, opt->flags)))
1460
switch (opt->flags & PLUGIN_VAR_TYPEMASK) {
1461
case PLUGIN_VAR_BOOL:
1462
(((sessionvar_bool_t *)opt)->resolve)= mysql_sys_var_ptr_bool;
1464
case PLUGIN_VAR_INT:
1465
(((sessionvar_int_t *)opt)->resolve)= mysql_sys_var_ptr_int;
1467
case PLUGIN_VAR_LONG:
1468
(((sessionvar_long_t *)opt)->resolve)= mysql_sys_var_ptr_long;
1470
case PLUGIN_VAR_LONGLONG:
1471
(((sessionvar_int64_t_t *)opt)->resolve)= mysql_sys_var_ptr_int64_t;
1473
case PLUGIN_VAR_STR:
1474
(((sessionvar_str_t *)opt)->resolve)= mysql_sys_var_ptr_str;
1477
errmsg_printf(ERRMSG_LVL_ERROR, _("Unknown variable type code 0x%x in plugin '%s'."),
1478
opt->flags, plugin_name.c_str());
1483
for (plugin_option= tmp->getManifest().system_vars;
1484
plugin_option && *plugin_option; plugin_option++, index++)
1486
switch ((opt= *plugin_option)->flags & PLUGIN_VAR_TYPEMASK) {
1487
case PLUGIN_VAR_BOOL:
1489
opt->check= check_func_bool;
1491
opt->update= update_func_bool;
1493
case PLUGIN_VAR_INT:
1495
opt->check= check_func_int;
1497
opt->update= update_func_int;
1499
case PLUGIN_VAR_LONG:
1501
opt->check= check_func_long;
1503
opt->update= update_func_long;
1505
case PLUGIN_VAR_LONGLONG:
1507
opt->check= check_func_int64_t;
1509
opt->update= update_func_int64_t;
1511
case PLUGIN_VAR_STR:
1513
opt->check= check_func_str;
1516
opt->update= update_func_str;
1517
if ((opt->flags & (PLUGIN_VAR_MEMALLOC | PLUGIN_VAR_READONLY)) == false)
1519
opt->flags|= PLUGIN_VAR_READONLY;
1520
errmsg_printf(ERRMSG_LVL_WARN, _("Server variable %s of plugin %s was forced "
1521
"to be read-only: string variable without "
1522
"update_func and PLUGIN_VAR_MEMALLOC flag"),
1523
opt->name, plugin_name.c_str());
1528
errmsg_printf(ERRMSG_LVL_ERROR, _("Unknown variable type code 0x%x in plugin '%s'."),
1529
opt->flags, plugin_name.c_str());
1533
if ((opt->flags & (PLUGIN_VAR_NOCMDOPT | PLUGIN_VAR_SessionLOCAL))
1534
== PLUGIN_VAR_NOCMDOPT)
1539
errmsg_printf(ERRMSG_LVL_ERROR, _("Missing variable name in plugin '%s'."),
1540
plugin_name.c_str());
1544
if (!(opt->flags & PLUGIN_VAR_SessionLOCAL))
1546
optnamelen= strlen(opt->name);
1547
optname= (char*) mem_root->alloc_root(namelen + optnamelen + 2);
1548
sprintf(optname, "%s-%s", name.c_str(), opt->name);
1549
optnamelen= namelen + optnamelen + 1;
1553
/* this should not fail because register_var should create entry */
1554
if (!(v= find_bookmark(name, opt->name, opt->flags)))
1556
errmsg_printf(ERRMSG_LVL_ERROR, _("Thread local variable '%s' not allocated "
1557
"in plugin '%s'."), opt->name, plugin_name.c_str());
1561
*(int*)(opt + 1)= offset= v->offset;
1563
if (opt->flags & PLUGIN_VAR_NOCMDOPT)
1566
optname= (char*) mem_root->memdup_root(v->key.c_str(), (optnamelen= v->key.size()) + 1);
1569
/* convert '_' to '-' */
1570
for (p= optname; *p; p++)
1574
options->name= optname;
1575
options->comment= opt->comment;
1576
options->app_type= opt;
1577
options->id= localoptionid++;
1579
plugin_opt_set_limits(options, opt);
1581
if (opt->flags & PLUGIN_VAR_SessionLOCAL)
1582
options->value= options->u_max_value= (char**)
1583
(global_system_variables.dynamic_variables_ptr + offset);
1585
options->value= options->u_max_value= *(char***) (opt + 1);
1594
static option *construct_help_options(memory::Root *mem_root, module::Module *p)
1596
drizzle_sys_var **opt;
1598
uint32_t count= EXTRA_OPTIONS;
1600
for (opt= p->getManifest().system_vars; opt && *opt; opt++, count++) {};
1602
opts= (option*)mem_root->alloc_root((sizeof(option) * count));
1606
memset(opts, 0, sizeof(option) * count);
1608
if (construct_options(mem_root, p, opts))
1614
void drizzle_add_plugin_sysvar(sys_var_pluginvar *var)
1616
plugin_sysvar_vec.push_back(var);
1619
void drizzle_del_plugin_sysvar()
1621
vector<sys_var_pluginvar *>::iterator iter= plugin_sysvar_vec.begin();
1622
while(iter != plugin_sysvar_vec.end())
1627
plugin_sysvar_vec.clear();