503
585
global_variables_dynamic_size= 0;
588
/****************************************************************************
589
Internal type declarations for variables support
590
****************************************************************************/
592
#undef DRIZZLE_SYSVAR_NAME
593
#define DRIZZLE_SYSVAR_NAME(name) name
594
#define PLUGIN_VAR_TYPEMASK 0x007f
596
static const uint32_t EXTRA_OPTIONS= 1; /* handle the NULL option */
598
typedef DECLARE_DRIZZLE_SYSVAR_BOOL(sysvar_bool_t);
599
typedef DECLARE_DRIZZLE_SessionVAR_BOOL(sessionvar_bool_t);
600
typedef DECLARE_DRIZZLE_SYSVAR_BASIC(sysvar_str_t, char *);
601
typedef DECLARE_DRIZZLE_SessionVAR_BASIC(sessionvar_str_t, char *);
603
typedef DECLARE_DRIZZLE_SessionVAR_TYPELIB(sessionvar_enum_t, unsigned long);
604
typedef DECLARE_DRIZZLE_SessionVAR_TYPELIB(sessionvar_set_t, uint64_t);
606
typedef DECLARE_DRIZZLE_SYSVAR_SIMPLE(sysvar_int_t, int);
607
typedef DECLARE_DRIZZLE_SYSVAR_SIMPLE(sysvar_long_t, long);
608
typedef DECLARE_DRIZZLE_SYSVAR_SIMPLE(sysvar_int64_t_t, int64_t);
609
typedef DECLARE_DRIZZLE_SYSVAR_SIMPLE(sysvar_uint_t, uint);
610
typedef DECLARE_DRIZZLE_SYSVAR_SIMPLE(sysvar_ulong_t, ulong);
611
typedef DECLARE_DRIZZLE_SYSVAR_SIMPLE(sysvar_uint64_t_t, uint64_t);
613
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_int_t, int);
614
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_long_t, long);
615
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_int64_t_t, int64_t);
616
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_uint_t, uint);
617
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_ulong_t, ulong);
618
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_uint64_t_t, uint64_t);
620
typedef bool *(*mysql_sys_var_ptr_p)(Session* a_session, int offset);
623
/****************************************************************************
624
default variable data check and update functions
625
****************************************************************************/
627
static int check_func_bool(Session *, drizzle_sys_var *var,
628
void *save, drizzle_value *value)
630
char buff[STRING_BUFFER_USUAL_SIZE];
631
const char *strvalue= "NULL", *str;
635
if (value->value_type(value) == DRIZZLE_VALUE_TYPE_STRING)
637
length= sizeof(buff);
638
if (!(str= value->val_str(value, buff, &length)) ||
639
(result= find_type(&bool_typelib, str, length, 1)-1) < 0)
648
if (value->val_int(value, &tmp) < 0)
652
internal::llstr(tmp, buff);
658
*(int*)save= -result;
661
my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), var->name, strvalue);
666
static int check_func_int(Session *session, drizzle_sys_var *var,
667
void *save, drizzle_value *value)
671
struct option options;
672
value->val_int(value, &tmp);
673
plugin_opt_set_limits(&options, var);
675
if (var->flags & PLUGIN_VAR_UNSIGNED)
676
*(uint32_t *)save= (uint32_t) getopt_ull_limit_value((uint64_t) tmp, &options,
679
*(int *)save= (int) getopt_ll_limit_value(tmp, &options, &fixed);
681
return throw_bounds_warning(session, fixed, var->flags & PLUGIN_VAR_UNSIGNED,
682
var->name, (int64_t) tmp);
686
static int check_func_long(Session *session, drizzle_sys_var *var,
687
void *save, drizzle_value *value)
691
struct option options;
692
value->val_int(value, &tmp);
693
plugin_opt_set_limits(&options, var);
695
if (var->flags & PLUGIN_VAR_UNSIGNED)
696
*(ulong *)save= (ulong) getopt_ull_limit_value((uint64_t) tmp, &options,
699
*(long *)save= (long) getopt_ll_limit_value(tmp, &options, &fixed);
701
return throw_bounds_warning(session, fixed, var->flags & PLUGIN_VAR_UNSIGNED,
702
var->name, (int64_t) tmp);
706
static int check_func_int64_t(Session *session, drizzle_sys_var *var,
707
void *save, drizzle_value *value)
711
struct option options;
712
value->val_int(value, &tmp);
713
plugin_opt_set_limits(&options, var);
715
if (var->flags & PLUGIN_VAR_UNSIGNED)
716
*(uint64_t *)save= getopt_ull_limit_value((uint64_t) tmp, &options,
719
*(int64_t *)save= getopt_ll_limit_value(tmp, &options, &fixed);
721
return throw_bounds_warning(session, fixed, var->flags & PLUGIN_VAR_UNSIGNED,
722
var->name, (int64_t) tmp);
725
static int check_func_str(Session *session, drizzle_sys_var *,
726
void *save, drizzle_value *value)
728
char buff[STRING_BUFFER_USUAL_SIZE];
732
length= sizeof(buff);
733
if ((str= value->val_str(value, buff, &length)))
734
str= session->strmake(str, length);
735
*(const char**)save= str;
740
static void update_func_bool(Session *, drizzle_sys_var *,
741
void *tgt, const void *save)
743
*(bool *) tgt= *(int *) save ? 1 : 0;
747
static void update_func_int(Session *, drizzle_sys_var *,
748
void *tgt, const void *save)
750
*(int *)tgt= *(int *) save;
754
static void update_func_long(Session *, drizzle_sys_var *,
755
void *tgt, const void *save)
757
*(long *)tgt= *(long *) save;
761
static void update_func_int64_t(Session *, drizzle_sys_var *,
762
void *tgt, const void *save)
764
*(int64_t *)tgt= *(uint64_t *) save;
768
static void update_func_str(Session *, drizzle_sys_var *var,
769
void *tgt, const void *save)
771
char *old= *(char **) tgt;
772
*(char **)tgt= *(char **) save;
773
if (var->flags & PLUGIN_VAR_MEMALLOC)
775
*(char **)tgt= strdup(*(char **) save);
778
* There isn't a _really_ good thing to do here until this whole set_var
779
* mess gets redesigned
782
errmsg_printf(ERRMSG_LVL_ERROR, _("Out of memory."));
507
788
/****************************************************************************
508
789
System Variables support
509
790
****************************************************************************/
793
sys_var *find_sys_var(Session *, const char *str, uint32_t length)
796
sys_var_pluginvar *pi= NULL;
797
module::Module *module;
799
if ((var= intern_find_sys_var(str, length, false)) &&
800
(pi= var->cast_pluginvar()))
802
if (!(module= pi->plugin))
803
var= NULL; /* failed to lock it, it must be uninstalling */
804
else if (module->isInited == false)
811
If the variable exists but the plugin it is associated with is not ready
812
then the intern_plugin_lock did not raise an error, so we do it here.
816
my_error(ER_UNKNOWN_SYSTEM_VARIABLE, MYF(0), (char*) str);
822
static const string make_bookmark_name(const string &plugin, const char *name)
824
string varname(plugin);
825
varname.push_back('_');
826
varname.append(name);
828
for (string::iterator p= varname.begin() + 1; p != varname.end(); ++p)
839
called by register_var, construct_options and test_plugin_options.
840
Returns the 'bookmark' for the named variable.
841
LOCK_system_variables_hash should be at least read locked
843
static Bookmark *find_bookmark(const string &plugin, const char *name, int flags)
845
if (!(flags & PLUGIN_VAR_SessionLOCAL))
848
const string varname(make_bookmark_name(plugin, name));
850
bookmark_unordered_map::iterator iter= bookmark_hash.find(varname);
851
if (iter != bookmark_hash.end())
853
return &((*iter).second);
860
returns a bookmark for session-local variables, creating if neccessary.
861
returns null for non session-local variables.
862
Requires that a write lock is obtained on LOCK_system_variables_hash
864
static Bookmark *register_var(const string &plugin, const char *name,
867
if (!(flags & PLUGIN_VAR_SessionLOCAL))
870
uint32_t size= 0, offset, new_size;
871
Bookmark *result= NULL;
873
switch (flags & PLUGIN_VAR_TYPEMASK) {
874
case PLUGIN_VAR_BOOL:
875
size= ALIGN_SIZE(sizeof(bool));
878
size= ALIGN_SIZE(sizeof(int));
880
case PLUGIN_VAR_LONG:
881
size= ALIGN_SIZE(sizeof(long));
883
case PLUGIN_VAR_LONGLONG:
884
size= ALIGN_SIZE(sizeof(uint64_t));
887
size= ALIGN_SIZE(sizeof(char*));
895
if (!(result= find_bookmark(plugin, name, flags)))
897
const string varname(make_bookmark_name(plugin, name));
899
Bookmark new_bookmark;
900
new_bookmark.key= varname;
901
new_bookmark.offset= -1;
903
assert(size && !(size & (size-1))); /* must be power of 2 */
905
offset= global_system_variables.dynamic_variables_size;
906
offset= (offset + size - 1) & ~(size - 1);
907
new_bookmark.offset= (int) offset;
909
new_size= (offset + size + 63) & ~63;
911
if (new_size > global_variables_dynamic_size)
915
(char *)realloc(global_system_variables.dynamic_variables_ptr,
918
global_system_variables.dynamic_variables_ptr= tmpptr;
921
(char *)realloc(max_system_variables.dynamic_variables_ptr,
924
max_system_variables.dynamic_variables_ptr= tmpptr;
927
Clear the new variable value space. This is required for string
928
variables. If their value is non-NULL, it must point to a valid
931
memset(global_system_variables.dynamic_variables_ptr +
932
global_variables_dynamic_size, 0,
933
new_size - global_variables_dynamic_size);
934
memset(max_system_variables.dynamic_variables_ptr +
935
global_variables_dynamic_size, 0,
936
new_size - global_variables_dynamic_size);
937
global_variables_dynamic_size= new_size;
940
global_system_variables.dynamic_variables_head= offset;
941
max_system_variables.dynamic_variables_head= offset;
942
global_system_variables.dynamic_variables_size= offset + size;
943
max_system_variables.dynamic_variables_size= offset + size;
944
global_system_variables.dynamic_variables_version++;
945
max_system_variables.dynamic_variables_version++;
947
new_bookmark.version= global_system_variables.dynamic_variables_version;
948
new_bookmark.type_code= flags;
950
/* this should succeed because we have already checked if a dup exists */
951
bookmark_hash.insert(make_pair(varname, new_bookmark));
952
result= find_bookmark(plugin, name, flags);
959
returns a pointer to the memory which holds the session-local variable or
960
a pointer to the global variable if session==null.
961
If required, will sync with global variables if the requested variable
962
has not yet been allocated in the current thread.
964
static unsigned char *intern_sys_var_ptr(Session* session, int offset, bool global_lock)
967
assert((uint32_t)offset <= global_system_variables.dynamic_variables_head);
970
return (unsigned char*) global_system_variables.dynamic_variables_ptr + offset;
973
dynamic_variables_head points to the largest valid offset
975
if (!session->variables.dynamic_variables_ptr ||
976
(uint32_t)offset > session->variables.dynamic_variables_head)
979
if (!(tmpptr= (char *)realloc(session->variables.dynamic_variables_ptr,
980
global_variables_dynamic_size)))
982
session->variables.dynamic_variables_ptr= tmpptr;
985
LOCK_global_system_variables.lock();
987
//safe_mutex_assert_owner(&LOCK_global_system_variables);
989
memcpy(session->variables.dynamic_variables_ptr +
990
session->variables.dynamic_variables_size,
991
global_system_variables.dynamic_variables_ptr +
992
session->variables.dynamic_variables_size,
993
global_system_variables.dynamic_variables_size -
994
session->variables.dynamic_variables_size);
997
now we need to iterate through any newly copied 'defaults'
998
and if it is a string type with MEMALLOC flag, we need to strdup
1000
bookmark_unordered_map::iterator iter= bookmark_hash.begin();
1001
for (; iter != bookmark_hash.end() ; ++iter)
1003
sys_var_pluginvar *pi;
1005
const Bookmark &v= (*iter).second;
1006
const string var_name((*iter).first);
1008
if (v.version <= session->variables.dynamic_variables_version ||
1009
!(var= intern_find_sys_var(var_name.c_str(), var_name.size(), true)) ||
1010
!(pi= var->cast_pluginvar()) ||
1011
v.type_code != (pi->plugin_var->flags & PLUGIN_VAR_TYPEMASK))
1014
/* Here we do anything special that may be required of the data types */
1016
if ((pi->plugin_var->flags & PLUGIN_VAR_TYPEMASK) == PLUGIN_VAR_STR &&
1017
pi->plugin_var->flags & PLUGIN_VAR_MEMALLOC)
1019
char **pp= (char**) (session->variables.dynamic_variables_ptr +
1020
*(int*)(pi->plugin_var + 1));
1021
if ((*pp= *(char**) (global_system_variables.dynamic_variables_ptr +
1022
*(int*)(pi->plugin_var + 1))))
1030
LOCK_global_system_variables.unlock();
1032
session->variables.dynamic_variables_version=
1033
global_system_variables.dynamic_variables_version;
1034
session->variables.dynamic_variables_head=
1035
global_system_variables.dynamic_variables_head;
1036
session->variables.dynamic_variables_size=
1037
global_system_variables.dynamic_variables_size;
1039
return (unsigned char*)session->variables.dynamic_variables_ptr + offset;
1042
static bool *mysql_sys_var_ptr_bool(Session* a_session, int offset)
1044
return (bool *)intern_sys_var_ptr(a_session, offset, true);
1047
static int *mysql_sys_var_ptr_int(Session* a_session, int offset)
1049
return (int *)intern_sys_var_ptr(a_session, offset, true);
1052
static long *mysql_sys_var_ptr_long(Session* a_session, int offset)
1054
return (long *)intern_sys_var_ptr(a_session, offset, true);
1057
static int64_t *mysql_sys_var_ptr_int64_t(Session* a_session, int offset)
1059
return (int64_t *)intern_sys_var_ptr(a_session, offset, true);
1062
static char **mysql_sys_var_ptr_str(Session* a_session, int offset)
1064
return (char **)intern_sys_var_ptr(a_session, offset, true);
513
1067
void plugin_sessionvar_init(Session *session)
1118
@brief Free values of thread variables of a plugin.
1120
This must be called before a plugin is deleted. Otherwise its
1121
variables are no longer accessible and the value space is lost. Note
1122
that only string values with PLUGIN_VAR_MEMALLOC are allocated and
1125
@param[in] vars Chain of system variables of a plugin
1128
static void plugin_vars_free_values(module::Module::Variables &vars)
1131
for (module::Module::Variables::iterator iter= vars.begin();
1135
sys_var_pluginvar *piv= (*iter)->cast_pluginvar();
1137
((piv->plugin_var->flags & PLUGIN_VAR_TYPEMASK) == PLUGIN_VAR_STR) &&
1138
(piv->plugin_var->flags & PLUGIN_VAR_MEMALLOC))
1140
/* Free the string from global_system_variables. */
1141
char **valptr= (char**) piv->real_value_ptr(NULL, OPT_GLOBAL);
1150
bool sys_var_pluginvar::check_update_type(Item_result type)
1154
switch (plugin_var->flags & PLUGIN_VAR_TYPEMASK) {
1155
case PLUGIN_VAR_INT:
1156
case PLUGIN_VAR_LONG:
1157
case PLUGIN_VAR_LONGLONG:
1158
return type != INT_RESULT;
1159
case PLUGIN_VAR_STR:
1160
return type != STRING_RESULT;
1167
SHOW_TYPE sys_var_pluginvar::show_type()
1169
switch (plugin_var->flags & PLUGIN_VAR_TYPEMASK) {
1170
case PLUGIN_VAR_BOOL:
1171
return SHOW_MY_BOOL;
1172
case PLUGIN_VAR_INT:
1174
case PLUGIN_VAR_LONG:
1176
case PLUGIN_VAR_LONGLONG:
1177
return SHOW_LONGLONG;
1178
case PLUGIN_VAR_STR:
1179
return SHOW_CHAR_PTR;
1187
unsigned char* sys_var_pluginvar::real_value_ptr(Session *session, sql_var_t type)
1189
assert(session || (type == OPT_GLOBAL));
1190
if (plugin_var->flags & PLUGIN_VAR_SessionLOCAL)
1192
if (type == OPT_GLOBAL)
1195
return intern_sys_var_ptr(session, *(int*) (plugin_var+1), false);
1197
return *(unsigned char**) (plugin_var+1);
1201
TYPELIB* sys_var_pluginvar::plugin_var_typelib(void)
1203
switch (plugin_var->flags & (PLUGIN_VAR_TYPEMASK | PLUGIN_VAR_SessionLOCAL)) {
1204
case PLUGIN_VAR_SessionLOCAL:
1205
return ((sessionvar_enum_t *)plugin_var)->typelib;
1213
unsigned char* sys_var_pluginvar::value_ptr(Session *session, sql_var_t type, const LEX_STRING *)
1215
unsigned char* result;
1217
result= real_value_ptr(session, type);
1223
bool sys_var_pluginvar::check(Session *session, set_var *var)
1225
st_item_value_holder value;
1226
assert(is_readonly() || plugin_var->check);
1228
value.value_type= item_value_type;
1229
value.val_str= item_val_str;
1230
value.val_int= item_val_int;
1231
value.val_real= item_val_real;
1232
value.item= var->value;
1234
return is_readonly() ||
1235
plugin_var->check(session, plugin_var, &var->save_result, &value);
1239
void sys_var_pluginvar::set_default(Session *session, sql_var_t type)
1244
assert(is_readonly() || plugin_var->update);
1249
LOCK_global_system_variables.lock();
1250
tgt= real_value_ptr(session, type);
1251
src= ((void **) (plugin_var + 1) + 1);
1253
if (plugin_var->flags & PLUGIN_VAR_SessionLOCAL)
1255
if (type != OPT_GLOBAL)
1256
src= real_value_ptr(session, OPT_GLOBAL);
1258
switch (plugin_var->flags & PLUGIN_VAR_TYPEMASK) {
1259
case PLUGIN_VAR_INT:
1260
src= &((sessionvar_uint_t*) plugin_var)->def_val;
1262
case PLUGIN_VAR_LONG:
1263
src= &((sessionvar_ulong_t*) plugin_var)->def_val;
1265
case PLUGIN_VAR_LONGLONG:
1266
src= &((sessionvar_uint64_t_t*) plugin_var)->def_val;
1268
case PLUGIN_VAR_BOOL:
1269
src= &((sessionvar_bool_t*) plugin_var)->def_val;
1271
case PLUGIN_VAR_STR:
1272
src= &((sessionvar_str_t*) plugin_var)->def_val;
1279
/* session must equal current_session if PLUGIN_VAR_SessionLOCAL flag is set */
1280
assert(!(plugin_var->flags & PLUGIN_VAR_SessionLOCAL) ||
1281
session == current_session);
1283
if (!(plugin_var->flags & PLUGIN_VAR_SessionLOCAL) || type == OPT_GLOBAL)
1285
plugin_var->update(session, plugin_var, tgt, src);
1286
LOCK_global_system_variables.unlock();
1290
LOCK_global_system_variables.unlock();
1291
plugin_var->update(session, plugin_var, tgt, src);
1296
bool sys_var_pluginvar::update(Session *session, set_var *var)
1300
assert(is_readonly() || plugin_var->update);
1302
/* session must equal current_session if PLUGIN_VAR_SessionLOCAL flag is set */
1303
assert(!(plugin_var->flags & PLUGIN_VAR_SessionLOCAL) ||
1304
session == current_session);
1309
LOCK_global_system_variables.lock();
1310
tgt= real_value_ptr(session, var->type);
1312
if (!(plugin_var->flags & PLUGIN_VAR_SessionLOCAL) || var->type == OPT_GLOBAL)
1314
/* variable we are updating has global scope, so we unlock after updating */
1315
plugin_var->update(session, plugin_var, tgt, &var->save_result);
1316
LOCK_global_system_variables.unlock();
1320
LOCK_global_system_variables.unlock();
1321
plugin_var->update(session, plugin_var, tgt, &var->save_result);
1327
#define OPTION_SET_LIMITS(type, options, opt) \
1328
options->var_type= type; \
1329
options->def_value= (opt)->def_val; \
1330
options->min_value= (opt)->min_val; \
1331
options->max_value= (opt)->max_val; \
1332
options->block_size= (long) (opt)->blk_sz
1335
void plugin_opt_set_limits(struct option *options,
1336
const drizzle_sys_var *opt)
1338
options->sub_size= 0;
1340
switch (opt->flags & (PLUGIN_VAR_TYPEMASK |
1341
PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_SessionLOCAL)) {
1342
/* global system variables */
1343
case PLUGIN_VAR_INT:
1344
OPTION_SET_LIMITS(GET_INT, options, (sysvar_int_t*) opt);
1346
case PLUGIN_VAR_INT | PLUGIN_VAR_UNSIGNED:
1347
OPTION_SET_LIMITS(GET_UINT, options, (sysvar_uint_t*) opt);
1349
case PLUGIN_VAR_LONG:
1350
OPTION_SET_LIMITS(GET_LONG, options, (sysvar_long_t*) opt);
1352
case PLUGIN_VAR_LONG | PLUGIN_VAR_UNSIGNED:
1353
OPTION_SET_LIMITS(GET_ULONG_IS_FAIL, options, (sysvar_ulong_t*) opt);
1355
case PLUGIN_VAR_LONGLONG:
1356
OPTION_SET_LIMITS(GET_LL, options, (sysvar_int64_t_t*) opt);
1358
case PLUGIN_VAR_LONGLONG | PLUGIN_VAR_UNSIGNED:
1359
OPTION_SET_LIMITS(GET_ULL, options, (sysvar_uint64_t_t*) opt);
1361
case PLUGIN_VAR_BOOL:
1362
options->var_type= GET_BOOL;
1363
options->def_value= ((sysvar_bool_t*) opt)->def_val;
1365
case PLUGIN_VAR_STR:
1366
options->var_type= ((opt->flags & PLUGIN_VAR_MEMALLOC) ?
1367
GET_STR_ALLOC : GET_STR);
1368
options->def_value= (intptr_t) ((sysvar_str_t*) opt)->def_val;
1370
/* threadlocal variables */
1371
case PLUGIN_VAR_INT | PLUGIN_VAR_SessionLOCAL:
1372
OPTION_SET_LIMITS(GET_INT, options, (sessionvar_int_t*) opt);
1374
case PLUGIN_VAR_INT | PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_SessionLOCAL:
1375
OPTION_SET_LIMITS(GET_UINT, options, (sessionvar_uint_t*) opt);
1377
case PLUGIN_VAR_LONG | PLUGIN_VAR_SessionLOCAL:
1378
OPTION_SET_LIMITS(GET_LONG, options, (sessionvar_long_t*) opt);
1380
case PLUGIN_VAR_LONG | PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_SessionLOCAL:
1381
OPTION_SET_LIMITS(GET_ULONG_IS_FAIL, options, (sessionvar_ulong_t*) opt);
1383
case PLUGIN_VAR_LONGLONG | PLUGIN_VAR_SessionLOCAL:
1384
OPTION_SET_LIMITS(GET_LL, options, (sessionvar_int64_t_t*) opt);
1386
case PLUGIN_VAR_LONGLONG | PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_SessionLOCAL:
1387
OPTION_SET_LIMITS(GET_ULL, options, (sessionvar_uint64_t_t*) opt);
1389
case PLUGIN_VAR_BOOL | PLUGIN_VAR_SessionLOCAL:
1390
options->var_type= GET_BOOL;
1391
options->def_value= ((sessionvar_bool_t*) opt)->def_val;
1393
case PLUGIN_VAR_STR | PLUGIN_VAR_SessionLOCAL:
1394
options->var_type= ((opt->flags & PLUGIN_VAR_MEMALLOC) ?
1395
GET_STR_ALLOC : GET_STR);
1396
options->def_value= (intptr_t) ((sessionvar_str_t*) opt)->def_val;
1401
options->arg_type= REQUIRED_ARG;
1402
if (opt->flags & PLUGIN_VAR_NOCMDARG)
1403
options->arg_type= NO_ARG;
1404
if (opt->flags & PLUGIN_VAR_OPCMDARG)
1405
options->arg_type= OPT_ARG;
1408
static int construct_options(memory::Root *mem_root, module::Module *tmp,
1412
int localoptionid= 256;
1413
const string plugin_name(tmp->getManifest().name);
1415
size_t namelen= plugin_name.size(), optnamelen;
1418
int index= 0, offset= 0;
1419
drizzle_sys_var *opt, **plugin_option;
1422
string name(plugin_name);
1423
transform(name.begin(), name.end(), name.begin(), ::tolower);
1425
for (string::iterator iter= name.begin(); iter != name.end(); ++iter)
1432
Two passes as the 2nd pass will take pointer addresses for use
1433
by my_getopt and register_var() in the first pass uses realloc
1436
for (plugin_option= tmp->getManifest().system_vars;
1437
plugin_option && *plugin_option; plugin_option++, index++)
1439
opt= *plugin_option;
1440
if (!(opt->flags & PLUGIN_VAR_SessionLOCAL))
1442
if (!(register_var(name, opt->name, opt->flags)))
1444
switch (opt->flags & PLUGIN_VAR_TYPEMASK) {
1445
case PLUGIN_VAR_BOOL:
1446
(((sessionvar_bool_t *)opt)->resolve)= mysql_sys_var_ptr_bool;
1448
case PLUGIN_VAR_INT:
1449
(((sessionvar_int_t *)opt)->resolve)= mysql_sys_var_ptr_int;
1451
case PLUGIN_VAR_LONG:
1452
(((sessionvar_long_t *)opt)->resolve)= mysql_sys_var_ptr_long;
1454
case PLUGIN_VAR_LONGLONG:
1455
(((sessionvar_int64_t_t *)opt)->resolve)= mysql_sys_var_ptr_int64_t;
1457
case PLUGIN_VAR_STR:
1458
(((sessionvar_str_t *)opt)->resolve)= mysql_sys_var_ptr_str;
1461
errmsg_printf(ERRMSG_LVL_ERROR, _("Unknown variable type code 0x%x in plugin '%s'."),
1462
opt->flags, plugin_name.c_str());
1467
for (plugin_option= tmp->getManifest().system_vars;
1468
plugin_option && *plugin_option; plugin_option++, index++)
1470
switch ((opt= *plugin_option)->flags & PLUGIN_VAR_TYPEMASK) {
1471
case PLUGIN_VAR_BOOL:
1473
opt->check= check_func_bool;
1475
opt->update= update_func_bool;
1477
case PLUGIN_VAR_INT:
1479
opt->check= check_func_int;
1481
opt->update= update_func_int;
1483
case PLUGIN_VAR_LONG:
1485
opt->check= check_func_long;
1487
opt->update= update_func_long;
1489
case PLUGIN_VAR_LONGLONG:
1491
opt->check= check_func_int64_t;
1493
opt->update= update_func_int64_t;
1495
case PLUGIN_VAR_STR:
1497
opt->check= check_func_str;
1500
opt->update= update_func_str;
1501
if ((opt->flags & (PLUGIN_VAR_MEMALLOC | PLUGIN_VAR_READONLY)) == false)
1503
opt->flags|= PLUGIN_VAR_READONLY;
1504
errmsg_printf(ERRMSG_LVL_WARN, _("Server variable %s of plugin %s was forced "
1505
"to be read-only: string variable without "
1506
"update_func and PLUGIN_VAR_MEMALLOC flag"),
1507
opt->name, plugin_name.c_str());
1512
errmsg_printf(ERRMSG_LVL_ERROR, _("Unknown variable type code 0x%x in plugin '%s'."),
1513
opt->flags, plugin_name.c_str());
1517
if ((opt->flags & (PLUGIN_VAR_NOCMDOPT | PLUGIN_VAR_SessionLOCAL))
1518
== PLUGIN_VAR_NOCMDOPT)
1523
errmsg_printf(ERRMSG_LVL_ERROR, _("Missing variable name in plugin '%s'."),
1524
plugin_name.c_str());
1528
if (!(opt->flags & PLUGIN_VAR_SessionLOCAL))
1530
optnamelen= strlen(opt->name);
1531
optname= (char*) mem_root->alloc_root(namelen + optnamelen + 2);
1532
sprintf(optname, "%s-%s", name.c_str(), opt->name);
1533
optnamelen= namelen + optnamelen + 1;
1537
/* this should not fail because register_var should create entry */
1538
if (!(v= find_bookmark(name, opt->name, opt->flags)))
1540
errmsg_printf(ERRMSG_LVL_ERROR, _("Thread local variable '%s' not allocated "
1541
"in plugin '%s'."), opt->name, plugin_name.c_str());
1545
*(int*)(opt + 1)= offset= v->offset;
1547
if (opt->flags & PLUGIN_VAR_NOCMDOPT)
1550
optname= (char*) mem_root->memdup_root(v->key.c_str(), (optnamelen= v->key.size()) + 1);
1553
/* convert '_' to '-' */
1554
for (p= optname; *p; p++)
1558
options->name= optname;
1559
options->comment= opt->comment;
1560
options->app_type= opt;
1561
options->id= localoptionid++;
1563
plugin_opt_set_limits(options, opt);
1565
if (opt->flags & PLUGIN_VAR_SessionLOCAL)
1566
options->value= options->u_max_value= (char**)
1567
(global_system_variables.dynamic_variables_ptr + offset);
1569
options->value= options->u_max_value= *(char***) (opt + 1);
1578
static option *construct_help_options(memory::Root *mem_root, module::Module *p)
1580
drizzle_sys_var **opt;
1582
uint32_t count= EXTRA_OPTIONS;
1584
for (opt= p->getManifest().system_vars; opt && *opt; opt++, count++) {};
1586
opts= (option*)mem_root->alloc_root((sizeof(option) * count));
1590
memset(opts, 0, sizeof(option) * count);
1592
if (construct_options(mem_root, p, opts))
1598
void drizzle_add_plugin_sysvar(sys_var_pluginvar *var)
1600
plugin_sysvar_vec.push_back(var);
1603
void drizzle_del_plugin_sysvar()
1605
vector<sys_var_pluginvar *>::iterator iter= plugin_sysvar_vec.begin();
1606
while(iter != plugin_sysvar_vec.end())
1611
plugin_sysvar_vec.clear();