563
563
#define DRIZZLE_SYSVAR_NAME(name) name
564
564
#define PLUGIN_VAR_TYPEMASK 0x007f
566
#define EXTRA_OPTIONS 3 /* options for: 'foo', 'plugin-foo' and NULL */
566
static const uint32_t EXTRA_OPTIONS= 1; /* handle the NULL option */
568
568
typedef DECLARE_DRIZZLE_SYSVAR_BASIC(sysvar_bool_t, bool);
569
569
typedef DECLARE_DRIZZLE_SessionVAR_BASIC(sessionvar_bool_t, bool);
793
static const string make_bookmark_name(const string &plugin, const char *name, int flags)
795
/* Embed the flags into the first char of the string */
796
string varname(1, static_cast<char>(flags & PLUGIN_VAR_TYPEMASK));
797
varname.append(plugin);
798
varname.push_back('_');
799
varname.append(name);
801
for (string::iterator p= varname.begin() + 1; p != varname.end(); ++p)
795
812
called by register_var, construct_options and test_plugin_options.
796
813
Returns the 'bookmark' for the named variable.
797
814
LOCK_system_variables_hash should be at least read locked
799
static st_bookmark *find_bookmark(const char *plugin, const char *name, int flags)
816
static st_bookmark *find_bookmark(const string &plugin, const char *name, int flags)
801
818
st_bookmark *result= NULL;
802
uint32_t namelen, length, pluginlen= 0;
805
820
if (!(flags & PLUGIN_VAR_SessionLOCAL))
808
namelen= strlen(name);
810
pluginlen= strlen(plugin) + 1;
811
length= namelen + pluginlen + 2;
812
varname= (char*) malloc(length);
816
sprintf(varname+1,"%s_%s",plugin,name);
817
for (p= varname + 1; *p; p++)
822
memcpy(varname + 1, name, namelen + 1);
824
varname[0]= flags & PLUGIN_VAR_TYPEMASK;
823
const string varname(make_bookmark_name(plugin, name, flags));
826
826
result= (st_bookmark*) hash_search(&bookmark_hash,
827
(const unsigned char*) varname, length - 1);
827
(const unsigned char*) varname.c_str(), varname.size() - 1);
836
835
returns null for non session-local variables.
837
836
Requires that a write lock is obtained on LOCK_system_variables_hash
839
static st_bookmark *register_var(const char *plugin, const char *name,
838
static st_bookmark *register_var(const string &plugin, const char *name,
842
uint32_t length= strlen(plugin) + strlen(name) + 3, size= 0, offset, new_size;
841
if (!(flags & PLUGIN_VAR_SessionLOCAL))
844
uint32_t size= 0, offset, new_size;
843
845
st_bookmark *result;
846
if (!(flags & PLUGIN_VAR_SessionLOCAL))
849
847
switch (flags & PLUGIN_VAR_TYPEMASK) {
850
848
case PLUGIN_VAR_BOOL:
870
varname= ((char*) malloc(length));
871
sprintf(varname+1, "%s_%s", plugin, name);
872
for (p= varname + 1; *p; p++)
876
if (!(result= find_bookmark(NULL, varname + 1, flags)))
869
if (!(result= find_bookmark(plugin, name, flags)))
878
result= (st_bookmark*) alloc_root(&plugin_mem_root,
879
sizeof(struct st_bookmark) + length-1);
880
varname[0]= flags & PLUGIN_VAR_TYPEMASK;
881
memcpy(result->key, varname, length);
882
result->name_len= length - 2;
871
const string varname(make_bookmark_name(plugin, name, flags));
873
result= static_cast<st_bookmark*>(alloc_root(&plugin_mem_root,
874
sizeof(struct st_bookmark) + varname.size() + 1));
875
memset(result->key, 0, varname.size()+1);
876
memcpy(result->key, varname.c_str(), varname.size());
877
result->name_len= varname.size() - 2;
883
878
result->offset= -1;
885
880
assert(size && !(size & (size-1))); /* must be power of 2 */
1429
1423
static int construct_options(memory::Root *mem_root, plugin::Module *tmp,
1430
1424
my_option *options)
1432
const char *plugin_name= tmp->getManifest().name;
1433
uint32_t namelen= strlen(plugin_name), optnamelen;
1434
uint32_t buffer_length= namelen * 4 + 75;
1435
char *name= (char*) alloc_root(mem_root, buffer_length);
1436
bool *enabled_value= (bool*) alloc_root(mem_root, sizeof(bool));
1427
int localoptionid= 256;
1428
const string plugin_name(tmp->getManifest().name);
1430
size_t namelen= plugin_name.size(), optnamelen;
1437
1432
char *optname, *p;
1438
1433
int index= 0, offset= 0;
1439
1434
drizzle_sys_var *opt, **plugin_option;
1440
1435
st_bookmark *v;
1442
/* support --skip-plugin-foo syntax */
1443
memcpy(name, plugin_name, namelen + 1);
1444
my_casedn_str(&my_charset_utf8_general_ci, name);
1445
sprintf(name+namelen+1, "plugin-%s", name);
1446
/* Now we have namelen + 1 + 7 + namelen + 1 == namelen * 2 + 9. */
1448
for (p= name + namelen*2 + 8; p > name; p--)
1452
sprintf(name+namelen*2+10,
1453
"Enable %s plugin. Disable with --skip-%s (will save memory).",
1456
Now we have namelen * 2 + 10 (one char unused) + 7 + namelen + 9 +
1457
20 + namelen + 20 + 1 == namelen * 4 + 67.
1460
options[0].comment= name + namelen*2 + 10;
1463
This whole code around variables and command line parameters is turd
1466
e.g. the below assignemnt of having the plugin alaways enabled is never
1467
changed so that './drizzled --skip-innodb --help' shows innodb as enabled.
1469
But this is just as broken as it was in MySQL and properly fixing everything
1470
is a decent amount of "future work"
1472
*enabled_value= true; /* by default, plugin enabled */
1474
options[1].name= (options[0].name= name) + namelen + 1;
1475
options[0].id= options[1].id= 256; /* must be >255. dup id ok */
1476
options[0].var_type= options[1].var_type= GET_BOOL;
1477
options[0].arg_type= options[1].arg_type= NO_ARG;
1478
options[0].def_value= options[1].def_value= true;
1479
options[0].value= options[0].u_max_value=
1480
options[1].value= options[1].u_max_value= (char**) enabled_value;
1437
string name(plugin_name);
1438
transform(name.begin(), name.end(), name.begin(), ::tolower);
1440
for (string::iterator iter= name.begin(); iter != name.end(); ++iter)
1484
1447
Two passes as the 2nd pass will take pointer addresses for use
1556
1519
errmsg_printf(ERRMSG_LVL_WARN, _("Server variable %s of plugin %s was forced "
1557
1520
"to be read-only: string variable without "
1558
1521
"update_func and PLUGIN_VAR_MEMALLOC flag"),
1559
opt->name, plugin_name);
1522
opt->name, plugin_name.c_str());
1564
1527
errmsg_printf(ERRMSG_LVL_ERROR, _("Unknown variable type code 0x%x in plugin '%s'."),
1565
opt->flags, plugin_name);
1528
opt->flags, plugin_name.c_str());
1582
1545
optnamelen= strlen(opt->name);
1583
1546
optname= (char*) alloc_root(mem_root, namelen + optnamelen + 2);
1584
sprintf(optname, "%s-%s", name, opt->name);
1547
sprintf(optname, "%s-%s", name.c_str(), opt->name);
1585
1548
optnamelen= namelen + optnamelen + 1;
1590
1553
if (!(v= find_bookmark(name, opt->name, opt->flags)))
1592
1555
errmsg_printf(ERRMSG_LVL_ERROR, _("Thread local variable '%s' not allocated "
1593
"in plugin '%s'."), opt->name, plugin_name);
1556
"in plugin '%s'."), opt->name, plugin_name.c_str());
1732
1690
if (((o= *opt)->flags & PLUGIN_VAR_NOSYSVAR))
1735
if ((var= find_bookmark(tmp->getName().c_str(), o->name, o->flags)))
1693
if ((var= find_bookmark(tmp->getName(), o->name, o->flags)))
1736
1694
v= new sys_var_pluginvar(var->key + 1, o);