494
569
global_variables_dynamic_size= 0;
572
/****************************************************************************
573
Internal type declarations for variables support
574
****************************************************************************/
576
#undef DRIZZLE_SYSVAR_NAME
577
#define DRIZZLE_SYSVAR_NAME(name) name
578
#define PLUGIN_VAR_TYPEMASK 0x007f
580
static const uint32_t EXTRA_OPTIONS= 1; /* handle the NULL option */
582
typedef DECLARE_DRIZZLE_SYSVAR_BASIC(sysvar_bool_t, bool);
583
typedef DECLARE_DRIZZLE_SessionVAR_BASIC(sessionvar_bool_t, bool);
584
typedef DECLARE_DRIZZLE_SYSVAR_BASIC(sysvar_str_t, char *);
585
typedef DECLARE_DRIZZLE_SessionVAR_BASIC(sessionvar_str_t, char *);
587
typedef DECLARE_DRIZZLE_SessionVAR_TYPELIB(sessionvar_enum_t, unsigned long);
588
typedef DECLARE_DRIZZLE_SessionVAR_TYPELIB(sessionvar_set_t, uint64_t);
590
typedef DECLARE_DRIZZLE_SYSVAR_SIMPLE(sysvar_int_t, int);
591
typedef DECLARE_DRIZZLE_SYSVAR_SIMPLE(sysvar_long_t, long);
592
typedef DECLARE_DRIZZLE_SYSVAR_SIMPLE(sysvar_int64_t_t, int64_t);
593
typedef DECLARE_DRIZZLE_SYSVAR_SIMPLE(sysvar_uint_t, uint);
594
typedef DECLARE_DRIZZLE_SYSVAR_SIMPLE(sysvar_ulong_t, ulong);
595
typedef DECLARE_DRIZZLE_SYSVAR_SIMPLE(sysvar_uint64_t_t, uint64_t);
597
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_int_t, int);
598
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_long_t, long);
599
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_int64_t_t, int64_t);
600
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_uint_t, uint);
601
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_ulong_t, ulong);
602
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_uint64_t_t, uint64_t);
604
typedef bool *(*mysql_sys_var_ptr_p)(Session* a_session, int offset);
607
/****************************************************************************
608
default variable data check and update functions
609
****************************************************************************/
611
static int check_func_bool(Session *, drizzle_sys_var *var,
612
void *save, drizzle_value *value)
614
char buff[STRING_BUFFER_USUAL_SIZE];
615
const char *strvalue= "NULL", *str;
619
if (value->value_type(value) == DRIZZLE_VALUE_TYPE_STRING)
621
length= sizeof(buff);
622
if (!(str= value->val_str(value, buff, &length)) ||
623
(result= find_type(&bool_typelib, str, length, 1)-1) < 0)
632
if (value->val_int(value, &tmp) < 0)
636
internal::llstr(tmp, buff);
642
*(int*)save= -result;
645
my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), var->name, strvalue);
650
static int check_func_int(Session *session, drizzle_sys_var *var,
651
void *save, drizzle_value *value)
655
struct option options;
656
value->val_int(value, &tmp);
657
plugin_opt_set_limits(&options, var);
659
if (var->flags & PLUGIN_VAR_UNSIGNED)
660
*(uint32_t *)save= (uint32_t) getopt_ull_limit_value((uint64_t) tmp, &options,
663
*(int *)save= (int) getopt_ll_limit_value(tmp, &options, &fixed);
665
return throw_bounds_warning(session, fixed, var->flags & PLUGIN_VAR_UNSIGNED,
666
var->name, (int64_t) tmp);
670
static int check_func_long(Session *session, drizzle_sys_var *var,
671
void *save, drizzle_value *value)
675
struct option options;
676
value->val_int(value, &tmp);
677
plugin_opt_set_limits(&options, var);
679
if (var->flags & PLUGIN_VAR_UNSIGNED)
680
*(ulong *)save= (ulong) getopt_ull_limit_value((uint64_t) tmp, &options,
683
*(long *)save= (long) getopt_ll_limit_value(tmp, &options, &fixed);
685
return throw_bounds_warning(session, fixed, var->flags & PLUGIN_VAR_UNSIGNED,
686
var->name, (int64_t) tmp);
690
static int check_func_int64_t(Session *session, drizzle_sys_var *var,
691
void *save, drizzle_value *value)
695
struct option options;
696
value->val_int(value, &tmp);
697
plugin_opt_set_limits(&options, var);
699
if (var->flags & PLUGIN_VAR_UNSIGNED)
700
*(uint64_t *)save= getopt_ull_limit_value((uint64_t) tmp, &options,
703
*(int64_t *)save= getopt_ll_limit_value(tmp, &options, &fixed);
705
return throw_bounds_warning(session, fixed, var->flags & PLUGIN_VAR_UNSIGNED,
706
var->name, (int64_t) tmp);
709
static int check_func_str(Session *session, drizzle_sys_var *,
710
void *save, drizzle_value *value)
712
char buff[STRING_BUFFER_USUAL_SIZE];
716
length= sizeof(buff);
717
if ((str= value->val_str(value, buff, &length)))
718
str= session->strmake(str, length);
719
*(const char**)save= str;
724
static void update_func_bool(Session *, drizzle_sys_var *,
725
void *tgt, const void *save)
727
*(bool *) tgt= *(int *) save ? 1 : 0;
731
static void update_func_int(Session *, drizzle_sys_var *,
732
void *tgt, const void *save)
734
*(int *)tgt= *(int *) save;
738
static void update_func_long(Session *, drizzle_sys_var *,
739
void *tgt, const void *save)
741
*(long *)tgt= *(long *) save;
745
static void update_func_int64_t(Session *, drizzle_sys_var *,
746
void *tgt, const void *save)
748
*(int64_t *)tgt= *(uint64_t *) save;
752
static void update_func_str(Session *, drizzle_sys_var *var,
753
void *tgt, const void *save)
755
char *old= *(char **) tgt;
756
*(char **)tgt= *(char **) save;
757
if (var->flags & PLUGIN_VAR_MEMALLOC)
759
*(char **)tgt= strdup(*(char **) save);
762
* There isn't a _really_ good thing to do here until this whole set_var
763
* mess gets redesigned
766
errmsg_printf(ERRMSG_LVL_ERROR, _("Out of memory."));
498
772
/****************************************************************************
499
773
System Variables support
500
774
****************************************************************************/
503
sys_var *find_sys_var(const char *str, uint32_t length)
505
return intern_find_sys_var(str, length, false);
777
sys_var *find_sys_var(Session *, const char *str, uint32_t length)
780
sys_var_pluginvar *pi= NULL;
781
module::Module *module;
783
if ((var= intern_find_sys_var(str, length, false)) &&
784
(pi= var->cast_pluginvar()))
786
if (!(module= pi->plugin))
787
var= NULL; /* failed to lock it, it must be uninstalling */
788
else if (module->isInited == false)
795
If the variable exists but the plugin it is associated with is not ready
796
then the intern_plugin_lock did not raise an error, so we do it here.
799
my_error(ER_UNKNOWN_SYSTEM_VARIABLE, MYF(0), (char*) str);
803
static const string make_bookmark_name(const string &plugin, const char *name)
805
string varname(plugin);
806
varname.push_back('_');
807
varname.append(name);
809
for (string::iterator p= varname.begin() + 1; p != varname.end(); ++p)
820
called by register_var, construct_options and test_plugin_options.
821
Returns the 'bookmark' for the named variable.
822
LOCK_system_variables_hash should be at least read locked
824
static Bookmark *find_bookmark(const string &plugin, const char *name, int flags)
826
if (!(flags & PLUGIN_VAR_SessionLOCAL))
829
const string varname(make_bookmark_name(plugin, name));
831
bookmark_unordered_map::iterator iter= bookmark_hash.find(varname);
832
if (iter != bookmark_hash.end())
834
return &((*iter).second);
841
returns a bookmark for session-local variables, creating if neccessary.
842
returns null for non session-local variables.
843
Requires that a write lock is obtained on LOCK_system_variables_hash
845
static Bookmark *register_var(const string &plugin, const char *name,
848
if (!(flags & PLUGIN_VAR_SessionLOCAL))
851
uint32_t size= 0, offset, new_size;
852
Bookmark *result= NULL;
854
switch (flags & PLUGIN_VAR_TYPEMASK) {
855
case PLUGIN_VAR_BOOL:
856
size= ALIGN_SIZE(sizeof(bool));
859
size= ALIGN_SIZE(sizeof(int));
861
case PLUGIN_VAR_LONG:
862
size= ALIGN_SIZE(sizeof(long));
864
case PLUGIN_VAR_LONGLONG:
865
size= ALIGN_SIZE(sizeof(uint64_t));
868
size= ALIGN_SIZE(sizeof(char*));
876
if (!(result= find_bookmark(plugin, name, flags)))
878
const string varname(make_bookmark_name(plugin, name));
880
Bookmark new_bookmark;
881
new_bookmark.key= varname;
882
new_bookmark.offset= -1;
884
assert(size && !(size & (size-1))); /* must be power of 2 */
886
offset= global_system_variables.dynamic_variables_size;
887
offset= (offset + size - 1) & ~(size - 1);
888
new_bookmark.offset= (int) offset;
890
new_size= (offset + size + 63) & ~63;
892
if (new_size > global_variables_dynamic_size)
896
(char *)realloc(global_system_variables.dynamic_variables_ptr,
899
global_system_variables.dynamic_variables_ptr= tmpptr;
902
(char *)realloc(max_system_variables.dynamic_variables_ptr,
905
max_system_variables.dynamic_variables_ptr= tmpptr;
908
Clear the new variable value space. This is required for string
909
variables. If their value is non-NULL, it must point to a valid
912
memset(global_system_variables.dynamic_variables_ptr +
913
global_variables_dynamic_size, 0,
914
new_size - global_variables_dynamic_size);
915
memset(max_system_variables.dynamic_variables_ptr +
916
global_variables_dynamic_size, 0,
917
new_size - global_variables_dynamic_size);
918
global_variables_dynamic_size= new_size;
921
global_system_variables.dynamic_variables_head= offset;
922
max_system_variables.dynamic_variables_head= offset;
923
global_system_variables.dynamic_variables_size= offset + size;
924
max_system_variables.dynamic_variables_size= offset + size;
925
global_system_variables.dynamic_variables_version++;
926
max_system_variables.dynamic_variables_version++;
928
new_bookmark.version= global_system_variables.dynamic_variables_version;
929
new_bookmark.type_code= flags;
931
/* this should succeed because we have already checked if a dup exists */
932
bookmark_hash.insert(make_pair(varname, new_bookmark));
933
result= find_bookmark(plugin, name, flags);
940
returns a pointer to the memory which holds the session-local variable or
941
a pointer to the global variable if session==null.
942
If required, will sync with global variables if the requested variable
943
has not yet been allocated in the current thread.
945
static unsigned char *intern_sys_var_ptr(Session* session, int offset, bool global_lock)
948
assert((uint32_t)offset <= global_system_variables.dynamic_variables_head);
951
return (unsigned char*) global_system_variables.dynamic_variables_ptr + offset;
954
dynamic_variables_head points to the largest valid offset
956
if (!session->variables.dynamic_variables_ptr ||
957
(uint32_t)offset > session->variables.dynamic_variables_head)
960
if (!(tmpptr= (char *)realloc(session->variables.dynamic_variables_ptr,
961
global_variables_dynamic_size)))
963
session->variables.dynamic_variables_ptr= tmpptr;
966
LOCK_global_system_variables.lock();
968
//safe_mutex_assert_owner(&LOCK_global_system_variables);
970
memcpy(session->variables.dynamic_variables_ptr +
971
session->variables.dynamic_variables_size,
972
global_system_variables.dynamic_variables_ptr +
973
session->variables.dynamic_variables_size,
974
global_system_variables.dynamic_variables_size -
975
session->variables.dynamic_variables_size);
978
now we need to iterate through any newly copied 'defaults'
979
and if it is a string type with MEMALLOC flag, we need to strdup
981
bookmark_unordered_map::iterator iter= bookmark_hash.begin();
982
for (; iter != bookmark_hash.end() ; ++iter)
984
sys_var_pluginvar *pi;
986
const Bookmark &v= (*iter).second;
987
const string var_name((*iter).first);
989
if (v.version <= session->variables.dynamic_variables_version ||
990
!(var= intern_find_sys_var(var_name.c_str(), var_name.size(), true)) ||
991
!(pi= var->cast_pluginvar()) ||
992
v.type_code != (pi->plugin_var->flags & PLUGIN_VAR_TYPEMASK))
995
/* Here we do anything special that may be required of the data types */
997
if ((pi->plugin_var->flags & PLUGIN_VAR_TYPEMASK) == PLUGIN_VAR_STR &&
998
pi->plugin_var->flags & PLUGIN_VAR_MEMALLOC)
1000
char **pp= (char**) (session->variables.dynamic_variables_ptr +
1001
*(int*)(pi->plugin_var + 1));
1002
if ((*pp= *(char**) (global_system_variables.dynamic_variables_ptr +
1003
*(int*)(pi->plugin_var + 1))))
1011
LOCK_global_system_variables.unlock();
1013
session->variables.dynamic_variables_version=
1014
global_system_variables.dynamic_variables_version;
1015
session->variables.dynamic_variables_head=
1016
global_system_variables.dynamic_variables_head;
1017
session->variables.dynamic_variables_size=
1018
global_system_variables.dynamic_variables_size;
1020
return (unsigned char*)session->variables.dynamic_variables_ptr + offset;
1023
static bool *mysql_sys_var_ptr_bool(Session* a_session, int offset)
1025
return (bool *)intern_sys_var_ptr(a_session, offset, true);
1028
static int *mysql_sys_var_ptr_int(Session* a_session, int offset)
1030
return (int *)intern_sys_var_ptr(a_session, offset, true);
1033
static long *mysql_sys_var_ptr_long(Session* a_session, int offset)
1035
return (long *)intern_sys_var_ptr(a_session, offset, true);
1038
static int64_t *mysql_sys_var_ptr_int64_t(Session* a_session, int offset)
1040
return (int64_t *)intern_sys_var_ptr(a_session, offset, true);
1043
static char **mysql_sys_var_ptr_str(Session* a_session, int offset)
1045
return (char **)intern_sys_var_ptr(a_session, offset, true);
509
1048
void plugin_sessionvar_init(Session *session)
511
1050
session->variables.storage_engine= NULL;
512
cleanup_variables(&session->variables);
1051
cleanup_variables(session, &session->variables);
514
1053
session->variables= global_system_variables;
515
1054
session->variables.storage_engine= NULL;
552
1117
void plugin_sessionvar_cleanup(Session *session)
554
1119
unlock_variables(session, &session->variables);
555
cleanup_variables(&session->variables);
1120
cleanup_variables(session, &session->variables);
1125
@brief Free values of thread variables of a plugin.
1127
This must be called before a plugin is deleted. Otherwise its
1128
variables are no longer accessible and the value space is lost. Note
1129
that only string values with PLUGIN_VAR_MEMALLOC are allocated and
1132
@param[in] vars Chain of system variables of a plugin
1135
static void plugin_vars_free_values(sys_var *vars)
1138
for (sys_var *var= vars; var; var= var->getNext())
1140
sys_var_pluginvar *piv= var->cast_pluginvar();
1142
((piv->plugin_var->flags & PLUGIN_VAR_TYPEMASK) == PLUGIN_VAR_STR) &&
1143
(piv->plugin_var->flags & PLUGIN_VAR_MEMALLOC))
1145
/* Free the string from global_system_variables. */
1146
char **valptr= (char**) piv->real_value_ptr(NULL, OPT_GLOBAL);
1155
bool sys_var_pluginvar::check_update_type(Item_result type)
1159
switch (plugin_var->flags & PLUGIN_VAR_TYPEMASK) {
1160
case PLUGIN_VAR_INT:
1161
case PLUGIN_VAR_LONG:
1162
case PLUGIN_VAR_LONGLONG:
1163
return type != INT_RESULT;
1164
case PLUGIN_VAR_STR:
1165
return type != STRING_RESULT;
1172
SHOW_TYPE sys_var_pluginvar::show_type()
1174
switch (plugin_var->flags & PLUGIN_VAR_TYPEMASK) {
1175
case PLUGIN_VAR_BOOL:
1176
return SHOW_MY_BOOL;
1177
case PLUGIN_VAR_INT:
1179
case PLUGIN_VAR_LONG:
1181
case PLUGIN_VAR_LONGLONG:
1182
return SHOW_LONGLONG;
1183
case PLUGIN_VAR_STR:
1184
return SHOW_CHAR_PTR;
1192
unsigned char* sys_var_pluginvar::real_value_ptr(Session *session, sql_var_t type)
1194
assert(session || (type == OPT_GLOBAL));
1195
if (plugin_var->flags & PLUGIN_VAR_SessionLOCAL)
1197
if (type == OPT_GLOBAL)
1200
return intern_sys_var_ptr(session, *(int*) (plugin_var+1), false);
1202
return *(unsigned char**) (plugin_var+1);
1206
TYPELIB* sys_var_pluginvar::plugin_var_typelib(void)
1208
switch (plugin_var->flags & (PLUGIN_VAR_TYPEMASK | PLUGIN_VAR_SessionLOCAL)) {
1209
case PLUGIN_VAR_SessionLOCAL:
1210
return ((sessionvar_enum_t *)plugin_var)->typelib;
1218
unsigned char* sys_var_pluginvar::value_ptr(Session *session, sql_var_t type, const LEX_STRING *)
1220
unsigned char* result;
1222
result= real_value_ptr(session, type);
1228
bool sys_var_pluginvar::check(Session *session, set_var *var)
1230
st_item_value_holder value;
1231
assert(is_readonly() || plugin_var->check);
1233
value.value_type= item_value_type;
1234
value.val_str= item_val_str;
1235
value.val_int= item_val_int;
1236
value.val_real= item_val_real;
1237
value.item= var->value;
1239
return is_readonly() ||
1240
plugin_var->check(session, plugin_var, &var->save_result, &value);
1244
void sys_var_pluginvar::set_default(Session *session, sql_var_t type)
1249
assert(is_readonly() || plugin_var->update);
1254
LOCK_global_system_variables.lock();
1255
tgt= real_value_ptr(session, type);
1256
src= ((void **) (plugin_var + 1) + 1);
1258
if (plugin_var->flags & PLUGIN_VAR_SessionLOCAL)
1260
if (type != OPT_GLOBAL)
1261
src= real_value_ptr(session, OPT_GLOBAL);
1263
switch (plugin_var->flags & PLUGIN_VAR_TYPEMASK) {
1264
case PLUGIN_VAR_INT:
1265
src= &((sessionvar_uint_t*) plugin_var)->def_val;
1267
case PLUGIN_VAR_LONG:
1268
src= &((sessionvar_ulong_t*) plugin_var)->def_val;
1270
case PLUGIN_VAR_LONGLONG:
1271
src= &((sessionvar_uint64_t_t*) plugin_var)->def_val;
1273
case PLUGIN_VAR_BOOL:
1274
src= &((sessionvar_bool_t*) plugin_var)->def_val;
1276
case PLUGIN_VAR_STR:
1277
src= &((sessionvar_str_t*) plugin_var)->def_val;
1284
/* session must equal current_session if PLUGIN_VAR_SessionLOCAL flag is set */
1285
assert(!(plugin_var->flags & PLUGIN_VAR_SessionLOCAL) ||
1286
session == current_session);
1288
if (!(plugin_var->flags & PLUGIN_VAR_SessionLOCAL) || type == OPT_GLOBAL)
1290
plugin_var->update(session, plugin_var, tgt, src);
1291
LOCK_global_system_variables.unlock();
1295
LOCK_global_system_variables.unlock();
1296
plugin_var->update(session, plugin_var, tgt, src);
1301
bool sys_var_pluginvar::update(Session *session, set_var *var)
1305
assert(is_readonly() || plugin_var->update);
1307
/* session must equal current_session if PLUGIN_VAR_SessionLOCAL flag is set */
1308
assert(!(plugin_var->flags & PLUGIN_VAR_SessionLOCAL) ||
1309
session == current_session);
1314
LOCK_global_system_variables.lock();
1315
tgt= real_value_ptr(session, var->type);
1317
if (!(plugin_var->flags & PLUGIN_VAR_SessionLOCAL) || var->type == OPT_GLOBAL)
1319
/* variable we are updating has global scope, so we unlock after updating */
1320
plugin_var->update(session, plugin_var, tgt, &var->save_result);
1321
LOCK_global_system_variables.unlock();
1325
LOCK_global_system_variables.unlock();
1326
plugin_var->update(session, plugin_var, tgt, &var->save_result);
1332
#define OPTION_SET_LIMITS(type, options, opt) \
1333
options->var_type= type; \
1334
options->def_value= (opt)->def_val; \
1335
options->min_value= (opt)->min_val; \
1336
options->max_value= (opt)->max_val; \
1337
options->block_size= (long) (opt)->blk_sz
1340
void plugin_opt_set_limits(struct option *options,
1341
const drizzle_sys_var *opt)
1343
options->sub_size= 0;
1345
switch (opt->flags & (PLUGIN_VAR_TYPEMASK |
1346
PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_SessionLOCAL)) {
1347
/* global system variables */
1348
case PLUGIN_VAR_INT:
1349
OPTION_SET_LIMITS(GET_INT, options, (sysvar_int_t*) opt);
1351
case PLUGIN_VAR_INT | PLUGIN_VAR_UNSIGNED:
1352
OPTION_SET_LIMITS(GET_UINT, options, (sysvar_uint_t*) opt);
1354
case PLUGIN_VAR_LONG:
1355
OPTION_SET_LIMITS(GET_LONG, options, (sysvar_long_t*) opt);
1357
case PLUGIN_VAR_LONG | PLUGIN_VAR_UNSIGNED:
1358
OPTION_SET_LIMITS(GET_ULONG_IS_FAIL, options, (sysvar_ulong_t*) opt);
1360
case PLUGIN_VAR_LONGLONG:
1361
OPTION_SET_LIMITS(GET_LL, options, (sysvar_int64_t_t*) opt);
1363
case PLUGIN_VAR_LONGLONG | PLUGIN_VAR_UNSIGNED:
1364
OPTION_SET_LIMITS(GET_ULL, options, (sysvar_uint64_t_t*) opt);
1366
case PLUGIN_VAR_BOOL:
1367
options->var_type= GET_BOOL;
1368
options->def_value= ((sysvar_bool_t*) opt)->def_val;
1370
case PLUGIN_VAR_STR:
1371
options->var_type= ((opt->flags & PLUGIN_VAR_MEMALLOC) ?
1372
GET_STR_ALLOC : GET_STR);
1373
options->def_value= (intptr_t) ((sysvar_str_t*) opt)->def_val;
1375
/* threadlocal variables */
1376
case PLUGIN_VAR_INT | PLUGIN_VAR_SessionLOCAL:
1377
OPTION_SET_LIMITS(GET_INT, options, (sessionvar_int_t*) opt);
1379
case PLUGIN_VAR_INT | PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_SessionLOCAL:
1380
OPTION_SET_LIMITS(GET_UINT, options, (sessionvar_uint_t*) opt);
1382
case PLUGIN_VAR_LONG | PLUGIN_VAR_SessionLOCAL:
1383
OPTION_SET_LIMITS(GET_LONG, options, (sessionvar_long_t*) opt);
1385
case PLUGIN_VAR_LONG | PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_SessionLOCAL:
1386
OPTION_SET_LIMITS(GET_ULONG_IS_FAIL, options, (sessionvar_ulong_t*) opt);
1388
case PLUGIN_VAR_LONGLONG | PLUGIN_VAR_SessionLOCAL:
1389
OPTION_SET_LIMITS(GET_LL, options, (sessionvar_int64_t_t*) opt);
1391
case PLUGIN_VAR_LONGLONG | PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_SessionLOCAL:
1392
OPTION_SET_LIMITS(GET_ULL, options, (sessionvar_uint64_t_t*) opt);
1394
case PLUGIN_VAR_BOOL | PLUGIN_VAR_SessionLOCAL:
1395
options->var_type= GET_BOOL;
1396
options->def_value= ((sessionvar_bool_t*) opt)->def_val;
1398
case PLUGIN_VAR_STR | PLUGIN_VAR_SessionLOCAL:
1399
options->var_type= ((opt->flags & PLUGIN_VAR_MEMALLOC) ?
1400
GET_STR_ALLOC : GET_STR);
1401
options->def_value= (intptr_t) ((sessionvar_str_t*) opt)->def_val;
1406
options->arg_type= REQUIRED_ARG;
1407
if (opt->flags & PLUGIN_VAR_NOCMDARG)
1408
options->arg_type= NO_ARG;
1409
if (opt->flags & PLUGIN_VAR_OPCMDARG)
1410
options->arg_type= OPT_ARG;
1413
static int construct_options(memory::Root *mem_root, module::Module *tmp,
1417
int localoptionid= 256;
1418
const string plugin_name(tmp->getManifest().name);
1420
size_t namelen= plugin_name.size(), optnamelen;
1423
int index= 0, offset= 0;
1424
drizzle_sys_var *opt, **plugin_option;
1427
string name(plugin_name);
1428
transform(name.begin(), name.end(), name.begin(), ::tolower);
1430
for (string::iterator iter= name.begin(); iter != name.end(); ++iter)
1437
Two passes as the 2nd pass will take pointer addresses for use
1438
by my_getopt and register_var() in the first pass uses realloc
1441
for (plugin_option= tmp->getManifest().system_vars;
1442
plugin_option && *plugin_option; plugin_option++, index++)
1444
opt= *plugin_option;
1445
if (!(opt->flags & PLUGIN_VAR_SessionLOCAL))
1447
if (!(register_var(name, opt->name, opt->flags)))
1449
switch (opt->flags & PLUGIN_VAR_TYPEMASK) {
1450
case PLUGIN_VAR_BOOL:
1451
(((sessionvar_bool_t *)opt)->resolve)= mysql_sys_var_ptr_bool;
1453
case PLUGIN_VAR_INT:
1454
(((sessionvar_int_t *)opt)->resolve)= mysql_sys_var_ptr_int;
1456
case PLUGIN_VAR_LONG:
1457
(((sessionvar_long_t *)opt)->resolve)= mysql_sys_var_ptr_long;
1459
case PLUGIN_VAR_LONGLONG:
1460
(((sessionvar_int64_t_t *)opt)->resolve)= mysql_sys_var_ptr_int64_t;
1462
case PLUGIN_VAR_STR:
1463
(((sessionvar_str_t *)opt)->resolve)= mysql_sys_var_ptr_str;
1466
errmsg_printf(ERRMSG_LVL_ERROR, _("Unknown variable type code 0x%x in plugin '%s'."),
1467
opt->flags, plugin_name.c_str());
1472
for (plugin_option= tmp->getManifest().system_vars;
1473
plugin_option && *plugin_option; plugin_option++, index++)
1475
switch ((opt= *plugin_option)->flags & PLUGIN_VAR_TYPEMASK) {
1476
case PLUGIN_VAR_BOOL:
1478
opt->check= check_func_bool;
1480
opt->update= update_func_bool;
1482
case PLUGIN_VAR_INT:
1484
opt->check= check_func_int;
1486
opt->update= update_func_int;
1488
case PLUGIN_VAR_LONG:
1490
opt->check= check_func_long;
1492
opt->update= update_func_long;
1494
case PLUGIN_VAR_LONGLONG:
1496
opt->check= check_func_int64_t;
1498
opt->update= update_func_int64_t;
1500
case PLUGIN_VAR_STR:
1502
opt->check= check_func_str;
1505
opt->update= update_func_str;
1506
if ((opt->flags & (PLUGIN_VAR_MEMALLOC | PLUGIN_VAR_READONLY)) == false)
1508
opt->flags|= PLUGIN_VAR_READONLY;
1509
errmsg_printf(ERRMSG_LVL_WARN, _("Server variable %s of plugin %s was forced "
1510
"to be read-only: string variable without "
1511
"update_func and PLUGIN_VAR_MEMALLOC flag"),
1512
opt->name, plugin_name.c_str());
1517
errmsg_printf(ERRMSG_LVL_ERROR, _("Unknown variable type code 0x%x in plugin '%s'."),
1518
opt->flags, plugin_name.c_str());
1522
if ((opt->flags & (PLUGIN_VAR_NOCMDOPT | PLUGIN_VAR_SessionLOCAL))
1523
== PLUGIN_VAR_NOCMDOPT)
1528
errmsg_printf(ERRMSG_LVL_ERROR, _("Missing variable name in plugin '%s'."),
1529
plugin_name.c_str());
1533
if (!(opt->flags & PLUGIN_VAR_SessionLOCAL))
1535
optnamelen= strlen(opt->name);
1536
optname= (char*) mem_root->alloc_root(namelen + optnamelen + 2);
1537
sprintf(optname, "%s-%s", name.c_str(), opt->name);
1538
optnamelen= namelen + optnamelen + 1;
1542
/* this should not fail because register_var should create entry */
1543
if (!(v= find_bookmark(name, opt->name, opt->flags)))
1545
errmsg_printf(ERRMSG_LVL_ERROR, _("Thread local variable '%s' not allocated "
1546
"in plugin '%s'."), opt->name, plugin_name.c_str());
1550
*(int*)(opt + 1)= offset= v->offset;
1552
if (opt->flags & PLUGIN_VAR_NOCMDOPT)
1555
optname= (char*) mem_root->memdup_root(v->key.c_str(), (optnamelen= v->key.size()) + 1);
1558
/* convert '_' to '-' */
1559
for (p= optname; *p; p++)
1563
options->name= optname;
1564
options->comment= opt->comment;
1565
options->app_type= opt;
1566
options->id= localoptionid++;
1568
plugin_opt_set_limits(options, opt);
1570
if (opt->flags & PLUGIN_VAR_SessionLOCAL)
1571
options->value= options->u_max_value= (char**)
1572
(global_system_variables.dynamic_variables_ptr + offset);
1574
options->value= options->u_max_value= *(char***) (opt + 1);
1583
static option *construct_help_options(memory::Root *mem_root, module::Module *p)
1585
drizzle_sys_var **opt;
1587
uint32_t count= EXTRA_OPTIONS;
1589
for (opt= p->getManifest().system_vars; opt && *opt; opt++, count++) {};
1591
opts= (option*)mem_root->alloc_root((sizeof(option) * count));
1595
memset(opts, 0, sizeof(option) * count);
1597
if (construct_options(mem_root, p, opts))
1603
void drizzle_add_plugin_sysvar(sys_var_pluginvar *var)
1605
plugin_sysvar_vec.push_back(var);
1608
void drizzle_del_plugin_sysvar()
1610
vector<sys_var_pluginvar *>::iterator iter= plugin_sysvar_vec.begin();
1611
while(iter != plugin_sysvar_vec.end())
1616
plugin_sysvar_vec.clear();