~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
/* Copyright (C) 2005 MySQL AB
2
3
   This program is free software; you can redistribute it and/or modify
4
   it under the terms of the GNU General Public License as published by
5
   the Free Software Foundation; version 2 of the License.
6
7
   This program is distributed in the hope that it will be useful,
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
   GNU General Public License for more details.
11
12
   You should have received a copy of the GNU General Public License
13
   along with this program; if not, write to the Free Software
1802.10.2 by Monty Taylor
Update all of the copyright headers to include the correct address.
14
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
1 by brian
clean slate
15
1241.9.36 by Monty Taylor
ZOMG. I deleted drizzled/server_includes.h.
16
#include "config.h"
499.2.9 by Mark Atwood
fix mistakes
17
1122.2.13 by Monty Taylor
Header cleanup.
18
#include <dlfcn.h>
499.2.9 by Mark Atwood
fix mistakes
19
1502.3.1 by iwamatsu at nigauri
Add cstdio include to files needing it. Fixes the build on some debian
20
#include <cstdio>
534 by Monty Taylor
Removed stxnmov. Also deleted strstr which had already been removed.
21
#include <string>
656.1.1 by Monty Taylor
OOOh doggie. Got rid of my_alloca.
22
#include <vector>
873.2.21 by Monty Taylor
Removed the HASH for plugin_hash.
23
#include <map>
1067.4.4 by Nathan Williams
The rest of the files in the drizzled directory were purged of the cmin macro and replace with std::min (except for the definition in globals.h and 1 usage in stacktrace.cc).
24
#include <algorithm>
1625.1.7 by Monty Taylor
Added support for program_options based commandline argument passing.
25
#include <iostream>
534 by Monty Taylor
Removed stxnmov. Also deleted strstr which had already been removed.
26
1625.1.5 by Monty Taylor
Put in first bits to use program_options for plugin loading in parallel to
27
#include <boost/program_options.hpp>
28
1410.3.4 by Djellel E. Difallah
update references to old my_'s
29
#include "drizzled/option.h"
1241.9.64 by Monty Taylor
Moved remaining non-public portions of mysys and mystrings to drizzled/internal.
30
#include "drizzled/internal/m_string.h"
1122.2.13 by Monty Taylor
Header cleanup.
31
1251.2.2 by Jay Pipes
Pulls MyISAM-specific server variables into the MyISAM
32
#include "drizzled/plugin.h"
1530.2.5 by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant
33
#include "drizzled/module/load_list.h"
34
#include "drizzled/module/library.h"
35
#include "drizzled/module/registry.h"
1625.1.5 by Monty Taylor
Put in first bits to use program_options for plugin loading in parallel to
36
#include "drizzled/module/option_context.h"
1122.2.13 by Monty Taylor
Header cleanup.
37
#include "drizzled/sql_parse.h"
38
#include "drizzled/show.h"
1185 by Brian Aker
Merge Engine changes.
39
#include "drizzled/cursor.h"
1122.2.13 by Monty Taylor
Header cleanup.
40
#include "drizzled/set_var.h"
41
#include "drizzled/session.h"
42
#include "drizzled/item/null.h"
43
#include "drizzled/error.h"
44
#include "drizzled/gettext.h"
1130.3.23 by Monty Taylor
Removed more server_includes.h from headers.
45
#include "drizzled/errmsg_print.h"
1241.9.12 by Monty Taylor
Trims more out of server_includes.h.
46
#include "drizzled/strfunc.h"
1241.9.31 by Monty Taylor
Moved global pthread variables into their own header.
47
#include "drizzled/pthread_globals.h"
1283.1.5 by Monty Taylor
Added --plugin-remove option, which prunes plugins from the list of plugins
48
#include "drizzled/util/tokenize.h"
1122.2.13 by Monty Taylor
Header cleanup.
49
50
/* FreeBSD 2.2.2 does not define RTLD_NOW) */
51
#ifndef RTLD_NOW
52
#define RTLD_NOW 1
53
#endif
1 by brian
clean slate
54
1625.1.5 by Monty Taylor
Put in first bits to use program_options for plugin loading in parallel to
55
namespace po=boost::program_options;
56
534 by Monty Taylor
Removed stxnmov. Also deleted strstr which had already been removed.
57
using namespace std;
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
58
1530.2.5 by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant
59
/** These exist just to prevent symbols from being optimized out */
60
typedef drizzled::module::Manifest drizzled_builtin_list[];
61
extern drizzled_builtin_list PANDORA_BUILTIN_SYMBOLS_LIST;
1885.2.3 by Monty Taylor
Finalized the static/load_by_default split, supporting now an array of
62
extern drizzled_builtin_list PANDORA_BUILTIN_LOAD_SYMBOLS_LIST;
1530.2.5 by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant
63
drizzled::module::Manifest *drizzled_builtins[]=
64
{
65
  PANDORA_BUILTIN_SYMBOLS_LIST, NULL
66
};
1885.2.3 by Monty Taylor
Finalized the static/load_by_default split, supporting now an array of
67
drizzled::module::Manifest *drizzled_load_builtins[]=
68
{
69
  PANDORA_BUILTIN_LOAD_SYMBOLS_LIST, NULL
70
};
1530.2.5 by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant
71
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
72
namespace drizzled
73
{
992.1.39 by Monty Taylor
Removed the m4-based plugin system.
74
 
1122.2.13 by Monty Taylor
Header cleanup.
75
1101.1.27 by Monty Taylor
Fixed the plugin string valgrind leak.
76
class sys_var_pluginvar;
77
static vector<sys_var_pluginvar *> plugin_sysvar_vec;
1 by brian
clean slate
78
1776.4.7 by Monty Taylor
Made a typedef for the plugin vector<string>
79
typedef vector<string> PluginOptions;
80
static PluginOptions opt_plugin_load;
81
static PluginOptions opt_plugin_add;
82
static PluginOptions opt_plugin_remove;
1530.2.3 by Monty Taylor
Changed the builtin plugin code path to work exactly the same as dynamic.
83
const char *builtin_plugins= PANDORA_BUILTIN_LIST;
1885.2.3 by Monty Taylor
Finalized the static/load_by_default split, supporting now an array of
84
const char *builtin_load_plugins= PANDORA_BUILTIN_LOAD_LIST;
1 by brian
clean slate
85
86
/* Note that 'int version' must be the first field of every plugin
87
   sub-structure (plugin->info).
88
*/
89
962.1.6 by Brian Aker
Cut down on shutdown loop of plugins (cutting stuff out in order to simplify
90
static bool initialized= false;
1 by brian
clean slate
91
908.2.1 by Monty Taylor
First pass at refactoring plugins - factored out sql_map.
92
1 by brian
clean slate
93
static bool reap_needed= false;
94
95
/*
96
  write-lock on LOCK_system_variables_hash is required before modifying
97
  the following variables/structures
98
*/
1485 by Brian Aker
Updates to confine memroot
99
static memory::Root plugin_mem_root(4096);
482 by Brian Aker
Remove uint.
100
static uint32_t global_variables_dynamic_size= 0;
1 by brian
clean slate
101
102
103
/*
104
  hidden part of opaque value passed to variable check functions.
105
  Used to provide a object-like structure to non C++ consumers.
106
*/
1228.1.5 by Monty Taylor
Merged in some naming things.
107
struct st_item_value_holder : public drizzle_value
1 by brian
clean slate
108
{
109
  Item *item;
110
};
111
1720.5.2 by Monty Taylor
Renamed st_bookmark. Removed name_len.
112
class Bookmark
1 by brian
clean slate
113
{
1720.5.2 by Monty Taylor
Renamed st_bookmark. Removed name_len.
114
public:
115
  Bookmark() :
116
    type_code(0),
117
    offset(0),
118
    version(0),
119
    key("")
120
  {}
1720.5.1 by Monty Taylor
Convert HASH in module/loader.cc to boost::unordered_map.
121
  uint8_t type_code;
1 by brian
clean slate
122
  int offset;
482 by Brian Aker
Remove uint.
123
  uint32_t version;
1720.5.1 by Monty Taylor
Convert HASH in module/loader.cc to boost::unordered_map.
124
  string key;
1 by brian
clean slate
125
};
1720.5.2 by Monty Taylor
Renamed st_bookmark. Removed name_len.
126
127
typedef boost::unordered_map<string, Bookmark> bookmark_unordered_map;
1720.5.1 by Monty Taylor
Convert HASH in module/loader.cc to boost::unordered_map.
128
static bookmark_unordered_map bookmark_hash;
1 by brian
clean slate
129
130
131
/*
132
  sys_var class for access to all plugin variables visible to the user
133
*/
134
class sys_var_pluginvar: public sys_var
135
{
136
public:
1530.2.5 by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant
137
  module::Module *plugin;
1228.1.5 by Monty Taylor
Merged in some naming things.
138
  drizzle_sys_var *plugin_var;
1 by brian
clean slate
139
1101.1.27 by Monty Taylor
Fixed the plugin string valgrind leak.
140
  sys_var_pluginvar(const std::string name_arg,
1228.1.5 by Monty Taylor
Merged in some naming things.
141
                    drizzle_sys_var *plugin_var_arg)
1 by brian
clean slate
142
    :sys_var(name_arg), plugin_var(plugin_var_arg) {}
143
  sys_var_pluginvar *cast_pluginvar() { return this; }
144
  bool is_readonly() const { return plugin_var->flags & PLUGIN_VAR_READONLY; }
1273.13.24 by Brian Aker
Updating style, simplified code.
145
  bool check_type(sql_var_t type)
520.1.21 by Brian Aker
THD -> Session rename
146
  { return !(plugin_var->flags & PLUGIN_VAR_SessionLOCAL) && type != OPT_GLOBAL; }
1 by brian
clean slate
147
  bool check_update_type(Item_result type);
148
  SHOW_TYPE show_type();
1273.13.24 by Brian Aker
Updating style, simplified code.
149
  unsigned char* real_value_ptr(Session *session, sql_var_t type);
1 by brian
clean slate
150
  TYPELIB* plugin_var_typelib(void);
1273.13.24 by Brian Aker
Updating style, simplified code.
151
  unsigned char* value_ptr(Session *session, sql_var_t type,
779.3.10 by Monty Taylor
Turned on -Wshadow.
152
                           const LEX_STRING *base);
520.1.22 by Brian Aker
Second pass of thd cleanup
153
  bool check(Session *session, set_var *var);
1273.13.24 by Brian Aker
Updating style, simplified code.
154
  bool check_default(sql_var_t)
77.1.46 by Monty Taylor
Finished the warnings work!
155
    { return is_readonly(); }
1273.13.24 by Brian Aker
Updating style, simplified code.
156
  void set_default(Session *session, sql_var_t);
520.1.22 by Brian Aker
Second pass of thd cleanup
157
  bool update(Session *session, set_var *var);
1 by brian
clean slate
158
};
159
160
161
/* prototypes */
1283.1.5 by Monty Taylor
Added --plugin-remove option, which prunes plugins from the list of plugins
162
static void plugin_prune_list(vector<string> &plugin_list,
163
                              const vector<string> &plugins_to_remove);
1530.2.5 by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant
164
static bool plugin_load_list(module::Registry &registry,
1757.2.6 by Monty Taylor
We've gotten further. Now things sometimes work, but some things aren't
165
                             memory::Root *tmp_root,
1530.2.3 by Monty Taylor
Changed the builtin plugin code path to work exactly the same as dynamic.
166
                             const set<string> &plugin_list,
1633.1.1 by Monty Taylor
Added in support for program_options output in --help output.
167
                             po::options_description &long_options,
1530.2.3 by Monty Taylor
Changed the builtin plugin code path to work exactly the same as dynamic.
168
                             bool builtin= false);
1530.2.5 by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant
169
static int test_plugin_options(memory::Root *, module::Module *,
1633.1.1 by Monty Taylor
Added in support for program_options output in --help output.
170
                               po::options_description &long_options);
1878.3.2 by Monty Taylor
Split out show_type into its own header and made sys_var work through
171
static void unlock_variables(Session *session, drizzle_system_variables *vars);
172
static void cleanup_variables(drizzle_system_variables *vars);
1851.1.1 by Monty Taylor
Removed sys_var_chain.
173
static void plugin_vars_free_values(module::Module::Variables &vars);
1 by brian
clean slate
174
175
/* declared in set_var.cc */
482 by Brian Aker
Remove uint.
176
extern sys_var *intern_find_sys_var(const char *str, uint32_t length, bool no_error);
520.1.22 by Brian Aker
Second pass of thd cleanup
177
extern bool throw_bounds_warning(Session *session, bool fixed, bool unsignd,
1022.2.38 by Monty Taylor
Changed name to std::string.
178
                                 const std::string &name, int64_t val);
179
180
static bool throw_bounds_warning(Session *session, bool fixed, bool unsignd,
181
                                 const char *name, int64_t val)
182
{
183
  const std::string name_str(name);
184
  return throw_bounds_warning(session, fixed, unsignd, name_str, val);
185
}
1 by brian
clean slate
186
187
/****************************************************************************
188
  Value type thunks, allows the C world to play in the C++ world
189
****************************************************************************/
190
1228.1.5 by Monty Taylor
Merged in some naming things.
191
static int item_value_type(drizzle_value *value)
1 by brian
clean slate
192
{
193
  switch (((st_item_value_holder*)value)->item->result_type()) {
194
  case INT_RESULT:
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
195
    return DRIZZLE_VALUE_TYPE_INT;
1 by brian
clean slate
196
  case REAL_RESULT:
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
197
    return DRIZZLE_VALUE_TYPE_REAL;
1 by brian
clean slate
198
  default:
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
199
    return DRIZZLE_VALUE_TYPE_STRING;
1 by brian
clean slate
200
  }
201
}
202
1228.1.5 by Monty Taylor
Merged in some naming things.
203
static const char *item_val_str(drizzle_value *value,
1 by brian
clean slate
204
                                char *buffer, int *length)
205
{
206
  String str(buffer, *length, system_charset_info), *res;
207
  if (!(res= ((st_item_value_holder*)value)->item->val_str(&str)))
208
    return NULL;
209
  *length= res->length();
210
  if (res->c_ptr_quick() == buffer)
211
    return buffer;
212
213
  /*
214
    Lets be nice and create a temporary string since the
215
    buffer was too small
216
  */
520.1.22 by Brian Aker
Second pass of thd cleanup
217
  return current_session->strmake(res->c_ptr_quick(), res->length());
1 by brian
clean slate
218
}
219
220
1228.1.5 by Monty Taylor
Merged in some naming things.
221
static int item_val_int(drizzle_value *value, int64_t *buf)
1 by brian
clean slate
222
{
223
  Item *item= ((st_item_value_holder*)value)->item;
224
  *buf= item->val_int();
225
  if (item->is_null())
226
    return 1;
227
  return 0;
228
}
229
230
1228.1.5 by Monty Taylor
Merged in some naming things.
231
static int item_val_real(drizzle_value *value, double *buf)
1 by brian
clean slate
232
{
233
  Item *item= ((st_item_value_holder*)value)->item;
234
  *buf= item->val_real();
235
  if (item->is_null())
236
    return 1;
237
  return 0;
238
}
239
240
241
/****************************************************************************
242
  Plugin support code
243
****************************************************************************/
244
1228.1.3 by Monty Taylor
All of the outstanding plugin loader system cleanups:
245
1 by brian
clean slate
246
247
248
/*
249
  NOTE
250
    Requires that a write-lock is held on LOCK_system_variables_hash
251
*/
1530.2.5 by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant
252
static bool plugin_add(module::Registry &registry, memory::Root *tmp_root,
253
                       module::Library *library,
1633.1.1 by Monty Taylor
Added in support for program_options output in --help output.
254
                       po::options_description &long_options)
1 by brian
clean slate
255
{
908.2.1 by Monty Taylor
First pass at refactoring plugins - factored out sql_map.
256
  if (! initialized)
1228.1.3 by Monty Taylor
All of the outstanding plugin loader system cleanups:
257
    return true;
908.2.1 by Monty Taylor
First pass at refactoring plugins - factored out sql_map.
258
1228.1.3 by Monty Taylor
All of the outstanding plugin loader system cleanups:
259
  if (registry.find(library->getName()))
1 by brian
clean slate
260
  {
1228.1.3 by Monty Taylor
All of the outstanding plugin loader system cleanups:
261
    errmsg_printf(ERRMSG_LVL_WARN, ER(ER_PLUGIN_EXISTS),
262
                  library->getName().c_str());
263
    return false;
1 by brian
clean slate
264
  }
1093.3.4 by Monty Taylor
Naming cleanups.
265
1530.2.5 by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant
266
  module::Module *tmp= NULL;
1 by brian
clean slate
267
  /* Find plugin by name */
1530.2.5 by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant
268
  const module::Manifest *manifest= library->getManifest();
1228.1.3 by Monty Taylor
All of the outstanding plugin loader system cleanups:
269
1284.2.1 by Monty Taylor
Add a fatal error if a plugin has a name which has already been registered.
270
  if (registry.find(manifest->name))
271
  {
272
    errmsg_printf(ERRMSG_LVL_ERROR, 
273
                  _("Plugin '%s' contains the name '%s' in its manifest, which "
274
                    "has already been registered.\n"),
275
                  library->getName().c_str(),
276
                  manifest->name);
277
    return true;
278
  }
279
1530.2.5 by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant
280
  tmp= new (std::nothrow) module::Module(manifest, library);
1228.1.3 by Monty Taylor
All of the outstanding plugin loader system cleanups:
281
  if (tmp == NULL)
282
    return true;
283
1757.2.6 by Monty Taylor
We've gotten further. Now things sometimes work, but some things aren't
284
  if (!test_plugin_options(tmp_root, tmp, long_options))
1 by brian
clean slate
285
  {
1228.1.3 by Monty Taylor
All of the outstanding plugin loader system cleanups:
286
    registry.add(tmp);
287
    return false;
1 by brian
clean slate
288
  }
1228.1.3 by Monty Taylor
All of the outstanding plugin loader system cleanups:
289
  errmsg_printf(ERRMSG_LVL_ERROR, ER(ER_CANT_FIND_DL_ENTRY),
290
                library->getName().c_str());
291
  return true;
1 by brian
clean slate
292
}
293
294
1530.2.5 by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant
295
static void delete_module(module::Module *module)
1 by brian
clean slate
296
{
297
  /* Free allocated strings before deleting the plugin. */
1851.1.1 by Monty Taylor
Removed sys_var_chain.
298
  plugin_vars_free_values(module->getSysVars());
1192.2.3 by Monty Taylor
Renamed plugin::Handle to plugin::Module for clarity.
299
  module->isInited= false;
300
  delete module;
1 by brian
clean slate
301
}
302
1228.1.3 by Monty Taylor
All of the outstanding plugin loader system cleanups:
303
1530.2.5 by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant
304
static void reap_plugins(module::Registry &registry)
1 by brian
clean slate
305
{
1530.2.5 by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant
306
  std::map<std::string, module::Module *>::const_iterator modules=
1228.1.3 by Monty Taylor
All of the outstanding plugin loader system cleanups:
307
    registry.getModulesMap().begin();
1324.2.3 by Monty Taylor
Remove plugin deinit.
308
1228.1.3 by Monty Taylor
All of the outstanding plugin loader system cleanups:
309
  while (modules != registry.getModulesMap().end())
1 by brian
clean slate
310
  {
1530.2.5 by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant
311
    module::Module *module= (*modules).second;
1324.2.3 by Monty Taylor
Remove plugin deinit.
312
    delete_module(module);
1228.1.3 by Monty Taylor
All of the outstanding plugin loader system cleanups:
313
    ++modules;
688 by Brian Aker
Second pass through memory allocation issues (this solves the ones around
314
  }
1324.2.3 by Monty Taylor
Remove plugin deinit.
315
1101.1.27 by Monty Taylor
Fixed the plugin string valgrind leak.
316
  drizzle_del_plugin_sysvar();
1 by brian
clean slate
317
}
318
1119.1.1 by Monty Taylor
--help doesn't need --datadir to work.
319
1530.2.5 by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant
320
static void plugin_initialize_vars(module::Module *module)
1 by brian
clean slate
321
{
322
  /*
323
    set the plugin attribute of plugin's sys vars so they are pointing
324
    to the active plugin
325
  */
1851.1.1 by Monty Taylor
Removed sys_var_chain.
326
  for (module::Module::Variables::iterator iter= module->getSysVars().begin();
327
       iter != module->getSysVars().end();
328
       ++iter)
1 by brian
clean slate
329
  {
1851.1.1 by Monty Taylor
Removed sys_var_chain.
330
    sys_var *current_var= *iter;
331
    current_var->cast_pluginvar()->plugin= module;
1 by brian
clean slate
332
  }
1119.1.1 by Monty Taylor
--help doesn't need --datadir to work.
333
}
334
335
1530.2.5 by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant
336
static bool plugin_initialize(module::Registry &registry,
337
                              module::Module *module)
1119.1.1 by Monty Taylor
--help doesn't need --datadir to work.
338
{
1192.2.3 by Monty Taylor
Renamed plugin::Handle to plugin::Module for clarity.
339
  assert(module->isInited == false);
1119.1.1 by Monty Taylor
--help doesn't need --datadir to work.
340
1530.2.6 by Monty Taylor
Moved plugin::Context to module::Context.
341
  module::Context loading_context(registry, module);
1192.2.3 by Monty Taylor
Renamed plugin::Handle to plugin::Module for clarity.
342
  if (module->getManifest().init)
1119.1.1 by Monty Taylor
--help doesn't need --datadir to work.
343
  {
1324.2.1 by Monty Taylor
Create a plugin::Context object to carry information about the plugin module
344
    if (module->getManifest().init(loading_context))
1119.1.1 by Monty Taylor
--help doesn't need --datadir to work.
345
    {
346
      errmsg_printf(ERRMSG_LVL_ERROR,
347
                    _("Plugin '%s' init function returned error.\n"),
1192.2.3 by Monty Taylor
Renamed plugin::Handle to plugin::Module for clarity.
348
                    module->getName().c_str());
1119.1.1 by Monty Taylor
--help doesn't need --datadir to work.
349
      return true;
350
    }
351
  }
1192.2.3 by Monty Taylor
Renamed plugin::Handle to plugin::Module for clarity.
352
  module->isInited= true;
1119.1.1 by Monty Taylor
--help doesn't need --datadir to work.
353
1 by brian
clean slate
354
965.1.1 by Brian Aker
Refactor plugin loading to remove mask (one step closer to getting rid of
355
  return false;
1 by brian
clean slate
356
}
357
1776.4.1 by Monty Taylor
Migrates the creation of the plugin lists to have program_options directly
358
static void compose_plugin_options(vector<string> &target,
359
                                   vector<string> options)
360
{
361
  for (vector<string>::iterator it= options.begin();
362
       it != options.end();
363
       ++it)
364
  {
365
    tokenize(*it, target, ",", true);
366
  }
367
}
368
369
void compose_plugin_add(vector<string> options)
370
{
371
  compose_plugin_options(opt_plugin_add, options);
372
}
373
374
void compose_plugin_remove(vector<string> options)
375
{
376
  compose_plugin_options(opt_plugin_remove, options);
377
}
378
379
void notify_plugin_load(string in_plugin_load)
380
{
381
  tokenize(in_plugin_load, opt_plugin_load, ",", true);
382
}
1 by brian
clean slate
383
384
/*
385
  The logic is that we first load and initialize all compiled in plugins.
386
  From there we load up the dynamic types (assuming we have not been told to
387
  skip this part).
388
389
  Finally we initialize everything, aka the dynamic that have yet to initialize.
390
*/
1530.2.5 by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant
391
bool plugin_init(module::Registry &registry,
1633.1.1 by Monty Taylor
Added in support for program_options output in --help output.
392
                 po::options_description &long_options)
1 by brian
clean slate
393
{
1485 by Brian Aker
Updates to confine memroot
394
  memory::Root tmp_root(4096);
1 by brian
clean slate
395
396
  if (initialized)
1241.10.4 by Monty Taylor
Actually throw errors on failure to init plugins.
397
    return false;
1 by brian
clean slate
398
399
  initialized= 1;
400
1885.2.3 by Monty Taylor
Finalized the static/load_by_default split, supporting now an array of
401
  PluginOptions builtin_load_list;
402
  tokenize(builtin_load_plugins, builtin_load_list, ",", true);
403
1776.4.7 by Monty Taylor
Made a typedef for the plugin vector<string>
404
  PluginOptions builtin_list;
1530.2.3 by Monty Taylor
Changed the builtin plugin code path to work exactly the same as dynamic.
405
  tokenize(builtin_plugins, builtin_list, ",", true);
1 by brian
clean slate
406
1241.10.4 by Monty Taylor
Actually throw errors on failure to init plugins.
407
  bool load_failed= false;
1776.4.1 by Monty Taylor
Migrates the creation of the plugin lists to have program_options directly
408
409
  if (opt_plugin_add.size() > 0)
410
  {
1885.2.3 by Monty Taylor
Finalized the static/load_by_default split, supporting now an array of
411
    for (PluginOptions::iterator iter= opt_plugin_add.begin();
412
         iter != opt_plugin_add.end();
413
         ++iter)
414
    {
415
      if (find(builtin_list.begin(),
416
               builtin_list.end(), *iter) != builtin_list.end())
417
      {
418
        builtin_load_list.push_back(*iter);
419
      }
420
      else
421
      {
422
        opt_plugin_load.push_back(*iter);
423
      }
424
    }
1776.4.1 by Monty Taylor
Migrates the creation of the plugin lists to have program_options directly
425
  }
426
427
  if (opt_plugin_remove.size() > 0)
428
  {
429
    plugin_prune_list(opt_plugin_load, opt_plugin_remove);
1885.2.3 by Monty Taylor
Finalized the static/load_by_default split, supporting now an array of
430
    plugin_prune_list(builtin_load_list, opt_plugin_remove);
1530.2.3 by Monty Taylor
Changed the builtin plugin code path to work exactly the same as dynamic.
431
  }
432
433
434
  /*
435
    First we register builtin plugins
436
  */
1885.2.3 by Monty Taylor
Finalized the static/load_by_default split, supporting now an array of
437
  const set<string> builtin_list_set(builtin_load_list.begin(),
438
                                     builtin_load_list.end());
1757.2.6 by Monty Taylor
We've gotten further. Now things sometimes work, but some things aren't
439
  load_failed= plugin_load_list(registry, &tmp_root,
1633.1.1 by Monty Taylor
Added in support for program_options output in --help output.
440
                                builtin_list_set, long_options, true);
1530.2.3 by Monty Taylor
Changed the builtin plugin code path to work exactly the same as dynamic.
441
  if (load_failed)
442
  {
443
    tmp_root.free_root(MYF(0));
444
    return true;
1283.1.5 by Monty Taylor
Added --plugin-remove option, which prunes plugins from the list of plugins
445
  }
1377.3.11 by Monty Taylor
Suppress duplicate plugin names.
446
447
  /* Uniquify the list */
1776.4.1 by Monty Taylor
Migrates the creation of the plugin lists to have program_options directly
448
  const set<string> plugin_list_set(opt_plugin_load.begin(),
449
                                    opt_plugin_load.end());
1283.1.5 by Monty Taylor
Added --plugin-remove option, which prunes plugins from the list of plugins
450
  
1 by brian
clean slate
451
  /* Register all dynamic plugins */
1757.2.6 by Monty Taylor
We've gotten further. Now things sometimes work, but some things aren't
452
  load_failed= plugin_load_list(registry, &tmp_root,
1633.1.1 by Monty Taylor
Added in support for program_options output in --help output.
453
                                plugin_list_set, long_options);
1241.10.4 by Monty Taylor
Actually throw errors on failure to init plugins.
454
  if (load_failed)
455
  {
1487 by Brian Aker
More updates for memory::Root
456
    tmp_root.free_root(MYF(0));
1241.10.4 by Monty Taylor
Actually throw errors on failure to init plugins.
457
    return true;
1 by brian
clean slate
458
  }
459
1672.2.1 by Monty Taylor
Fixed plugin option processing. Now we pre-load the modules registering
460
  tmp_root.free_root(MYF(0));
461
462
  return false;
463
}
464
1794.3.5 by Monty Taylor
Fixed temporoary dir sequencing.
465
bool plugin_finalize(module::Registry &registry)
1672.2.1 by Monty Taylor
Fixed plugin option processing. Now we pre-load the modules registering
466
{
1 by brian
clean slate
467
468
  /*
469
    Now we initialize all remaining plugins
470
  */
1530.2.5 by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant
471
  std::map<std::string, module::Module *>::const_iterator modules=
1228.1.3 by Monty Taylor
All of the outstanding plugin loader system cleanups:
472
    registry.getModulesMap().begin();
473
    
474
  while (modules != registry.getModulesMap().end())
1 by brian
clean slate
475
  {
1672.2.1 by Monty Taylor
Fixed plugin option processing. Now we pre-load the modules registering
476
    module::Module *module= (*modules).second;
1228.1.3 by Monty Taylor
All of the outstanding plugin loader system cleanups:
477
    ++modules;
1192.2.3 by Monty Taylor
Renamed plugin::Handle to plugin::Module for clarity.
478
    if (module->isInited == false)
1 by brian
clean slate
479
    {
1192.2.3 by Monty Taylor
Renamed plugin::Handle to plugin::Module for clarity.
480
      plugin_initialize_vars(module);
1119.1.1 by Monty Taylor
--help doesn't need --datadir to work.
481
1192.2.3 by Monty Taylor
Renamed plugin::Handle to plugin::Module for clarity.
482
      if (plugin_initialize(registry, module))
1702.4.1 by LinuxJedi
Remove module pointer from registry when module doesn't load to avoid a double-free on shutdown.
483
      {
484
        registry.remove(module);
1324.2.3 by Monty Taylor
Remove plugin deinit.
485
        delete_module(module);
1794.3.5 by Monty Taylor
Fixed temporoary dir sequencing.
486
        return true;
1702.4.1 by LinuxJedi
Remove module pointer from registry when module doesn't load to avoid a double-free on shutdown.
487
      }
1 by brian
clean slate
488
    }
489
  }
1794.3.5 by Monty Taylor
Fixed temporoary dir sequencing.
490
  return false;
1228.1.3 by Monty Taylor
All of the outstanding plugin loader system cleanups:
491
}
492
1283.1.5 by Monty Taylor
Added --plugin-remove option, which prunes plugins from the list of plugins
493
class PrunePlugin :
494
  public unary_function<string, bool>
495
{
496
  const string to_match;
497
  PrunePlugin();
498
  PrunePlugin& operator=(const PrunePlugin&);
499
public:
500
  explicit PrunePlugin(const string &match_in) :
501
    to_match(match_in)
502
  { }
503
504
  result_type operator()(const string &match_against)
505
  {
506
    return match_against == to_match;
507
  }
508
};
509
510
static void plugin_prune_list(vector<string> &plugin_list,
511
                              const vector<string> &plugins_to_remove)
512
{
513
  for (vector<string>::const_iterator iter= plugins_to_remove.begin();
514
       iter != plugins_to_remove.end();
515
       ++iter)
516
  {
517
    plugin_list.erase(remove_if(plugin_list.begin(),
518
                                plugin_list.end(),
519
                                PrunePlugin(*iter)),
520
                      plugin_list.end());
521
  }
522
}
1 by brian
clean slate
523
524
/*
525
  called only by plugin_init()
526
*/
1530.2.5 by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant
527
static bool plugin_load_list(module::Registry &registry,
1757.2.6 by Monty Taylor
We've gotten further. Now things sometimes work, but some things aren't
528
                             memory::Root *tmp_root,
1530.2.3 by Monty Taylor
Changed the builtin plugin code path to work exactly the same as dynamic.
529
                             const set<string> &plugin_list,
1633.1.1 by Monty Taylor
Added in support for program_options output in --help output.
530
                             po::options_description &long_options,
1530.2.3 by Monty Taylor
Changed the builtin plugin code path to work exactly the same as dynamic.
531
                             bool builtin)
1 by brian
clean slate
532
{
1530.2.5 by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant
533
  module::Library *library= NULL;
1228.1.3 by Monty Taylor
All of the outstanding plugin loader system cleanups:
534
1377.3.11 by Monty Taylor
Suppress duplicate plugin names.
535
  for (set<string>::const_iterator iter= plugin_list.begin();
1283.1.5 by Monty Taylor
Added --plugin-remove option, which prunes plugins from the list of plugins
536
       iter != plugin_list.end();
537
       ++iter)
1 by brian
clean slate
538
  {
1283.1.5 by Monty Taylor
Added --plugin-remove option, which prunes plugins from the list of plugins
539
    const string plugin_name(*iter);
1530.2.4 by Monty Taylor
Fixed style catches from Jay.
540
541
    library= registry.addLibrary(plugin_name, builtin);
1228.1.3 by Monty Taylor
All of the outstanding plugin loader system cleanups:
542
    if (library == NULL)
543
    {
544
      errmsg_printf(ERRMSG_LVL_ERROR,
1284.2.1 by Monty Taylor
Add a fatal error if a plugin has a name which has already been registered.
545
                    _("Couldn't load plugin library named '%s'.\n"),
1228.1.3 by Monty Taylor
All of the outstanding plugin loader system cleanups:
546
                    plugin_name.c_str());
547
      return true;
548
    }
549
1487 by Brian Aker
More updates for memory::Root
550
    tmp_root->free_root(MYF(memory::MARK_BLOCKS_FREE));
1757.2.6 by Monty Taylor
We've gotten further. Now things sometimes work, but some things aren't
551
    if (plugin_add(registry, tmp_root, library, long_options))
1228.1.3 by Monty Taylor
All of the outstanding plugin loader system cleanups:
552
    {
553
      registry.removeLibrary(plugin_name);
554
      errmsg_printf(ERRMSG_LVL_ERROR,
1284.2.1 by Monty Taylor
Add a fatal error if a plugin has a name which has already been registered.
555
                    _("Couldn't load plugin named '%s'.\n"),
1228.1.3 by Monty Taylor
All of the outstanding plugin loader system cleanups:
556
                    plugin_name.c_str());
557
      return true;
558
559
    }
1 by brian
clean slate
560
  }
1228.1.3 by Monty Taylor
All of the outstanding plugin loader system cleanups:
561
  return false;
1 by brian
clean slate
562
}
563
564
1530.2.5 by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant
565
void module_shutdown(module::Registry &registry)
1 by brian
clean slate
566
{
567
568
  if (initialized)
569
  {
570
    reap_needed= true;
571
1110.1.3 by Monty Taylor
Added ListenHandler as a member of PluginRegistry.
572
    reap_plugins(registry);
962.1.6 by Brian Aker
Cut down on shutdown loop of plugins (cutting stuff out in order to simplify
573
    unlock_variables(NULL, &global_system_variables);
574
    unlock_variables(NULL, &max_system_variables);
1 by brian
clean slate
575
1851.1.1 by Monty Taylor
Removed sys_var_chain.
576
    cleanup_variables(&global_system_variables);
577
    cleanup_variables(&max_system_variables);
1 by brian
clean slate
578
579
    initialized= 0;
580
  }
581
582
  /* Dispose of the memory */
1487 by Brian Aker
More updates for memory::Root
583
  plugin_mem_root.free_root(MYF(0));
1 by brian
clean slate
584
585
  global_variables_dynamic_size= 0;
586
}
587
588
/****************************************************************************
589
  Internal type declarations for variables support
590
****************************************************************************/
591
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
592
#undef DRIZZLE_SYSVAR_NAME
593
#define DRIZZLE_SYSVAR_NAME(name) name
1 by brian
clean slate
594
#define PLUGIN_VAR_TYPEMASK 0x007f
595
1283.1.1 by Monty Taylor
Remove code which adds skip options for plugins, since that's not how we
596
static const uint32_t EXTRA_OPTIONS= 1; /* handle the NULL option */
1 by brian
clean slate
597
1816.2.4 by Monty Taylor
Cleaned up a bunch more warnings.
598
typedef DECLARE_DRIZZLE_SYSVAR_BOOL(sysvar_bool_t);
599
typedef DECLARE_DRIZZLE_SessionVAR_BOOL(sessionvar_bool_t);
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
600
typedef DECLARE_DRIZZLE_SYSVAR_BASIC(sysvar_str_t, char *);
520.1.22 by Brian Aker
Second pass of thd cleanup
601
typedef DECLARE_DRIZZLE_SessionVAR_BASIC(sessionvar_str_t, char *);
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
602
520.1.22 by Brian Aker
Second pass of thd cleanup
603
typedef DECLARE_DRIZZLE_SessionVAR_TYPELIB(sessionvar_enum_t, unsigned long);
604
typedef DECLARE_DRIZZLE_SessionVAR_TYPELIB(sessionvar_set_t, uint64_t);
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
605
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);
612
520.1.22 by Brian Aker
Second pass of thd cleanup
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);
1 by brian
clean slate
619
520.1.22 by Brian Aker
Second pass of thd cleanup
620
typedef bool *(*mysql_sys_var_ptr_p)(Session* a_session, int offset);
1 by brian
clean slate
621
622
623
/****************************************************************************
624
  default variable data check and update functions
625
****************************************************************************/
626
1228.1.5 by Monty Taylor
Merged in some naming things.
627
static int check_func_bool(Session *, drizzle_sys_var *var,
628
                           void *save, drizzle_value *value)
1 by brian
clean slate
629
{
630
  char buff[STRING_BUFFER_USUAL_SIZE];
631
  const char *strvalue= "NULL", *str;
632
  int result, length;
53.2.2 by Monty Taylor
Updated everything that needs updating to compile with -std=gnu99 -pedantic
633
  int64_t tmp;
1 by brian
clean slate
634
319.1.1 by Grant Limberg
renamed all instances of MYSQL_ to DRIZZLE_
635
  if (value->value_type(value) == DRIZZLE_VALUE_TYPE_STRING)
1 by brian
clean slate
636
  {
637
    length= sizeof(buff);
638
    if (!(str= value->val_str(value, buff, &length)) ||
639
        (result= find_type(&bool_typelib, str, length, 1)-1) < 0)
640
    {
641
      if (str)
642
        strvalue= str;
643
      goto err;
644
    }
645
  }
646
  else
647
  {
648
    if (value->val_int(value, &tmp) < 0)
649
      goto err;
650
    if (tmp > 1)
651
    {
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
652
      internal::llstr(tmp, buff);
1 by brian
clean slate
653
      strvalue= buff;
654
      goto err;
655
    }
656
    result= (int) tmp;
657
  }
658
  *(int*)save= -result;
659
  return 0;
660
err:
661
  my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), var->name, strvalue);
662
  return 1;
663
}
664
665
1228.1.5 by Monty Taylor
Merged in some naming things.
666
static int check_func_int(Session *session, drizzle_sys_var *var,
667
                          void *save, drizzle_value *value)
1 by brian
clean slate
668
{
143 by Brian Aker
Bool cleanup.
669
  bool fixed;
53.2.2 by Monty Taylor
Updated everything that needs updating to compile with -std=gnu99 -pedantic
670
  int64_t tmp;
1410.3.4 by Djellel E. Difallah
update references to old my_'s
671
  struct option options;
1 by brian
clean slate
672
  value->val_int(value, &tmp);
673
  plugin_opt_set_limits(&options, var);
674
675
  if (var->flags & PLUGIN_VAR_UNSIGNED)
895 by Brian Aker
Completion (?) of uint conversion.
676
    *(uint32_t *)save= (uint32_t) getopt_ull_limit_value((uint64_t) tmp, &options,
1 by brian
clean slate
677
                                                   &fixed);
678
  else
679
    *(int *)save= (int) getopt_ll_limit_value(tmp, &options, &fixed);
680
520.1.22 by Brian Aker
Second pass of thd cleanup
681
  return throw_bounds_warning(session, fixed, var->flags & PLUGIN_VAR_UNSIGNED,
152 by Brian Aker
longlong replacement
682
                              var->name, (int64_t) tmp);
1 by brian
clean slate
683
}
684
685
1228.1.5 by Monty Taylor
Merged in some naming things.
686
static int check_func_long(Session *session, drizzle_sys_var *var,
687
                          void *save, drizzle_value *value)
1 by brian
clean slate
688
{
143 by Brian Aker
Bool cleanup.
689
  bool fixed;
53.2.2 by Monty Taylor
Updated everything that needs updating to compile with -std=gnu99 -pedantic
690
  int64_t tmp;
1410.3.4 by Djellel E. Difallah
update references to old my_'s
691
  struct option options;
1 by brian
clean slate
692
  value->val_int(value, &tmp);
693
  plugin_opt_set_limits(&options, var);
694
695
  if (var->flags & PLUGIN_VAR_UNSIGNED)
151 by Brian Aker
Ulonglong to uint64_t
696
    *(ulong *)save= (ulong) getopt_ull_limit_value((uint64_t) tmp, &options,
1 by brian
clean slate
697
                                                   &fixed);
698
  else
699
    *(long *)save= (long) getopt_ll_limit_value(tmp, &options, &fixed);
700
520.1.22 by Brian Aker
Second pass of thd cleanup
701
  return throw_bounds_warning(session, fixed, var->flags & PLUGIN_VAR_UNSIGNED,
152 by Brian Aker
longlong replacement
702
                              var->name, (int64_t) tmp);
1 by brian
clean slate
703
}
704
705
1228.1.5 by Monty Taylor
Merged in some naming things.
706
static int check_func_int64_t(Session *session, drizzle_sys_var *var,
707
                               void *save, drizzle_value *value)
1 by brian
clean slate
708
{
143 by Brian Aker
Bool cleanup.
709
  bool fixed;
53.2.2 by Monty Taylor
Updated everything that needs updating to compile with -std=gnu99 -pedantic
710
  int64_t tmp;
1410.3.4 by Djellel E. Difallah
update references to old my_'s
711
  struct option options;
1 by brian
clean slate
712
  value->val_int(value, &tmp);
713
  plugin_opt_set_limits(&options, var);
714
715
  if (var->flags & PLUGIN_VAR_UNSIGNED)
151 by Brian Aker
Ulonglong to uint64_t
716
    *(uint64_t *)save= getopt_ull_limit_value((uint64_t) tmp, &options,
1 by brian
clean slate
717
                                               &fixed);
718
  else
152 by Brian Aker
longlong replacement
719
    *(int64_t *)save= getopt_ll_limit_value(tmp, &options, &fixed);
1 by brian
clean slate
720
520.1.22 by Brian Aker
Second pass of thd cleanup
721
  return throw_bounds_warning(session, fixed, var->flags & PLUGIN_VAR_UNSIGNED,
152 by Brian Aker
longlong replacement
722
                              var->name, (int64_t) tmp);
1 by brian
clean slate
723
}
724
1228.1.5 by Monty Taylor
Merged in some naming things.
725
static int check_func_str(Session *session, drizzle_sys_var *,
726
                          void *save, drizzle_value *value)
1 by brian
clean slate
727
{
728
  char buff[STRING_BUFFER_USUAL_SIZE];
729
  const char *str;
730
  int length;
731
732
  length= sizeof(buff);
733
  if ((str= value->val_str(value, buff, &length)))
520.1.22 by Brian Aker
Second pass of thd cleanup
734
    str= session->strmake(str, length);
1 by brian
clean slate
735
  *(const char**)save= str;
736
  return 0;
737
}
738
739
1228.1.5 by Monty Taylor
Merged in some naming things.
740
static void update_func_bool(Session *, drizzle_sys_var *,
1 by brian
clean slate
741
                             void *tgt, const void *save)
742
{
199 by Brian Aker
my_bool...
743
  *(bool *) tgt= *(int *) save ? 1 : 0;
1 by brian
clean slate
744
}
745
746
1228.1.5 by Monty Taylor
Merged in some naming things.
747
static void update_func_int(Session *, drizzle_sys_var *,
1 by brian
clean slate
748
                             void *tgt, const void *save)
749
{
750
  *(int *)tgt= *(int *) save;
751
}
752
753
1228.1.5 by Monty Taylor
Merged in some naming things.
754
static void update_func_long(Session *, drizzle_sys_var *,
1 by brian
clean slate
755
                             void *tgt, const void *save)
756
{
757
  *(long *)tgt= *(long *) save;
758
}
759
760
1228.1.5 by Monty Taylor
Merged in some naming things.
761
static void update_func_int64_t(Session *, drizzle_sys_var *,
77.1.46 by Monty Taylor
Finished the warnings work!
762
                                 void *tgt, const void *save)
1 by brian
clean slate
763
{
152 by Brian Aker
longlong replacement
764
  *(int64_t *)tgt= *(uint64_t *) save;
1 by brian
clean slate
765
}
766
767
1228.1.5 by Monty Taylor
Merged in some naming things.
768
static void update_func_str(Session *, drizzle_sys_var *var,
1 by brian
clean slate
769
                             void *tgt, const void *save)
770
{
771
  char *old= *(char **) tgt;
772
  *(char **)tgt= *(char **) save;
773
  if (var->flags & PLUGIN_VAR_MEMALLOC)
774
  {
656.1.19 by Monty Taylor
Removed my_strdup from drizzled/
775
    *(char **)tgt= strdup(*(char **) save);
477 by Monty Taylor
Removed my_free(). It turns out that it had been def'd to ignore the flags passed to it in the second arg anyway. Gotta love that.
776
    free(old);
656.1.52 by Monty Taylor
Added more return value checks.
777
    /*
778
     * There isn't a _really_ good thing to do here until this whole set_var
779
     * mess gets redesigned
780
     */
781
    if (tgt == NULL)
755.2.1 by Mark Atwood
replace sql_print_error etc with errmsg_print
782
      errmsg_printf(ERRMSG_LVL_ERROR, _("Out of memory."));
656.1.52 by Monty Taylor
Added more return value checks.
783
1 by brian
clean slate
784
  }
785
}
786
787
788
/****************************************************************************
789
  System Variables support
790
****************************************************************************/
791
792
970.1.1 by Brian Aker
Removed dead passed variables.
793
sys_var *find_sys_var(Session *, const char *str, uint32_t length)
1 by brian
clean slate
794
{
795
  sys_var *var;
796
  sys_var_pluginvar *pi= NULL;
1530.2.5 by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant
797
  module::Module *module;
1 by brian
clean slate
798
799
  if ((var= intern_find_sys_var(str, length, false)) &&
800
      (pi= var->cast_pluginvar()))
801
  {
1192.2.3 by Monty Taylor
Renamed plugin::Handle to plugin::Module for clarity.
802
    if (!(module= pi->plugin))
1 by brian
clean slate
803
      var= NULL; /* failed to lock it, it must be uninstalling */
1192.2.3 by Monty Taylor
Renamed plugin::Handle to plugin::Module for clarity.
804
    else if (module->isInited == false)
1 by brian
clean slate
805
    {
806
      var= NULL;
807
    }
808
  }
809
810
  /*
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.
813
  */
814
  if (pi && !var)
1851.1.1 by Monty Taylor
Removed sys_var_chain.
815
  {
1 by brian
clean slate
816
    my_error(ER_UNKNOWN_SYSTEM_VARIABLE, MYF(0), (char*) str);
1851.1.1 by Monty Taylor
Removed sys_var_chain.
817
    assert(false);
818
  }
51.1.1 by Jay Pipes
Merged PatG's removal of various DBUG stuff with still keeping DBUG_ASSERT calls since they seem to be breaking test runs
819
  return(var);
1 by brian
clean slate
820
}
821
1720.5.1 by Monty Taylor
Convert HASH in module/loader.cc to boost::unordered_map.
822
static const string make_bookmark_name(const string &plugin, const char *name)
1283.1.1 by Monty Taylor
Remove code which adds skip options for plugins, since that's not how we
823
{
1720.5.1 by Monty Taylor
Convert HASH in module/loader.cc to boost::unordered_map.
824
  string varname(plugin);
1283.1.1 by Monty Taylor
Remove code which adds skip options for plugins, since that's not how we
825
  varname.push_back('_');
826
  varname.append(name);
827
828
  for (string::iterator p= varname.begin() + 1; p != varname.end(); ++p)
829
  {
830
    if (*p == '-')
831
    {
832
      *p= '_';
833
    }
834
  }
835
  return varname;
836
}
1 by brian
clean slate
837
838
/*
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
842
*/
1720.5.2 by Monty Taylor
Renamed st_bookmark. Removed name_len.
843
static Bookmark *find_bookmark(const string &plugin, const char *name, int flags)
1 by brian
clean slate
844
{
520.1.21 by Brian Aker
THD -> Session rename
845
  if (!(flags & PLUGIN_VAR_SessionLOCAL))
1 by brian
clean slate
846
    return NULL;
847
1720.5.1 by Monty Taylor
Convert HASH in module/loader.cc to boost::unordered_map.
848
  const string varname(make_bookmark_name(plugin, name));
849
850
  bookmark_unordered_map::iterator iter= bookmark_hash.find(varname);
851
  if (iter != bookmark_hash.end())
852
  {
853
    return &((*iter).second);
854
  }
855
  return NULL;
1 by brian
clean slate
856
}
857
858
859
/*
520.1.22 by Brian Aker
Second pass of thd cleanup
860
  returns a bookmark for session-local variables, creating if neccessary.
861
  returns null for non session-local variables.
1 by brian
clean slate
862
  Requires that a write lock is obtained on LOCK_system_variables_hash
863
*/
1720.5.2 by Monty Taylor
Renamed st_bookmark. Removed name_len.
864
static Bookmark *register_var(const string &plugin, const char *name,
1 by brian
clean slate
865
                                 int flags)
866
{
1283.1.1 by Monty Taylor
Remove code which adds skip options for plugins, since that's not how we
867
  if (!(flags & PLUGIN_VAR_SessionLOCAL))
868
    return NULL;
869
870
  uint32_t size= 0, offset, new_size;
1720.5.2 by Monty Taylor
Renamed st_bookmark. Removed name_len.
871
  Bookmark *result= NULL;
1 by brian
clean slate
872
873
  switch (flags & PLUGIN_VAR_TYPEMASK) {
874
  case PLUGIN_VAR_BOOL:
937.2.12 by Stewart Smith
ensure correct alignment of all plugin variables. Manifesting as innodb_mysql test failure with SIGBUS on Sparc
875
    size= ALIGN_SIZE(sizeof(bool));
1 by brian
clean slate
876
    break;
877
  case PLUGIN_VAR_INT:
937.2.12 by Stewart Smith
ensure correct alignment of all plugin variables. Manifesting as innodb_mysql test failure with SIGBUS on Sparc
878
    size= ALIGN_SIZE(sizeof(int));
1 by brian
clean slate
879
    break;
880
  case PLUGIN_VAR_LONG:
937.2.12 by Stewart Smith
ensure correct alignment of all plugin variables. Manifesting as innodb_mysql test failure with SIGBUS on Sparc
881
    size= ALIGN_SIZE(sizeof(long));
1 by brian
clean slate
882
    break;
883
  case PLUGIN_VAR_LONGLONG:
937.2.12 by Stewart Smith
ensure correct alignment of all plugin variables. Manifesting as innodb_mysql test failure with SIGBUS on Sparc
884
    size= ALIGN_SIZE(sizeof(uint64_t));
1 by brian
clean slate
885
    break;
886
  case PLUGIN_VAR_STR:
937.2.12 by Stewart Smith
ensure correct alignment of all plugin variables. Manifesting as innodb_mysql test failure with SIGBUS on Sparc
887
    size= ALIGN_SIZE(sizeof(char*));
1 by brian
clean slate
888
    break;
889
  default:
51.1.62 by Jay Pipes
Removed/replaced BUG symbols and standardized TRUE/FALSE
890
    assert(0);
1 by brian
clean slate
891
    return NULL;
892
  };
893
894
1283.1.1 by Monty Taylor
Remove code which adds skip options for plugins, since that's not how we
895
  if (!(result= find_bookmark(plugin, name, flags)))
1 by brian
clean slate
896
  {
1720.5.1 by Monty Taylor
Convert HASH in module/loader.cc to boost::unordered_map.
897
    const string varname(make_bookmark_name(plugin, name));
1283.1.1 by Monty Taylor
Remove code which adds skip options for plugins, since that's not how we
898
1720.5.2 by Monty Taylor
Renamed st_bookmark. Removed name_len.
899
    Bookmark new_bookmark;
1720.5.1 by Monty Taylor
Convert HASH in module/loader.cc to boost::unordered_map.
900
    new_bookmark.key= varname;
901
    new_bookmark.offset= -1;
1 by brian
clean slate
902
51.1.62 by Jay Pipes
Removed/replaced BUG symbols and standardized TRUE/FALSE
903
    assert(size && !(size & (size-1))); /* must be power of 2 */
1 by brian
clean slate
904
905
    offset= global_system_variables.dynamic_variables_size;
906
    offset= (offset + size - 1) & ~(size - 1);
1720.5.1 by Monty Taylor
Convert HASH in module/loader.cc to boost::unordered_map.
907
    new_bookmark.offset= (int) offset;
1 by brian
clean slate
908
909
    new_size= (offset + size + 63) & ~63;
910
911
    if (new_size > global_variables_dynamic_size)
912
    {
656.1.46 by Monty Taylor
More malloc return cleanups.
913
      char* tmpptr= NULL;
914
      if (!(tmpptr=
915
              (char *)realloc(global_system_variables.dynamic_variables_ptr,
916
                              new_size)))
917
        return NULL;
918
      global_system_variables.dynamic_variables_ptr= tmpptr;
919
      tmpptr= NULL;
920
      if (!(tmpptr=
921
              (char *)realloc(max_system_variables.dynamic_variables_ptr,
922
                              new_size)))
923
        return NULL;
924
      max_system_variables.dynamic_variables_ptr= tmpptr;
656.1.26 by Monty Taylor
Finally removed all of the my_malloc stuff.
925
           
1 by brian
clean slate
926
      /*
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
929
        string.
930
      */
212.6.1 by Mats Kindahl
Replacing all bzero() calls with memset() calls and removing the bzero.c file.
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 +
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
935
             global_variables_dynamic_size, 0,
212.6.1 by Mats Kindahl
Replacing all bzero() calls with memset() calls and removing the bzero.c file.
936
             new_size - global_variables_dynamic_size);
1 by brian
clean slate
937
      global_variables_dynamic_size= new_size;
938
    }
939
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++;
946
1720.5.1 by Monty Taylor
Convert HASH in module/loader.cc to boost::unordered_map.
947
    new_bookmark.version= global_system_variables.dynamic_variables_version;
948
    new_bookmark.type_code= flags;
1 by brian
clean slate
949
950
    /* this should succeed because we have already checked if a dup exists */
1720.5.1 by Monty Taylor
Convert HASH in module/loader.cc to boost::unordered_map.
951
    bookmark_hash.insert(make_pair(varname, new_bookmark));
952
    result= find_bookmark(plugin, name, flags);
1 by brian
clean slate
953
  }
954
  return result;
955
}
956
957
958
/*
520.1.22 by Brian Aker
Second pass of thd cleanup
959
  returns a pointer to the memory which holds the session-local variable or
960
  a pointer to the global variable if session==null.
1 by brian
clean slate
961
  If required, will sync with global variables if the requested variable
962
  has not yet been allocated in the current thread.
963
*/
520.1.22 by Brian Aker
Second pass of thd cleanup
964
static unsigned char *intern_sys_var_ptr(Session* session, int offset, bool global_lock)
1 by brian
clean slate
965
{
51.1.62 by Jay Pipes
Removed/replaced BUG symbols and standardized TRUE/FALSE
966
  assert(offset >= 0);
895 by Brian Aker
Completion (?) of uint conversion.
967
  assert((uint32_t)offset <= global_system_variables.dynamic_variables_head);
1 by brian
clean slate
968
520.1.22 by Brian Aker
Second pass of thd cleanup
969
  if (!session)
481 by Brian Aker
Remove all of uchar.
970
    return (unsigned char*) global_system_variables.dynamic_variables_ptr + offset;
1 by brian
clean slate
971
972
  /*
973
    dynamic_variables_head points to the largest valid offset
974
  */
520.1.22 by Brian Aker
Second pass of thd cleanup
975
  if (!session->variables.dynamic_variables_ptr ||
895 by Brian Aker
Completion (?) of uint conversion.
976
      (uint32_t)offset > session->variables.dynamic_variables_head)
1 by brian
clean slate
977
  {
656.1.46 by Monty Taylor
More malloc return cleanups.
978
    char *tmpptr= NULL;
979
    if (!(tmpptr= (char *)realloc(session->variables.dynamic_variables_ptr,
980
                                  global_variables_dynamic_size)))
981
      return NULL;
982
    session->variables.dynamic_variables_ptr= tmpptr;
1 by brian
clean slate
983
984
    if (global_lock)
1689.2.1 by Brian Aker
Convert LOCK_global_system_variables to boost.
985
      LOCK_global_system_variables.lock();
1 by brian
clean slate
986
1241.9.62 by Monty Taylor
Removed plugin/myisam/myisam.h from session.h
987
    //safe_mutex_assert_owner(&LOCK_global_system_variables);
1 by brian
clean slate
988
520.1.22 by Brian Aker
Second pass of thd cleanup
989
    memcpy(session->variables.dynamic_variables_ptr +
990
             session->variables.dynamic_variables_size,
1 by brian
clean slate
991
           global_system_variables.dynamic_variables_ptr +
520.1.22 by Brian Aker
Second pass of thd cleanup
992
             session->variables.dynamic_variables_size,
1 by brian
clean slate
993
           global_system_variables.dynamic_variables_size -
520.1.22 by Brian Aker
Second pass of thd cleanup
994
             session->variables.dynamic_variables_size);
1 by brian
clean slate
995
996
    /*
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
999
    */
1720.5.1 by Monty Taylor
Convert HASH in module/loader.cc to boost::unordered_map.
1000
    bookmark_unordered_map::iterator iter= bookmark_hash.begin();
1001
    for (; iter != bookmark_hash.end() ; ++iter)
1 by brian
clean slate
1002
    {
1003
      sys_var_pluginvar *pi;
1004
      sys_var *var;
1720.5.2 by Monty Taylor
Renamed st_bookmark. Removed name_len.
1005
      const Bookmark &v= (*iter).second;
1720.5.1 by Monty Taylor
Convert HASH in module/loader.cc to boost::unordered_map.
1006
      const string var_name((*iter).first);
1 by brian
clean slate
1007
1720.5.1 by Monty Taylor
Convert HASH in module/loader.cc to boost::unordered_map.
1008
      if (v.version <= session->variables.dynamic_variables_version ||
1009
          !(var= intern_find_sys_var(var_name.c_str(), var_name.size(), true)) ||
1 by brian
clean slate
1010
          !(pi= var->cast_pluginvar()) ||
1720.5.1 by Monty Taylor
Convert HASH in module/loader.cc to boost::unordered_map.
1011
          v.type_code != (pi->plugin_var->flags & PLUGIN_VAR_TYPEMASK))
1 by brian
clean slate
1012
        continue;
1013
1014
      /* Here we do anything special that may be required of the data types */
1015
1016
      if ((pi->plugin_var->flags & PLUGIN_VAR_TYPEMASK) == PLUGIN_VAR_STR &&
1017
          pi->plugin_var->flags & PLUGIN_VAR_MEMALLOC)
1018
      {
520.1.22 by Brian Aker
Second pass of thd cleanup
1019
         char **pp= (char**) (session->variables.dynamic_variables_ptr +
1 by brian
clean slate
1020
                             *(int*)(pi->plugin_var + 1));
1021
         if ((*pp= *(char**) (global_system_variables.dynamic_variables_ptr +
1022
                             *(int*)(pi->plugin_var + 1))))
656.1.19 by Monty Taylor
Removed my_strdup from drizzled/
1023
           *pp= strdup(*pp);
656.1.52 by Monty Taylor
Added more return value checks.
1024
         if (*pp == NULL)
1025
           return NULL;
1 by brian
clean slate
1026
      }
1027
    }
1028
1029
    if (global_lock)
1689.2.1 by Brian Aker
Convert LOCK_global_system_variables to boost.
1030
      LOCK_global_system_variables.unlock();
1 by brian
clean slate
1031
520.1.22 by Brian Aker
Second pass of thd cleanup
1032
    session->variables.dynamic_variables_version=
1 by brian
clean slate
1033
           global_system_variables.dynamic_variables_version;
520.1.22 by Brian Aker
Second pass of thd cleanup
1034
    session->variables.dynamic_variables_head=
1 by brian
clean slate
1035
           global_system_variables.dynamic_variables_head;
520.1.22 by Brian Aker
Second pass of thd cleanup
1036
    session->variables.dynamic_variables_size=
1 by brian
clean slate
1037
           global_system_variables.dynamic_variables_size;
1038
  }
520.1.22 by Brian Aker
Second pass of thd cleanup
1039
  return (unsigned char*)session->variables.dynamic_variables_ptr + offset;
1040
}
1041
1042
static bool *mysql_sys_var_ptr_bool(Session* a_session, int offset)
1043
{
1044
  return (bool *)intern_sys_var_ptr(a_session, offset, true);
1045
}
1046
1047
static int *mysql_sys_var_ptr_int(Session* a_session, int offset)
1048
{
1049
  return (int *)intern_sys_var_ptr(a_session, offset, true);
1050
}
1051
1052
static long *mysql_sys_var_ptr_long(Session* a_session, int offset)
1053
{
1054
  return (long *)intern_sys_var_ptr(a_session, offset, true);
1055
}
1056
1057
static int64_t *mysql_sys_var_ptr_int64_t(Session* a_session, int offset)
1058
{
1059
  return (int64_t *)intern_sys_var_ptr(a_session, offset, true);
1060
}
1061
1062
static char **mysql_sys_var_ptr_str(Session* a_session, int offset)
1063
{
1064
  return (char **)intern_sys_var_ptr(a_session, offset, true);
1065
}
1066
1067
void plugin_sessionvar_init(Session *session)
1068
{
971.1.21 by Monty Taylor
Store StorageEngine in system variables, rather than storage engine plugin.
1069
  session->variables.storage_engine= NULL;
1851.1.1 by Monty Taylor
Removed sys_var_chain.
1070
  cleanup_variables(&session->variables);
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
1071
520.1.22 by Brian Aker
Second pass of thd cleanup
1072
  session->variables= global_system_variables;
971.1.21 by Monty Taylor
Store StorageEngine in system variables, rather than storage engine plugin.
1073
  session->variables.storage_engine= NULL;
1 by brian
clean slate
1074
1075
  /* we are going to allocate these lazily */
520.1.22 by Brian Aker
Second pass of thd cleanup
1076
  session->variables.dynamic_variables_version= 0;
1077
  session->variables.dynamic_variables_size= 0;
1078
  session->variables.dynamic_variables_ptr= 0;
1 by brian
clean slate
1079
971.1.21 by Monty Taylor
Store StorageEngine in system variables, rather than storage engine plugin.
1080
  session->variables.storage_engine= global_system_variables.storage_engine;
1 by brian
clean slate
1081
}
1082
1083
1084
/*
1085
  Unlocks all system variables which hold a reference
1086
*/
1878.3.2 by Monty Taylor
Split out show_type into its own header and made sys_var work through
1087
static void unlock_variables(Session *, struct drizzle_system_variables *vars)
1 by brian
clean slate
1088
{
971.1.21 by Monty Taylor
Store StorageEngine in system variables, rather than storage engine plugin.
1089
  vars->storage_engine= NULL;
1 by brian
clean slate
1090
}
1091
1092
1093
/*
1094
  Frees memory used by system variables
1095
1096
  Unlike plugin_vars_free_values() it frees all variables of all plugins,
1097
  it's used on shutdown.
1098
*/
1878.3.2 by Monty Taylor
Split out show_type into its own header and made sys_var work through
1099
static void cleanup_variables(drizzle_system_variables *vars)
1 by brian
clean slate
1100
{
971.1.21 by Monty Taylor
Store StorageEngine in system variables, rather than storage engine plugin.
1101
  assert(vars->storage_engine == NULL);
1 by brian
clean slate
1102
477 by Monty Taylor
Removed my_free(). It turns out that it had been def'd to ignore the flags passed to it in the second arg anyway. Gotta love that.
1103
  free(vars->dynamic_variables_ptr);
1 by brian
clean slate
1104
  vars->dynamic_variables_ptr= NULL;
1105
  vars->dynamic_variables_size= 0;
1106
  vars->dynamic_variables_version= 0;
1107
}
1108
1109
520.1.22 by Brian Aker
Second pass of thd cleanup
1110
void plugin_sessionvar_cleanup(Session *session)
1 by brian
clean slate
1111
{
520.1.22 by Brian Aker
Second pass of thd cleanup
1112
  unlock_variables(session, &session->variables);
1851.1.1 by Monty Taylor
Removed sys_var_chain.
1113
  cleanup_variables(&session->variables);
1 by brian
clean slate
1114
}
1115
1116
1117
/**
1118
  @brief Free values of thread variables of a plugin.
1119
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
1123
  must be freed.
1124
1125
  @param[in]        vars        Chain of system variables of a plugin
1126
*/
1127
1851.1.1 by Monty Taylor
Removed sys_var_chain.
1128
static void plugin_vars_free_values(module::Module::Variables &vars)
1 by brian
clean slate
1129
{
1130
1851.1.1 by Monty Taylor
Removed sys_var_chain.
1131
  for (module::Module::Variables::iterator iter= vars.begin();
1132
       iter != vars.end();
1133
       ++iter)
1 by brian
clean slate
1134
  {
1851.1.1 by Monty Taylor
Removed sys_var_chain.
1135
    sys_var_pluginvar *piv= (*iter)->cast_pluginvar();
1 by brian
clean slate
1136
    if (piv &&
1137
        ((piv->plugin_var->flags & PLUGIN_VAR_TYPEMASK) == PLUGIN_VAR_STR) &&
1138
        (piv->plugin_var->flags & PLUGIN_VAR_MEMALLOC))
1139
    {
1140
      /* Free the string from global_system_variables. */
1141
      char **valptr= (char**) piv->real_value_ptr(NULL, OPT_GLOBAL);
477 by Monty Taylor
Removed my_free(). It turns out that it had been def'd to ignore the flags passed to it in the second arg anyway. Gotta love that.
1142
      free(*valptr);
1 by brian
clean slate
1143
      *valptr= NULL;
1144
    }
1145
  }
51.1.1 by Jay Pipes
Merged PatG's removal of various DBUG stuff with still keeping DBUG_ASSERT calls since they seem to be breaking test runs
1146
  return;
1 by brian
clean slate
1147
}
1148
1149
1150
bool sys_var_pluginvar::check_update_type(Item_result type)
1151
{
1152
  if (is_readonly())
1153
    return 1;
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;
1161
  default:
1162
    return 0;
1163
  }
