618
494
global_variables_dynamic_size= 0;
621
/****************************************************************************
622
Internal type declarations for variables support
623
****************************************************************************/
625
#undef DRIZZLE_SYSVAR_NAME
626
#define DRIZZLE_SYSVAR_NAME(name) name
627
#define PLUGIN_VAR_TYPEMASK 0x007f
629
static const uint32_t EXTRA_OPTIONS= 1; /* handle the NULL option */
631
typedef DECLARE_DRIZZLE_SYSVAR_BOOL(sysvar_bool_t);
632
typedef DECLARE_DRIZZLE_SessionVAR_BOOL(sessionvar_bool_t);
633
typedef DECLARE_DRIZZLE_SYSVAR_BASIC(sysvar_str_t, char *);
634
typedef DECLARE_DRIZZLE_SessionVAR_BASIC(sessionvar_str_t, char *);
636
typedef DECLARE_DRIZZLE_SessionVAR_TYPELIB(sessionvar_enum_t, unsigned long);
637
typedef DECLARE_DRIZZLE_SessionVAR_TYPELIB(sessionvar_set_t, uint64_t);
639
typedef DECLARE_DRIZZLE_SYSVAR_SIMPLE(sysvar_int_t, int);
640
typedef DECLARE_DRIZZLE_SYSVAR_SIMPLE(sysvar_long_t, long);
641
typedef DECLARE_DRIZZLE_SYSVAR_SIMPLE(sysvar_int64_t_t, int64_t);
642
typedef DECLARE_DRIZZLE_SYSVAR_SIMPLE(sysvar_uint_t, uint);
643
typedef DECLARE_DRIZZLE_SYSVAR_SIMPLE(sysvar_ulong_t, ulong);
644
typedef DECLARE_DRIZZLE_SYSVAR_SIMPLE(sysvar_uint64_t_t, uint64_t);
646
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_int_t, int);
647
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_long_t, long);
648
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_int64_t_t, int64_t);
649
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_uint_t, uint);
650
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_ulong_t, ulong);
651
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_uint64_t_t, uint64_t);
653
typedef bool *(*mysql_sys_var_ptr_p)(Session* a_session, int offset);
656
/****************************************************************************
657
default variable data check and update functions
658
****************************************************************************/
660
static int check_func_bool(Session *, drizzle_sys_var *var,
661
void *save, drizzle_value *value)
663
char buff[STRING_BUFFER_USUAL_SIZE];
664
const char *strvalue= "NULL", *str;
668
if (value->value_type(value) == DRIZZLE_VALUE_TYPE_STRING)
670
length= sizeof(buff);
671
if (!(str= value->val_str(value, buff, &length)) ||
672
(result= find_type(&bool_typelib, str, length, 1)-1) < 0)
681
if (value->val_int(value, &tmp) < 0)
685
internal::llstr(tmp, buff);
691
*(int*)save= -result;
694
my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), var->name, strvalue);
699
static int check_func_int(Session *session, drizzle_sys_var *var,
700
void *save, drizzle_value *value)
704
struct option options;
705
value->val_int(value, &tmp);
706
plugin_opt_set_limits(&options, var);
708
if (var->flags & PLUGIN_VAR_UNSIGNED)
709
*(uint32_t *)save= (uint32_t) getopt_ull_limit_value((uint64_t) tmp, &options,
712
*(int *)save= (int) getopt_ll_limit_value(tmp, &options, &fixed);
714
return throw_bounds_warning(session, fixed, var->flags & PLUGIN_VAR_UNSIGNED,
715
var->name, (int64_t) tmp);
719
static int check_func_long(Session *session, drizzle_sys_var *var,
720
void *save, drizzle_value *value)
724
struct option options;
725
value->val_int(value, &tmp);
726
plugin_opt_set_limits(&options, var);
728
if (var->flags & PLUGIN_VAR_UNSIGNED)
729
*(ulong *)save= (ulong) getopt_ull_limit_value((uint64_t) tmp, &options,
732
*(long *)save= (long) getopt_ll_limit_value(tmp, &options, &fixed);
734
return throw_bounds_warning(session, fixed, var->flags & PLUGIN_VAR_UNSIGNED,
735
var->name, (int64_t) tmp);
739
static int check_func_int64_t(Session *session, drizzle_sys_var *var,
740
void *save, drizzle_value *value)
744
struct option options;
745
value->val_int(value, &tmp);
746
plugin_opt_set_limits(&options, var);
748
if (var->flags & PLUGIN_VAR_UNSIGNED)
749
*(uint64_t *)save= getopt_ull_limit_value((uint64_t) tmp, &options,
752
*(int64_t *)save= getopt_ll_limit_value(tmp, &options, &fixed);
754
return throw_bounds_warning(session, fixed, var->flags & PLUGIN_VAR_UNSIGNED,
755
var->name, (int64_t) tmp);
758
static int check_func_str(Session *session, drizzle_sys_var *,
759
void *save, drizzle_value *value)
761
char buff[STRING_BUFFER_USUAL_SIZE];
765
length= sizeof(buff);
766
if ((str= value->val_str(value, buff, &length)))
767
str= session->strmake(str, length);
768
*(const char**)save= str;
773
static void update_func_bool(Session *, drizzle_sys_var *,
774
void *tgt, const void *save)
776
*(bool *) tgt= *(int *) save ? 1 : 0;
780
static void update_func_int(Session *, drizzle_sys_var *,
781
void *tgt, const void *save)
783
*(int *)tgt= *(int *) save;
787
static void update_func_long(Session *, drizzle_sys_var *,
788
void *tgt, const void *save)
790
*(long *)tgt= *(long *) save;
794
static void update_func_int64_t(Session *, drizzle_sys_var *,
795
void *tgt, const void *save)
797
*(int64_t *)tgt= *(uint64_t *) save;
801
static void update_func_str(Session *, drizzle_sys_var *var,
802
void *tgt, const void *save)
804
char *old= *(char **) tgt;
805
*(char **)tgt= *(char **) save;
806
if (var->flags & PLUGIN_VAR_MEMALLOC)
808
*(char **)tgt= strdup(*(char **) save);
811
* There isn't a _really_ good thing to do here until this whole set_var
812
* mess gets redesigned
815
errmsg_printf(ERRMSG_LVL_ERROR, _("Out of memory."));
821
498
/****************************************************************************
822
499
System Variables support
826
503
sys_var *find_sys_var(const char *str, uint32_t length)
829
sys_var_pluginvar *pi= NULL;
830
module::Module *module;
832
if ((var= intern_find_sys_var(str, length, false)) &&
833
(pi= var->cast_pluginvar()))
835
if (!(module= pi->plugin))
836
var= NULL; /* failed to lock it, it must be uninstalling */
837
else if (module->isInited == false)
844
If the variable exists but the plugin it is associated with is not ready
845
then the intern_plugin_lock did not raise an error, so we do it here.
849
my_error(ER_UNKNOWN_SYSTEM_VARIABLE, MYF(0), (char*) str);
855
static const string make_bookmark_name(const string &plugin, const char *name)
857
string varname(plugin);
858
varname.push_back('_');
859
varname.append(name);
861
dashes_to_underscores(varname);
866
called by register_var, construct_options and test_plugin_options.
867
Returns the 'bookmark' for the named variable.
868
LOCK_system_variables_hash should be at least read locked
870
static Bookmark *find_bookmark(const string &plugin, const char *name, int flags)
872
if (!(flags & PLUGIN_VAR_SessionLOCAL))
875
const string varname(make_bookmark_name(plugin, name));
877
bookmark_unordered_map::iterator iter= bookmark_hash.find(varname);
878
if (iter != bookmark_hash.end())
880
return &((*iter).second);
887
returns a bookmark for session-local variables, creating if neccessary.
888
returns null for non session-local variables.
889
Requires that a write lock is obtained on LOCK_system_variables_hash
891
static Bookmark *register_var(const string &plugin, const char *name,
894
if (!(flags & PLUGIN_VAR_SessionLOCAL))
897
uint32_t size= 0, offset, new_size;
898
Bookmark *result= NULL;
900
switch (flags & PLUGIN_VAR_TYPEMASK) {
901
case PLUGIN_VAR_BOOL:
902
size= ALIGN_SIZE(sizeof(bool));
905
size= ALIGN_SIZE(sizeof(int));
907
case PLUGIN_VAR_LONG:
908
size= ALIGN_SIZE(sizeof(long));
910
case PLUGIN_VAR_LONGLONG:
911
size= ALIGN_SIZE(sizeof(uint64_t));
914
size= ALIGN_SIZE(sizeof(char*));
922
if (!(result= find_bookmark(plugin, name, flags)))
924
const string varname(make_bookmark_name(plugin, name));
926
Bookmark new_bookmark;
927
new_bookmark.key= varname;
928
new_bookmark.offset= -1;
930
assert(size && !(size & (size-1))); /* must be power of 2 */
932
offset= global_system_variables.dynamic_variables_size;
933
offset= (offset + size - 1) & ~(size - 1);
934
new_bookmark.offset= (int) offset;
936
new_size= (offset + size + 63) & ~63;
938
if (new_size > global_variables_dynamic_size)
942
(char *)realloc(global_system_variables.dynamic_variables_ptr,
945
global_system_variables.dynamic_variables_ptr= tmpptr;
948
(char *)realloc(max_system_variables.dynamic_variables_ptr,
951
max_system_variables.dynamic_variables_ptr= tmpptr;
954
Clear the new variable value space. This is required for string
955
variables. If their value is non-NULL, it must point to a valid
958
memset(global_system_variables.dynamic_variables_ptr +
959
global_variables_dynamic_size, 0,
960
new_size - global_variables_dynamic_size);
961
memset(max_system_variables.dynamic_variables_ptr +
962
global_variables_dynamic_size, 0,
963
new_size - global_variables_dynamic_size);
964
global_variables_dynamic_size= new_size;
967
global_system_variables.dynamic_variables_head= offset;
968
max_system_variables.dynamic_variables_head= offset;
969
global_system_variables.dynamic_variables_size= offset + size;
970
max_system_variables.dynamic_variables_size= offset + size;
971
global_system_variables.dynamic_variables_version++;
972
max_system_variables.dynamic_variables_version++;
974
new_bookmark.version= global_system_variables.dynamic_variables_version;
975
new_bookmark.type_code= flags;
977
/* this should succeed because we have already checked if a dup exists */
978
bookmark_hash.insert(make_pair(varname, new_bookmark));
979
result= find_bookmark(plugin, name, flags);
986
returns a pointer to the memory which holds the session-local variable or
987
a pointer to the global variable if session==null.
988
If required, will sync with global variables if the requested variable
989
has not yet been allocated in the current thread.
991
static unsigned char *intern_sys_var_ptr(Session* session, int offset, bool global_lock)
994
assert((uint32_t)offset <= global_system_variables.dynamic_variables_head);
997
return (unsigned char*) global_system_variables.dynamic_variables_ptr + offset;
1000
dynamic_variables_head points to the largest valid offset
1002
if (!session->variables.dynamic_variables_ptr ||
1003
(uint32_t)offset > session->variables.dynamic_variables_head)
1006
if (!(tmpptr= (char *)realloc(session->variables.dynamic_variables_ptr,
1007
global_variables_dynamic_size)))
1009
session->variables.dynamic_variables_ptr= tmpptr;
1012
LOCK_global_system_variables.lock();
1014
//safe_mutex_assert_owner(&LOCK_global_system_variables);
1016
memcpy(session->variables.dynamic_variables_ptr +
1017
session->variables.dynamic_variables_size,
1018
global_system_variables.dynamic_variables_ptr +
1019
session->variables.dynamic_variables_size,
1020
global_system_variables.dynamic_variables_size -
1021
session->variables.dynamic_variables_size);
1024
now we need to iterate through any newly copied 'defaults'
1025
and if it is a string type with MEMALLOC flag, we need to strdup
1027
bookmark_unordered_map::iterator iter= bookmark_hash.begin();
1028
for (; iter != bookmark_hash.end() ; ++iter)
1030
sys_var_pluginvar *pi;
1032
const Bookmark &v= (*iter).second;
1033
const string var_name((*iter).first);
1035
if (v.version <= session->variables.dynamic_variables_version ||
1036
!(var= intern_find_sys_var(var_name.c_str(), var_name.size(), true)) ||
1037
!(pi= var->cast_pluginvar()) ||
1038
v.type_code != (pi->plugin_var->flags & PLUGIN_VAR_TYPEMASK))
1041
/* Here we do anything special that may be required of the data types */
1043
if ((pi->plugin_var->flags & PLUGIN_VAR_TYPEMASK) == PLUGIN_VAR_STR &&
1044
pi->plugin_var->flags & PLUGIN_VAR_MEMALLOC)
1046
char **pp= (char**) (session->variables.dynamic_variables_ptr +
1047
*(int*)(pi->plugin_var + 1));
1048
if ((*pp= *(char**) (global_system_variables.dynamic_variables_ptr +
1049
*(int*)(pi->plugin_var + 1))))
1057
LOCK_global_system_variables.unlock();
1059
session->variables.dynamic_variables_version=
1060
global_system_variables.dynamic_variables_version;
1061
session->variables.dynamic_variables_head=
1062
global_system_variables.dynamic_variables_head;
1063
session->variables.dynamic_variables_size=
1064
global_system_variables.dynamic_variables_size;
1066
return (unsigned char*)session->variables.dynamic_variables_ptr + offset;
1069
static bool *mysql_sys_var_ptr_bool(Session* a_session, int offset)
1071
return (bool *)intern_sys_var_ptr(a_session, offset, true);
1074
static int *mysql_sys_var_ptr_int(Session* a_session, int offset)
1076
return (int *)intern_sys_var_ptr(a_session, offset, true);
1079
static long *mysql_sys_var_ptr_long(Session* a_session, int offset)
1081
return (long *)intern_sys_var_ptr(a_session, offset, true);
1084
static int64_t *mysql_sys_var_ptr_int64_t(Session* a_session, int offset)
1086
return (int64_t *)intern_sys_var_ptr(a_session, offset, true);
1089
static char **mysql_sys_var_ptr_str(Session* a_session, int offset)
1091
return (char **)intern_sys_var_ptr(a_session, offset, true);
505
return intern_find_sys_var(str, length, false);
1094
509
void plugin_sessionvar_init(Session *session)
1145
@brief Free values of thread variables of a plugin.
1147
This must be called before a plugin is deleted. Otherwise its
1148
variables are no longer accessible and the value space is lost. Note
1149
that only string values with PLUGIN_VAR_MEMALLOC are allocated and
1152
@param[in] vars Chain of system variables of a plugin
1155
static void plugin_vars_free_values(module::Module::Variables &vars)
1158
for (module::Module::Variables::iterator iter= vars.begin();
1162
sys_var_pluginvar *piv= (*iter)->cast_pluginvar();
1164
((piv->plugin_var->flags & PLUGIN_VAR_TYPEMASK) == PLUGIN_VAR_STR) &&
1165
(piv->plugin_var->flags & PLUGIN_VAR_MEMALLOC))
1167
/* Free the string from global_system_variables. */
1168
char **valptr= (char**) piv->real_value_ptr(NULL, OPT_GLOBAL);
1177
bool sys_var_pluginvar::check_update_type(Item_result type)
1181
switch (plugin_var->flags & PLUGIN_VAR_TYPEMASK) {
1182
case PLUGIN_VAR_INT:
1183
case PLUGIN_VAR_LONG:
1184
case PLUGIN_VAR_LONGLONG:
1185
return type != INT_RESULT;
1186
case PLUGIN_VAR_STR:
1187
return type != STRING_RESULT;
1194
SHOW_TYPE sys_var_pluginvar::show_type()
1196
switch (plugin_var->flags & PLUGIN_VAR_TYPEMASK) {
1197
case PLUGIN_VAR_BOOL:
1198
return SHOW_MY_BOOL;
1199
case PLUGIN_VAR_INT:
1201
case PLUGIN_VAR_LONG:
1203
case PLUGIN_VAR_LONGLONG:
1204
return SHOW_LONGLONG;
1205
case PLUGIN_VAR_STR:
1206
return SHOW_CHAR_PTR;
1214
unsigned char* sys_var_pluginvar::real_value_ptr(Session *session, sql_var_t type)
1216
assert(session || (type == OPT_GLOBAL));
1217
if (plugin_var->flags & PLUGIN_VAR_SessionLOCAL)
1219
if (type == OPT_GLOBAL)
1222
return intern_sys_var_ptr(session, *(int*) (plugin_var+1), false);
1224
return *(unsigned char**) (plugin_var+1);
1228
TYPELIB* sys_var_pluginvar::plugin_var_typelib(void)
1230
switch (plugin_var->flags & (PLUGIN_VAR_TYPEMASK | PLUGIN_VAR_SessionLOCAL)) {
1231
case PLUGIN_VAR_SessionLOCAL:
1232
return ((sessionvar_enum_t *)plugin_var)->typelib;
1240
unsigned char* sys_var_pluginvar::value_ptr(Session *session, sql_var_t type, const LEX_STRING *)
1242
unsigned char* result;
1244
result= real_value_ptr(session, type);
1250
bool sys_var_pluginvar::check(Session *session, set_var *var)
1252
st_item_value_holder value;
1253
assert(is_readonly() || plugin_var->check);
1255
value.value_type= item_value_type;
1256
value.val_str= item_val_str;
1257
value.val_int= item_val_int;
1258
value.val_real= item_val_real;
1259
value.item= var->value;
1261
return is_readonly() ||
1262
plugin_var->check(session, plugin_var, &var->save_result, &value);
1266
void sys_var_pluginvar::set_default(Session *session, sql_var_t type)
1271
assert(is_readonly() || plugin_var->update);
1276
LOCK_global_system_variables.lock();
1277
tgt= real_value_ptr(session, type);
1278
src= ((void **) (plugin_var + 1) + 1);
1280
if (plugin_var->flags & PLUGIN_VAR_SessionLOCAL)
1282
if (type != OPT_GLOBAL)
1283
src= real_value_ptr(session, OPT_GLOBAL);
1285
switch (plugin_var->flags & PLUGIN_VAR_TYPEMASK) {
1286
case PLUGIN_VAR_INT:
1287
src= &((sessionvar_uint_t*) plugin_var)->def_val;
1289
case PLUGIN_VAR_LONG:
1290
src= &((sessionvar_ulong_t*) plugin_var)->def_val;
1292
case PLUGIN_VAR_LONGLONG:
1293
src= &((sessionvar_uint64_t_t*) plugin_var)->def_val;
1295
case PLUGIN_VAR_BOOL:
1296
src= &((sessionvar_bool_t*) plugin_var)->def_val;
1298
case PLUGIN_VAR_STR:
1299
src= &((sessionvar_str_t*) plugin_var)->def_val;
1306
/* session must equal current_session if PLUGIN_VAR_SessionLOCAL flag is set */
1307
assert(!(plugin_var->flags & PLUGIN_VAR_SessionLOCAL) ||
1308
session == current_session);
1310
if (!(plugin_var->flags & PLUGIN_VAR_SessionLOCAL) || type == OPT_GLOBAL)
1312
plugin_var->update(session, plugin_var, tgt, src);
1313
LOCK_global_system_variables.unlock();
1317
LOCK_global_system_variables.unlock();
1318
plugin_var->update(session, plugin_var, tgt, src);
1323
bool sys_var_pluginvar::update(Session *session, set_var *var)
1327
assert(is_readonly() || plugin_var->update);
1329
/* session must equal current_session if PLUGIN_VAR_SessionLOCAL flag is set */
1330
assert(!(plugin_var->flags & PLUGIN_VAR_SessionLOCAL) ||
1331
session == current_session);
1336
LOCK_global_system_variables.lock();
1337
tgt= real_value_ptr(session, var->type);
1339
if (!(plugin_var->flags & PLUGIN_VAR_SessionLOCAL) || var->type == OPT_GLOBAL)
1341
/* variable we are updating has global scope, so we unlock after updating */
1342
plugin_var->update(session, plugin_var, tgt, &var->save_result);
1343
LOCK_global_system_variables.unlock();
1347
LOCK_global_system_variables.unlock();
1348
plugin_var->update(session, plugin_var, tgt, &var->save_result);
1354
#define OPTION_SET_LIMITS(type, options, opt) \
1355
options->var_type= type; \
1356
options->def_value= (opt)->def_val; \
1357
options->min_value= (opt)->min_val; \
1358
options->max_value= (opt)->max_val; \
1359
options->block_size= (long) (opt)->blk_sz
1362
void plugin_opt_set_limits(struct option *options,
1363
const drizzle_sys_var *opt)
1365
options->sub_size= 0;
1367
switch (opt->flags & (PLUGIN_VAR_TYPEMASK |
1368
PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_SessionLOCAL)) {
1369
/* global system variables */
1370
case PLUGIN_VAR_INT:
1371
OPTION_SET_LIMITS(GET_INT, options, (sysvar_int_t*) opt);
1373
case PLUGIN_VAR_INT | PLUGIN_VAR_UNSIGNED:
1374
OPTION_SET_LIMITS(GET_UINT, options, (sysvar_uint_t*) opt);
1376
case PLUGIN_VAR_LONG:
1377
OPTION_SET_LIMITS(GET_LONG, options, (sysvar_long_t*) opt);
1379
case PLUGIN_VAR_LONG | PLUGIN_VAR_UNSIGNED:
1380
OPTION_SET_LIMITS(GET_ULONG_IS_FAIL, options, (sysvar_ulong_t*) opt);
1382
case PLUGIN_VAR_LONGLONG:
1383
OPTION_SET_LIMITS(GET_LL, options, (sysvar_int64_t_t*) opt);
1385
case PLUGIN_VAR_LONGLONG | PLUGIN_VAR_UNSIGNED:
1386
OPTION_SET_LIMITS(GET_ULL, options, (sysvar_uint64_t_t*) opt);
1388
case PLUGIN_VAR_BOOL:
1389
options->var_type= GET_BOOL;
1390
options->def_value= ((sysvar_bool_t*) opt)->def_val;
1392
case PLUGIN_VAR_STR:
1393
options->var_type= ((opt->flags & PLUGIN_VAR_MEMALLOC) ?
1394
GET_STR_ALLOC : GET_STR);
1395
options->def_value= (intptr_t) ((sysvar_str_t*) opt)->def_val;
1397
/* threadlocal variables */
1398
case PLUGIN_VAR_INT | PLUGIN_VAR_SessionLOCAL:
1399
OPTION_SET_LIMITS(GET_INT, options, (sessionvar_int_t*) opt);
1401
case PLUGIN_VAR_INT | PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_SessionLOCAL:
1402
OPTION_SET_LIMITS(GET_UINT, options, (sessionvar_uint_t*) opt);
1404
case PLUGIN_VAR_LONG | PLUGIN_VAR_SessionLOCAL:
1405
OPTION_SET_LIMITS(GET_LONG, options, (sessionvar_long_t*) opt);
1407
case PLUGIN_VAR_LONG | PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_SessionLOCAL:
1408
OPTION_SET_LIMITS(GET_ULONG_IS_FAIL, options, (sessionvar_ulong_t*) opt);
1410
case PLUGIN_VAR_LONGLONG | PLUGIN_VAR_SessionLOCAL:
1411
OPTION_SET_LIMITS(GET_LL, options, (sessionvar_int64_t_t*) opt);
1413
case PLUGIN_VAR_LONGLONG | PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_SessionLOCAL:
1414
OPTION_SET_LIMITS(GET_ULL, options, (sessionvar_uint64_t_t*) opt);
1416
case PLUGIN_VAR_BOOL | PLUGIN_VAR_SessionLOCAL:
1417
options->var_type= GET_BOOL;
1418
options->def_value= ((sessionvar_bool_t*) opt)->def_val;
1420
case PLUGIN_VAR_STR | PLUGIN_VAR_SessionLOCAL:
1421
options->var_type= ((opt->flags & PLUGIN_VAR_MEMALLOC) ?
1422
GET_STR_ALLOC : GET_STR);
1423
options->def_value= (intptr_t) ((sessionvar_str_t*) opt)->def_val;
1428
options->arg_type= REQUIRED_ARG;
1429
if (opt->flags & PLUGIN_VAR_NOCMDARG)
1430
options->arg_type= NO_ARG;
1431
if (opt->flags & PLUGIN_VAR_OPCMDARG)
1432
options->arg_type= OPT_ARG;
1435
static int construct_options(memory::Root *mem_root, module::Module *tmp,
1439
int localoptionid= 256;
1440
const string plugin_name(tmp->getManifest().name);
1442
size_t namelen= plugin_name.size(), optnamelen;
1445
int index= 0, offset= 0;
1446
drizzle_sys_var *opt, **plugin_option;
1449
string name(plugin_name);
1450
transform(name.begin(), name.end(), name.begin(), ::tolower);
1452
underscores_to_dashes(name);
1455
Two passes as the 2nd pass will take pointer addresses for use
1456
by my_getopt and register_var() in the first pass uses realloc
1459
for (plugin_option= tmp->getManifest().system_vars;
1460
plugin_option && *plugin_option; plugin_option++, index++)
1462
opt= *plugin_option;
1463
if (!(opt->flags & PLUGIN_VAR_SessionLOCAL))
1465
if (!(register_var(name, opt->name, opt->flags)))
1467
switch (opt->flags & PLUGIN_VAR_TYPEMASK) {
1468
case PLUGIN_VAR_BOOL:
1469
(((sessionvar_bool_t *)opt)->resolve)= mysql_sys_var_ptr_bool;
1471
case PLUGIN_VAR_INT:
1472
(((sessionvar_int_t *)opt)->resolve)= mysql_sys_var_ptr_int;
1474
case PLUGIN_VAR_LONG:
1475
(((sessionvar_long_t *)opt)->resolve)= mysql_sys_var_ptr_long;
1477
case PLUGIN_VAR_LONGLONG:
1478
(((sessionvar_int64_t_t *)opt)->resolve)= mysql_sys_var_ptr_int64_t;
1480
case PLUGIN_VAR_STR:
1481
(((sessionvar_str_t *)opt)->resolve)= mysql_sys_var_ptr_str;
1484
errmsg_printf(ERRMSG_LVL_ERROR, _("Unknown variable type code 0x%x in plugin '%s'."),
1485
opt->flags, plugin_name.c_str());
1490
for (plugin_option= tmp->getManifest().system_vars;
1491
plugin_option && *plugin_option; plugin_option++, index++)
1493
switch ((opt= *plugin_option)->flags & PLUGIN_VAR_TYPEMASK) {
1494
case PLUGIN_VAR_BOOL:
1496
opt->check= check_func_bool;
1498
opt->update= update_func_bool;
1500
case PLUGIN_VAR_INT:
1502
opt->check= check_func_int;
1504
opt->update= update_func_int;
1506
case PLUGIN_VAR_LONG:
1508
opt->check= check_func_long;
1510
opt->update= update_func_long;
1512
case PLUGIN_VAR_LONGLONG:
1514
opt->check= check_func_int64_t;
1516
opt->update= update_func_int64_t;
1518
case PLUGIN_VAR_STR:
1520
opt->check= check_func_str;
1523
opt->update= update_func_str;
1524
if ((opt->flags & (PLUGIN_VAR_MEMALLOC | PLUGIN_VAR_READONLY)) == false)
1526
opt->flags|= PLUGIN_VAR_READONLY;
1527
errmsg_printf(ERRMSG_LVL_WARN, _("Server variable %s of plugin %s was forced "
1528
"to be read-only: string variable without "
1529
"update_func and PLUGIN_VAR_MEMALLOC flag"),
1530
opt->name, plugin_name.c_str());
1535
errmsg_printf(ERRMSG_LVL_ERROR, _("Unknown variable type code 0x%x in plugin '%s'."),
1536
opt->flags, plugin_name.c_str());
1540
if ((opt->flags & (PLUGIN_VAR_NOCMDOPT | PLUGIN_VAR_SessionLOCAL))
1541
== PLUGIN_VAR_NOCMDOPT)
1546
errmsg_printf(ERRMSG_LVL_ERROR, _("Missing variable name in plugin '%s'."),
1547
plugin_name.c_str());
1551
if (!(opt->flags & PLUGIN_VAR_SessionLOCAL))
1553
optnamelen= strlen(opt->name);
1554
optname= (char*) mem_root->alloc_root(namelen + optnamelen + 2);
1555
sprintf(optname, "%s-%s", name.c_str(), opt->name);
1556
optnamelen= namelen + optnamelen + 1;
1560
/* this should not fail because register_var should create entry */
1561
if (!(v= find_bookmark(name, opt->name, opt->flags)))
1563
errmsg_printf(ERRMSG_LVL_ERROR, _("Thread local variable '%s' not allocated "
1564
"in plugin '%s'."), opt->name, plugin_name.c_str());
1568
*(int*)(opt + 1)= offset= v->offset;
1570
if (opt->flags & PLUGIN_VAR_NOCMDOPT)
1573
optname= (char*) mem_root->memdup_root(v->key.c_str(), (optnamelen= v->key.size()) + 1);
1576
/* convert '_' to '-' */
1577
for (p= optname; *p; p++)
1581
options->name= optname;
1582
options->comment= opt->comment;
1583
options->app_type= opt;
1584
options->id= localoptionid++;
1586
plugin_opt_set_limits(options, opt);
1588
if (opt->flags & PLUGIN_VAR_SessionLOCAL)
1589
options->value= options->u_max_value= (char**)
1590
(global_system_variables.dynamic_variables_ptr + offset);
1592
options->value= options->u_max_value= *(char***) (opt + 1);
1601
static option *construct_help_options(memory::Root *mem_root, module::Module *p)
1603
drizzle_sys_var **opt;
1605
uint32_t count= EXTRA_OPTIONS;
1607
for (opt= p->getManifest().system_vars; opt && *opt; opt++, count++) {};
1609
opts= (option*)mem_root->alloc_root((sizeof(option) * count));
1613
memset(opts, 0, sizeof(option) * count);
1615
if (construct_options(mem_root, p, opts))
1621
void drizzle_add_plugin_sysvar(sys_var_pluginvar *var)
1623
plugin_sysvar_vec.push_back(var);
1626
void drizzle_del_plugin_sysvar()
1628
vector<sys_var_pluginvar *>::iterator iter= plugin_sysvar_vec.begin();
1629
while(iter != plugin_sysvar_vec.end())
1634
plugin_sysvar_vec.clear();