~drizzle-developers/ubuntu/natty/drizzle/natty

« back to all changes in this revision

Viewing changes to drizzled/sql_plugin.cc

  • Committer: Brian Aker
  • Date: 2009-07-29 18:35:48 UTC
  • mfrom: (1101.1.12 merge)
  • Revision ID: brian@gaz-20090729183548-yp36iwoaemfc76z0
Merging Monty (which includes new replication)

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
#include <drizzled/qcache.h>
24
24
#include <drizzled/sql_parse.h>
25
25
#include <drizzled/scheduling.h>
26
 
#include <drizzled/transaction_services.h>
 
26
#include <drizzled/replication_services.h>
27
27
#include <drizzled/show.h>
28
28
#include <drizzled/handler.h>
29
29
#include <drizzled/set_var.h>
44
44
 
45
45
using namespace std;
46
46
using namespace drizzled;
47
 
using namespace drizzled::plugin;
48
47
 
49
 
typedef Manifest builtin_plugin[];
 
48
typedef plugin::Manifest builtin_plugin[];
50
49
extern builtin_plugin DRIZZLED_BUILTIN_LIST;
51
 
static Manifest *drizzled_builtins[]=
 
50
static plugin::Manifest *drizzled_builtins[]=
52
51
{
53
 
  DRIZZLED_BUILTIN_LIST,(Manifest *)0
 
52
  DRIZZLED_BUILTIN_LIST,(plugin::Manifest *)NULL
54
53
};
55
54
 