1164
}
1165
1166
1167
SHOW_TYPE sys_var_pluginvar::show_type()
1168
{
1169
  switch (plugin_var->flags & PLUGIN_VAR_TYPEMASK) {
1170
  case PLUGIN_VAR_BOOL:
1171
    return SHOW_MY_BOOL;
1172
  case PLUGIN_VAR_INT:
1173
    return SHOW_INT;
1174
  case PLUGIN_VAR_LONG:
1175
    return SHOW_LONG;
1176
  case PLUGIN_VAR_LONGLONG:
1177
    return SHOW_LONGLONG;
1178
  case PLUGIN_VAR_STR:
1179
    return SHOW_CHAR_PTR;
1180
  default:
51.1.62 by Jay Pipes
Removed/replaced BUG symbols and standardized TRUE/FALSE
1181
    assert(0);
1 by brian
clean slate
1182
    return SHOW_UNDEF;
1183
  }
1184
}
1185
1186
1273.13.24 by Brian Aker
Updating style, simplified code.
1187
unsigned char* sys_var_pluginvar::real_value_ptr(Session *session, sql_var_t type)
1 by brian
clean slate
1188
{
520.1.22 by Brian Aker
Second pass of thd cleanup
1189
  assert(session || (type == OPT_GLOBAL));
520.1.21 by Brian Aker
THD -> Session rename
1190
  if (plugin_var->flags & PLUGIN_VAR_SessionLOCAL)
1 by brian
clean slate
1191
  {
1192
    if (type == OPT_GLOBAL)
520.1.22 by Brian Aker
Second pass of thd cleanup
1193
      session= NULL;
1 by brian
clean slate
1194
520.1.22 by Brian Aker
Second pass of thd cleanup
1195
    return intern_sys_var_ptr(session, *(int*) (plugin_var+1), false);
1 by brian
clean slate
1196
  }
481 by Brian Aker
Remove all of uchar.
1197
  return *(unsigned char**) (plugin_var+1);
1 by brian
clean slate
1198
}
1199
1200
1201
TYPELIB* sys_var_pluginvar::plugin_var_typelib(void)
1202
{
520.1.21 by Brian Aker
THD -> Session rename
1203
  switch (plugin_var->flags & (PLUGIN_VAR_TYPEMASK | PLUGIN_VAR_SessionLOCAL)) {
1280.1.6 by Brian Aker
removw DRIZZLE_SYSVAR_ENUM
1204
  case PLUGIN_VAR_SessionLOCAL:
520.1.22 by Brian Aker
Second pass of thd cleanup
1205
    return ((sessionvar_enum_t *)plugin_var)->typelib;
1 by brian
clean slate
1206
  default:
1207
    return NULL;
1208
  }
1209
  return NULL;
1210
}
1211
1212
1273.13.24 by Brian Aker
Updating style, simplified code.
1213
unsigned char* sys_var_pluginvar::value_ptr(Session *session, sql_var_t type, const LEX_STRING *)
1 by brian
clean slate
1214
{
481 by Brian Aker
Remove all of uchar.
1215
  unsigned char* result;
1 by brian
clean slate
1216
520.1.22 by Brian Aker
Second pass of thd cleanup
1217
  result= real_value_ptr(session, type);
1 by brian
clean slate
1218
1219
  return result;
1220
}
1221
1222
520.1.22 by Brian Aker
Second pass of thd cleanup
1223
bool sys_var_pluginvar::check(Session *session, set_var *var)
1 by brian
clean slate
1224
{
1225
  st_item_value_holder value;
51.1.62 by Jay Pipes
Removed/replaced BUG symbols and standardized TRUE/FALSE
1226
  assert(is_readonly() || plugin_var->check);
1 by brian
clean slate
1227
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;
1233
1234
  return is_readonly() ||
520.1.22 by Brian Aker
Second pass of thd cleanup
1235
         plugin_var->check(session, plugin_var, &var->save_result, &value);
1 by brian
clean slate
1236
}
1237
1238
1273.13.24 by Brian Aker
Updating style, simplified code.
1239
void sys_var_pluginvar::set_default(Session *session, sql_var_t type)
1 by brian
clean slate
1240
{
1241
  const void *src;
1242
  void *tgt;
1243
51.1.62 by Jay Pipes
Removed/replaced BUG symbols and standardized TRUE/FALSE
1244
  assert(is_readonly() || plugin_var->update);
1 by brian
clean slate
1245
1246
  if (is_readonly())
1247
    return;
1248
1689.2.1 by Brian Aker
Convert LOCK_global_system_variables to boost.
1249
  LOCK_global_system_variables.lock();
520.1.22 by Brian Aker
Second pass of thd cleanup
1250
  tgt= real_value_ptr(session, type);
1 by brian
clean slate
1251
  src= ((void **) (plugin_var + 1) + 1);
1252
520.1.21 by Brian Aker
THD -> Session rename
1253
  if (plugin_var->flags & PLUGIN_VAR_SessionLOCAL)
1 by brian
clean slate
1254
  {
1255
    if (type != OPT_GLOBAL)
520.1.22 by Brian Aker
Second pass of thd cleanup
1256
      src= real_value_ptr(session, OPT_GLOBAL);
1 by brian
clean slate
1257
    else
1258
    switch (plugin_var->flags & PLUGIN_VAR_TYPEMASK) {
1259
	case PLUGIN_VAR_INT:
520.1.22 by Brian Aker
Second pass of thd cleanup
1260
	  src= &((sessionvar_uint_t*) plugin_var)->def_val;
1 by brian
clean slate
1261
	  break;
1262
	case PLUGIN_VAR_LONG:
520.1.22 by Brian Aker
Second pass of thd cleanup
1263
	  src= &((sessionvar_ulong_t*) plugin_var)->def_val;
1 by brian
clean slate
1264
	  break;
1265
	case PLUGIN_VAR_LONGLONG:
520.1.22 by Brian Aker
Second pass of thd cleanup
1266
	  src= &((sessionvar_uint64_t_t*) plugin_var)->def_val;
1 by brian
clean slate
1267
	  break;
1268
	case PLUGIN_VAR_BOOL:
520.1.22 by Brian Aker
Second pass of thd cleanup
1269
	  src= &((sessionvar_bool_t*) plugin_var)->def_val;
1 by brian
clean slate
1270
	  break;
1271
	case PLUGIN_VAR_STR:
520.1.22 by Brian Aker
Second pass of thd cleanup
1272
	  src= &((sessionvar_str_t*) plugin_var)->def_val;
1 by brian
clean slate
1273
	  break;
1274
	default:
51.1.62 by Jay Pipes
Removed/replaced BUG symbols and standardized TRUE/FALSE
1275
	  assert(0);
1 by brian
clean slate
1276
	}
1277
  }
1278
520.1.22 by Brian Aker
Second pass of thd cleanup
1279
  /* session must equal current_session if PLUGIN_VAR_SessionLOCAL flag is set */
520.1.21 by Brian Aker
THD -> Session rename
1280
  assert(!(plugin_var->flags & PLUGIN_VAR_SessionLOCAL) ||
520.1.22 by Brian Aker
Second pass of thd cleanup
1281
              session == current_session);
1 by brian
clean slate
1282
520.1.21 by Brian Aker
THD -> Session rename
1283
  if (!(plugin_var->flags & PLUGIN_VAR_SessionLOCAL) || type == OPT_GLOBAL)
1 by brian
clean slate
1284
  {
520.1.22 by Brian Aker
Second pass of thd cleanup
1285
    plugin_var->update(session, plugin_var, tgt, src);
1689.2.1 by Brian Aker
Convert LOCK_global_system_variables to boost.
1286
    LOCK_global_system_variables.unlock();
1 by brian
clean slate
1287
  }
1288
  else
1289
  {
1689.2.1 by Brian Aker
Convert LOCK_global_system_variables to boost.
1290
    LOCK_global_system_variables.unlock();
520.1.22 by Brian Aker
Second pass of thd cleanup
1291
    plugin_var->update(session, plugin_var, tgt, src);
1 by brian
clean slate
1292
  }
1293
}
1294
1295
520.1.22 by Brian Aker
Second pass of thd cleanup
1296
bool sys_var_pluginvar::update(Session *session, set_var *var)
1 by brian
clean slate
1297
{
1298
  void *tgt;
1299
51.1.62 by Jay Pipes
Removed/replaced BUG symbols and standardized TRUE/FALSE
1300
  assert(is_readonly() || plugin_var->update);
1 by brian
clean slate
1301
520.1.22 by Brian Aker
Second pass of thd cleanup
1302
  /* session must equal current_session if PLUGIN_VAR_SessionLOCAL flag is set */
520.1.21 by Brian Aker
THD -> Session rename
1303
  assert(!(plugin_var->flags & PLUGIN_VAR_SessionLOCAL) ||
520.1.22 by Brian Aker
Second pass of thd cleanup
1304
              session == current_session);
1 by brian
clean slate
1305
1306
  if (is_readonly())
1307
    return 1;
1308
1689.2.1 by Brian Aker
Convert LOCK_global_system_variables to boost.
1309
  LOCK_global_system_variables.lock();
520.1.22 by Brian Aker
Second pass of thd cleanup
1310
  tgt= real_value_ptr(session, var->type);
1 by brian
clean slate
1311
520.1.21 by Brian Aker
THD -> Session rename
1312
  if (!(plugin_var->flags & PLUGIN_VAR_SessionLOCAL) || var->type == OPT_GLOBAL)
1 by brian
clean slate
1313
  {
1314
    /* variable we are updating has global scope, so we unlock after updating */
520.1.22 by Brian Aker
Second pass of thd cleanup
1315
    plugin_var->update(session, plugin_var, tgt, &var->save_result);
1689.2.1 by Brian Aker
Convert LOCK_global_system_variables to boost.
1316
    LOCK_global_system_variables.unlock();
1 by brian
clean slate
1317
  }
1318
  else
1319
  {
1689.2.1 by Brian Aker
Convert LOCK_global_system_variables to boost.
1320
    LOCK_global_system_variables.unlock();
520.1.22 by Brian Aker
Second pass of thd cleanup
1321
    plugin_var->update(session, plugin_var, tgt, &var->save_result);
1 by brian
clean slate
1322
  }
1323
 return 0;
1324
}
1325
1326
1327
#define OPTION_SET_LIMITS(type, options, opt) \
322.2.2 by Mats Kindahl
Hiding THD::proc_info field and providing a setter and getter.
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;         \
1 by brian
clean slate
1332
  options->block_size= (long) (opt)->blk_sz
