494
570
global_variables_dynamic_size= 0;
573
/****************************************************************************
574
Internal type declarations for variables support
575
****************************************************************************/
577
#undef DRIZZLE_SYSVAR_NAME
578
#define DRIZZLE_SYSVAR_NAME(name) name
579
#define PLUGIN_VAR_TYPEMASK 0x007f
581
static const uint32_t EXTRA_OPTIONS= 1; /* handle the NULL option */
583
typedef DECLARE_DRIZZLE_SYSVAR_BOOL(sysvar_bool_t);
584
typedef DECLARE_DRIZZLE_SessionVAR_BOOL(sessionvar_bool_t);
585
typedef DECLARE_DRIZZLE_SYSVAR_BASIC(sysvar_str_t, char *);
586
typedef DECLARE_DRIZZLE_SessionVAR_BASIC(sessionvar_str_t, char *);
588
typedef DECLARE_DRIZZLE_SessionVAR_TYPELIB(sessionvar_enum_t, unsigned long);
589
typedef DECLARE_DRIZZLE_SessionVAR_TYPELIB(sessionvar_set_t, uint64_t);
591
typedef DECLARE_DRIZZLE_SYSVAR_SIMPLE(sysvar_int_t, int);
592
typedef DECLARE_DRIZZLE_SYSVAR_SIMPLE(sysvar_long_t, long);
593
typedef DECLARE_DRIZZLE_SYSVAR_SIMPLE(sysvar_int64_t_t, int64_t);
594
typedef DECLARE_DRIZZLE_SYSVAR_SIMPLE(sysvar_uint_t, uint);
595
typedef DECLARE_DRIZZLE_SYSVAR_SIMPLE(sysvar_ulong_t, ulong);
596
typedef DECLARE_DRIZZLE_SYSVAR_SIMPLE(sysvar_uint64_t_t, uint64_t);
598
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_int_t, int);
599
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_long_t, long);
600
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_int64_t_t, int64_t);
601
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_uint_t, uint);
602
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_ulong_t, ulong);
603
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_uint64_t_t, uint64_t);
605
typedef bool *(*mysql_sys_var_ptr_p)(Session* a_session, int offset);
608
/****************************************************************************
609
default variable data check and update functions
610
****************************************************************************/
612
static int check_func_bool(Session *, drizzle_sys_var *var,
613
void *save, drizzle_value *value)
615
char buff[STRING_BUFFER_USUAL_SIZE];
616
const char *strvalue= "NULL", *str;
620
if (value->value_type(value) == DRIZZLE_VALUE_TYPE_STRING)
622
length= sizeof(buff);
623
if (!(str= value->val_str(value, buff, &length)) ||
624
(result= find_type(&bool_typelib, str, length, 1)-1) < 0)
633
if (value->val_int(value, &tmp) < 0)
637
internal::llstr(tmp, buff);
643
*(int*)save= -result;
646
my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), var->name, strvalue);
651
static int check_func_int(Session *session, drizzle_sys_var *var,
652
void *save, drizzle_value *value)
656
struct option options;
657
value->val_int(value, &tmp);
658
plugin_opt_set_limits(&options, var);
660
if (var->flags & PLUGIN_VAR_UNSIGNED)
661
*(uint32_t *)save= (uint32_t) getopt_ull_limit_value((uint64_t) tmp, &options,
664
*(int *)save= (int) getopt_ll_limit_value(tmp, &options, &fixed);
666
return throw_bounds_warning(session, fixed, var->flags & PLUGIN_VAR_UNSIGNED,
667
var->name, (int64_t) tmp);
671
static int check_func_long(Session *session, drizzle_sys_var *var,
672
void *save, drizzle_value *value)
676
struct option options;
677
value->val_int(value, &tmp);
678
plugin_opt_set_limits(&options, var);
680
if (var->flags & PLUGIN_VAR_UNSIGNED)
681
*(ulong *)save= (ulong) getopt_ull_limit_value((uint64_t) tmp, &options,
684
*(long *)save= (long) getopt_ll_limit_value(tmp, &options, &fixed);
686
return throw_bounds_warning(session, fixed, var->flags & PLUGIN_VAR_UNSIGNED,
687
var->name, (int64_t) tmp);
691
static int check_func_int64_t(Session *session, drizzle_sys_var *var,
692
void *save, drizzle_value *value)
696
struct option options;
697
value->val_int(value, &tmp);
698
plugin_opt_set_limits(&options, var);
700
if (var->flags & PLUGIN_VAR_UNSIGNED)
701
*(uint64_t *)save= getopt_ull_limit_value((uint64_t) tmp, &options,
704
*(int64_t *)save= getopt_ll_limit_value(tmp, &options, &fixed);
706
return throw_bounds_warning(session, fixed, var->flags & PLUGIN_VAR_UNSIGNED,
707
var->name, (int64_t) tmp);
710
static int check_func_str(Session *session, drizzle_sys_var *,
711
void *save, drizzle_value *value)
713
char buff[STRING_BUFFER_USUAL_SIZE];
717
length= sizeof(buff);
718
if ((str= value->val_str(value, buff, &length)))
719
str= session->strmake(str, length);
720
*(const char**)save= str;
725
static void update_func_bool(Session *, drizzle_sys_var *,
726
void *tgt, const void *save)
728
*(bool *) tgt= *(int *) save ? 1 : 0;
732
static void update_func_int(Session *, drizzle_sys_var *,
733
void *tgt, const void *save)
735
*(int *)tgt= *(int *) save;
739
static void update_func_long(Session *, drizzle_sys_var *,
740
void *tgt, const void *save)
742
*(long *)tgt= *(long *) save;
746
static void update_func_int64_t(Session *, drizzle_sys_var *,
747
void *tgt, const void *save)
749
*(int64_t *)tgt= *(uint64_t *) save;
753
static void update_func_str(Session *, drizzle_sys_var *var,
754
void *tgt, const void *save)
756
char *old= *(char **) tgt;
757
*(char **)tgt= *(char **) save;
758
if (var->flags & PLUGIN_VAR_MEMALLOC)
760
*(char **)tgt= strdup(*(char **) save);
763
* There isn't a _really_ good thing to do here until this whole set_var
764
* mess gets redesigned
767
errmsg_printf(ERRMSG_LVL_ERROR, _("Out of memory."));
498
773
/****************************************************************************
499
774
System Variables support
500
775
****************************************************************************/
503
sys_var *find_sys_var(const char *str, uint32_t length)
505
return intern_find_sys_var(str, length, false);
778
sys_var *find_sys_var(Session *, const char *str, uint32_t length)
781
sys_var_pluginvar *pi= NULL;
782
module::Module *module;
784
if ((var= intern_find_sys_var(str, length, false)) &&
785
(pi= var->cast_pluginvar()))
787
if (!(module= pi->plugin))
788
var= NULL; /* failed to lock it, it must be uninstalling */
789
else if (module->isInited == false)
796
If the variable exists but the plugin it is associated with is not ready
797
then the intern_plugin_lock did not raise an error, so we do it here.
800
my_error(ER_UNKNOWN_SYSTEM_VARIABLE, MYF(0), (char*) str);
804
static const string make_bookmark_name(const string &plugin, const char *name)
806
string varname(plugin);
807
varname.push_back('_');
808
varname.append(name);
810
for (string::iterator p= varname.begin() + 1; p != varname.end(); ++p)
821
called by register_var, construct_options and test_plugin_options.
822
Returns the 'bookmark' for the named variable.
823
LOCK_system_variables_hash should be at least read locked
825
static Bookmark *find_bookmark(const string &plugin, const char *name, int flags)
827
if (!(flags & PLUGIN_VAR_SessionLOCAL))
830
const string varname(make_bookmark_name(plugin, name));
832
bookmark_unordered_map::iterator iter= bookmark_hash.find(varname);
833
if (iter != bookmark_hash.end())
835
return &((*iter).second);
842
returns a bookmark for session-local variables, creating if neccessary.
843
returns null for non session-local variables.
844
Requires that a write lock is obtained on LOCK_system_variables_hash
846
static Bookmark *register_var(const string &plugin, const char *name,
849
if (!(flags & PLUGIN_VAR_SessionLOCAL))
852
uint32_t size= 0, offset, new_size;
853
Bookmark *result= NULL;
855
switch (flags & PLUGIN_VAR_TYPEMASK) {
856
case PLUGIN_VAR_BOOL:
857
size= ALIGN_SIZE(sizeof(bool));
860
size= ALIGN_SIZE(sizeof(int));
862
case PLUGIN_VAR_LONG:
863
size= ALIGN_SIZE(sizeof(long));
865
case PLUGIN_VAR_LONGLONG:
866
size= ALIGN_SIZE(sizeof(uint64_t));
869
size= ALIGN_SIZE(sizeof(char*));
877
if (!(result= find_bookmark(plugin, name, flags)))
879
const string varname(make_bookmark_name(plugin, name));
881
Bookmark new_bookmark;
882
new_bookmark.key= varname;
883
new_bookmark.offset= -1;
885
assert(size && !(size & (size-1))); /* must be power of 2 */
887
offset= global_system_variables.dynamic_variables_size;
888
offset= (offset + size - 1) & ~(size - 1);
889
new_bookmark.offset= (int) offset;
891
new_size= (offset + size + 63) & ~63;
893
if (new_size > global_variables_dynamic_size)
897
(char *)realloc(global_system_variables.dynamic_variables_ptr,
900
global_system_variables.dynamic_variables_ptr= tmpptr;
903
(char *)realloc(max_system_variables.dynamic_variables_ptr,
906
max_system_variables.dynamic_variables_ptr= tmpptr;
909
Clear the new variable value space. This is required for string
910
variables. If their value is non-NULL, it must point to a valid
913
memset(global_system_variables.dynamic_variables_ptr +
914
global_variables_dynamic_size, 0,
915
new_size - global_variables_dynamic_size);
916
memset(max_system_variables.dynamic_variables_ptr +
917
global_variables_dynamic_size, 0,
918
new_size - global_variables_dynamic_size);
919
global_variables_dynamic_size= new_size;
922
global_system_variables.dynamic_variables_head= offset;
923
max_system_variables.dynamic_variables_head= offset;
924
global_system_variables.dynamic_variables_size= offset + size;
925
max_system_variables.dynamic_variables_size= offset + size;
926
global_system_variables.dynamic_variables_version++;
927
max_system_variables.dynamic_variables_version++;
929
new_bookmark.version= global_system_variables.dynamic_variables_version;
930
new_bookmark.type_code= flags;
932
/* this should succeed because we have already checked if a dup exists */
933
bookmark_hash.insert(make_pair(varname, new_bookmark));
934
result= find_bookmark(plugin, name, flags);
941
returns a pointer to the memory which holds the session-local variable or
942
a pointer to the global variable if session==null.
943
If required, will sync with global variables if the requested variable
944
has not yet been allocated in the current thread.
946
static unsigned char *intern_sys_var_ptr(Session* session, int offset, bool global_lock)
949
assert((uint32_t)offset <= global_system_variables.dynamic_variables_head);
952
return (unsigned char*) global_system_variables.dynamic_variables_ptr + offset;
955
dynamic_variables_head points to the largest valid offset
957
if (!session->variables.dynamic_variables_ptr ||
958
(uint32_t)offset > session->variables.dynamic_variables_head)
961
if (!(tmpptr= (char *)realloc(session->variables.dynamic_variables_ptr,
962
global_variables_dynamic_size)))
964
session->variables.dynamic_variables_ptr= tmpptr;
967
LOCK_global_system_variables.lock();
969
//safe_mutex_assert_owner(&LOCK_global_system_variables);
971
memcpy(session->variables.dynamic_variables_ptr +
972
session->variables.dynamic_variables_size,
973
global_system_variables.dynamic_variables_ptr +
974
session->variables.dynamic_variables_size,
975
global_system_variables.dynamic_variables_size -
976
session->variables.dynamic_variables_size);
979
now we need to iterate through any newly copied 'defaults'
980
and if it is a string type with MEMALLOC flag, we need to strdup
982
bookmark_unordered_map::iterator iter= bookmark_hash.begin();
983
for (; iter != bookmark_hash.end() ; ++iter)
985
sys_var_pluginvar *pi;
987
const Bookmark &v= (*iter).second;
988
const string var_name((*iter).first);
990
if (v.version <= session->variables.dynamic_variables_version ||
991
!(var= intern_find_sys_var(var_name.c_str(), var_name.size(), true)) ||
992
!(pi= var->cast_pluginvar()) ||
993
v.type_code != (pi->plugin_var->flags & PLUGIN_VAR_TYPEMASK))
996
/* Here we do anything special that may be required of the data types */
998
if ((pi->plugin_var->flags & PLUGIN_VAR_TYPEMASK) == PLUGIN_VAR_STR &&
999
pi->plugin_var->flags & PLUGIN_VAR_MEMALLOC)
1001
char **pp= (char**) (session->variables.dynamic_variables_ptr +
1002
*(int*)(pi->plugin_var + 1));
1003
if ((*pp= *(char**) (global_system_variables.dynamic_variables_ptr +
1004
*(int*)(pi->plugin_var + 1))))
1012
LOCK_global_system_variables.unlock();
1014
session->variables.dynamic_variables_version=
1015
global_system_variables.dynamic_variables_version;
1016
session->variables.dynamic_variables_head=
1017
global_system_variables.dynamic_variables_head;
1018
session->variables.dynamic_variables_size=
1019
global_system_variables.dynamic_variables_size;
1021
return (unsigned char*)session->variables.dynamic_variables_ptr + offset;
1024
static bool *mysql_sys_var_ptr_bool(Session* a_session, int offset)
1026
return (bool *)intern_sys_var_ptr(a_session, offset, true);
1029
static int *mysql_sys_var_ptr_int(Session* a_session, int offset)
1031
return (int *)intern_sys_var_ptr(a_session, offset, true);
1034
static long *mysql_sys_var_ptr_long(Session* a_session, int offset)
1036
return (long *)intern_sys_var_ptr(a_session, offset, true);
1039
static int64_t *mysql_sys_var_ptr_int64_t(Session* a_session, int offset)
1041
return (int64_t *)intern_sys_var_ptr(a_session, offset, true);
1044
static char **mysql_sys_var_ptr_str(Session* a_session, int offset)
1046
return (char **)intern_sys_var_ptr(a_session, offset, true);
509
1049
void plugin_sessionvar_init(Session *session)
511
1051
session->variables.storage_engine= NULL;
512
cleanup_variables(&session->variables);
1052
cleanup_variables(session, &session->variables);
514
1054
session->variables= global_system_variables;
515
1055
session->variables.storage_engine= NULL;
552
1118
void plugin_sessionvar_cleanup(Session *session)
554
1120
unlock_variables(session, &session->variables);
555
cleanup_variables(&session->variables);
1121
cleanup_variables(session, &session->variables);
1126
@brief Free values of thread variables of a plugin.
1128
This must be called before a plugin is deleted. Otherwise its
1129
variables are no longer accessible and the value space is lost. Note
1130
that only string values with PLUGIN_VAR_MEMALLOC are allocated and
1133
@param[in] vars Chain of system variables of a plugin
1136
static void plugin_vars_free_values(sys_var *vars)
1139
for (sys_var *var= vars; var; var= var->getNext())
1141
sys_var_pluginvar *piv= var->cast_pluginvar();
1143
((piv->plugin_var->flags & PLUGIN_VAR_TYPEMASK) == PLUGIN_VAR_STR) &&
1144
(piv->plugin_var->flags & PLUGIN_VAR_MEMALLOC))
1146
/* Free the string from global_system_variables. */
1147
char **valptr= (char**) piv->real_value_ptr(NULL, OPT_GLOBAL);
1156
bool sys_var_pluginvar::check_update_type(Item_result type)
1160
switch (plugin_var->flags & PLUGIN_VAR_TYPEMASK) {
1161
case PLUGIN_VAR_INT:
1162
case PLUGIN_VAR_LONG:
1163
case PLUGIN_VAR_LONGLONG:
1164
return type != INT_RESULT;
1165
case PLUGIN_VAR_STR:
1166
return type != STRING_RESULT;
1173
SHOW_TYPE sys_var_pluginvar::show_type()
1175
switch (plugin_var->flags & PLUGIN_VAR_TYPEMASK) {
1176
case PLUGIN_VAR_BOOL:
1177
return SHOW_MY_BOOL;
1178
case PLUGIN_VAR_INT:
1180
case PLUGIN_VAR_LONG:
1182
case PLUGIN_VAR_LONGLONG:
1183
return SHOW_LONGLONG;
1184
case PLUGIN_VAR_STR:
1185
return SHOW_CHAR_PTR;
1193
unsigned char* sys_var_pluginvar::real_value_ptr(Session *session, sql_var_t type)
1195
assert(session || (type == OPT_GLOBAL));
1196
if (plugin_var->flags & PLUGIN_VAR_SessionLOCAL)
1198
if (type == OPT_GLOBAL)
1201
return intern_sys_var_ptr(session, *(int*) (plugin_var+1), false);
1203
return *(unsigned char**) (plugin_var+1);
1207
TYPELIB* sys_var_pluginvar::plugin_var_typelib(void)
1209
switch (plugin_var->flags & (PLUGIN_VAR_TYPEMASK | PLUGIN_VAR_SessionLOCAL)) {
1210
case PLUGIN_VAR_SessionLOCAL:
1211
return ((sessionvar_enum_t *)plugin_var)->typelib;
1219
unsigned char* sys_var_pluginvar::value_ptr(Session *session, sql_var_t type, const LEX_STRING *)
1221
unsigned char* result;
1223
result= real_value_ptr(session, type);
1229
bool sys_var_pluginvar::check(Session *session, set_var *var)
1231
st_item_value_holder value;
1232
assert(is_readonly() || plugin_var->check);
1234
value.value_type= item_value_type;
1235
value.val_str= item_val_str;
1236
value.val_int= item_val_int;
1237
value.val_real= item_val_real;
1238
value.item= var->value;
1240
return is_readonly() ||
1241
plugin_var->check(session, plugin_var, &var->save_result, &value);
1245
void sys_var_pluginvar::set_default(Session *session, sql_var_t type)
1250
assert(is_readonly() || plugin_var->update);
1255
LOCK_global_system_variables.lock();
1256
tgt= real_value_ptr(session, type);
1257
src= ((void **) (plugin_var + 1) + 1);
1259
if (plugin_var->flags & PLUGIN_VAR_SessionLOCAL)
1261
if (type != OPT_GLOBAL)
1262
src= real_value_ptr(session, OPT_GLOBAL);
1264
switch (plugin_var->flags & PLUGIN_VAR_TYPEMASK) {
1265
case PLUGIN_VAR_INT:
1266
src= &((sessionvar_uint_t*) plugin_var)->def_val;
1268
case PLUGIN_VAR_LONG:
1269
src= &((sessionvar_ulong_t*) plugin_var)->def_val;
1271
case PLUGIN_VAR_LONGLONG:
1272
src= &((sessionvar_uint64_t_t*) plugin_var)->def_val;
1274
case PLUGIN_VAR_BOOL:
1275
src= &((sessionvar_bool_t*) plugin_var)->def_val;
1277
case PLUGIN_VAR_STR:
1278
src= &((sessionvar_str_t*) plugin_var)->def_val;
1285
/* session must equal current_session if PLUGIN_VAR_SessionLOCAL flag is set */
1286
assert(!(plugin_var->flags & PLUGIN_VAR_SessionLOCAL) ||
1287
session == current_session);
1289
if (!(plugin_var->flags & PLUGIN_VAR_SessionLOCAL) || type == OPT_GLOBAL)
1291
plugin_var->update(session, plugin_var, tgt, src);
1292
LOCK_global_system_variables.unlock();
1296
LOCK_global_system_variables.unlock();
1297
plugin_var->update(session, plugin_var, tgt, src);
1302
bool sys_var_pluginvar::update(Session *session, set_var *var)
1306
assert(is_readonly() || plugin_var->update);
1308
/* session must equal current_session if PLUGIN_VAR_SessionLOCAL flag is set */
1309
assert(!(plugin_var->flags & PLUGIN_VAR_SessionLOCAL) ||
1310
session == current_session);
1315
LOCK_global_system_variables.lock();
1316
tgt= real_value_ptr(session, var->type);
1318
if (!(plugin_var->flags & PLUGIN_VAR_SessionLOCAL) || var->type == OPT_GLOBAL)
1320
/* variable we are updating has global scope, so we unlock after updating */
1321
plugin_var->update(session, plugin_var, tgt, &var->save_result);
1322
LOCK_global_system_variables.unlock();
1326
LOCK_global_system_variables.unlock();
1327
plugin_var->update(session, plugin_var, tgt, &var->save_result);
1333
#define OPTION_SET_LIMITS(type, options, opt) \
1334
options->var_type= type; \
1335
options->def_value= (opt)->def_val; \
1336
options->min_value= (opt)->min_val; \
1337
options->max_value= (opt)->max_val; \
1338
options->block_size= (long) (opt)->blk_sz
1341
void plugin_opt_set_limits(struct option *options,
1342
const drizzle_sys_var *opt)
1344
options->sub_size= 0;
1346
switch (opt->flags & (PLUGIN_VAR_TYPEMASK |
1347
PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_SessionLOCAL)) {
1348
/* global system variables */
1349
case PLUGIN_VAR_INT:
1350
OPTION_SET_LIMITS(GET_INT, options, (sysvar_int_t*) opt);
1352
case PLUGIN_VAR_INT | PLUGIN_VAR_UNSIGNED:
1353
OPTION_SET_LIMITS(GET_UINT, options, (sysvar_uint_t*) opt);
1355
case PLUGIN_VAR_LONG:
1356
OPTION_SET_LIMITS(GET_LONG, options, (sysvar_long_t*) opt);
1358
case PLUGIN_VAR_LONG | PLUGIN_VAR_UNSIGNED:
1359
OPTION_SET_LIMITS(GET_ULONG_IS_FAIL, options, (sysvar_ulong_t*) opt);
1361
case PLUGIN_VAR_LONGLONG:
1362
OPTION_SET_LIMITS(GET_LL, options, (sysvar_int64_t_t*) opt);
1364
case PLUGIN_VAR_LONGLONG | PLUGIN_VAR_UNSIGNED:
1365
OPTION_SET_LIMITS(GET_ULL, options, (sysvar_uint64_t_t*) opt);
1367
case PLUGIN_VAR_BOOL:
1368
options->var_type= GET_BOOL;
1369
options->def_value= ((sysvar_bool_t*) opt)->def_val;
1371
case PLUGIN_VAR_STR:
1372
options->var_type= ((opt->flags & PLUGIN_VAR_MEMALLOC) ?
1373
GET_STR_ALLOC : GET_STR);
1374
options->def_value= (intptr_t) ((sysvar_str_t*) opt)->def_val;
1376
/* threadlocal variables */
1377
case PLUGIN_VAR_INT | PLUGIN_VAR_SessionLOCAL:
1378
OPTION_SET_LIMITS(GET_INT, options, (sessionvar_int_t*) opt);
1380
case PLUGIN_VAR_INT | PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_SessionLOCAL:
1381
OPTION_SET_LIMITS(GET_UINT, options, (sessionvar_uint_t*) opt);
1383
case PLUGIN_VAR_LONG | PLUGIN_VAR_SessionLOCAL:
1384
OPTION_SET_LIMITS(GET_LONG, options, (sessionvar_long_t*) opt);
1386
case PLUGIN_VAR_LONG | PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_SessionLOCAL:
1387
OPTION_SET_LIMITS(GET_ULONG_IS_FAIL, options, (sessionvar_ulong_t*) opt);
1389
case PLUGIN_VAR_LONGLONG | PLUGIN_VAR_SessionLOCAL:
1390
OPTION_SET_LIMITS(GET_LL, options, (sessionvar_int64_t_t*) opt);
1392
case PLUGIN_VAR_LONGLONG | PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_SessionLOCAL:
1393
OPTION_SET_LIMITS(GET_ULL, options, (sessionvar_uint64_t_t*) opt);
1395
case PLUGIN_VAR_BOOL | PLUGIN_VAR_SessionLOCAL:
1396
options->var_type= GET_BOOL;
1397
options->def_value= ((sessionvar_bool_t*) opt)->def_val;
1399
case PLUGIN_VAR_STR | PLUGIN_VAR_SessionLOCAL:
1400
options->var_type= ((opt->flags & PLUGIN_VAR_MEMALLOC) ?
1401
GET_STR_ALLOC : GET_STR);
1402
options->def_value= (intptr_t) ((sessionvar_str_t*) opt)->def_val;
1407
options->arg_type= REQUIRED_ARG;
1408
if (opt->flags & PLUGIN_VAR_NOCMDARG)
1409
options->arg_type= NO_ARG;
1410
if (opt->flags & PLUGIN_VAR_OPCMDARG)
1411
options->arg_type= OPT_ARG;
1414
static int construct_options(memory::Root *mem_root, module::Module *tmp,
1418
int localoptionid= 256;
1419
const string plugin_name(tmp->getManifest().name);
1421
size_t namelen= plugin_name.size(), optnamelen;
1424
int index= 0, offset= 0;
1425
drizzle_sys_var *opt, **plugin_option;
1428
string name(plugin_name);
1429
transform(name.begin(), name.end(), name.begin(), ::tolower);
1431
for (string::iterator iter= name.begin(); iter != name.end(); ++iter)
1438
Two passes as the 2nd pass will take pointer addresses for use
1439
by my_getopt and register_var() in the first pass uses realloc
1442
for (plugin_option= tmp->getManifest().system_vars;
1443
plugin_option && *plugin_option; plugin_option++, index++)
1445
opt= *plugin_option;
1446
if (!(opt->flags & PLUGIN_VAR_SessionLOCAL))
1448
if (!(register_var(name, opt->name, opt->flags)))
1450
switch (opt->flags & PLUGIN_VAR_TYPEMASK) {
1451
case PLUGIN_VAR_BOOL:
1452
(((sessionvar_bool_t *)opt)->resolve)= mysql_sys_var_ptr_bool;
1454
case PLUGIN_VAR_INT:
1455
(((sessionvar_int_t *)opt)->resolve)= mysql_sys_var_ptr_int;
1457
case PLUGIN_VAR_LONG:
1458
(((sessionvar_long_t *)opt)->resolve)= mysql_sys_var_ptr_long;
1460
case PLUGIN_VAR_LONGLONG:
1461
(((sessionvar_int64_t_t *)opt)->resolve)= mysql_sys_var_ptr_int64_t;
1463
case PLUGIN_VAR_STR:
1464
(((sessionvar_str_t *)opt)->resolve)= mysql_sys_var_ptr_str;
1467
errmsg_printf(ERRMSG_LVL_ERROR, _("Unknown variable type code 0x%x in plugin '%s'."),
1468
opt->flags, plugin_name.c_str());
1473
for (plugin_option= tmp->getManifest().system_vars;
1474
plugin_option && *plugin_option; plugin_option++, index++)
1476
switch ((opt= *plugin_option)->flags & PLUGIN_VAR_TYPEMASK) {
1477
case PLUGIN_VAR_BOOL:
1479
opt->check= check_func_bool;
1481
opt->update= update_func_bool;
1483
case PLUGIN_VAR_INT:
1485
opt->check= check_func_int;
1487
opt->update= update_func_int;
1489
case PLUGIN_VAR_LONG:
1491
opt->check= check_func_long;
1493
opt->update= update_func_long;
1495
case PLUGIN_VAR_LONGLONG:
1497
opt->check= check_func_int64_t;
1499
opt->update= update_func_int64_t;
1501
case PLUGIN_VAR_STR:
1503
opt->check= check_func_str;
1506
opt->update= update_func_str;
1507
if ((opt->flags & (PLUGIN_VAR_MEMALLOC | PLUGIN_VAR_READONLY)) == false)
1509
opt->flags|= PLUGIN_VAR_READONLY;
1510
errmsg_printf(ERRMSG_LVL_WARN, _("Server variable %s of plugin %s was forced "
1511
"to be read-only: string variable without "
1512
"update_func and PLUGIN_VAR_MEMALLOC flag"),
1513
opt->name, plugin_name.c_str());
1518
errmsg_printf(ERRMSG_LVL_ERROR, _("Unknown variable type code 0x%x in plugin '%s'."),
1519
opt->flags, plugin_name.c_str());
1523
if ((opt->flags & (PLUGIN_VAR_NOCMDOPT | PLUGIN_VAR_SessionLOCAL))
1524
== PLUGIN_VAR_NOCMDOPT)
1529
errmsg_printf(ERRMSG_LVL_ERROR, _("Missing variable name in plugin '%s'."),
1530
plugin_name.c_str());
1534
if (!(opt->flags & PLUGIN_VAR_SessionLOCAL))
1536
optnamelen= strlen(opt->name);
1537
optname= (char*) mem_root->alloc_root(namelen + optnamelen + 2);
1538
sprintf(optname, "%s-%s", name.c_str(), opt->name);
1539
optnamelen= namelen + optnamelen + 1;
1543
/* this should not fail because register_var should create entry */
1544
if (!(v= find_bookmark(name, opt->name, opt->flags)))
1546
errmsg_printf(ERRMSG_LVL_ERROR, _("Thread local variable '%s' not allocated "
1547
"in plugin '%s'."), opt->name, plugin_name.c_str());
1551
*(int*)(opt + 1)= offset= v->offset;
1553
if (opt->flags & PLUGIN_VAR_NOCMDOPT)
1556
optname= (char*) mem_root->memdup_root(v->key.c_str(), (optnamelen= v->key.size()) + 1);
1559
/* convert '_' to '-' */
1560
for (p= optname; *p; p++)
1564
options->name= optname;
1565
options->comment= opt->comment;
1566
options->app_type= opt;
1567
options->id= localoptionid++;
1569
plugin_opt_set_limits(options, opt);
1571
if (opt->flags & PLUGIN_VAR_SessionLOCAL)
1572
options->value= options->u_max_value= (char**)
1573
(global_system_variables.dynamic_variables_ptr + offset);
1575
options->value= options->u_max_value= *(char***) (opt + 1);
1584
static option *construct_help_options(memory::Root *mem_root, module::Module *p)
1586
drizzle_sys_var **opt;
1588
uint32_t count= EXTRA_OPTIONS;
1590
for (opt= p->getManifest().system_vars; opt && *opt; opt++, count++) {};
1592
opts= (option*)mem_root->alloc_root((sizeof(option) * count));
1596
memset(opts, 0, sizeof(option) * count);
1598
if (construct_options(mem_root, p, opts))
1604
void drizzle_add_plugin_sysvar(sys_var_pluginvar *var)
1606
plugin_sysvar_vec.push_back(var);
1609
void drizzle_del_plugin_sysvar()
1611
vector<sys_var_pluginvar *>::iterator iter= plugin_sysvar_vec.begin();
1612
while(iter != plugin_sysvar_vec.end())
1617
plugin_sysvar_vec.clear();