56
55
char *opt_plugin_load= NULL;
124
123
class sys_var_pluginvar: public sys_var
125
124
{
126
125
public:
127
 
  Handle *plugin;
 
126
  plugin::Handle *plugin;
128
127
  struct st_mysql_sys_var *plugin_var;
129
128
 
130
129
  static void *operator new(size_t size, MEM_ROOT *mem_root)
156
155
/* prototypes */
157
156
static bool plugin_load_list(MEM_ROOT *tmp_root, int *argc, char **argv,
158
157
                             const char *list);
159
 
static int test_plugin_options(MEM_ROOT *, Handle *,
 
158
static int test_plugin_options(MEM_ROOT *, plugin::Handle *,
160
159
                               int *, char **);
161
 
static bool register_builtin(Handle *,
162
 
                             Handle **);
 
160
static bool register_builtin(plugin::Handle *,
 
161
                             plugin::Handle **);
163
162
static void unlock_variables(Session *session, struct system_variables *vars);
164
163
static void cleanup_variables(Session *session, struct system_variables *vars);
165
164
static void plugin_vars_free_values(sys_var *vars);
238
237
  Plugin support code
239
238
****************************************************************************/
240
239
 
241
 
static Library *plugin_dl_find(const LEX_STRING *dl)
 
240
static plugin::Library *plugin_dl_find(const LEX_STRING *dl)
242
241
{
243
242
  uint32_t i;
244
 
  Library *tmp;
 
243
  plugin::Library *tmp;
245
244
 
246
245
  for (i= 0; i < plugin_dl_array.elements; i++)
247
246
  {
248
 
    tmp= *dynamic_element(&plugin_dl_array, i, Library **);
 
247
    tmp= *dynamic_element(&plugin_dl_array, i, plugin::Library **);
249
248
    if (! my_strnncoll(files_charset_info,
250
249
                       (const unsigned char *)dl->str, dl->length,
251
250
                       (const unsigned char *)tmp->dl.str, tmp->dl.length))
254
253
  return(0);
255
254
}
256
255
 
257
 
static Library *plugin_dl_insert_or_reuse(Library *plugin_dl)
 
256
static plugin::Library *plugin_dl_insert_or_reuse(plugin::Library *plugin_dl)
258
257
{
259
258
  uint32_t i;
260
 
  Library *tmp;
 
259
  plugin::Library *tmp;
261
260
 
262
261
  for (i= 0; i < plugin_dl_array.elements; i++)
263
262
  {
264
 
    tmp= *dynamic_element(&plugin_dl_array, i, Library **);
 
263
    tmp= *dynamic_element(&plugin_dl_array, i, plugin::Library **);
265
264
    {
266
 
      memcpy(tmp, plugin_dl, sizeof(Library));
 
265
      memcpy(tmp, plugin_dl, sizeof(plugin::Library));
267
266
      return(tmp);
268
267
    }
269
268
  }
270
269
  if (insert_dynamic(&plugin_dl_array, (unsigned char*)&plugin_dl))
271
270
    return(0);
272
271
  tmp= *dynamic_element(&plugin_dl_array, plugin_dl_array.elements - 1,
273
 
                        Library **)=
274
 
      (Library *) memdup_root(&plugin_mem_root, (unsigned char*)plugin_dl,
275
 
                                           sizeof(Library));
 
272
                        plugin::Library **)=
 
273
      (plugin::Library *) memdup_root(&plugin_mem_root,
 
274
                                      (unsigned char*)plugin_dl,
 
275
                                      sizeof(plugin::Library));
276
276
  return(tmp);
277
277
}
278
278
 
279
 
static inline void free_plugin_mem(Library *p)
 
279
static inline void free_plugin_mem(plugin::Library *p)
280
280
{
281
281
  if (p->handle)
282
282
    dlclose(p->handle);
284
284
}
285
285
 
286
286
 
287
 
static Library *plugin_dl_add(const LEX_STRING *dl, int report)
 
287
static plugin::Library *plugin_dl_add(const LEX_STRING *dl, int report)
288
288
{
289
289
  string dlpath;
290
290
  uint32_t plugin_dir_len;
291
 
  Library *tmp, plugin_dl;
 
291
  plugin::Library *tmp, plugin_dl;
292
292
  void *sym;
293
293
  plugin_dir_len= strlen(opt_plugin_dir);
294
294
  dlpath.reserve(FN_REFLEN);
347
347
    return(0);
348
348
  }
349
349
 
350
 
  plugin_dl.plugins= static_cast<Manifest *>(sym);
 
350
  plugin_dl.plugins= static_cast<plugin::Manifest *>(sym);
351
351
 
352
352
  /* Duplicate and convert dll name */
353
353
  plugin_dl.dl.length= dl->length * files_charset_info->mbmaxlen + 1;
366
366
  {
367
367
    free_plugin_mem(&plugin_dl);
368
368
    if (report & REPORT_TO_USER)
369
 
      my_error(ER_OUTOFMEMORY, MYF(0), sizeof(Library));
 
369
      my_error(ER_OUTOFMEMORY, MYF(0), sizeof(plugin::Library));
370
370
    if (report & REPORT_TO_LOG)
371
 
      errmsg_printf(ERRMSG_LVL_ERROR, ER(ER_OUTOFMEMORY), sizeof(Library));
 
371
      errmsg_printf(ERRMSG_LVL_ERROR, ER(ER_OUTOFMEMORY),
 
372
                    sizeof(plugin::Library));
372
373
    return(0);
373
374
  }
374
375
  return(tmp);
381
382
 
382
383
  for (i= 0; i < plugin_dl_array.elements; i++)
383
384
  {
384
 
    Library *tmp= *dynamic_element(&plugin_dl_array, i,
385
 
                                               Library **);
 
385
    plugin::Library *tmp= *dynamic_element(&plugin_dl_array, i,
 
386
                                           plugin::Library **);
386
387
    if (! my_strnncoll(files_charset_info,
387
388
                       (const unsigned char *)dl->str, dl->length,
388
389
                       (const unsigned char *)tmp->dl.str, tmp->dl.length))
390
391
      /* Do not remove this element, unless no other plugin uses this dll. */
391
392
      {
392
393
        free_plugin_mem(tmp);
393
 
        memset(tmp, 0, sizeof(Library));
 
394
        memset(tmp, 0, sizeof(plugin::Library));
394
395
      }
395
396
      break;
396
397
    }
400
401
 
401
402
 
402
403
 
403
 
static Handle *plugin_insert_or_reuse(Handle *plugin)
 
404
static plugin::Handle *plugin_insert_or_reuse(plugin::Handle *plugin)
404
405
{
405
406
  if (insert_dynamic(&plugin_array, (unsigned char*)&plugin))
406
407
    return(0);
407
408
  plugin= *dynamic_element(&plugin_array, plugin_array.elements - 1,
408
 
                        Handle **);
 
409
                        plugin::Handle **);
409
410
  return(plugin);
410
411
}
411
412
 
420
421
{
421
422
  PluginRegistry &registry= PluginRegistry::getPluginRegistry();
422
423
 
423
 
  Manifest *manifest;
 
424
  plugin::Manifest *manifest;
424
425
  if (! initialized)
425
426
    return(0);
426
427
 
432
433
      errmsg_printf(ERRMSG_LVL_ERROR, ER(ER_UDF_EXISTS), name->str);
433
434
    return(true);
434
435
  }
435
 
  Library *library= plugin_dl_add(dl, report);
 
436
  plugin::Library *library= plugin_dl_add(dl, report);
436
437
  if (library == NULL)
437
438
    return true;
438
439
 
439
 
  Handle *tmp= NULL;
 
440
  plugin::Handle *tmp= NULL;
440
441
  /* Find plugin by name */
441
442
  for (manifest= library->plugins; manifest->name; manifest++)
442
443
  {
445
446
                       (const unsigned char *)manifest->name,
446
447
                       strlen(manifest->name)))