1333
1334
1410.3.4 by Djellel E. Difallah
update references to old my_'s
1335
void plugin_opt_set_limits(struct option *options,
1251.2.2 by Jay Pipes
Pulls MyISAM-specific server variables into the MyISAM
1336
													 const drizzle_sys_var *opt)
1 by brian
clean slate
1337
{
1338
  options->sub_size= 0;
1339
1340
  switch (opt->flags & (PLUGIN_VAR_TYPEMASK |
520.1.21 by Brian Aker
THD -> Session rename
1341
                        PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_SessionLOCAL)) {
1 by brian
clean slate
1342
  /* global system variables */
1343
  case PLUGIN_VAR_INT:
1344
    OPTION_SET_LIMITS(GET_INT, options, (sysvar_int_t*) opt);
1345
    break;
1346
  case PLUGIN_VAR_INT | PLUGIN_VAR_UNSIGNED:
1347
    OPTION_SET_LIMITS(GET_UINT, options, (sysvar_uint_t*) opt);
1348
    break;
1349
  case PLUGIN_VAR_LONG:
1350
    OPTION_SET_LIMITS(GET_LONG, options, (sysvar_long_t*) opt);
1351
    break;
1352
  case PLUGIN_VAR_LONG | PLUGIN_VAR_UNSIGNED:
896.4.16 by Stewart Smith
for getopt, replace GET_ULONG with GET_UINT32.
1353
    OPTION_SET_LIMITS(GET_ULONG_IS_FAIL, options, (sysvar_ulong_t*) opt);
1 by brian
clean slate
1354
    break;
1355
  case PLUGIN_VAR_LONGLONG:
152 by Brian Aker
longlong replacement
1356
    OPTION_SET_LIMITS(GET_LL, options, (sysvar_int64_t_t*) opt);
1 by brian
clean slate
1357
    break;
1358
  case PLUGIN_VAR_LONGLONG | PLUGIN_VAR_UNSIGNED:
151 by Brian Aker
Ulonglong to uint64_t
1359
    OPTION_SET_LIMITS(GET_ULL, options, (sysvar_uint64_t_t*) opt);
1 by brian
clean slate
1360
    break;
1361
  case PLUGIN_VAR_BOOL:
1362
    options->var_type= GET_BOOL;
1363
    options->def_value= ((sysvar_bool_t*) opt)->def_val;
1364
    break;
1365
  case PLUGIN_VAR_STR:
1366
    options->var_type= ((opt->flags & PLUGIN_VAR_MEMALLOC) ?
1367
                        GET_STR_ALLOC : GET_STR);
157 by Brian Aker
Second pass cleanup on removal of my_uint types
1368
    options->def_value= (intptr_t) ((sysvar_str_t*) opt)->def_val;
1 by brian
clean slate
1369
    break;
1370
  /* threadlocal variables */
520.1.21 by Brian Aker
THD -> Session rename
1371
  case PLUGIN_VAR_INT | PLUGIN_VAR_SessionLOCAL:
520.1.22 by Brian Aker
Second pass of thd cleanup
1372
    OPTION_SET_LIMITS(GET_INT, options, (sessionvar_int_t*) opt);
1 by brian
clean slate
1373
    break;
520.1.21 by Brian Aker
THD -> Session rename
1374
  case PLUGIN_VAR_INT | PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_SessionLOCAL:
520.1.22 by Brian Aker
Second pass of thd cleanup
1375
    OPTION_SET_LIMITS(GET_UINT, options, (sessionvar_uint_t*) opt);
1 by brian
clean slate
1376
    break;
520.1.21 by Brian Aker
THD -> Session rename
1377
  case PLUGIN_VAR_LONG | PLUGIN_VAR_SessionLOCAL:
520.1.22 by Brian Aker
Second pass of thd cleanup
1378
    OPTION_SET_LIMITS(GET_LONG, options, (sessionvar_long_t*) opt);
1 by brian
clean slate
1379
    break;
520.1.21 by Brian Aker
THD -> Session rename
1380
  case PLUGIN_VAR_LONG | PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_SessionLOCAL:
896.4.16 by Stewart Smith
for getopt, replace GET_ULONG with GET_UINT32.
1381
    OPTION_SET_LIMITS(GET_ULONG_IS_FAIL, options, (sessionvar_ulong_t*) opt);
1 by brian
clean slate
1382
    break;
520.1.21 by Brian Aker
THD -> Session rename
1383
  case PLUGIN_VAR_LONGLONG | PLUGIN_VAR_SessionLOCAL:
520.1.22 by Brian Aker
Second pass of thd cleanup
1384
    OPTION_SET_LIMITS(GET_LL, options, (sessionvar_int64_t_t*) opt);
1 by brian
clean slate
1385
    break;
520.1.21 by Brian Aker
THD -> Session rename
1386
  case PLUGIN_VAR_LONGLONG | PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_SessionLOCAL:
520.1.22 by Brian Aker
Second pass of thd cleanup
1387
    OPTION_SET_LIMITS(GET_ULL, options, (sessionvar_uint64_t_t*) opt);
1 by brian
clean slate
1388
    break;
520.1.21 by Brian Aker
THD -> Session rename
1389
  case PLUGIN_VAR_BOOL | PLUGIN_VAR_SessionLOCAL:
1 by brian
clean slate
1390
    options->var_type= GET_BOOL;
520.1.22 by Brian Aker
Second pass of thd cleanup
1391
    options->def_value= ((sessionvar_bool_t*) opt)->def_val;
1 by brian
clean slate
1392
    break;
520.1.21 by Brian Aker
THD -> Session rename
1393
  case PLUGIN_VAR_STR | PLUGIN_VAR_SessionLOCAL:
1 by brian
clean slate
1394
    options->var_type= ((opt->flags & PLUGIN_VAR_MEMALLOC) ?
1395
                        GET_STR_ALLOC : GET_STR);
520.1.22 by Brian Aker
Second pass of thd cleanup
1396
    options->def_value= (intptr_t) ((sessionvar_str_t*) opt)->def_val;
1 by brian
clean slate
1397
    break;
1398
  default:
51.1.62 by Jay Pipes
Removed/replaced BUG symbols and standardized TRUE/FALSE
1399
    assert(0);
1 by brian
clean slate
1400
  }
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;
1406
}
1407
1530.2.5 by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant
1408
static int construct_options(memory::Root *mem_root, module::Module *tmp,
1410.3.4 by Djellel E. Difallah
update references to old my_'s
1409
                             option *options)
