503
564
global_variables_dynamic_size= 0;
567
/****************************************************************************
568
Internal type declarations for variables support
569
****************************************************************************/
571
#undef DRIZZLE_SYSVAR_NAME
572
#define DRIZZLE_SYSVAR_NAME(name) name
573
#define PLUGIN_VAR_TYPEMASK 0x007f
575
static const uint32_t EXTRA_OPTIONS= 1; /* handle the NULL option */
577
typedef DECLARE_DRIZZLE_SYSVAR_BOOL(sysvar_bool_t);
578
typedef DECLARE_DRIZZLE_SessionVAR_BOOL(sessionvar_bool_t);
579
typedef DECLARE_DRIZZLE_SYSVAR_BASIC(sysvar_str_t, char *);
580
typedef DECLARE_DRIZZLE_SessionVAR_BASIC(sessionvar_str_t, char *);
582
typedef DECLARE_DRIZZLE_SessionVAR_TYPELIB(sessionvar_enum_t, unsigned long);
583
typedef DECLARE_DRIZZLE_SessionVAR_TYPELIB(sessionvar_set_t, uint64_t);
585
typedef DECLARE_DRIZZLE_SYSVAR_SIMPLE(sysvar_int_t, int);
586
typedef DECLARE_DRIZZLE_SYSVAR_SIMPLE(sysvar_long_t, long);
587
typedef DECLARE_DRIZZLE_SYSVAR_SIMPLE(sysvar_int64_t_t, int64_t);
588
typedef DECLARE_DRIZZLE_SYSVAR_SIMPLE(sysvar_uint_t, uint);
589
typedef DECLARE_DRIZZLE_SYSVAR_SIMPLE(sysvar_ulong_t, ulong);
590
typedef DECLARE_DRIZZLE_SYSVAR_SIMPLE(sysvar_uint64_t_t, uint64_t);
592
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_int_t, int);
593
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_long_t, long);
594
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_int64_t_t, int64_t);
595
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_uint_t, uint);
596
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_ulong_t, ulong);
597
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_uint64_t_t, uint64_t);
599
typedef bool *(*mysql_sys_var_ptr_p)(Session* a_session, int offset);
602
/****************************************************************************
603
default variable data check and update functions
604
****************************************************************************/
606
static int check_func_bool(Session *, drizzle_sys_var *var,
607
void *save, drizzle_value *value)
609
char buff[STRING_BUFFER_USUAL_SIZE];
610
const char *strvalue= "NULL", *str;
614
if (value->value_type(value) == DRIZZLE_VALUE_TYPE_STRING)
616
length= sizeof(buff);
617
if (!(str= value->val_str(value, buff, &length)) ||
618
(result= find_type(&bool_typelib, str, length, 1)-1) < 0)
627
if (value->val_int(value, &tmp) < 0)
631
internal::llstr(tmp, buff);
637
*(int*)save= -result;
640
my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), var->name, strvalue);
645
static int check_func_int(Session *session, drizzle_sys_var *var,
646
void *save, drizzle_value *value)
650
struct option options;
651
value->val_int(value, &tmp);
652
plugin_opt_set_limits(&options, var);
654
if (var->flags & PLUGIN_VAR_UNSIGNED)
655
*(uint32_t *)save= (uint32_t) getopt_ull_limit_value((uint64_t) tmp, &options,
658
*(int *)save= (int) getopt_ll_limit_value(tmp, &options, &fixed);
660
return throw_bounds_warning(session, fixed, var->flags & PLUGIN_VAR_UNSIGNED,
661
var->name, (int64_t) tmp);
665
static int check_func_long(Session *session, drizzle_sys_var *var,
666
void *save, drizzle_value *value)
670
struct option options;
671
value->val_int(value, &tmp);
672
plugin_opt_set_limits(&options, var);
674
if (var->flags & PLUGIN_VAR_UNSIGNED)
675
*(ulong *)save= (ulong) getopt_ull_limit_value((uint64_t) tmp, &options,
678
*(long *)save= (long) getopt_ll_limit_value(tmp, &options, &fixed);
680
return throw_bounds_warning(session, fixed, var->flags & PLUGIN_VAR_UNSIGNED,
681
var->name, (int64_t) tmp);
685
static int check_func_int64_t(Session *session, drizzle_sys_var *var,
686
void *save, drizzle_value *value)
690
struct option options;
691
value->val_int(value, &tmp);
692
plugin_opt_set_limits(&options, var);
694
if (var->flags & PLUGIN_VAR_UNSIGNED)
695
*(uint64_t *)save= getopt_ull_limit_value((uint64_t) tmp, &options,
698
*(int64_t *)save= getopt_ll_limit_value(tmp, &options, &fixed);
700
return throw_bounds_warning(session, fixed, var->flags & PLUGIN_VAR_UNSIGNED,
701
var->name, (int64_t) tmp);
704
static int check_func_str(Session *session, drizzle_sys_var *,
705
void *save, drizzle_value *value)
707
char buff[STRING_BUFFER_USUAL_SIZE];
711
length= sizeof(buff);
712
if ((str= value->val_str(value, buff, &length)))
713
str= session->strmake(str, length);
714
*(const char**)save= str;
719
static void update_func_bool(Session *, drizzle_sys_var *,
720
void *tgt, const void *save)
722
*(bool *) tgt= *(int *) save ? 1 : 0;
726
static void update_func_int(Session *, drizzle_sys_var *,
727
void *tgt, const void *save)
729
*(int *)tgt= *(int *) save;
733
static void update_func_long(Session *, drizzle_sys_var *,
734
void *tgt, const void *save)
736
*(long *)tgt= *(long *) save;
740
static void update_func_int64_t(Session *, drizzle_sys_var *,
741
void *tgt, const void *save)
743
*(int64_t *)tgt= *(uint64_t *) save;
747
static void update_func_str(Session *, drizzle_sys_var *var,
748
void *tgt, const void *save)
750
char *old= *(char **) tgt;
751
*(char **)tgt= *(char **) save;
752
if (var->flags & PLUGIN_VAR_MEMALLOC)
754
*(char **)tgt= strdup(*(char **) save);
757
* There isn't a _really_ good thing to do here until this whole set_var
758
* mess gets redesigned
761
errmsg_printf(ERRMSG_LVL_ERROR, _("Out of memory."));
507
767
/****************************************************************************
508
768
System Variables support
509
769
****************************************************************************/
772
sys_var *find_sys_var(Session *, const char *str, uint32_t length)
775
sys_var_pluginvar *pi= NULL;
776
module::Module *module;
778
if ((var= intern_find_sys_var(str, length, false)) &&
779
(pi= var->cast_pluginvar()))
781
if (!(module= pi->plugin))
782
var= NULL; /* failed to lock it, it must be uninstalling */
783
else if (module->isInited == false)
790
If the variable exists but the plugin it is associated with is not ready
791
then the intern_plugin_lock did not raise an error, so we do it here.
795
my_error(ER_UNKNOWN_SYSTEM_VARIABLE, MYF(0), (char*) str);
801
static const string make_bookmark_name(const string &plugin, const char *name)
803
string varname(plugin);
804
varname.push_back('_');
805
varname.append(name);
807
for (string::iterator p= varname.begin() + 1; p != varname.end(); ++p)
818
called by register_var, construct_options and test_plugin_options.
819
Returns the 'bookmark' for the named variable.
820
LOCK_system_variables_hash should be at least read locked
822
static Bookmark *find_bookmark(const string &plugin, const char *name, int flags)
824
if (!(flags & PLUGIN_VAR_SessionLOCAL))
827
const string varname(make_bookmark_name(plugin, name));
829
bookmark_unordered_map::iterator iter= bookmark_hash.find(varname);
830
if (iter != bookmark_hash.end())
832
return &((*iter).second);
839
returns a bookmark for session-local variables, creating if neccessary.
840
returns null for non session-local variables.
841
Requires that a write lock is obtained on LOCK_system_variables_hash
843
static Bookmark *register_var(const string &plugin, const char *name,
846
if (!(flags & PLUGIN_VAR_SessionLOCAL))
849
uint32_t size= 0, offset, new_size;
850
Bookmark *result= NULL;
852
switch (flags & PLUGIN_VAR_TYPEMASK) {
853
case PLUGIN_VAR_BOOL:
854
size= ALIGN_SIZE(sizeof(bool));
857
size= ALIGN_SIZE(sizeof(int));
859
case PLUGIN_VAR_LONG:
860
size= ALIGN_SIZE(sizeof(long));
862
case PLUGIN_VAR_LONGLONG:
863
size= ALIGN_SIZE(sizeof(uint64_t));
866
size= ALIGN_SIZE(sizeof(char*));
874
if (!(result= find_bookmark(plugin, name, flags)))
876
const string varname(make_bookmark_name(plugin, name));
878
Bookmark new_bookmark;
879
new_bookmark.key= varname;
880
new_bookmark.offset= -1;
882
assert(size && !(size & (size-1))); /* must be power of 2 */
884
offset= global_system_variables.dynamic_variables_size;
885
offset= (offset + size - 1) & ~(size - 1);
886
new_bookmark.offset= (int) offset;
888
new_size= (offset + size + 63) & ~63;
890
if (new_size > global_variables_dynamic_size)
894
(char *)realloc(global_system_variables.dynamic_variables_ptr,
897
global_system_variables.dynamic_variables_ptr= tmpptr;
900
(char *)realloc(max_system_variables.dynamic_variables_ptr,
903
max_system_variables.dynamic_variables_ptr= tmpptr;
906
Clear the new variable value space. This is required for string
907
variables. If their value is non-NULL, it must point to a valid
910
memset(global_system_variables.dynamic_variables_ptr +
911
global_variables_dynamic_size, 0,
912
new_size - global_variables_dynamic_size);
913
memset(max_system_variables.dynamic_variables_ptr +
914
global_variables_dynamic_size, 0,
915
new_size - global_variables_dynamic_size);
916
global_variables_dynamic_size= new_size;
919
global_system_variables.dynamic_variables_head= offset;
920
max_system_variables.dynamic_variables_head= offset;
921
global_system_variables.dynamic_variables_size= offset + size;
922
max_system_variables.dynamic_variables_size= offset + size;
923
global_system_variables.dynamic_variables_version++;
924
max_system_variables.dynamic_variables_version++;
926
new_bookmark.version= global_system_variables.dynamic_variables_version;
927
new_bookmark.type_code= flags;
929
/* this should succeed because we have already checked if a dup exists */
930
bookmark_hash.insert(make_pair(varname, new_bookmark));
931
result= find_bookmark(plugin, name, flags);
938
returns a pointer to the memory which holds the session-local variable or
939
a pointer to the global variable if session==null.
940
If required, will sync with global variables if the requested variable
941
has not yet been allocated in the current thread.
943
static unsigned char *intern_sys_var_ptr(Session* session, int offset, bool global_lock)
946
assert((uint32_t)offset <= global_system_variables.dynamic_variables_head);
949
return (unsigned char*) global_system_variables.dynamic_variables_ptr + offset;
952
dynamic_variables_head points to the largest valid offset
954
if (!session->variables.dynamic_variables_ptr ||
955
(uint32_t)offset > session->variables.dynamic_variables_head)
958
if (!(tmpptr= (char *)realloc(session->variables.dynamic_variables_ptr,
959
global_variables_dynamic_size)))
961
session->variables.dynamic_variables_ptr= tmpptr;
964
LOCK_global_system_variables.lock();
966
//safe_mutex_assert_owner(&LOCK_global_system_variables);
968
memcpy(session->variables.dynamic_variables_ptr +
969
session->variables.dynamic_variables_size,
970
global_system_variables.dynamic_variables_ptr +
971
session->variables.dynamic_variables_size,
972
global_system_variables.dynamic_variables_size -
973
session->variables.dynamic_variables_size);
976
now we need to iterate through any newly copied 'defaults'
977
and if it is a string type with MEMALLOC flag, we need to strdup
979
bookmark_unordered_map::iterator iter= bookmark_hash.begin();
980
for (; iter != bookmark_hash.end() ; ++iter)
982
sys_var_pluginvar *pi;
984
const Bookmark &v= (*iter).second;
985
const string var_name((*iter).first);
987
if (v.version <= session->variables.dynamic_variables_version ||
988
!(var= intern_find_sys_var(var_name.c_str(), var_name.size(), true)) ||
989
!(pi= var->cast_pluginvar()) ||
990
v.type_code != (pi->plugin_var->flags & PLUGIN_VAR_TYPEMASK))
993
/* Here we do anything special that may be required of the data types */
995
if ((pi->plugin_var->flags & PLUGIN_VAR_TYPEMASK) == PLUGIN_VAR_STR &&
996
pi->plugin_var->flags & PLUGIN_VAR_MEMALLOC)
998
char **pp= (char**) (session->variables.dynamic_variables_ptr +
999
*(int*)(pi->plugin_var + 1));
1000
if ((*pp= *(char**) (global_system_variables.dynamic_variables_ptr +
1001
*(int*)(pi->plugin_var + 1))))
1009
LOCK_global_system_variables.unlock();
1011
session->variables.dynamic_variables_version=
1012
global_system_variables.dynamic_variables_version;
1013
session->variables.dynamic_variables_head=
1014
global_system_variables.dynamic_variables_head;
1015
session->variables.dynamic_variables_size=
1016
global_system_variables.dynamic_variables_size;
1018
return (unsigned char*)session->variables.dynamic_variables_ptr + offset;
1021
static bool *mysql_sys_var_ptr_bool(Session* a_session, int offset)
1023
return (bool *)intern_sys_var_ptr(a_session, offset, true);
1026
static int *mysql_sys_var_ptr_int(Session* a_session, int offset)
1028
return (int *)intern_sys_var_ptr(a_session, offset, true);
1031
static long *mysql_sys_var_ptr_long(Session* a_session, int offset)
1033
return (long *)intern_sys_var_ptr(a_session, offset, true);
1036
static int64_t *mysql_sys_var_ptr_int64_t(Session* a_session, int offset)
1038
return (int64_t *)intern_sys_var_ptr(a_session, offset, true);
1041
static char **mysql_sys_var_ptr_str(Session* a_session, int offset)
1043
return (char **)intern_sys_var_ptr(a_session, offset, true);
513
1046
void plugin_sessionvar_init(Session *session)
1097
@brief Free values of thread variables of a plugin.
1099
This must be called before a plugin is deleted. Otherwise its
1100
variables are no longer accessible and the value space is lost. Note
1101
that only string values with PLUGIN_VAR_MEMALLOC are allocated and
1104
@param[in] vars Chain of system variables of a plugin
1107
static void plugin_vars_free_values(module::Module::Variables &vars)
1110
for (module::Module::Variables::iterator iter= vars.begin();
1114
sys_var_pluginvar *piv= (*iter)->cast_pluginvar();
1116
((piv->plugin_var->flags & PLUGIN_VAR_TYPEMASK) == PLUGIN_VAR_STR) &&
1117
(piv->plugin_var->flags & PLUGIN_VAR_MEMALLOC))
1119
/* Free the string from global_system_variables. */
1120
char **valptr= (char**) piv->real_value_ptr(NULL, OPT_GLOBAL);
1129
bool sys_var_pluginvar::check_update_type(Item_result type)
1133
switch (plugin_var->flags & PLUGIN_VAR_TYPEMASK) {
1134
case PLUGIN_VAR_INT:
1135
case PLUGIN_VAR_LONG:
1136
case PLUGIN_VAR_LONGLONG:
1137
return type != INT_RESULT;
1138
case PLUGIN_VAR_STR:
1139
return type != STRING_RESULT;
1146
SHOW_TYPE sys_var_pluginvar::show_type()
1148
switch (plugin_var->flags & PLUGIN_VAR_TYPEMASK) {
1149
case PLUGIN_VAR_BOOL:
1150
return SHOW_MY_BOOL;
1151
case PLUGIN_VAR_INT:
1153
case PLUGIN_VAR_LONG:
1155
case PLUGIN_VAR_LONGLONG:
1156
return SHOW_LONGLONG;
1157
case PLUGIN_VAR_STR:
1158
return SHOW_CHAR_PTR;
1166
unsigned char* sys_var_pluginvar::real_value_ptr(Session *session, sql_var_t type)
1168
assert(session || (type == OPT_GLOBAL));
1169
if (plugin_var->flags & PLUGIN_VAR_SessionLOCAL)
1171
if (type == OPT_GLOBAL)
1174
return intern_sys_var_ptr(session, *(int*) (plugin_var+1), false);
1176
return *(unsigned char**) (plugin_var+1);
1180
TYPELIB* sys_var_pluginvar::plugin_var_typelib(void)
1182
switch (plugin_var->flags & (PLUGIN_VAR_TYPEMASK | PLUGIN_VAR_SessionLOCAL)) {
1183
case PLUGIN_VAR_SessionLOCAL:
1184
return ((sessionvar_enum_t *)plugin_var)->typelib;
1192
unsigned char* sys_var_pluginvar::value_ptr(Session *session, sql_var_t type, const LEX_STRING *)
1194
unsigned char* result;
1196
result= real_value_ptr(session, type);
1202
bool sys_var_pluginvar::check(Session *session, set_var *var)
1204
st_item_value_holder value;
1205
assert(is_readonly() || plugin_var->check);
1207
value.value_type= item_value_type;
1208
value.val_str= item_val_str;
1209
value.val_int= item_val_int;
1210
value.val_real= item_val_real;
1211
value.item= var->value;
1213
return is_readonly() ||
1214
plugin_var->check(session, plugin_var, &var->save_result, &value);
1218
void sys_var_pluginvar::set_default(Session *session, sql_var_t type)
1223
assert(is_readonly() || plugin_var->update);
1228
LOCK_global_system_variables.lock();
1229
tgt= real_value_ptr(session, type);
1230
src= ((void **) (plugin_var + 1) + 1);
1232
if (plugin_var->flags & PLUGIN_VAR_SessionLOCAL)
1234
if (type != OPT_GLOBAL)
1235
src= real_value_ptr(session, OPT_GLOBAL);
1237
switch (plugin_var->flags & PLUGIN_VAR_TYPEMASK) {
1238
case PLUGIN_VAR_INT:
1239
src= &((sessionvar_uint_t*) plugin_var)->def_val;
1241
case PLUGIN_VAR_LONG:
1242
src= &((sessionvar_ulong_t*) plugin_var)->def_val;
1244
case PLUGIN_VAR_LONGLONG:
1245
src= &((sessionvar_uint64_t_t*) plugin_var)->def_val;
1247
case PLUGIN_VAR_BOOL:
1248
src= &((sessionvar_bool_t*) plugin_var)->def_val;
1250
case PLUGIN_VAR_STR:
1251
src= &((sessionvar_str_t*) plugin_var)->def_val;
1258
/* session must equal current_session if PLUGIN_VAR_SessionLOCAL flag is set */
1259
assert(!(plugin_var->flags & PLUGIN_VAR_SessionLOCAL) ||
1260
session == current_session);
1262
if (!(plugin_var->flags & PLUGIN_VAR_SessionLOCAL) || type == OPT_GLOBAL)
1264
plugin_var->update(session, plugin_var, tgt, src);
1265
LOCK_global_system_variables.unlock();
1269
LOCK_global_system_variables.unlock();
1270
plugin_var->update(session, plugin_var, tgt, src);
1275
bool sys_var_pluginvar::update(Session *session, set_var *var)
1279
assert(is_readonly() || plugin_var->update);
1281
/* session must equal current_session if PLUGIN_VAR_SessionLOCAL flag is set */
1282
assert(!(plugin_var->flags & PLUGIN_VAR_SessionLOCAL) ||
1283
session == current_session);
1288
LOCK_global_system_variables.lock();
1289
tgt= real_value_ptr(session, var->type);
1291
if (!(plugin_var->flags & PLUGIN_VAR_SessionLOCAL) || var->type == OPT_GLOBAL)
1293
/* variable we are updating has global scope, so we unlock after updating */
1294
plugin_var->update(session, plugin_var, tgt, &var->save_result);
1295
LOCK_global_system_variables.unlock();
1299
LOCK_global_system_variables.unlock();
1300
plugin_var->update(session, plugin_var, tgt, &var->save_result);
1306
#define OPTION_SET_LIMITS(type, options, opt) \
1307
options->var_type= type; \
1308
options->def_value= (opt)->def_val; \
1309
options->min_value= (opt)->min_val; \
1310
options->max_value= (opt)->max_val; \
1311
options->block_size= (long) (opt)->blk_sz
1314
void plugin_opt_set_limits(struct option *options,
1315
const drizzle_sys_var *opt)
1317
options->sub_size= 0;
1319
switch (opt->flags & (PLUGIN_VAR_TYPEMASK |
1320
PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_SessionLOCAL)) {
1321
/* global system variables */
1322
case PLUGIN_VAR_INT:
1323
OPTION_SET_LIMITS(GET_INT, options, (sysvar_int_t*) opt);
1325
case PLUGIN_VAR_INT | PLUGIN_VAR_UNSIGNED:
1326
OPTION_SET_LIMITS(GET_UINT, options, (sysvar_uint_t*) opt);
1328
case PLUGIN_VAR_LONG:
1329
OPTION_SET_LIMITS(GET_LONG, options, (sysvar_long_t*) opt);
1331
case PLUGIN_VAR_LONG | PLUGIN_VAR_UNSIGNED:
1332
OPTION_SET_LIMITS(GET_ULONG_IS_FAIL, options, (sysvar_ulong_t*) opt);
1334
case PLUGIN_VAR_LONGLONG:
1335
OPTION_SET_LIMITS(GET_LL, options, (sysvar_int64_t_t*) opt);
1337
case PLUGIN_VAR_LONGLONG | PLUGIN_VAR_UNSIGNED:
1338
OPTION_SET_LIMITS(GET_ULL, options, (sysvar_uint64_t_t*) opt);
1340
case PLUGIN_VAR_BOOL:
1341
options->var_type= GET_BOOL;
1342
options->def_value= ((sysvar_bool_t*) opt)->def_val;
1344
case PLUGIN_VAR_STR:
1345
options->var_type= ((opt->flags & PLUGIN_VAR_MEMALLOC) ?
1346
GET_STR_ALLOC : GET_STR);
1347
options->def_value= (intptr_t) ((sysvar_str_t*) opt)->def_val;
1349
/* threadlocal variables */
1350
case PLUGIN_VAR_INT | PLUGIN_VAR_SessionLOCAL:
1351
OPTION_SET_LIMITS(GET_INT, options, (sessionvar_int_t*) opt);
1353
case PLUGIN_VAR_INT | PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_SessionLOCAL:
1354
OPTION_SET_LIMITS(GET_UINT, options, (sessionvar_uint_t*) opt);
1356
case PLUGIN_VAR_LONG | PLUGIN_VAR_SessionLOCAL:
1357
OPTION_SET_LIMITS(GET_LONG, options, (sessionvar_long_t*) opt);
1359
case PLUGIN_VAR_LONG | PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_SessionLOCAL:
1360
OPTION_SET_LIMITS(GET_ULONG_IS_FAIL, options, (sessionvar_ulong_t*) opt);
1362
case PLUGIN_VAR_LONGLONG | PLUGIN_VAR_SessionLOCAL:
1363
OPTION_SET_LIMITS(GET_LL, options, (sessionvar_int64_t_t*) opt);
1365
case PLUGIN_VAR_LONGLONG | PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_SessionLOCAL:
1366
OPTION_SET_LIMITS(GET_ULL, options, (sessionvar_uint64_t_t*) opt);
1368
case PLUGIN_VAR_BOOL | PLUGIN_VAR_SessionLOCAL:
1369
options->var_type= GET_BOOL;
1370
options->def_value= ((sessionvar_bool_t*) opt)->def_val;
1372
case PLUGIN_VAR_STR | PLUGIN_VAR_SessionLOCAL:
1373
options->var_type= ((opt->flags & PLUGIN_VAR_MEMALLOC) ?
1374
GET_STR_ALLOC : GET_STR);
1375
options->def_value= (intptr_t) ((sessionvar_str_t*) opt)->def_val;
1380
options->arg_type= REQUIRED_ARG;
1381
if (opt->flags & PLUGIN_VAR_NOCMDARG)
1382
options->arg_type= NO_ARG;
1383
if (opt->flags & PLUGIN_VAR_OPCMDARG)
1384
options->arg_type= OPT_ARG;
1387
static int construct_options(memory::Root *mem_root, module::Module *tmp,
1391
int localoptionid= 256;
1392
const string plugin_name(tmp->getManifest().name);
1394
size_t namelen= plugin_name.size(), optnamelen;
1397
int index= 0, offset= 0;
1398
drizzle_sys_var *opt, **plugin_option;
1401
string name(plugin_name);
1402
transform(name.begin(), name.end(), name.begin(), ::tolower);
1404
for (string::iterator iter= name.begin(); iter != name.end(); ++iter)
1411
Two passes as the 2nd pass will take pointer addresses for use
1412
by my_getopt and register_var() in the first pass uses realloc
1415
for (plugin_option= tmp->getManifest().system_vars;
1416
plugin_option && *plugin_option; plugin_option++, index++)
1418
opt= *plugin_option;
1419
if (!(opt->flags & PLUGIN_VAR_SessionLOCAL))
1421
if (!(register_var(name, opt->name, opt->flags)))
1423
switch (opt->flags & PLUGIN_VAR_TYPEMASK) {
1424
case PLUGIN_VAR_BOOL:
1425
(((sessionvar_bool_t *)opt)->resolve)= mysql_sys_var_ptr_bool;
1427
case PLUGIN_VAR_INT:
1428
(((sessionvar_int_t *)opt)->resolve)= mysql_sys_var_ptr_int;
1430
case PLUGIN_VAR_LONG:
1431
(((sessionvar_long_t *)opt)->resolve)= mysql_sys_var_ptr_long;
1433
case PLUGIN_VAR_LONGLONG:
1434
(((sessionvar_int64_t_t *)opt)->resolve)= mysql_sys_var_ptr_int64_t;
1436
case PLUGIN_VAR_STR:
1437
(((sessionvar_str_t *)opt)->resolve)= mysql_sys_var_ptr_str;
1440
errmsg_printf(ERRMSG_LVL_ERROR, _("Unknown variable type code 0x%x in plugin '%s'."),
1441
opt->flags, plugin_name.c_str());
1446
for (plugin_option= tmp->getManifest().system_vars;
1447
plugin_option && *plugin_option; plugin_option++, index++)
1449
switch ((opt= *plugin_option)->flags & PLUGIN_VAR_TYPEMASK) {
1450
case PLUGIN_VAR_BOOL:
1452
opt->check= check_func_bool;
1454
opt->update= update_func_bool;
1456
case PLUGIN_VAR_INT:
1458
opt->check= check_func_int;
1460
opt->update= update_func_int;
1462
case PLUGIN_VAR_LONG:
1464
opt->check= check_func_long;
1466
opt->update= update_func_long;
1468
case PLUGIN_VAR_LONGLONG:
1470
opt->check= check_func_int64_t;
1472
opt->update= update_func_int64_t;
1474
case PLUGIN_VAR_STR:
1476
opt->check= check_func_str;
1479
opt->update= update_func_str;
1480
if ((opt->flags & (PLUGIN_VAR_MEMALLOC | PLUGIN_VAR_READONLY)) == false)
1482
opt->flags|= PLUGIN_VAR_READONLY;
1483
errmsg_printf(ERRMSG_LVL_WARN, _("Server variable %s of plugin %s was forced "
1484
"to be read-only: string variable without "
1485
"update_func and PLUGIN_VAR_MEMALLOC flag"),
1486
opt->name, plugin_name.c_str());
1491
errmsg_printf(ERRMSG_LVL_ERROR, _("Unknown variable type code 0x%x in plugin '%s'."),
1492
opt->flags, plugin_name.c_str());
1496
if ((opt->flags & (PLUGIN_VAR_NOCMDOPT | PLUGIN_VAR_SessionLOCAL))
1497
== PLUGIN_VAR_NOCMDOPT)
1502
errmsg_printf(ERRMSG_LVL_ERROR, _("Missing variable name in plugin '%s'."),
1503
plugin_name.c_str());
1507
if (!(opt->flags & PLUGIN_VAR_SessionLOCAL))
1509
optnamelen= strlen(opt->name);
1510
optname= (char*) mem_root->alloc_root(namelen + optnamelen + 2);
1511
sprintf(optname, "%s-%s", name.c_str(), opt->name);
1512
optnamelen= namelen + optnamelen + 1;
1516
/* this should not fail because register_var should create entry */
1517
if (!(v= find_bookmark(name, opt->name, opt->flags)))
1519
errmsg_printf(ERRMSG_LVL_ERROR, _("Thread local variable '%s' not allocated "
1520
"in plugin '%s'."), opt->name, plugin_name.c_str());
1524
*(int*)(opt + 1)= offset= v->offset;
1526
if (opt->flags & PLUGIN_VAR_NOCMDOPT)
1529
optname= (char*) mem_root->memdup_root(v->key.c_str(), (optnamelen= v->key.size()) + 1);
1532
/* convert '_' to '-' */
1533
for (p= optname; *p; p++)
1537
options->name= optname;
1538
options->comment= opt->comment;
1539
options->app_type= opt;
1540
options->id= localoptionid++;
1542
plugin_opt_set_limits(options, opt);
1544
if (opt->flags & PLUGIN_VAR_SessionLOCAL)
1545
options->value= options->u_max_value= (char**)
1546
(global_system_variables.dynamic_variables_ptr + offset);
1548
options->value= options->u_max_value= *(char***) (opt + 1);
1557
static option *construct_help_options(memory::Root *mem_root, module::Module *p)
1559
drizzle_sys_var **opt;
1561
uint32_t count= EXTRA_OPTIONS;
1563
for (opt= p->getManifest().system_vars; opt && *opt; opt++, count++) {};
1565
opts= (option*)mem_root->alloc_root((sizeof(option) * count));
1569
memset(opts, 0, sizeof(option) * count);
1571
if (construct_options(mem_root, p, opts))
1577
void drizzle_add_plugin_sysvar(sys_var_pluginvar *var)
1579
plugin_sysvar_vec.push_back(var);
1582
void drizzle_del_plugin_sysvar()
1584
vector<sys_var_pluginvar *>::iterator iter= plugin_sysvar_vec.begin();
1585
while(iter != plugin_sysvar_vec.end())
1590
plugin_sysvar_vec.clear();