447
448
    {
448
 
      tmp= new (std::nothrow) Handle(manifest, library);
 
449
      tmp= new (std::nothrow) plugin::Handle(manifest, library);
449
450
      if (tmp == NULL)
450
451
        return true;
451
452
 
475
476
}
476
477
 
477
478
 
478
 
static void plugin_del(Handle *plugin)
 
479
static void plugin_del(plugin::Handle *plugin)
479
480
{
480
481
  PluginRegistry &registry= PluginRegistry::getPluginRegistry();
481
482
  if (plugin->isInited)
580
581
int plugin_init(int *argc, char **argv, int flags)
581
582
{
582
583
  uint32_t idx;
583
 
  Manifest **builtins;
584
 
  Manifest *manifest;
585
 
  Handle *handle;
 
584
  plugin::Manifest **builtins;
 
585
  plugin::Manifest *manifest;
 
586
  plugin::Handle *handle;
586
587
  MEM_ROOT tmp_root;
587
588
 
588
589
  if (initialized)
597
598
 
598
599
 
599
600
  if (my_init_dynamic_array(&plugin_dl_array,
600
 
                            sizeof(Library *),16,16) ||
 
601
                            sizeof(plugin::Library *),16,16) ||
601
602
      my_init_dynamic_array(&plugin_array,
602
 
                            sizeof(Handle *),16,16))
 
603
                            sizeof(plugin::Handle *),16,16))
603
604
    goto err;
604
605
 
605
606
  initialized= 1;