1 by brian
clean slate
1410
{
1283.1.1 by Monty Taylor
Remove code which adds skip options for plugins, since that's not how we
1411
  
1412
  int localoptionid= 256;
1413
  const string plugin_name(tmp->getManifest().name);
1414
1415
  size_t namelen= plugin_name.size(), optnamelen;
1416
1 by brian
clean slate
1417
  char *optname, *p;
1418
  int index= 0, offset= 0;
1228.1.5 by Monty Taylor
Merged in some naming things.
1419
  drizzle_sys_var *opt, **plugin_option;
1720.5.2 by Monty Taylor
Renamed st_bookmark. Removed name_len.
1420
  Bookmark *v;
1 by brian
clean slate
1421
1283.1.1 by Monty Taylor
Remove code which adds skip options for plugins, since that's not how we
1422
  string name(plugin_name);
1423
  transform(name.begin(), name.end(), name.begin(), ::tolower);
1424
1425
  for (string::iterator iter= name.begin(); iter != name.end(); ++iter)
1426
  {
1427
    if (*iter == '_')
1428
      *iter= '-';
1429
  }
1 by brian
clean slate
1430
1431
  /*
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
1434
  */
1435
1093.3.4 by Monty Taylor
Naming cleanups.
1436
  for (plugin_option= tmp->getManifest().system_vars;
1 by brian
clean slate
1437
       plugin_option && *plugin_option; plugin_option++, index++)
1438
  {
1439
    opt= *plugin_option;
520.1.21 by Brian Aker
THD -> Session rename
1440
    if (!(opt->flags & PLUGIN_VAR_SessionLOCAL))
1 by brian
clean slate
1441
      continue;
1442
    if (!(register_var(name, opt->name, opt->flags)))
1443
      continue;
1444
    switch (opt->flags & PLUGIN_VAR_TYPEMASK) {
1445
    case PLUGIN_VAR_BOOL:
520.1.22 by Brian Aker
Second pass of thd cleanup
1446
      (((sessionvar_bool_t *)opt)->resolve)= mysql_sys_var_ptr_bool;
1 by brian
clean slate
1447
      break;
1448
    case PLUGIN_VAR_INT:
520.1.22 by Brian Aker
Second pass of thd cleanup
1449
      (((sessionvar_int_t *)opt)->resolve)= mysql_sys_var_ptr_int;
1 by brian
clean slate
1450
      break;
1451
    case PLUGIN_VAR_LONG:
520.1.22 by Brian Aker
Second pass of thd cleanup
1452
      (((sessionvar_long_t *)opt)->resolve)= mysql_sys_var_ptr_long;
1 by brian
clean slate
1453
      break;
1454
    case PLUGIN_VAR_LONGLONG:
520.1.22 by Brian Aker
Second pass of thd cleanup
1455
      (((sessionvar_int64_t_t *)opt)->resolve)= mysql_sys_var_ptr_int64_t;
1 by brian
clean slate
1456
      break;
1457
    case PLUGIN_VAR_STR:
520.1.22 by Brian Aker
Second pass of thd cleanup
1458
      (((sessionvar_str_t *)opt)->resolve)= mysql_sys_var_ptr_str;
1 by brian
clean slate
1459
      break;
1460
    default:
755.2.1 by Mark Atwood
replace sql_print_error etc with errmsg_print
1461
      errmsg_printf(ERRMSG_LVL_ERROR, _("Unknown variable type code 0x%x in plugin '%s'."),
1283.1.1 by Monty Taylor
Remove code which adds skip options for plugins, since that's not how we
1462
                      opt->flags, plugin_name.c_str());
51.1.1 by Jay Pipes
Merged PatG's removal of various DBUG stuff with still keeping DBUG_ASSERT calls since they seem to be breaking test runs
1463
      return(-1);
1 by brian
clean slate
1464
    };
1465
  }
1466
1093.3.4 by Monty Taylor
Naming cleanups.
1467
  for (plugin_option= tmp->getManifest().system_vars;
1 by brian
clean slate
1468
       plugin_option && *plugin_option; plugin_option++, index++)
1469
  {
1470
    switch ((opt= *plugin_option)->flags & PLUGIN_VAR_TYPEMASK) {
1471
    case PLUGIN_VAR_BOOL:
1472
      if (!opt->check)
1473
        opt->check= check_func_bool;
1474
      if (!opt->update)
1475
        opt->update= update_func_bool;
1476
      break;
1477
    case PLUGIN_VAR_INT:
1478
      if (!opt->check)
1479
        opt->check= check_func_int;
1480
      if (!opt->update)
1481
        opt->update= update_func_int;
1482
      break;
1483
    case PLUGIN_VAR_LONG:
1484
      if (!opt->check)
1485
        opt->check= check_func_long;
1486
      if (!opt->update)
1487
        opt->update= update_func_long;
1488
      break;
1489
    case PLUGIN_VAR_LONGLONG:
1490
      if (!opt->check)
152 by Brian Aker
longlong replacement
1491
        opt->check= check_func_int64_t;
1 by brian
clean slate
1492
      if (!opt->update)
152 by Brian Aker
longlong replacement
1493
        opt->update= update_func_int64_t;
1 by brian
clean slate
1494
      break;
1495
    case PLUGIN_VAR_STR:
1496
      if (!opt->check)
1497
        opt->check= check_func_str;
1498
      if (!opt->update)
1499
      {
1500
        opt->update= update_func_str;
9 by Brian Aker
Warnings cleanup
1501
        if ((opt->flags & (PLUGIN_VAR_MEMALLOC | PLUGIN_VAR_READONLY)) == false)
1 by brian
clean slate
1502
        {
1503
          opt->flags|= PLUGIN_VAR_READONLY;
755.2.1 by Mark Atwood
replace sql_print_error etc with errmsg_print
1504
          errmsg_printf(ERRMSG_LVL_WARN, _("Server variable %s of plugin %s was forced "
1 by brian
clean slate
1505
                            "to be read-only: string variable without "
338 by Monty Taylor
Tagged more strings.
1506
                            "update_func and PLUGIN_VAR_MEMALLOC flag"),
1283.1.1 by Monty Taylor
Remove code which adds skip options for plugins, since that's not how we
1507
                            opt->name, plugin_name.c_str());
1 by brian
clean slate
1508
        }
1509
      }
1510
      break;
1511
    default:
755.2.1 by Mark Atwood
replace sql_print_error etc with errmsg_print
1512
      errmsg_printf(ERRMSG_LVL_ERROR, _("Unknown variable type code 0x%x in plugin '%s'."),
1283.1.1 by Monty Taylor
Remove code which adds skip options for plugins, since that's not how we
1513
                      opt->flags, plugin_name.c_str());
51.1.1 by Jay Pipes
Merged PatG's removal of various DBUG stuff with still keeping DBUG_ASSERT calls since they seem to be breaking test runs
1514
      return(-1);
1 by brian
clean slate
1515
    }
1516
520.1.21 by Brian Aker
THD -> Session rename
1517
    if ((opt->flags & (PLUGIN_VAR_NOCMDOPT | PLUGIN_VAR_SessionLOCAL))
1 by brian
clean slate
1518
                    == PLUGIN_VAR_NOCMDOPT)
1519
      continue;
1520
1521
    if (!opt->name)
1522
    {
755.2.1 by Mark Atwood
replace sql_print_error etc with errmsg_print
1523
      errmsg_printf(ERRMSG_LVL_ERROR, _("Missing variable name in plugin '%s'."),
1283.1.1 by Monty Taylor
Remove code which adds skip options for plugins, since that's not how we
1524
                    plugin_name.c_str());
51.1.1 by Jay Pipes
Merged PatG's removal of various DBUG stuff with still keeping DBUG_ASSERT calls since they seem to be breaking test runs
1525
      return(-1);
1 by brian
clean slate
1526
    }
1527
520.1.21 by Brian Aker
THD -> Session rename
1528
    if (!(opt->flags & PLUGIN_VAR_SessionLOCAL))
1 by brian
clean slate
1529
    {
1530
      optnamelen= strlen(opt->name);
1485 by Brian Aker
Updates to confine memroot
1531
      optname= (char*) mem_root->alloc_root(namelen + optnamelen + 2);
1283.1.1 by Monty Taylor
Remove code which adds skip options for plugins, since that's not how we
1532
      sprintf(optname, "%s-%s", name.c_str(), opt->name);
1 by brian
clean slate
1533
      optnamelen= namelen + optnamelen + 1;
1534
    }
1535
    else
1536
    {
1537
      /* this should not fail because register_var should create entry */
1538
      if (!(v= find_bookmark(name, opt->name, opt->flags)))
1539
      {
755.2.1 by Mark Atwood
replace sql_print_error etc with errmsg_print
1540
        errmsg_printf(ERRMSG_LVL_ERROR, _("Thread local variable '%s' not allocated "
1283.1.1 by Monty Taylor
Remove code which adds skip options for plugins, since that's not how we
1541
                      "in plugin '%s'."), opt->name, plugin_name.c_str());
51.1.1 by Jay Pipes
Merged PatG's removal of various DBUG stuff with still keeping DBUG_ASSERT calls since they seem to be breaking test runs
1542
        return(-1);
1 by brian
clean slate
1543
      }
1544
1545
      *(int*)(opt + 1)= offset= v->offset;
1546
1547
      if (opt->flags & PLUGIN_VAR_NOCMDOPT)
1548
        continue;
1549
1720.5.2 by Monty Taylor
Renamed st_bookmark. Removed name_len.
1550
      optname= (char*) mem_root->memdup_root(v->key.c_str(), (optnamelen= v->key.size()) + 1);
1 by brian
clean slate
1551
    }
1552
1553
    /* convert '_' to '-' */
1554
    for (p= optname; *p; p++)
1555
      if (*p == '_')
1556
        *p= '-';
1557
1558
    options->name= optname;
1559
    options->comment= opt->comment;
1560
    options->app_type= opt;
1283.1.1 by Monty Taylor
Remove code which adds skip options for plugins, since that's not how we
1561
    options->id= localoptionid++;
1 by brian
clean slate
1562
1563
    plugin_opt_set_limits(options, opt);
1564
520.1.21 by Brian Aker
THD -> Session rename
1565
    if (opt->flags & PLUGIN_VAR_SessionLOCAL)
77.1.78 by Monty Taylor
One last bunch of warnings edits.
1566
      options->value= options->u_max_value= (char**)
1 by brian
clean slate
1567
        (global_system_variables.dynamic_variables_ptr + offset);
1568
    else
77.1.78 by Monty Taylor
One last bunch of warnings edits.
1569
      options->value= options->u_max_value= *(char***) (opt + 1);
1 by brian
clean slate
1570
1283.1.1 by Monty Taylor
Remove code which adds skip options for plugins, since that's not how we
1571
    options++;
1 by brian
clean slate
1572
  }
1573
51.1.1 by Jay Pipes
Merged PatG's removal of various DBUG stuff with still keeping DBUG_ASSERT calls since they seem to be breaking test runs
1574
  return(0);
1 by brian
clean slate
1575
}
1576
1577
1530.2.5 by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant
1578
static option *construct_help_options(memory::Root *mem_root, module::Module *p)
1 by brian
clean slate
1579
{
1228.1.5 by Monty Taylor
Merged in some naming things.
1580
  drizzle_sys_var **opt;
1410.3.4 by Djellel E. Difallah
update references to old my_'s
1581
  option *opts;
482 by Brian Aker
Remove uint.
1582
  uint32_t count= EXTRA_OPTIONS;
1 by brian
clean slate
1583
1283.1.1 by Monty Taylor
Remove code which adds skip options for plugins, since that's not how we
1584
  for (opt= p->getManifest().system_vars; opt && *opt; opt++, count++) {};
1 by brian
clean slate
1585
1485 by Brian Aker
Updates to confine memroot
1586
  opts= (option*)mem_root->alloc_root((sizeof(option) * count));
1093.3.5 by Monty Taylor
Removed a dynamic array.
1587
  if (opts == NULL)
1019.1.6 by Brian Aker
A number of random cleanups.
1588
    return NULL;
1 by brian
clean slate
1589
1410.3.4 by Djellel E. Difallah
update references to old my_'s
1590
  memset(opts, 0, sizeof(option) * count);
1 by brian
clean slate
1591
1241.10.5 by Monty Taylor
Removed hardcoded option options around myisam and memory.
1592
  if (construct_options(mem_root, p, opts))
1019.1.6 by Brian Aker
A number of random cleanups.
1593
    return NULL;
1 by brian
clean slate
1594
51.1.1 by Jay Pipes
Merged PatG's removal of various DBUG stuff with still keeping DBUG_ASSERT calls since they seem to be breaking test runs
1595
  return(opts);
1 by brian
clean slate
1596
}
1597
1101.1.27 by Monty Taylor
Fixed the plugin string valgrind leak.
1598
void drizzle_add_plugin_sysvar(sys_var_pluginvar *var)
1599
{
1600
  plugin_sysvar_vec.push_back(var);
1601
}
1602
1603
void drizzle_del_plugin_sysvar()
1604
{
1605
  vector<sys_var_pluginvar *>::iterator iter= plugin_sysvar_vec.begin();
1606
  while(iter != plugin_sysvar_vec.end())
1607
  {
1608
    delete *iter;
1609
    ++iter;
1610
  }
1611
  plugin_sysvar_vec.clear();
1612
}
1 by brian
clean slate
1613
1614
/*
1615
  SYNOPSIS
1616
    test_plugin_options()
1617
    tmp_root                    temporary scratch space
1618
    plugin                      internal plugin structure
1619
    default_enabled             default plugin enable status
1620
  RETURNS:
1621
    0 SUCCESS - plugin should be enabled/loaded
1622
  NOTE:
1623
    Requires that a write-lock is held on LOCK_system_variables_hash
1624
*/
1625.1.5 by Monty Taylor
Put in first bits to use program_options for plugin loading in parallel to
1625
static int test_plugin_options(memory::Root *module_root,
1626
                               module::Module *test_module,
1633.1.1 by Monty Taylor
Added in support for program_options output in --help output.
1627
                               po::options_description &long_options)
1 by brian
clean slate
1628
{
1228.1.5 by Monty Taylor
Merged in some naming things.
1629
  drizzle_sys_var **opt;
1410.3.4 by Djellel E. Difallah
update references to old my_'s
1630
  option *opts= NULL;
1 by brian
clean slate
1631
  int error;
1228.1.5 by Monty Taylor
Merged in some naming things.
1632
  drizzle_sys_var *o;
1720.5.2 by Monty Taylor
Renamed st_bookmark. Removed name_len.
1633
  Bookmark *var;
482 by Brian Aker
Remove uint.
1634
  uint32_t len, count= EXTRA_OPTIONS;
1 by brian
clean slate
1635
1625.1.5 by Monty Taylor
Put in first bits to use program_options for plugin loading in parallel to
1636
  if (test_module->getManifest().init_options != NULL)
1637
  {
1672.2.2 by Monty Taylor
Fixed the headings.
1638
    string plugin_section_title("Options used by ");
1639
    plugin_section_title.append(test_module->getName());
1640
    po::options_description module_options(plugin_section_title);
1625.1.5 by Monty Taylor
Put in first bits to use program_options for plugin loading in parallel to
1641
    module::option_context opt_ctx(test_module->getName(),
1642
                                   module_options.add_options());
1643
    test_module->getManifest().init_options(opt_ctx);
1633.1.1 by Monty Taylor
Added in support for program_options output in --help output.
1644
    long_options.add(module_options);
1625.1.7 by Monty Taylor
Added support for program_options based commandline argument passing.
1645
1625.1.5 by Monty Taylor
Put in first bits to use program_options for plugin loading in parallel to
1646
  }
1643.2.2 by Monty Taylor
In the case where we were handling new-style options, we were skipping too
1647
1648
  for (opt= test_module->getManifest().system_vars; opt && *opt; opt++)
1649
  {
1650
    count++;
1651
  }
1652
1757.2.6 by Monty Taylor
We've gotten further. Now things sometimes work, but some things aren't
1653
  if (count > EXTRA_OPTIONS)
1643.2.2 by Monty Taylor
In the case where we were handling new-style options, we were skipping too
1654
  {
1655
    if (!(opts= (option*) module_root->alloc_root(sizeof(option) * count)))
1656
    {
1657
      errmsg_printf(ERRMSG_LVL_ERROR,
1658
                    _("Out of memory for plugin '%s'."),
1659
                    test_module->getName().c_str());
1660
      return(-1);
1661
    }
1662
    memset(opts, 0, sizeof(option) * count);
1663
1664
    if (construct_options(module_root, test_module, opts))
1665
    {
1666
      errmsg_printf(ERRMSG_LVL_ERROR,
1667
                    _("Bad options for plugin '%s'."),
1668
                    test_module->getName().c_str());
1669
      return(-1);
1670
    }
1671
1625.1.7 by Monty Taylor
Added support for program_options based commandline argument passing.
1672
  }
1 by brian
clean slate
1673
1674
  error= 1;
1675
779.3.53 by Monty Taylor
Revert the fail.
1676
  {
1625.1.5 by Monty Taylor
Put in first bits to use program_options for plugin loading in parallel to
1677
    for (opt= test_module->getManifest().system_vars; opt && *opt; opt++)
779.3.53 by Monty Taylor
Revert the fail.
1678
    {
1106.1.2 by Brian Aker
Additional fixes from Monty
1679
      sys_var *v;
779.3.53 by Monty Taylor
Revert the fail.
1680
      if (((o= *opt)->flags & PLUGIN_VAR_NOSYSVAR))
1681
        continue;
1682
1625.1.5 by Monty Taylor
Put in first bits to use program_options for plugin loading in parallel to
1683
      if ((var= find_bookmark(test_module->getName(), o->name, o->flags)))
1684
      {
1720.5.1 by Monty Taylor
Convert HASH in module/loader.cc to boost::unordered_map.
1685
        v= new sys_var_pluginvar(var->key.c_str(), o);
1625.1.5 by Monty Taylor
Put in first bits to use program_options for plugin loading in parallel to
1686
      }
779.3.53 by Monty Taylor
Revert the fail.
1687
      else
1688
      {
1625.1.5 by Monty Taylor
Put in first bits to use program_options for plugin loading in parallel to
1689
        len= test_module->getName().length() + strlen(o->name) + 2;
1690
        string vname(test_module->getName());
1101.1.27 by Monty Taylor
Fixed the plugin string valgrind leak.
1691
        vname.push_back('-');
1692
        vname.append(o->name);
1693
        transform(vname.begin(), vname.end(), vname.begin(), ::tolower);
1694
        string::iterator p= vname.begin();      
1695
        while  (p != vname.end())
1696
        {
779.3.53 by Monty Taylor
Revert the fail.
1697
          if (*p == '-')
1698
            *p= '_';
1101.1.27 by Monty Taylor
Fixed the plugin string valgrind leak.
1699
          ++p;
1700
        }
779.3.53 by Monty Taylor
Revert the fail.
1701
1101.1.27 by Monty Taylor
Fixed the plugin string valgrind leak.
1702
        v= new sys_var_pluginvar(vname, o);
779.3.53 by Monty Taylor
Revert the fail.
1703
      }
1704
      assert(v); /* check that an object was actually constructed */
1705
1101.1.27 by Monty Taylor
Fixed the plugin string valgrind leak.
1706
      drizzle_add_plugin_sysvar(static_cast<sys_var_pluginvar *>(v));
1851.1.1 by Monty Taylor
Removed sys_var_chain.
1707
      try
1708
      {
1709
        add_sys_var_to_list(v);
1710
        test_module->addSysVar(v);
1711
      }
1712
      catch (...)
779.3.53 by Monty Taylor
Revert the fail.
1713
      {
1625.1.5 by Monty Taylor
Put in first bits to use program_options for plugin loading in parallel to
1714
        errmsg_printf(ERRMSG_LVL_ERROR,
1715
                      _("Plugin '%s' has conflicting system variables"),
1716
                      test_module->getName().c_str());
779.3.53 by Monty Taylor
Revert the fail.
1717
        goto err;
1718
      }
1851.1.1 by Monty Taylor
Removed sys_var_chain.
1719
779.3.53 by Monty Taylor
Revert the fail.
1720
    }
1851.1.1 by Monty Taylor
Removed sys_var_chain.
1721
779.3.53 by Monty Taylor
Revert the fail.
1722
    return(0);
1723
  }
1724
1 by brian
clean slate
1725
err:
1726
  if (opts)
1727
    my_cleanup_options(opts);
51.1.1 by Jay Pipes
Merged PatG's removal of various DBUG stuff with still keeping DBUG_ASSERT calls since they seem to be breaking test runs
1728
  return(error);
1 by brian
clean slate
1729
}
1730
1731
1732
/****************************************************************************
1733
  Help Verbose text with Plugin System Variables
1734
****************************************************************************/
1735
1093.3.5 by Monty Taylor
Removed a dynamic array.
1736
class OptionCmp
1737
{
1738
public:
1410.3.4 by Djellel E. Difallah
update references to old my_'s
1739
  bool operator() (const option &a, const option &b)
1093.3.5 by Monty Taylor
Removed a dynamic array.
1740
  {
1741
    return my_strcasecmp(&my_charset_utf8_general_ci, a.name, b.name);
1742
  }
1743
};
1744
1745
1757.2.3 by Monty Taylor
Made printing of --help work via program_options from the core. Removed
1746
void my_print_help_inc_plugins(option *main_options)
1093.3.5 by Monty Taylor
Removed a dynamic array.
1747
{
1530.2.5 by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant
1748
  module::Registry &registry= module::Registry::singleton();
1410.3.4 by Djellel E. Difallah
update references to old my_'s
1749
  vector<option> all_options;
1485 by Brian Aker
Updates to confine memroot
1750
  memory::Root mem_root(4096);
1410.3.4 by Djellel E. Difallah
update references to old my_'s
1751
  option *opt= NULL;
1 by brian
clean slate
1752
1530.2.5 by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant
1753
1 by brian
clean slate
1754
  if (initialized)
1228.1.3 by Monty Taylor
All of the outstanding plugin loader system cleanups:
1755
  {
1530.2.5 by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant
1756
    std::map<std::string, module::Module *>::const_iterator modules=
1228.1.3 by Monty Taylor
All of the outstanding plugin loader system cleanups:
1757
      registry.getModulesMap().begin();
1758
    
1759
    while (modules != registry.getModulesMap().end())
1 by brian
clean slate
1760
    {
1530.2.5 by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant
1761
      module::Module *p= (*modules).second;
1228.1.3 by Monty Taylor
All of the outstanding plugin loader system cleanups:
1762
      ++modules;
1 by brian
clean slate
1763
1633.1.3 by Monty Taylor
Removed duplicate entries from the help output.
1764
      /* If we have an init_options function, we are registering
1765
         commmand line options that way, so don't do them this way */
1766
      if (p->getManifest().init_options != NULL)
1767
        continue;
1768
1093.3.5 by Monty Taylor
Removed a dynamic array.
1769
      if (p->getManifest().system_vars == NULL)
1770
        continue;
1771
1772
      opt= construct_help_options(&mem_root, p);
1773
      if (opt == NULL)
1 by brian
clean slate
1774
        continue;
1775
1776
      /* Only options with a non-NULL comment are displayed in help text */
1777
      for (;opt->id; opt++)
1093.3.5 by Monty Taylor
Removed a dynamic array.
1778
      {
1 by brian
clean slate
1779
        if (opt->comment)
1093.3.5 by Monty Taylor
Removed a dynamic array.
1780
        {
1781
          all_options.push_back(*opt);
1782
          
1783
        }
1784
      }
1 by brian
clean slate
1785
    }
1228.1.3 by Monty Taylor
All of the outstanding plugin loader system cleanups:
1786
  }
1 by brian
clean slate
1787
1788
  for (;main_options->id; main_options++)
1093.3.5 by Monty Taylor
Removed a dynamic array.
1789
  {
1790
    if (main_options->comment)
1791
    {
1792
      all_options.push_back(*main_options);
1793
    }
1794
  }
1 by brian
clean slate
1795
1093.3.5 by Monty Taylor
Removed a dynamic array.
1796
  /** 
1410.3.4 by Djellel E. Difallah
update references to old my_'s
1797
   * @TODO: Fix the option building so that it doens't break sort
1093.3.5 by Monty Taylor
Removed a dynamic array.
1798
   *
1799
   * sort(all_options.begin(), all_options.end(), OptionCmp());
1800
   */
1 by brian
clean slate
1801
1802
  /* main_options now points to the empty option terminator */
1093.3.5 by Monty Taylor
Removed a dynamic array.
1803
  all_options.push_back(*main_options);
1804
1757.2.3 by Monty Taylor
Made printing of --help work via program_options from the core. Removed
1805
  my_print_help(&*(all_options.begin()));
1093.3.5 by Monty Taylor
Removed a dynamic array.
1806
1487 by Brian Aker
More updates for memory::Root
1807
  mem_root.free_root(MYF(0));
1 by brian
clean slate
1808
}
1809
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
1810
} /* namespace drizzled */
1530.2.3 by Monty Taylor
Changed the builtin plugin code path to work exactly the same as dynamic.
1811
1812