611
612
  {
612
613
    for (manifest= *builtins; manifest->name; manifest++)
613
614
    {
614
 
      handle= new (std::nothrow) Handle(manifest);
 
615
      handle= new (std::nothrow) plugin::Handle(manifest);
615
616
      if (handle == NULL)
616
617
        return true;
617
618
 
644
645
  */
645
646
  for (idx= 0; idx < plugin_array.elements; idx++)
646
647
  {
647
 
    handle= *dynamic_element(&plugin_array, idx, Handle **);
 
648
    handle= *dynamic_element(&plugin_array, idx, plugin::Handle **);
648
649
    if (handle->isInited == false)
649
650
    {
650
651
      if (plugin_initialize(handle))
665
666
}
666
667
 
667
668
 
668
 
static bool register_builtin(Handle *tmp,
669
 
                             Handle **ptr)
 
669
static bool register_builtin(plugin::Handle *tmp,
 
670
                             plugin::Handle **ptr)
670
671
{
671
672
 
672
673
  PluginRegistry &registry= PluginRegistry::getPluginRegistry();
678
679
    return(1);
679
680
 
680
681
  *ptr= *dynamic_element(&plugin_array, plugin_array.elements - 1,
681
 
                         Handle **);
 
682
                         plugin::Handle **);
682
683
 
683
684
  registry.add(*ptr);
684
685
 
694
695
{
695
696
  char buffer[FN_REFLEN];
696
697
  LEX_STRING name= {buffer, 0}, dl= {NULL, 0}, *str= &name;
697
 
  Library *plugin_dl;
698
 
  Manifest *plugin;
 
698
  plugin::Library *plugin_dl;
 
699
  plugin::Manifest *plugin;
699
700
  char *p= buffer;
700
701
  while (list)
701
702
  {
771
772
{
772
773
  uint32_t idx;
773
774
  size_t count= plugin_array.elements;
774
 
  vector<Handle *> plugins;
775
 
  vector<Library *> dl;
 
775
  vector<plugin::Handle *> plugins;
 
776
  vector<plugin::Library *> dl;
776
777
 
777
778
  if (initialized)
778
779
  {
796
797
  dl.reserve(count);
797
798
  for (idx= 0; idx < count; idx++)
798
799
    dl.push_back(*dynamic_element(&plugin_dl_array, idx,
799
 
                 Library **));
 
800
                 plugin::Library **));
800
801
  for (idx= 0; idx < count; idx++)
801
802
    free_plugin_mem(dl[idx]);
802
803
  delete_dynamic(&plugin_dl_array);
1116
1117
{
1117
1118
  sys_var *var;
1118
1119
  sys_var_pluginvar *pi= NULL;
1119
 
  Handle *plugin;
 
1120
  plugin::Handle *plugin;
1120
1121
 
1121
1122
  pthread_rwlock_rdlock(&LOCK_system_variables_hash);
1122
1123
  if ((var= intern_find_sys_var(str, length, false)) &&
1860
1861
}
1861
1862
 
1862
1863
 
1863
 
static int construct_options(MEM_ROOT *mem_root, Handle *tmp,
 
1864
static int construct_options(MEM_ROOT *mem_root, plugin::Handle *tmp,
1864
1865
                             my_option *options, bool can_disable)
1865
1866
{
1866
1867
  const char *plugin_name= tmp->getManifest().name;
2075
2076
}
2076
2077
 
2077
2078
 
2078
 
static my_option *construct_help_options(MEM_ROOT *mem_root, Handle *p)
 
2079
static my_option *construct_help_options(MEM_ROOT *mem_root, plugin::Handle *p)
2079
2080
{
2080
2081
  st_mysql_sys_var **opt;
2081
2082
  my_option *opts;
2118
2119
  NOTE:
2119
2120
    Requires that a write-lock is held on LOCK_system_variables_hash
2120
2121
*/
2121
 
static int test_plugin_options(MEM_ROOT *tmp_root, Handle *tmp,
 
2122
static int test_plugin_options(MEM_ROOT *tmp_root, plugin::Handle *tmp,
2122
2123
                               int *argc, char **argv)
2123
2124
{
2124
2125
  struct sys_var_chain chain= { NULL, NULL };
2240
2241
void my_print_help_inc_plugins(my_option *main_options)
2241
2242
{
2242
2243
  vector<my_option> all_options;
2243
 
  Handle *p;
 
2244
  plugin::Handle *p;
2244
2245
  MEM_ROOT mem_root;
2245
2246
  my_option *opt= NULL;
2246
2247
 
2249
2250
  if (initialized)
2250
2251
    for (uint32_t idx= 0; idx < plugin_array.elements; idx++)
2251
2252
    {
2252
 
      p= *dynamic_element(&plugin_array, idx, Handle **);
 
2253
      p= *dynamic_element(&plugin_array, idx, plugin::Handle **);
2253
2254
 
2254
2255
      if (p->getManifest().system_vars == NULL)
2255
2256
        continue;