~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to server/sql_plugin.cc

  • Committer: Brian Aker
  • Date: 2008-07-14 16:24:25 UTC
  • Revision ID: brian@tangent.org-20080714162425-juw3vw221gs9kysh
Cleanup around intptr_t

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
   along with this program; if not, write to the Free Software
14
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
 
#include <drizzled/server_includes.h>
17
 
#include <mysys/my_getopt.h>
18
 
#include <authentication.h>
19
 
#include <logging.h>
20
 
#include <drizzled/drizzled_error_messages.h>
 
16
#include "mysql_priv.h"
 
17
#include <my_pthread.h>
 
18
#include <my_getopt.h>
21
19
#define REPORT_TO_LOG  1
22
20
#define REPORT_TO_USER 2
23
21
 
33
31
  When you ad a new plugin type, add both a string and make sure that the
34
32
  init and deinit array are correctly updated.
35
33
*/
36
 
const LEX_STRING plugin_type_names[DRIZZLE_MAX_PLUGIN_TYPE_NUM]=
 
34
const LEX_STRING plugin_type_names[MYSQL_MAX_PLUGIN_TYPE_NUM]=
37
35
{
 
36
  { C_STRING_WITH_LEN("UDF") },
 
37
  { C_STRING_WITH_LEN("STORAGE ENGINE") },
 
38
  { C_STRING_WITH_LEN("FTPARSER") },
38
39
  { C_STRING_WITH_LEN("DAEMON") },
39
 
  { C_STRING_WITH_LEN("STORAGE ENGINE") },
40
40
  { C_STRING_WITH_LEN("INFORMATION SCHEMA") },
41
 
  { C_STRING_WITH_LEN("UDF") },
42
 
  { C_STRING_WITH_LEN("UDA") },
43
 
  { C_STRING_WITH_LEN("AUDIT") },
44
 
  { C_STRING_WITH_LEN("LOGGER") },
45
 
  { C_STRING_WITH_LEN("AUTH") }
 
41
  { C_STRING_WITH_LEN("AUDIT") }
46
42
};
47
43
 
48
44
extern int initialize_schema_table(st_plugin_int *plugin);
56
52
  plugin_type_deinitialize should equal to the number of plugins
57
53
  defined.
58
54
*/
59
 
plugin_type_init plugin_type_initialize[DRIZZLE_MAX_PLUGIN_TYPE_NUM]=
60
 
{
61
 
  0,  /* Daemon */
62
 
  ha_initialize_handlerton,  /* Storage Engine */
63
 
  initialize_schema_table,  /* Information Schema */
64
 
  initialize_udf,  /* UDF */
65
 
  0,  /* UDA */
66
 
  0,  /* Audit */
67
 
  logging_initializer,  /* Logger */
68
 
  authentication_initializer  /* Auth */
69
 
};
70
 
 
71
 
plugin_type_init plugin_type_deinitialize[DRIZZLE_MAX_PLUGIN_TYPE_NUM]=
72
 
{
73
 
  0,  /* Daemon */
74
 
  ha_finalize_handlerton,  /* Storage Engine */
75
 
  finalize_schema_table,  /* Information Schema */
76
 
  finalize_udf,  /* UDF */
77
 
  0,  /* UDA */
78
 
  0,  /* Audit */
79
 
  logging_finalizer,  /* Logger */
80
 
  authentication_finalizer  /* Auth */
81
 
};
82
 
 
 
55
plugin_type_init plugin_type_initialize[MYSQL_MAX_PLUGIN_TYPE_NUM]=
 
56
{
 
57
  initialize_udf,ha_initialize_handlerton,0,0,initialize_schema_table,
 
58
  0
 
59
};
 
60
 
 
61
plugin_type_init plugin_type_deinitialize[MYSQL_MAX_PLUGIN_TYPE_NUM]=
 
62
{
 
63
  finalize_udf,ha_finalize_handlerton,0,0,finalize_schema_table,
 
64
  0
 
65
};
 
66
 
 
67
static const char *plugin_interface_version_sym=
 
68
                   "_mysql_plugin_interface_version_";
 
69
static const char *sizeof_st_plugin_sym=
 
70
                   "_mysql_sizeof_struct_st_plugin_";
83
71
static const char *plugin_declarations_sym= "_mysql_plugin_declarations_";
 
72
static int min_plugin_interface_version= MYSQL_PLUGIN_INTERFACE_VERSION & ~0xFF;
84
73
 
85
74
/* Note that 'int version' must be the first field of every plugin
86
75
   sub-structure (plugin->info).
87
76
*/
 
77
static int min_plugin_info_interface_version[MYSQL_MAX_PLUGIN_TYPE_NUM]=
 
78
{
 
79
  MYSQL_UDF_INTERFACE_VERSION,
 
80
  MYSQL_HANDLERTON_INTERFACE_VERSION,
 
81
  MYSQL_FTPARSER_INTERFACE_VERSION,
 
82
  MYSQL_DAEMON_INTERFACE_VERSION,
 
83
  MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION,
 
84
  MYSQL_AUDIT_INTERFACE_VERSION
 
85
};
 
86
static int cur_plugin_info_interface_version[MYSQL_MAX_PLUGIN_TYPE_NUM]=
 
87
{
 
88
  MYSQL_UDF_INTERFACE_VERSION,
 
89
  MYSQL_HANDLERTON_INTERFACE_VERSION,
 
90
  MYSQL_FTPARSER_INTERFACE_VERSION,
 
91
  MYSQL_DAEMON_INTERFACE_VERSION,
 
92
  MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION,
 
93
  MYSQL_AUDIT_INTERFACE_VERSION
 
94
};
88
95
 
89
96
static bool initialized= 0;
90
97
 
91
98
static DYNAMIC_ARRAY plugin_dl_array;
92
99
static DYNAMIC_ARRAY plugin_array;
93
 
static HASH plugin_hash[DRIZZLE_MAX_PLUGIN_TYPE_NUM];
 
100
static HASH plugin_hash[MYSQL_MAX_PLUGIN_TYPE_NUM];
94
101
static bool reap_needed= false;
95
102
static int plugin_array_version=0;
96
103
 
99
106
  the following variables/structures
100
107
*/
101
108
static MEM_ROOT plugin_mem_root;
102
 
static uint32_t global_variables_dynamic_size= 0;
 
109
static uint global_variables_dynamic_size= 0;
103
110
static HASH bookmark_hash;
104
111
 
105
112
 
126
133
*/
127
134
struct st_bookmark
128
135
{
129
 
  uint32_t name_len;
 
136
  uint name_len;
130
137
  int offset;
131
 
  uint32_t version;
 
138
  uint version;
132
139
  char key[1];
133
140
};
134
141
 
138
145
*/
139
146
struct st_mysql_sys_var
140
147
{
141
 
  DRIZZLE_PLUGIN_VAR_HEADER;
 
148
  MYSQL_PLUGIN_VAR_HEADER;
142
149
};
143
150
 
144
151
 
153
160
 
154
161
  static void *operator new(size_t size, MEM_ROOT *mem_root)
155
162
  { return (void*) alloc_root(mem_root, (uint) size); }
156
 
  static void operator delete(void *ptr_arg __attribute__((unused)),
157
 
                              size_t size __attribute__((unused)))
 
163
  static void operator delete(void *ptr_arg __attribute__((__unused__)),
 
164
                              size_t size __attribute__((__unused__)))
158
165
  { TRASH(ptr_arg, size); }
159
166
 
160
167
  sys_var_pluginvar(const char *name_arg,
166
173
  { return !(plugin_var->flags & PLUGIN_VAR_THDLOCAL) && type != OPT_GLOBAL; }
167
174
  bool check_update_type(Item_result type);
168
175
  SHOW_TYPE show_type();
169
 
  unsigned char* real_value_ptr(THD *thd, enum_var_type type);
 
176
  uchar* real_value_ptr(THD *thd, enum_var_type type);
170
177
  TYPELIB* plugin_var_typelib(void);
171
 
  unsigned char* value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
 
178
  uchar* value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
172
179
  bool check(THD *thd, set_var *var);
173
 
  bool check_default(enum_var_type type __attribute__((unused)))
 
180
  bool check_default(enum_var_type type __attribute__((__unused__)))
174
181
    { return is_readonly(); }
175
182
  void set_default(THD *thd,
176
 
                   enum_var_type type __attribute__((unused)));
 
183
                   enum_var_type type __attribute__((__unused__)));
177
184
  bool update(THD *thd, set_var *var);
178
185
};
179
186
 
199
206
 
200
207
 
201
208
/* declared in set_var.cc */
202
 
extern sys_var *intern_find_sys_var(const char *str, uint32_t length, bool no_error);
 
209
extern sys_var *intern_find_sys_var(const char *str, uint length, bool no_error);
203
210
extern bool throw_bounds_warning(THD *thd, bool fixed, bool unsignd,
204
211
                                 const char *name, int64_t val);
205
212
 
211
218
{
212
219
  switch (((st_item_value_holder*)value)->item->result_type()) {
213
220
  case INT_RESULT:
214
 
    return DRIZZLE_VALUE_TYPE_INT;
 
221
    return MYSQL_VALUE_TYPE_INT;
215
222
  case REAL_RESULT:
216
 
    return DRIZZLE_VALUE_TYPE_REAL;
 
223
    return MYSQL_VALUE_TYPE_REAL;
217
224
  default:
218
 
    return DRIZZLE_VALUE_TYPE_STRING;
 
225
    return MYSQL_VALUE_TYPE_STRING;
219
226
  }
220
227
}
221
228
 
263
270
 
264
271
static struct st_plugin_dl *plugin_dl_find(const LEX_STRING *dl)
265
272
{
266
 
  uint32_t i;
 
273
  uint i;
267
274
  struct st_plugin_dl *tmp;
268
275
  for (i= 0; i < plugin_dl_array.elements; i++)
269
276
  {
270
277
    tmp= *dynamic_element(&plugin_dl_array, i, struct st_plugin_dl **);
271
278
    if (tmp->ref_count &&
272
279
        ! my_strnncoll(files_charset_info,
273
 
                       (const unsigned char *)dl->str, dl->length,
274
 
                       (const unsigned char *)tmp->dl.str, tmp->dl.length))
 
280
                       (const uchar *)dl->str, dl->length,
 
281
                       (const uchar *)tmp->dl.str, tmp->dl.length))
275
282
      return(tmp);
276
283
  }
277
284
  return(0);
279
286
 
280
287
static st_plugin_dl *plugin_dl_insert_or_reuse(struct st_plugin_dl *plugin_dl)
281
288
{
282
 
  uint32_t i;
 
289
  uint i;
283
290
  struct st_plugin_dl *tmp;
284
291
  for (i= 0; i < plugin_dl_array.elements; i++)
285
292
  {
290
297
      return(tmp);
291
298
    }
292
299
  }
293
 
  if (insert_dynamic(&plugin_dl_array, (unsigned char*)&plugin_dl))
 
300
  if (insert_dynamic(&plugin_dl_array, (uchar*)&plugin_dl))
294
301
    return(0);
295
302
  tmp= *dynamic_element(&plugin_dl_array, plugin_dl_array.elements - 1,
296
303
                        struct st_plugin_dl **)=
297
 
      (struct st_plugin_dl *) memdup_root(&plugin_mem_root, (unsigned char*)plugin_dl,
 
304
      (struct st_plugin_dl *) memdup_root(&plugin_mem_root, (uchar*)plugin_dl,
298
305
                                           sizeof(struct st_plugin_dl));
299
306
  return(tmp);
300
307
}
303
310
{
304
311
  if (p->handle)
305
312
    dlclose(p->handle);
306
 
  free(p->dl.str);
 
313
  my_free(p->dl.str, MYF(MY_ALLOW_ZERO_PTR));
 
314
  if (p->version != MYSQL_PLUGIN_INTERFACE_VERSION)
 
315
    my_free((uchar*)p->plugins, MYF(MY_ALLOW_ZERO_PTR));
307
316
}
308
317
 
309
318
 
310
319
static st_plugin_dl *plugin_dl_add(const LEX_STRING *dl, int report)
311
320
{
 
321
#ifdef HAVE_DLOPEN
312
322
  char dlpath[FN_REFLEN];
313
 
  uint32_t plugin_dir_len, dummy_errors, dlpathlen;
 
323
  uint plugin_dir_len, dummy_errors, dlpathlen;
314
324
  struct st_plugin_dl *tmp, plugin_dl;
315
325
  void *sym;
316
326
  plugin_dir_len= strlen(opt_plugin_dir);
319
329
    This is done to ensure that only approved libraries from the
320
330
    plugin directory are used (to make this even remotely secure).
321
331
  */
322
 
  if (strchr(dl->str, FN_LIBCHAR) ||
 
332
  if (my_strchr(files_charset_info, dl->str, dl->str + dl->length, FN_LIBCHAR) ||
323
333
      check_string_char_length((LEX_STRING *) dl, "", NAME_CHAR_LEN,
324
334
                               system_charset_info, 1) ||
325
335
      plugin_dir_len + dl->length + 1 >= FN_REFLEN)
336
346
    tmp->ref_count++;
337
347
    return(tmp);
338
348
  }
339
 
  memset(&plugin_dl, 0, sizeof(plugin_dl));
 
349
  bzero(&plugin_dl, sizeof(plugin_dl));
340
350
  /* Compile dll path */
341
351
  dlpathlen=
342
 
    strxnmov(dlpath, sizeof(dlpath) - 1, opt_plugin_dir, "/", dl->str, NULL) -
 
352
    strxnmov(dlpath, sizeof(dlpath) - 1, opt_plugin_dir, "/", dl->str, NullS) -
343
353
    dlpath;
344
354
  plugin_dl.ref_count= 1;
345
355
  /* Open new dll handle */
346
 
  if (!(plugin_dl.handle= dlopen(dlpath, RTLD_LAZY|RTLD_GLOBAL)))
 
356
  if (!(plugin_dl.handle= dlopen(dlpath, RTLD_NOW)))
347
357
  {
348
358
    const char *errmsg=dlerror();
349
359
    if (!strncmp(dlpath, errmsg, dlpathlen))
358
368
      sql_print_error(ER(ER_CANT_OPEN_LIBRARY), dlpath, errno, errmsg);
359
369
    return(0);
360
370
  }
361
 
 
 
371
  /* Determine interface version */
 
372
  if (!(sym= dlsym(plugin_dl.handle, plugin_interface_version_sym)))
 
373
  {
 
374
    free_plugin_mem(&plugin_dl);
 
375
    if (report & REPORT_TO_USER)
 
376
      my_error(ER_CANT_FIND_DL_ENTRY, MYF(0), plugin_interface_version_sym);
 
377
    if (report & REPORT_TO_LOG)
 
378
      sql_print_error(ER(ER_CANT_FIND_DL_ENTRY), plugin_interface_version_sym);
 
379
    return(0);
 
380
  }
 
381
  plugin_dl.version= *(int *)sym;
 
382
  /* Versioning */
 
383
  if (plugin_dl.version < min_plugin_interface_version ||
 
384
      (plugin_dl.version >> 8) > (MYSQL_PLUGIN_INTERFACE_VERSION >> 8))
 
385
  {
 
386
    free_plugin_mem(&plugin_dl);
 
387
    if (report & REPORT_TO_USER)
 
388
      my_error(ER_CANT_OPEN_LIBRARY, MYF(0), dlpath, 0,
 
389
               "plugin interface version mismatch");
 
390
    if (report & REPORT_TO_LOG)
 
391
      sql_print_error(ER(ER_CANT_OPEN_LIBRARY), dlpath, 0,
 
392
                      "plugin interface version mismatch");
 
393
    return(0);
 
394
  }
362
395
  /* Find plugin declarations */
363
396
  if (!(sym= dlsym(plugin_dl.handle, plugin_declarations_sym)))
364
397
  {
370
403
    return(0);
371
404
  }
372
405
 
 
406
  if (plugin_dl.version != MYSQL_PLUGIN_INTERFACE_VERSION)
 
407
  {
 
408
    int i;
 
409
    uint sizeof_st_plugin;
 
410
    struct st_mysql_plugin *old, *cur;
 
411
    char *ptr= (char *)sym;
 
412
 
 
413
    if ((sym= dlsym(plugin_dl.handle, sizeof_st_plugin_sym)))
 
414
      sizeof_st_plugin= *(int *)sym;
 
415
    else
 
416
    {
 
417
#ifdef ERROR_ON_NO_SIZEOF_PLUGIN_SYMBOL
 
418
      free_plugin_mem(&plugin_dl);
 
419
      if (report & REPORT_TO_USER)
 
420
        my_error(ER_CANT_FIND_DL_ENTRY, MYF(0), sizeof_st_plugin_sym);
 
421
      if (report & REPORT_TO_LOG)
 
422
        sql_print_error(ER(ER_CANT_FIND_DL_ENTRY), sizeof_st_plugin_sym);
 
423
      return(0);
 
424
#else
 
425
      /*
 
426
        When the following assert starts failing, we'll have to switch
 
427
        to the upper branch of the #ifdef
 
428
      */
 
429
      assert(min_plugin_interface_version == 0);
 
430
      sizeof_st_plugin= (int)offsetof(struct st_mysql_plugin, version);
 
431
#endif
 
432
    }
 
433
 
 
434
    for (i= 0;
 
435
         ((struct st_mysql_plugin *)(ptr+i*sizeof_st_plugin))->info;
 
436
         i++)
 
437
      /* no op */;
 
438
 
 
439
    cur= (struct st_mysql_plugin*)
 
440
          my_malloc(i*sizeof(struct st_mysql_plugin), MYF(MY_ZEROFILL|MY_WME));
 
441
    if (!cur)
 
442
    {
 
443
      free_plugin_mem(&plugin_dl);
 
444
      if (report & REPORT_TO_USER)
 
445
        my_error(ER_OUTOFMEMORY, MYF(0), plugin_dl.dl.length);
 
446
      if (report & REPORT_TO_LOG)
 
447
        sql_print_error(ER(ER_OUTOFMEMORY), plugin_dl.dl.length);
 
448
      return(0);
 
449
    }
 
450
    /*
 
451
      All st_plugin fields not initialized in the plugin explicitly, are
 
452
      set to 0. It matches C standard behaviour for struct initializers that
 
453
      have less values than the struct definition.
 
454
    */
 
455
    for (i=0;
 
456
         (old=(struct st_mysql_plugin *)(ptr+i*sizeof_st_plugin))->info;
 
457
         i++)
 
458
      memcpy(cur+i, old, min(sizeof(cur[i]), sizeof_st_plugin));
 
459
 
 
460
    sym= cur;
 
461
  }
373
462
  plugin_dl.plugins= (struct st_mysql_plugin *)sym;
374
463
 
375
464
  /* Duplicate and convert dll name */
398
487
    return(0);
399
488
  }
400
489
  return(tmp);
 
490
#else
 
491
  if (report & REPORT_TO_USER)
 
492
    my_error(ER_FEATURE_DISABLED, MYF(0), "plugin", "HAVE_DLOPEN");
 
493
  if (report & REPORT_TO_LOG)
 
494
    sql_print_error(ER(ER_FEATURE_DISABLED), "plugin", "HAVE_DLOPEN");
 
495
  return(0);
 
496
#endif
401
497
}
402
498
 
403
499
 
404
500
static void plugin_dl_del(const LEX_STRING *dl)
405
501
{
406
 
  uint32_t i;
 
502
#ifdef HAVE_DLOPEN
 
503
  uint i;
407
504
 
408
505
  for (i= 0; i < plugin_dl_array.elements; i++)
409
506
  {
411
508
                                               struct st_plugin_dl **);
412
509
    if (tmp->ref_count &&
413
510
        ! my_strnncoll(files_charset_info,
414
 
                       (const unsigned char *)dl->str, dl->length,
415
 
                       (const unsigned char *)tmp->dl.str, tmp->dl.length))
 
511
                       (const uchar *)dl->str, dl->length,
 
512
                       (const uchar *)tmp->dl.str, tmp->dl.length))
416
513
    {
417
514
      /* Do not remove this element, unless no other plugin uses this dll. */
418
515
      if (! --tmp->ref_count)
419
516
      {
420
517
        free_plugin_mem(tmp);
421
 
        memset(tmp, 0, sizeof(struct st_plugin_dl));
 
518
        bzero(tmp, sizeof(struct st_plugin_dl));
422
519
      }
423
520
      break;
424
521
    }
425
522
  }
426
523
  return;
 
524
#endif
427
525
}
428
526
 
429
527
 
430
528
static struct st_plugin_int *plugin_find_internal(const LEX_STRING *name, int type)
431
529
{
432
 
  uint32_t i;
 
530
  uint i;
433
531
  if (! initialized)
434
532
    return(0);
435
533
 
436
 
  if (type == DRIZZLE_ANY_PLUGIN)
 
534
  if (type == MYSQL_ANY_PLUGIN)
437
535
  {
438
 
    for (i= 0; i < DRIZZLE_MAX_PLUGIN_TYPE_NUM; i++)
 
536
    for (i= 0; i < MYSQL_MAX_PLUGIN_TYPE_NUM; i++)
439
537
    {
440
538
      struct st_plugin_int *plugin= (st_plugin_int *)
441
 
        hash_search(&plugin_hash[i], (const unsigned char *)name->str, name->length);
 
539
        hash_search(&plugin_hash[i], (const uchar *)name->str, name->length);
442
540
      if (plugin)
443
541
        return(plugin);
444
542
    }
445
543
  }
446
544
  else
447
545
    return((st_plugin_int *)
448
 
        hash_search(&plugin_hash[type], (const unsigned char *)name->str, name->length));
 
546
        hash_search(&plugin_hash[type], (const uchar *)name->str, name->length));
449
547
  return(0);
450
548
}
451
549
 
466
564
 
467
565
bool plugin_is_ready(const LEX_STRING *name, int type)
468
566
{
469
 
  bool rc= false;
 
567
  bool rc= FALSE;
470
568
  if (plugin_status(name, type) == SHOW_OPTION_YES)
471
 
    rc= true;
 
569
    rc= TRUE;
472
570
  return rc;
473
571
}
474
572
 
499
597
    pi->ref_count++;
500
598
 
501
599
    if (lex)
502
 
      insert_dynamic(&lex->plugins, (unsigned char*)&plugin);
 
600
      insert_dynamic(&lex->plugins, (uchar*)&plugin);
503
601
    return(plugin);
504
602
  }
505
603
  return(NULL);
529
627
 
530
628
static st_plugin_int *plugin_insert_or_reuse(struct st_plugin_int *plugin)
531
629
{
532
 
  uint32_t i;
 
630
  uint i;
533
631
  struct st_plugin_int *tmp;
534
632
  for (i= 0; i < plugin_array.elements; i++)
535
633
  {
540
638
      return(tmp);
541
639
    }
542
640
  }
543
 
  if (insert_dynamic(&plugin_array, (unsigned char*)&plugin))
 
641
  if (insert_dynamic(&plugin_array, (uchar*)&plugin))
544
642
    return(0);
545
643
  tmp= *dynamic_element(&plugin_array, plugin_array.elements - 1,
546
644
                        struct st_plugin_int **)=
547
 
       (struct st_plugin_int *) memdup_root(&plugin_mem_root, (unsigned char*)plugin,
 
645
       (struct st_plugin_int *) memdup_root(&plugin_mem_root, (uchar*)plugin,
548
646
                                            sizeof(struct st_plugin_int));
549
647
  return(tmp);
550
648
}
560
658
{
561
659
  struct st_plugin_int tmp;
562
660
  struct st_mysql_plugin *plugin;
563
 
  if (plugin_find_internal(name, DRIZZLE_ANY_PLUGIN))
 
661
  if (plugin_find_internal(name, MYSQL_ANY_PLUGIN))
564
662
  {
565
663
    if (report & REPORT_TO_USER)
566
664
      my_error(ER_UDF_EXISTS, MYF(0), name->str);
567
665
    if (report & REPORT_TO_LOG)
568
666
      sql_print_error(ER(ER_UDF_EXISTS), name->str);
569
 
    return(true);
 
667
    return(TRUE);
570
668
  }
571
669
  /* Clear the whole struct to catch future extensions. */
572
 
  memset(&tmp, 0, sizeof(tmp));
 
670
  bzero((char*) &tmp, sizeof(tmp));
573
671
  if (! (tmp.plugin_dl= plugin_dl_add(dl, report)))
574
 
    return(true);
 
672
    return(TRUE);
575
673
  /* Find plugin by name */
576
 
  for (plugin= tmp.plugin_dl->plugins; plugin->name; plugin++)
 
674
  for (plugin= tmp.plugin_dl->plugins; plugin->info; plugin++)
577
675
  {
578
 
    uint32_t name_len= strlen(plugin->name);
579
 
    if (plugin->type >= 0 && plugin->type < DRIZZLE_MAX_PLUGIN_TYPE_NUM &&
 
676
    uint name_len= strlen(plugin->name);
 
677
    if (plugin->type >= 0 && plugin->type < MYSQL_MAX_PLUGIN_TYPE_NUM &&
580
678
        ! my_strnncoll(system_charset_info,
581
 
                       (const unsigned char *)name->str, name->length,
582
 
                       (const unsigned char *)plugin->name,
 
679
                       (const uchar *)name->str, name->length,
 
680
                       (const uchar *)plugin->name,
583
681
                       name_len))
584
682
    {
585
683
      struct st_plugin_int *tmp_plugin_ptr;
586
 
 
 
684
      if (*(int*)plugin->info <
 
685
          min_plugin_info_interface_version[plugin->type] ||
 
686
          ((*(int*)plugin->info) >> 8) >
 
687
          (cur_plugin_info_interface_version[plugin->type] >> 8))
 
688
      {
 
689
        char buf[256];
 
690
        strxnmov(buf, sizeof(buf) - 1, "API version for ",
 
691
                 plugin_type_names[plugin->type].str,
 
692
                 " plugin is too different", NullS);
 
693
        if (report & REPORT_TO_USER)
 
694
          my_error(ER_CANT_OPEN_LIBRARY, MYF(0), dl->str, 0, buf);
 
695
        if (report & REPORT_TO_LOG)
 
696
          sql_print_error(ER(ER_CANT_OPEN_LIBRARY), dl->str, 0, buf);
 
697
        goto err;
 
698
      }
587
699
      tmp.plugin= plugin;
588
700
      tmp.name.str= (char *)plugin->name;
589
701
      tmp.name.length= name_len;
594
706
        if ((tmp_plugin_ptr= plugin_insert_or_reuse(&tmp)))
595
707
        {
596
708
          plugin_array_version++;
597
 
          if (!my_hash_insert(&plugin_hash[plugin->type], (unsigned char*)tmp_plugin_ptr))
 
709
          if (!my_hash_insert(&plugin_hash[plugin->type], (uchar*)tmp_plugin_ptr))
598
710
          {
599
711
            init_alloc_root(&tmp_plugin_ptr->mem_root, 4096, 4096);
600
 
            return(false);
 
712
            return(FALSE);
601
713
          }
602
714
          tmp_plugin_ptr->state= PLUGIN_IS_FREED;
603
715
        }
606
718
      }
607
719
      /* plugin was disabled */
608
720
      plugin_dl_del(dl);
609
 
      return(false);
 
721
      return(FALSE);
610
722
    }
611
723
  }
612
724
  if (report & REPORT_TO_USER)
615
727
    sql_print_error(ER(ER_CANT_FIND_DL_ENTRY), name->str);
616
728
err:
617
729
  plugin_dl_del(dl);
618
 
  return(true);
 
730
  return(TRUE);
619
731
}
620
732
 
621
733
 
645
757
  {
646
758
    if ((*plugin_type_deinitialize[plugin->plugin->type])(plugin))
647
759
    {
648
 
      sql_print_error(_("Plugin '%s' of type %s failed deinitialization"),
 
760
      sql_print_error("Plugin '%s' of type %s failed deinitialization",
649
761
                      plugin->name.str, plugin_type_names[plugin->plugin->type].str);
650
762
    }
651
763
  }
659
771
    exit until NDB is shut down.
660
772
  */
661
773
  if (ref_check && plugin->ref_count)
662
 
    sql_print_error(_("Plugin '%s' has ref_count=%d after deinitialization."),
 
774
    sql_print_error("Plugin '%s' has ref_count=%d after deinitialization.",
663
775
                    plugin->name.str, plugin->ref_count);
664
776
}
665
777
 
668
780
{
669
781
  /* Free allocated strings before deleting the plugin. */
670
782
  plugin_vars_free_values(plugin->system_vars);
671
 
  hash_delete(&plugin_hash[plugin->plugin->type], (unsigned char*)plugin);
 
783
  hash_delete(&plugin_hash[plugin->plugin->type], (uchar*)plugin);
672
784
  if (plugin->plugin_dl)
673
785
    plugin_dl_del(&plugin->plugin_dl->dl);
674
786
  plugin->state= PLUGIN_IS_FREED;
682
794
 
683
795
static void reap_plugins(void)
684
796
{
685
 
  uint32_t count, idx;
 
797
  uint count, idx;
686
798
  struct st_plugin_int *plugin, **reap, **list;
687
799
 
688
800
  if (!reap_needed)
724
836
 
725
837
  pi= plugin_ref_to_int(plugin);
726
838
 
727
 
  free((unsigned char*) plugin);
 
839
  my_free((uchar*) plugin, MYF(MY_WME));
728
840
 
729
841
  if (lex)
730
842
  {
762
874
}
763
875
 
764
876
 
765
 
void plugin_unlock_list(THD *thd, plugin_ref *list, uint32_t count)
 
877
void plugin_unlock_list(THD *thd, plugin_ref *list, uint count)
766
878
{
767
879
  LEX *lex= thd ? thd->lex : 0;
768
880
  assert(list);
779
891
  {
780
892
    if ((*plugin_type_initialize[plugin->plugin->type])(plugin))
781
893
    {
782
 
      sql_print_error(_("Plugin '%s' registration as a %s failed."),
 
894
      sql_print_error("Plugin '%s' registration as a %s failed.",
783
895
                      plugin->name.str, plugin_type_names[plugin->plugin->type].str);
784
896
      goto err;
785
897
    }
788
900
  {
789
901
    if (plugin->plugin->init(plugin))
790
902
    {
791
 
      sql_print_error(_("Plugin '%s' init function returned error."),
 
903
      sql_print_error("Plugin '%s' init function returned error.",
792
904
                      plugin->name.str);
793
905
      goto err;
794
906
    }
839
951
}
840
952
 
841
953
 
842
 
extern "C" unsigned char *get_plugin_hash_key(const unsigned char *, size_t *, bool);
843
 
extern "C" unsigned char *get_bookmark_hash_key(const unsigned char *, size_t *, bool);
844
 
 
845
 
 
846
 
unsigned char *get_plugin_hash_key(const unsigned char *buff, size_t *length,
 
954
extern "C" uchar *get_plugin_hash_key(const uchar *, size_t *, bool);
 
955
extern "C" uchar *get_bookmark_hash_key(const uchar *, size_t *, bool);
 
956
 
 
957
 
 
958
uchar *get_plugin_hash_key(const uchar *buff, size_t *length,
847
959
                           bool not_used __attribute__((unused)))
848
960
{
849
961
  struct st_plugin_int *plugin= (st_plugin_int *)buff;
850
962
  *length= (uint)plugin->name.length;
851
 
  return((unsigned char *)plugin->name.str);
 
963
  return((uchar *)plugin->name.str);
852
964
}
853
965
 
854
966
 
855
 
unsigned char *get_bookmark_hash_key(const unsigned char *buff, size_t *length,
 
967
uchar *get_bookmark_hash_key(const uchar *buff, size_t *length,
856
968
                             bool not_used __attribute__((unused)))
857
969
{
858
970
  struct st_bookmark *var= (st_bookmark *)buff;
859
971
  *length= var->name_len + 1;
860
 
  return (unsigned char*) var->key;
 
972
  return (uchar*) var->key;
861
973
}
862
974
 
863
975
 
870
982
*/
871
983
int plugin_init(int *argc, char **argv, int flags)
872
984
{
873
 
  uint32_t i;
 
985
  uint i;
874
986
  struct st_mysql_plugin **builtins;
875
987
  struct st_mysql_plugin *plugin;
876
988
  struct st_plugin_int tmp, *plugin_ptr, **reap;
893
1005
                            sizeof(struct st_plugin_int *),16,16))
894
1006
    goto err;
895
1007
 
896
 
  for (i= 0; i < DRIZZLE_MAX_PLUGIN_TYPE_NUM; i++)
 
1008
  for (i= 0; i < MYSQL_MAX_PLUGIN_TYPE_NUM; i++)
897
1009
  {
898
1010
    if (hash_init(&plugin_hash[i], system_charset_info, 16, 0, 0,
899
1011
                  get_plugin_hash_key, NULL, HASH_UNIQUE))
907
1019
  */
908
1020
  for (builtins= mysqld_builtins; *builtins; builtins++)
909
1021
  {
910
 
    for (plugin= *builtins; plugin->name; plugin++)
 
1022
    for (plugin= *builtins; plugin->info; plugin++)
911
1023
    {
912
 
      memset(&tmp, 0, sizeof(tmp));
 
1024
      bzero(&tmp, sizeof(tmp));
913
1025
      tmp.plugin= plugin;
914
1026
      tmp.name.str= (char *)plugin->name;
915
1027
      tmp.name.length= strlen(plugin->name);
928
1040
        initialize the global default storage engine so that it may
929
1041
        not be null in any child thread.
930
1042
      */
931
 
      if (my_strcasecmp(&my_charset_utf8_general_ci, plugin->name, "MyISAM") == 0)
 
1043
      if (my_strcasecmp(&my_charset_latin1, plugin->name, "MyISAM") == 0)
932
1044
      {
933
1045
        assert(!global_system_variables.table_plugin);
934
1046
        global_system_variables.table_plugin=
1003
1115
  tmp->ref_count= 0;
1004
1116
  tmp->plugin_dl= 0;
1005
1117
 
1006
 
  if (insert_dynamic(&plugin_array, (unsigned char*)&tmp))
 
1118
  if (insert_dynamic(&plugin_array, (uchar*)&tmp))
1007
1119
    return(1);
1008
1120
 
1009
1121
  *ptr= *dynamic_element(&plugin_array, plugin_array.elements - 1,
1010
1122
                         struct st_plugin_int **)=
1011
 
        (struct st_plugin_int *) memdup_root(&plugin_mem_root, (unsigned char*)tmp,
 
1123
        (struct st_plugin_int *) memdup_root(&plugin_mem_root, (uchar*)tmp,
1012
1124
                                             sizeof(struct st_plugin_int));
1013
1125
 
1014
 
  if (my_hash_insert(&plugin_hash[plugin->type],(unsigned char*) *ptr))
 
1126
  if (my_hash_insert(&plugin_hash[plugin->type],(uchar*) *ptr))
1015
1127
    return(1);
1016
1128
 
1017
1129
  return(0);
1033
1145
  {
1034
1146
    if (p == buffer + sizeof(buffer) - 1)
1035
1147
    {
1036
 
      sql_print_error(_("plugin-load parameter too long"));
1037
 
      return(true);
 
1148
      sql_print_error("plugin-load parameter too long");
 
1149
      return(TRUE);
1038
1150
    }
1039
1151
 
1040
1152
    switch ((*(p++)= *(list++))) {
1055
1167
        dl= name;
1056
1168
        if ((plugin_dl= plugin_dl_add(&dl, REPORT_TO_LOG)))
1057
1169
        {
1058
 
          for (plugin= plugin_dl->plugins; plugin->name; plugin++)
 
1170
          for (plugin= plugin_dl->plugins; plugin->info; plugin++)
1059
1171
          {
1060
1172
            name.str= (char *) plugin->name;
1061
1173
            name.length= strlen(name.str);
1091
1203
      continue;
1092
1204
    }
1093
1205
  }
1094
 
  return(false);
 
1206
  return(FALSE);
1095
1207
error:
1096
 
  sql_print_error(_("Couldn't load plugin named '%s' with soname '%s'."),
 
1208
  sql_print_error("Couldn't load plugin named '%s' with soname '%s'.",
1097
1209
                  name.str, dl.str);
1098
 
  return(true);
 
1210
  return(TRUE);
1099
1211
}
1100
1212
 
1101
1213
 
1102
1214
void plugin_shutdown(void)
1103
1215
{
1104
 
  uint32_t i, count= plugin_array.elements, free_slots= 0;
 
1216
  uint i, count= plugin_array.elements, free_slots= 0;
1105
1217
  struct st_plugin_int **plugins, *plugin;
1106
1218
  struct st_plugin_dl **dl;
1107
1219
 
1144
1256
    }
1145
1257
 
1146
1258
    if (count > free_slots)
1147
 
      sql_print_warning(_("Forcing shutdown of %d plugins"),
1148
 
                        count - free_slots);
 
1259
      sql_print_warning("Forcing shutdown of %d plugins", count - free_slots);
1149
1260
 
1150
1261
    plugins= (struct st_plugin_int **) my_alloca(sizeof(void*) * (count+1));
1151
1262
 
1166
1277
    for (i= 0; i < count; i++)
1167
1278
      if (!(plugins[i]->state & (PLUGIN_IS_UNINITIALIZED | PLUGIN_IS_FREED)))
1168
1279
      {
1169
 
        sql_print_information(_("Plugin '%s' will be forced to shutdown"),
 
1280
        sql_print_information("Plugin '%s' will be forced to shutdown",
1170
1281
                              plugins[i]->name.str);
1171
1282
        /*
1172
1283
          We are forcing deinit on plugins so we don't want to do a ref_count
1182
1293
    for (i= 0; i < count; i++)
1183
1294
    {
1184
1295
      if (plugins[i]->ref_count)
1185
 
        sql_print_error(_("Plugin '%s' has ref_count=%d after shutdown."),
 
1296
        sql_print_error("Plugin '%s' has ref_count=%d after shutdown.",
1186
1297
                        plugins[i]->name.str, plugins[i]->ref_count);
1187
1298
      if (plugins[i]->state & PLUGIN_IS_UNINITIALIZED)
1188
1299
        plugin_del(plugins[i]);
1202
1313
 
1203
1314
  /* Dispose of the memory */
1204
1315
 
1205
 
  for (i= 0; i < DRIZZLE_MAX_PLUGIN_TYPE_NUM; i++)
 
1316
  for (i= 0; i < MYSQL_MAX_PLUGIN_TYPE_NUM; i++)
1206
1317
    hash_free(&plugin_hash[i]);
1207
1318
  delete_dynamic(&plugin_array);
1208
1319
 
1225
1336
 
1226
1337
 
1227
1338
bool plugin_foreach_with_mask(THD *thd, plugin_foreach_func *func,
1228
 
                       int type, uint32_t state_mask, void *arg)
 
1339
                       int type, uint state_mask, void *arg)
1229
1340
{
1230
 
  uint32_t idx, total;
 
1341
  uint idx, total;
1231
1342
  struct st_plugin_int *plugin, **plugins;
1232
1343
  int version=plugin_array_version;
1233
1344
 
1234
1345
  if (!initialized)
1235
 
    return(false);
 
1346
    return(FALSE);
1236
1347
 
1237
1348
  state_mask= ~state_mask; // do it only once
1238
1349
 
1239
 
  total= type == DRIZZLE_ANY_PLUGIN ? plugin_array.elements
 
1350
  total= type == MYSQL_ANY_PLUGIN ? plugin_array.elements
1240
1351
                                  : plugin_hash[type].records;
1241
1352
  /*
1242
1353
    Do the alloca out here in case we do have a working alloca:
1243
1354
        leaving the nested stack frame invalidates alloca allocation.
1244
1355
  */
1245
1356
  plugins=(struct st_plugin_int **)my_alloca(total*sizeof(plugin));
1246
 
  if (type == DRIZZLE_ANY_PLUGIN)
 
1357
  if (type == MYSQL_ANY_PLUGIN)
1247
1358
  {
1248
1359
    for (idx= 0; idx < total; idx++)
1249
1360
    {
1264
1375
  {
1265
1376
    if (unlikely(version != plugin_array_version))
1266
1377
    {
1267
 
      for (uint32_t i=idx; i < total; i++)
 
1378
      for (uint i=idx; i < total; i++)
1268
1379
        if (plugins[i] && plugins[i]->state & state_mask)
1269
1380
          plugins[i]=0;
1270
1381
    }
1271
1382
    plugin= plugins[idx];
1272
 
    /* It will stop iterating on first engine error when "func" returns true */
 
1383
    /* It will stop iterating on first engine error when "func" returns TRUE */
1273
1384
    if (plugin && func(thd, plugin_int_to_ref(plugin), arg))
1274
1385
        goto err;
1275
1386
  }
1276
1387
 
1277
1388
  my_afree(plugins);
1278
 
  return(false);
 
1389
  return(FALSE);
1279
1390
err:
1280
1391
  my_afree(plugins);
1281
 
  return(true);
 
1392
  return(TRUE);
1282
1393
}
1283
1394
 
1284
1395
 
1286
1397
  Internal type declarations for variables support
1287
1398
****************************************************************************/
1288
1399
 
1289
 
#undef DRIZZLE_SYSVAR_NAME
1290
 
#define DRIZZLE_SYSVAR_NAME(name) name
 
1400
#undef MYSQL_SYSVAR_NAME
 
1401
#define MYSQL_SYSVAR_NAME(name) name
1291
1402
#define PLUGIN_VAR_TYPEMASK 0x007f
1292
1403
 
1293
1404
#define EXTRA_OPTIONS 3 /* options for: 'foo', 'plugin-foo' and NULL */
1294
1405
 
1295
 
typedef DECLARE_DRIZZLE_SYSVAR_BASIC(sysvar_bool_t, bool);
1296
 
typedef DECLARE_DRIZZLE_THDVAR_BASIC(thdvar_bool_t, bool);
1297
 
typedef DECLARE_DRIZZLE_SYSVAR_BASIC(sysvar_str_t, char *);
1298
 
typedef DECLARE_DRIZZLE_THDVAR_BASIC(thdvar_str_t, char *);
1299
 
 
1300
 
typedef DECLARE_DRIZZLE_SYSVAR_TYPELIB(sysvar_enum_t, unsigned long);
1301
 
typedef DECLARE_DRIZZLE_THDVAR_TYPELIB(thdvar_enum_t, unsigned long);
1302
 
typedef DECLARE_DRIZZLE_SYSVAR_TYPELIB(sysvar_set_t, uint64_t);
1303
 
typedef DECLARE_DRIZZLE_THDVAR_TYPELIB(thdvar_set_t, uint64_t);
1304
 
 
1305
 
typedef DECLARE_DRIZZLE_SYSVAR_SIMPLE(sysvar_int_t, int);
1306
 
typedef DECLARE_DRIZZLE_SYSVAR_SIMPLE(sysvar_long_t, long);
1307
 
typedef DECLARE_DRIZZLE_SYSVAR_SIMPLE(sysvar_int64_t_t, int64_t);
1308
 
typedef DECLARE_DRIZZLE_SYSVAR_SIMPLE(sysvar_uint_t, uint);
1309
 
typedef DECLARE_DRIZZLE_SYSVAR_SIMPLE(sysvar_ulong_t, ulong);
1310
 
typedef DECLARE_DRIZZLE_SYSVAR_SIMPLE(sysvar_uint64_t_t, uint64_t);
1311
 
 
1312
 
typedef DECLARE_DRIZZLE_THDVAR_SIMPLE(thdvar_int_t, int);
1313
 
typedef DECLARE_DRIZZLE_THDVAR_SIMPLE(thdvar_long_t, long);
1314
 
typedef DECLARE_DRIZZLE_THDVAR_SIMPLE(thdvar_int64_t_t, int64_t);
1315
 
typedef DECLARE_DRIZZLE_THDVAR_SIMPLE(thdvar_uint_t, uint);
1316
 
typedef DECLARE_DRIZZLE_THDVAR_SIMPLE(thdvar_ulong_t, ulong);
1317
 
typedef DECLARE_DRIZZLE_THDVAR_SIMPLE(thdvar_uint64_t_t, uint64_t);
1318
 
 
1319
 
typedef bool *(*mysql_sys_var_ptr_p)(THD* a_thd, int offset);
 
1406
typedef DECLARE_MYSQL_SYSVAR_BASIC(sysvar_bool_t, bool);
 
1407
typedef DECLARE_MYSQL_THDVAR_BASIC(thdvar_bool_t, bool);
 
1408
typedef DECLARE_MYSQL_SYSVAR_BASIC(sysvar_str_t, char *);
 
1409
typedef DECLARE_MYSQL_THDVAR_BASIC(thdvar_str_t, char *);
 
1410
 
 
1411
typedef DECLARE_MYSQL_SYSVAR_TYPELIB(sysvar_enum_t, unsigned long);
 
1412
typedef DECLARE_MYSQL_THDVAR_TYPELIB(thdvar_enum_t, unsigned long);
 
1413
typedef DECLARE_MYSQL_SYSVAR_TYPELIB(sysvar_set_t, uint64_t);
 
1414
typedef DECLARE_MYSQL_THDVAR_TYPELIB(thdvar_set_t, uint64_t);
 
1415
 
 
1416
typedef DECLARE_MYSQL_SYSVAR_SIMPLE(sysvar_int_t, int);
 
1417
typedef DECLARE_MYSQL_SYSVAR_SIMPLE(sysvar_long_t, long);
 
1418
typedef DECLARE_MYSQL_SYSVAR_SIMPLE(sysvar_int64_t_t, int64_t);
 
1419
typedef DECLARE_MYSQL_SYSVAR_SIMPLE(sysvar_uint_t, uint);
 
1420
typedef DECLARE_MYSQL_SYSVAR_SIMPLE(sysvar_ulong_t, ulong);
 
1421
typedef DECLARE_MYSQL_SYSVAR_SIMPLE(sysvar_uint64_t_t, uint64_t);
 
1422
 
 
1423
typedef DECLARE_MYSQL_THDVAR_SIMPLE(thdvar_int_t, int);
 
1424
typedef DECLARE_MYSQL_THDVAR_SIMPLE(thdvar_long_t, long);
 
1425
typedef DECLARE_MYSQL_THDVAR_SIMPLE(thdvar_int64_t_t, int64_t);
 
1426
typedef DECLARE_MYSQL_THDVAR_SIMPLE(thdvar_uint_t, uint);
 
1427
typedef DECLARE_MYSQL_THDVAR_SIMPLE(thdvar_ulong_t, ulong);
 
1428
typedef DECLARE_MYSQL_THDVAR_SIMPLE(thdvar_uint64_t_t, uint64_t);
 
1429
 
 
1430
#define SET_PLUGIN_VAR_RESOLVE(opt)\
 
1431
  *(mysql_sys_var_ptr_p*)&((opt)->resolve)= mysql_sys_var_ptr
 
1432
typedef uchar *(*mysql_sys_var_ptr_p)(void* a_thd, int offset);
1320
1433
 
1321
1434
 
1322
1435
/****************************************************************************
1323
1436
  default variable data check and update functions
1324
1437
****************************************************************************/
1325
1438
 
1326
 
static int check_func_bool(THD *thd __attribute__((unused)),
 
1439
static int check_func_bool(THD *thd __attribute__((__unused__)),
1327
1440
                           struct st_mysql_sys_var *var,
1328
1441
                           void *save, st_mysql_value *value)
1329
1442
{
1332
1445
  int result, length;
1333
1446
  int64_t tmp;
1334
1447
 
1335
 
  if (value->value_type(value) == DRIZZLE_VALUE_TYPE_STRING)
 
1448
  if (value->value_type(value) == MYSQL_VALUE_TYPE_STRING)
1336
1449
  {
1337
1450
    length= sizeof(buff);
1338
1451
    if (!(str= value->val_str(value, buff, &length)) ||
1373
1486
  plugin_opt_set_limits(&options, var);
1374
1487
 
1375
1488
  if (var->flags & PLUGIN_VAR_UNSIGNED)
1376
 
    *(uint32_t *)save= (uint) getopt_ull_limit_value((uint64_t) tmp, &options,
 
1489
    *(uint *)save= (uint) getopt_ull_limit_value((uint64_t) tmp, &options,
1377
1490
                                                   &fixed);
1378
1491
  else
1379
1492
    *(int *)save= (int) getopt_ll_limit_value(tmp, &options, &fixed);
1423
1536
}
1424
1537
 
1425
1538
static int check_func_str(THD *thd,
1426
 
                          struct st_mysql_sys_var *var __attribute__((unused)),
 
1539
                          struct st_mysql_sys_var *var __attribute__((__unused__)),
1427
1540
                          void *save, st_mysql_value *value)
1428
1541
{
1429
1542
  char buff[STRING_BUFFER_USUAL_SIZE];
1438
1551
}
1439
1552
 
1440
1553
 
1441
 
static int check_func_enum(THD *thd __attribute__((unused)),
 
1554
static int check_func_enum(THD *thd __attribute__((__unused__)),
1442
1555
                           struct st_mysql_sys_var *var,
1443
1556
                           void *save, st_mysql_value *value)
1444
1557
{
1454
1567
  else
1455
1568
    typelib= ((sysvar_enum_t*) var)->typelib;
1456
1569
 
1457
 
  if (value->value_type(value) == DRIZZLE_VALUE_TYPE_STRING)
 
1570
  if (value->value_type(value) == MYSQL_VALUE_TYPE_STRING)
1458
1571
  {
1459
1572
    length= sizeof(buff);
1460
1573
    if (!(str= value->val_str(value, buff, &length)))
1485
1598
}
1486
1599
 
1487
1600
 
1488
 
static int check_func_set(THD *thd __attribute__((unused)),
 
1601
static int check_func_set(THD *thd __attribute__((__unused__)),
1489
1602
                          struct st_mysql_sys_var *var,
1490
1603
                          void *save, st_mysql_value *value)
1491
1604
{
1493
1606
  const char *strvalue= "NULL", *str;
1494
1607
  TYPELIB *typelib;
1495
1608
  uint64_t result;
1496
 
  uint32_t error_len;
 
1609
  uint error_len;
1497
1610
  bool not_used;
1498
1611
  int length;
1499
1612
 
1502
1615
  else
1503
1616
    typelib= ((sysvar_set_t*)var)->typelib;
1504
1617
 
1505
 
  if (value->value_type(value) == DRIZZLE_VALUE_TYPE_STRING)
 
1618
  if (value->value_type(value) == MYSQL_VALUE_TYPE_STRING)
1506
1619
  {
1507
1620
    length= sizeof(buff);
1508
1621
    if (!(str= value->val_str(value, buff, &length)))
1511
1624
                     &error, &error_len, &not_used);
1512
1625
    if (error_len)
1513
1626
    {
1514
 
      strmake(buff, error, cmin(sizeof(buff), (unsigned long)error_len));
 
1627
      strmake(buff, error, min(sizeof(buff), error_len));
1515
1628
      strvalue= buff;
1516
1629
      goto err;
1517
1630
    }
1520
1633
  {
1521
1634
    if (value->val_int(value, (int64_t *)&result))
1522
1635
      goto err;
1523
 
    if (unlikely((result >= (1UL << typelib->count)) &&
 
1636
    if (unlikely((result >= (1ULL << typelib->count)) &&
1524
1637
                 (typelib->count < sizeof(long)*8)))
1525
1638
    {
1526
1639
      llstr(result, buff);
1536
1649
}
1537
1650
 
1538
1651
 
1539
 
static void update_func_bool(THD *thd __attribute__((unused)),
1540
 
                             struct st_mysql_sys_var *var __attribute__((unused)),
 
1652
static void update_func_bool(THD *thd __attribute__((__unused__)),
 
1653
                             struct st_mysql_sys_var *var __attribute__((__unused__)),
1541
1654
                             void *tgt, const void *save)
1542
1655
{
1543
 
  *(bool *) tgt= *(int *) save ? 1 : 0;
 
1656
  *(my_bool *) tgt= *(int *) save ? 1 : 0;
1544
1657
}
1545
1658
 
1546
1659
 
1547
 
static void update_func_int(THD *thd __attribute__((unused)),
1548
 
                            struct st_mysql_sys_var *var __attribute__((unused)),
 
1660
static void update_func_int(THD *thd __attribute__((__unused__)),
 
1661
                            struct st_mysql_sys_var *var __attribute__((__unused__)),
1549
1662
                             void *tgt, const void *save)
1550
1663
{
1551
1664
  *(int *)tgt= *(int *) save;
1552
1665
}
1553
1666
 
1554
1667
 
1555
 
static void update_func_long(THD *thd __attribute__((unused)),
1556
 
                             struct st_mysql_sys_var *var __attribute__((unused)),
 
1668
static void update_func_long(THD *thd __attribute__((__unused__)),
 
1669
                             struct st_mysql_sys_var *var __attribute__((__unused__)),
1557
1670
                             void *tgt, const void *save)
1558
1671
{
1559
1672
  *(long *)tgt= *(long *) save;
1560
1673
}
1561
1674
 
1562
1675
 
1563
 
static void update_func_int64_t(THD *thd __attribute__((unused)),
1564
 
                                 struct st_mysql_sys_var *var __attribute__((unused)),
 
1676
static void update_func_int64_t(THD *thd __attribute__((__unused__)),
 
1677
                                 struct st_mysql_sys_var *var __attribute__((__unused__)),
1565
1678
                                 void *tgt, const void *save)
1566
1679
{
1567
1680
  *(int64_t *)tgt= *(uint64_t *) save;
1568
1681
}
1569
1682
 
1570
1683
 
1571
 
static void update_func_str(THD *thd __attribute__((unused)), struct st_mysql_sys_var *var,
 
1684
static void update_func_str(THD *thd __attribute__((__unused__)), struct st_mysql_sys_var *var,
1572
1685
                             void *tgt, const void *save)
1573
1686
{
1574
1687
  char *old= *(char **) tgt;
1576
1689
  if (var->flags & PLUGIN_VAR_MEMALLOC)
1577
1690
  {
1578
1691
    *(char **)tgt= my_strdup(*(char **) save, MYF(0));
1579
 
    free(old);
 
1692
    my_free(old, MYF(0));
1580
1693
  }
1581
1694
}
1582
1695
 
1586
1699
****************************************************************************/
1587
1700
 
1588
1701
 
1589
 
sys_var *find_sys_var(THD *thd, const char *str, uint32_t length)
 
1702
sys_var *find_sys_var(THD *thd, const char *str, uint length)
1590
1703
{
1591
1704
  sys_var *var;
1592
1705
  sys_var_pluginvar *pi= NULL;
1629
1742
static st_bookmark *find_bookmark(const char *plugin, const char *name, int flags)
1630
1743
{
1631
1744
  st_bookmark *result= NULL;
1632
 
  uint32_t namelen, length, pluginlen= 0;
 
1745
  uint namelen, length, pluginlen= 0;
1633
1746
  char *varname, *p;
1634
1747
 
1635
1748
  if (!(flags & PLUGIN_VAR_THDLOCAL))
1643
1756
 
1644
1757
  if (plugin)
1645
1758
  {
1646
 
    strxmov(varname + 1, plugin, "_", name, NULL);
 
1759
    strxmov(varname + 1, plugin, "_", name, NullS);
1647
1760
    for (p= varname + 1; *p; p++)
1648
1761
      if (*p == '-')
1649
1762
        *p= '_';
1654
1767
  varname[0]= flags & PLUGIN_VAR_TYPEMASK;
1655
1768
 
1656
1769
  result= (st_bookmark*) hash_search(&bookmark_hash,
1657
 
                                     (const unsigned char*) varname, length - 1);
 
1770
                                     (const uchar*) varname, length - 1);
1658
1771
 
1659
1772
  my_afree(varname);
1660
1773
  return result;
1669
1782
static st_bookmark *register_var(const char *plugin, const char *name,
1670
1783
                                 int flags)
1671
1784
{
1672
 
  uint32_t length= strlen(plugin) + strlen(name) + 3, size= 0, offset, new_size;
 
1785
  uint length= strlen(plugin) + strlen(name) + 3, size= 0, offset, new_size;
1673
1786
  st_bookmark *result;
1674
1787
  char *varname, *p;
1675
1788
 
1678
1791
 
1679
1792
  switch (flags & PLUGIN_VAR_TYPEMASK) {
1680
1793
  case PLUGIN_VAR_BOOL:
1681
 
    size= sizeof(bool);
 
1794
    size= sizeof(my_bool);
1682
1795
    break;
1683
1796
  case PLUGIN_VAR_INT:
1684
1797
    size= sizeof(int);
1700
1813
  };
1701
1814
 
1702
1815
  varname= ((char*) my_alloca(length));
1703
 
  strxmov(varname + 1, plugin, "_", name, NULL);
 
1816
  strxmov(varname + 1, plugin, "_", name, NullS);
1704
1817
  for (p= varname + 1; *p; p++)
1705
1818
    if (*p == '-')
1706
1819
      *p= '_';
1735
1848
        variables. If their value is non-NULL, it must point to a valid
1736
1849
        string.
1737
1850
      */
1738
 
      memset(global_system_variables.dynamic_variables_ptr +
1739
 
             global_variables_dynamic_size, 0,
1740
 
             new_size - global_variables_dynamic_size);
1741
 
      memset(max_system_variables.dynamic_variables_ptr +
1742
 
             global_variables_dynamic_size, 0, 
1743
 
             new_size - global_variables_dynamic_size);
 
1851
      bzero(global_system_variables.dynamic_variables_ptr +
 
1852
            global_variables_dynamic_size,
 
1853
            new_size - global_variables_dynamic_size);
 
1854
      bzero(max_system_variables.dynamic_variables_ptr +
 
1855
            global_variables_dynamic_size,
 
1856
            new_size - global_variables_dynamic_size);
1744
1857
      global_variables_dynamic_size= new_size;
1745
1858
    }
1746
1859
 
1754
1867
    result->version= global_system_variables.dynamic_variables_version;
1755
1868
 
1756
1869
    /* this should succeed because we have already checked if a dup exists */
1757
 
    if (my_hash_insert(&bookmark_hash, (unsigned char*) result))
 
1870
    if (my_hash_insert(&bookmark_hash, (uchar*) result))
1758
1871
    {
1759
1872
      fprintf(stderr, "failed to add placeholder to hash");
1760
1873
      assert(0);
1771
1884
  If required, will sync with global variables if the requested variable
1772
1885
  has not yet been allocated in the current thread.
1773
1886
*/
1774
 
static unsigned char *intern_sys_var_ptr(THD* thd, int offset, bool global_lock)
 
1887
static uchar *intern_sys_var_ptr(THD* thd, int offset, bool global_lock)
1775
1888
{
1776
1889
  assert(offset >= 0);
1777
1890
  assert((uint)offset <= global_system_variables.dynamic_variables_head);
1778
1891
 
1779
1892
  if (!thd)
1780
 
    return (unsigned char*) global_system_variables.dynamic_variables_ptr + offset;
 
1893
    return (uchar*) global_system_variables.dynamic_variables_ptr + offset;
1781
1894
 
1782
1895
  /*
1783
1896
    dynamic_variables_head points to the largest valid offset
1785
1898
  if (!thd->variables.dynamic_variables_ptr ||
1786
1899
      (uint)offset > thd->variables.dynamic_variables_head)
1787
1900
  {
1788
 
    uint32_t idx;
 
1901
    uint idx;
1789
1902
 
1790
1903
    rw_rdlock(&LOCK_system_variables_hash);
1791
1904
 
1847
1960
 
1848
1961
    rw_unlock(&LOCK_system_variables_hash);
1849
1962
  }
1850
 
  return (unsigned char*)thd->variables.dynamic_variables_ptr + offset;
1851
 
}
1852
 
 
1853
 
static bool *mysql_sys_var_ptr_bool(THD* a_thd, int offset)
1854
 
{
1855
 
  return (bool *)intern_sys_var_ptr(a_thd, offset, true);
1856
 
}
1857
 
 
1858
 
static int *mysql_sys_var_ptr_int(THD* a_thd, int offset)
1859
 
{
1860
 
  return (int *)intern_sys_var_ptr(a_thd, offset, true);
1861
 
}
1862
 
 
1863
 
static long *mysql_sys_var_ptr_long(THD* a_thd, int offset)
1864
 
{
1865
 
  return (long *)intern_sys_var_ptr(a_thd, offset, true);
1866
 
}
1867
 
 
1868
 
static int64_t *mysql_sys_var_ptr_int64_t(THD* a_thd, int offset)
1869
 
{
1870
 
  return (int64_t *)intern_sys_var_ptr(a_thd, offset, true);
1871
 
}
1872
 
 
1873
 
static char **mysql_sys_var_ptr_str(THD* a_thd, int offset)
1874
 
{
1875
 
  return (char **)intern_sys_var_ptr(a_thd, offset, true);
1876
 
}
1877
 
 
1878
 
static uint64_t *mysql_sys_var_ptr_set(THD* a_thd, int offset)
1879
 
{
1880
 
  return (uint64_t *)intern_sys_var_ptr(a_thd, offset, true);
1881
 
}
1882
 
 
1883
 
static unsigned long *mysql_sys_var_ptr_enum(THD* a_thd, int offset)
1884
 
{
1885
 
  return (unsigned long *)intern_sys_var_ptr(a_thd, offset, true);
 
1963
  return (uchar*)thd->variables.dynamic_variables_ptr + offset;
 
1964
}
 
1965
 
 
1966
static uchar *mysql_sys_var_ptr(void* a_thd, int offset)
 
1967
{
 
1968
  return intern_sys_var_ptr((THD *)a_thd, offset, true);
1886
1969
}
1887
1970
 
1888
1971
 
1911
1994
/*
1912
1995
  Unlocks all system variables which hold a reference
1913
1996
*/
1914
 
static void unlock_variables(THD *thd __attribute__((unused)),
 
1997
static void unlock_variables(THD *thd __attribute__((__unused__)),
1915
1998
                             struct system_variables *vars)
1916
1999
{
1917
2000
  intern_plugin_unlock(NULL, vars->table_plugin);
1931
2014
  sys_var_pluginvar *pivar;
1932
2015
  sys_var *var;
1933
2016
  int flags;
1934
 
  uint32_t idx;
 
2017
  uint idx;
1935
2018
 
1936
2019
  rw_rdlock(&LOCK_system_variables_hash);
1937
2020
  for (idx= 0; idx < bookmark_hash.records; idx++)
1949
2032
        flags & PLUGIN_VAR_THDLOCAL && flags & PLUGIN_VAR_MEMALLOC)
1950
2033
    {
1951
2034
      char **ptr= (char**) pivar->real_value_ptr(thd, OPT_SESSION);
1952
 
      free(*ptr);
 
2035
      my_free(*ptr, MYF(MY_WME | MY_FAE | MY_ALLOW_ZERO_PTR));
1953
2036
      *ptr= NULL;
1954
2037
    }
1955
2038
  }
1957
2040
 
1958
2041
  assert(vars->table_plugin == NULL);
1959
2042
 
1960
 
  free(vars->dynamic_variables_ptr);
 
2043
  my_free(vars->dynamic_variables_ptr, MYF(MY_ALLOW_ZERO_PTR));
1961
2044
  vars->dynamic_variables_ptr= NULL;
1962
2045
  vars->dynamic_variables_size= 0;
1963
2046
  vars->dynamic_variables_version= 0;
1966
2049
 
1967
2050
void plugin_thdvar_cleanup(THD *thd)
1968
2051
{
1969
 
  uint32_t idx;
 
2052
  uint idx;
1970
2053
  plugin_ref *list;
1971
2054
 
1972
2055
  unlock_variables(thd, &thd->variables);
1975
2058
  if ((idx= thd->lex->plugins.elements))
1976
2059
  {
1977
2060
    list= ((plugin_ref*) thd->lex->plugins.buffer) + idx - 1;
1978
 
    while ((unsigned char*) list >= thd->lex->plugins.buffer)
 
2061
    while ((uchar*) list >= thd->lex->plugins.buffer)
1979
2062
      intern_plugin_unlock(NULL, *list--);
1980
2063
  }
1981
2064
 
2008
2091
    {
2009
2092
      /* Free the string from global_system_variables. */
2010
2093
      char **valptr= (char**) piv->real_value_ptr(NULL, OPT_GLOBAL);
2011
 
      free(*valptr);
 
2094
      my_free(*valptr, MYF(MY_WME | MY_FAE | MY_ALLOW_ZERO_PTR));
2012
2095
      *valptr= NULL;
2013
2096
    }
2014
2097
  }
2056
2139
}
2057
2140
 
2058
2141
 
2059
 
unsigned char* sys_var_pluginvar::real_value_ptr(THD *thd, enum_var_type type)
 
2142
uchar* sys_var_pluginvar::real_value_ptr(THD *thd, enum_var_type type)
2060
2143
{
2061
2144
  assert(thd || (type == OPT_GLOBAL));
2062
2145
  if (plugin_var->flags & PLUGIN_VAR_THDLOCAL)
2066
2149
 
2067
2150
    return intern_sys_var_ptr(thd, *(int*) (plugin_var+1), false);
2068
2151
  }
2069
 
  return *(unsigned char**) (plugin_var+1);
 
2152
  return *(uchar**) (plugin_var+1);
2070
2153
}
2071
2154
 
2072
2155
 
2088
2171
}
2089
2172
 
2090
2173
 
2091
 
unsigned char* sys_var_pluginvar::value_ptr(THD *thd, enum_var_type type,
2092
 
                                    LEX_STRING *base __attribute__((unused)))
 
2174
uchar* sys_var_pluginvar::value_ptr(THD *thd, enum_var_type type,
 
2175
                                    LEX_STRING *base __attribute__((__unused__)))
2093
2176
{
2094
 
  unsigned char* result;
 
2177
  uchar* result;
2095
2178
 
2096
2179
  result= real_value_ptr(thd, type);
2097
2180
 
2098
2181
  if ((plugin_var->flags & PLUGIN_VAR_TYPEMASK) == PLUGIN_VAR_ENUM)
2099
 
    result= (unsigned char*) get_type(plugin_var_typelib(), *(ulong*)result);
 
2182
    result= (uchar*) get_type(plugin_var_typelib(), *(ulong*)result);
2100
2183
  else if ((plugin_var->flags & PLUGIN_VAR_TYPEMASK) == PLUGIN_VAR_SET)
2101
2184
  {
2102
2185
    char buffer[STRING_BUFFER_USUAL_SIZE];
2103
2186
    String str(buffer, sizeof(buffer), system_charset_info);
2104
2187
    TYPELIB *typelib= plugin_var_typelib();
2105
2188
    uint64_t mask= 1, value= *(uint64_t*) result;
2106
 
    uint32_t i;
 
2189
    uint i;
2107
2190
 
2108
2191
    str.length(0);
2109
2192
    for (i= 0; i < typelib->count; i++, mask<<=1)
2114
2197
      str.append(',');
2115
2198
    }
2116
2199
 
2117
 
    result= (unsigned char*) "";
 
2200
    result= (uchar*) "";
2118
2201
    if (str.length())
2119
 
      result= (unsigned char*) thd->strmake(str.ptr(), str.length()-1);
 
2202
      result= (uchar*) thd->strmake(str.ptr(), str.length()-1);
2120
2203
  }
2121
2204
  return result;
2122
2205
}
2233
2316
 
2234
2317
 
2235
2318
#define OPTION_SET_LIMITS(type, options, opt) \
2236
 
  options->var_type= type;                    \
2237
 
  options->def_value= (opt)->def_val;         \
2238
 
  options->min_value= (opt)->min_val;         \
2239
 
  options->max_value= (opt)->max_val;         \
 
2319
  options->var_type= type; \
 
2320
  options->def_value= (opt)->def_val; \
 
2321
  options->min_value= (opt)->min_val; \
 
2322
  options->max_value= (opt)->max_val; \
2240
2323
  options->block_size= (long) (opt)->blk_sz
2241
2324
 
2242
2325
 
2278
2361
    options->typelib= ((sysvar_set_t*) opt)->typelib;
2279
2362
    options->def_value= ((sysvar_set_t*) opt)->def_val;
2280
2363
    options->min_value= options->block_size= 0;
2281
 
    options->max_value= (1UL << options->typelib->count) - 1;
 
2364
    options->max_value= (1ULL << options->typelib->count) - 1;
2282
2365
    break;
2283
2366
  case PLUGIN_VAR_BOOL:
2284
2367
    options->var_type= GET_BOOL;
2287
2370
  case PLUGIN_VAR_STR:
2288
2371
    options->var_type= ((opt->flags & PLUGIN_VAR_MEMALLOC) ?
2289
2372
                        GET_STR_ALLOC : GET_STR);
2290
 
    options->def_value= (intptr_t) ((sysvar_str_t*) opt)->def_val;
 
2373
    options->def_value= (intptr) ((sysvar_str_t*) opt)->def_val;
2291
2374
    break;
2292
2375
  /* threadlocal variables */
2293
2376
  case PLUGIN_VAR_INT | PLUGIN_VAR_THDLOCAL:
2320
2403
    options->typelib= ((thdvar_set_t*) opt)->typelib;
2321
2404
    options->def_value= ((thdvar_set_t*) opt)->def_val;
2322
2405
    options->min_value= options->block_size= 0;
2323
 
    options->max_value= (1UL << options->typelib->count) - 1;
 
2406
    options->max_value= (1ULL << options->typelib->count) - 1;
2324
2407
    break;
2325
2408
  case PLUGIN_VAR_BOOL | PLUGIN_VAR_THDLOCAL:
2326
2409
    options->var_type= GET_BOOL;
2329
2412
  case PLUGIN_VAR_STR | PLUGIN_VAR_THDLOCAL:
2330
2413
    options->var_type= ((opt->flags & PLUGIN_VAR_MEMALLOC) ?
2331
2414
                        GET_STR_ALLOC : GET_STR);
2332
 
    options->def_value= (intptr_t) ((thdvar_str_t*) opt)->def_val;
 
2415
    options->def_value= (intptr) ((thdvar_str_t*) opt)->def_val;
2333
2416
    break;
2334
2417
  default:
2335
2418
    assert(0);
2345
2428
                                         char *);
2346
2429
 
2347
2430
bool get_one_plugin_option(int optid __attribute__((unused)),
2348
 
                              const struct my_option *opt __attribute__((unused)),
2349
 
                              char *argument __attribute__((unused)))
 
2431
                              const struct my_option *opt __attribute__((__unused__)),
 
2432
                              char *argument __attribute__((__unused__)))
2350
2433
{
2351
2434
  return 0;
2352
2435
}
2356
2439
                             my_option *options, bool can_disable)
2357
2440
{
2358
2441
  const char *plugin_name= tmp->plugin->name;
2359
 
  uint32_t namelen= strlen(plugin_name), optnamelen;
2360
 
  uint32_t buffer_length= namelen * 4 + (can_disable ? 75 : 10);
 
2442
  uint namelen= strlen(plugin_name), optnamelen;
 
2443
  uint buffer_length= namelen * 4 + (can_disable ? 75 : 10);
2361
2444
  char *name= (char*) alloc_root(mem_root, buffer_length) + 1;
2362
2445
  char *optname, *p;
2363
2446
  int index= 0, offset= 0;
2366
2449
 
2367
2450
  /* support --skip-plugin-foo syntax */
2368
2451
  memcpy(name, plugin_name, namelen + 1);
2369
 
  my_casedn_str(&my_charset_utf8_general_ci, name);
2370
 
  strxmov(name + namelen + 1, "plugin-", name, NULL);
 
2452
  my_casedn_str(&my_charset_latin1, name);
 
2453
  strxmov(name + namelen + 1, "plugin-", name, NullS);
2371
2454
  /* Now we have namelen + 1 + 7 + namelen + 1 == namelen * 2 + 9. */
2372
2455
 
2373
2456
  for (p= name + namelen*2 + 8; p > name; p--)
2377
2460
  if (can_disable)
2378
2461
  {
2379
2462
    strxmov(name + namelen*2 + 10, "Enable ", plugin_name, " plugin. "
2380
 
            "Disable with --skip-", name," (will save memory).", NULL);
 
2463
            "Disable with --skip-", name," (will save memory).", NullS);
2381
2464
    /*
2382
2465
      Now we have namelen * 2 + 10 (one char unused) + 7 + namelen + 9 +
2383
2466
      20 + namelen + 20 + 1 == namelen * 4 + 67.
2410
2493
      continue;
2411
2494
    switch (opt->flags & PLUGIN_VAR_TYPEMASK) {
2412
2495
    case PLUGIN_VAR_BOOL:
2413
 
      (((thdvar_bool_t *)opt)->resolve)= mysql_sys_var_ptr_bool;
 
2496
      SET_PLUGIN_VAR_RESOLVE(((thdvar_bool_t *) opt));
2414
2497
      break;
2415
2498
    case PLUGIN_VAR_INT:
2416
 
      (((thdvar_int_t *)opt)->resolve)= mysql_sys_var_ptr_int;
 
2499
      SET_PLUGIN_VAR_RESOLVE((thdvar_int_t *) opt);
2417
2500
      break;
2418
2501
    case PLUGIN_VAR_LONG:
2419
 
      (((thdvar_long_t *)opt)->resolve)= mysql_sys_var_ptr_long;
 
2502
      SET_PLUGIN_VAR_RESOLVE((thdvar_long_t *) opt);
2420
2503
      break;
2421
2504
    case PLUGIN_VAR_LONGLONG:
2422
 
      (((thdvar_int64_t_t *)opt)->resolve)= mysql_sys_var_ptr_int64_t;
 
2505
      SET_PLUGIN_VAR_RESOLVE((thdvar_int64_t_t *) opt);
2423
2506
      break;
2424
2507
    case PLUGIN_VAR_STR:
2425
 
      (((thdvar_str_t *)opt)->resolve)= mysql_sys_var_ptr_str;
 
2508
      SET_PLUGIN_VAR_RESOLVE((thdvar_str_t *) opt);
2426
2509
      break;
2427
2510
    case PLUGIN_VAR_ENUM:
2428
 
      (((thdvar_enum_t *)opt)->resolve)= mysql_sys_var_ptr_enum;
 
2511
      SET_PLUGIN_VAR_RESOLVE((thdvar_enum_t *) opt);
2429
2512
      break;
2430
2513
    case PLUGIN_VAR_SET:
2431
 
      (((thdvar_set_t *)opt)->resolve)= mysql_sys_var_ptr_set;
 
2514
      SET_PLUGIN_VAR_RESOLVE((thdvar_set_t *) opt);
2432
2515
      break;
2433
2516
    default:
2434
 
      sql_print_error(_("Unknown variable type code 0x%x in plugin '%s'."),
 
2517
      sql_print_error("Unknown variable type code 0x%x in plugin '%s'.",
2435
2518
                      opt->flags, plugin_name);
2436
2519
      return(-1);
2437
2520
    };
2474
2557
        if ((opt->flags & (PLUGIN_VAR_MEMALLOC | PLUGIN_VAR_READONLY)) == false)
2475
2558
        {
2476
2559
          opt->flags|= PLUGIN_VAR_READONLY;
2477
 
          sql_print_warning(_("Server variable %s of plugin %s was forced "
 
2560
          sql_print_warning("Server variable %s of plugin %s was forced "
2478
2561
                            "to be read-only: string variable without "
2479
 
                            "update_func and PLUGIN_VAR_MEMALLOC flag"),
 
2562
                            "update_func and PLUGIN_VAR_MEMALLOC flag",
2480
2563
                            opt->name, plugin_name);
2481
2564
        }
2482
2565
      }
2494
2577
        opt->update= update_func_int64_t;
2495
2578
      break;
2496
2579
    default:
2497
 
      sql_print_error(_("Unknown variable type code 0x%x in plugin '%s'."),
 
2580
      sql_print_error("Unknown variable type code 0x%x in plugin '%s'.",
2498
2581
                      opt->flags, plugin_name);
2499
2582
      return(-1);
2500
2583
    }
2505
2588
 
2506
2589
    if (!opt->name)
2507
2590
    {
2508
 
      sql_print_error(_("Missing variable name in plugin '%s'."),
 
2591
      sql_print_error("Missing variable name in plugin '%s'.",
2509
2592
                      plugin_name);
2510
2593
      return(-1);
2511
2594
    }
2514
2597
    {
2515
2598
      optnamelen= strlen(opt->name);
2516
2599
      optname= (char*) alloc_root(mem_root, namelen + optnamelen + 2);
2517
 
      strxmov(optname, name, "-", opt->name, NULL);
 
2600
      strxmov(optname, name, "-", opt->name, NullS);
2518
2601
      optnamelen= namelen + optnamelen + 1;
2519
2602
    }
2520
2603
    else
2522
2605
      /* this should not fail because register_var should create entry */
2523
2606
      if (!(v= find_bookmark(name, opt->name, opt->flags)))
2524
2607
      {
2525
 
        sql_print_error(_("Thread local variable '%s' not allocated "
2526
 
                        "in plugin '%s'."), opt->name, plugin_name);
 
2608
        sql_print_error("Thread local variable '%s' not allocated "
 
2609
                        "in plugin '%s'.", opt->name, plugin_name);
2527
2610
        return(-1);
2528
2611
      }
2529
2612
 
2557
2640
    options[1]= options[0];
2558
2641
    options[1].name= p= (char*) alloc_root(mem_root, optnamelen + 8);
2559
2642
    options[1].comment= 0; // hidden
2560
 
    strxmov(p, "plugin-", optname, NULL);
 
2643
    strxmov(p, "plugin-", optname, NullS);
2561
2644
 
2562
2645
    options+= 2;
2563
2646
  }
2572
2655
  st_mysql_sys_var **opt;
2573
2656
  my_option *opts;
2574
2657
  bool can_disable;
2575
 
  uint32_t count= EXTRA_OPTIONS;
 
2658
  uint count= EXTRA_OPTIONS;
2576
2659
 
2577
2660
  for (opt= p->plugin->system_vars; opt && *opt; opt++, count+= 2) {};
2578
2661
 
2579
2662
  if (!(opts= (my_option*) alloc_root(mem_root, sizeof(my_option) * count)))
2580
2663
    return(NULL);
2581
2664
 
2582
 
  memset(opts, 0, sizeof(my_option) * count);
 
2665
  bzero(opts, sizeof(my_option) * count);
2583
2666
 
2584
 
  if ((my_strcasecmp(&my_charset_utf8_general_ci, p->name.str, "MyISAM") == 0))
 
2667
  if ((my_strcasecmp(&my_charset_latin1, p->name.str, "MyISAM") == 0))
2585
2668
    can_disable= false;
2586
 
  else if ((my_strcasecmp(&my_charset_utf8_general_ci, p->name.str, "MEMORY") == 0))
 
2669
  else if ((my_strcasecmp(&my_charset_latin1, p->name.str, "MEMORY") == 0))
2587
2670
    can_disable= false;
2588
2671
  else
2589
2672
    can_disable= true;
2624
2707
  st_mysql_sys_var *o;
2625
2708
  sys_var *v;
2626
2709
  struct st_bookmark *var;
2627
 
  uint32_t len, count= EXTRA_OPTIONS;
 
2710
  uint len, count= EXTRA_OPTIONS;
2628
2711
  assert(tmp->plugin && tmp->name.str);
2629
2712
 
2630
2713
  for (opt= tmp->plugin->system_vars; opt && *opt; opt++)
2631
2714
    count+= 2; /* --{plugin}-{optname} and --plugin-{plugin}-{optname} */
2632
2715
 
2633
 
  if ((my_strcasecmp(&my_charset_utf8_general_ci, tmp->name.str, "MyISAM") == 0))
 
2716
  if ((my_strcasecmp(&my_charset_latin1, tmp->name.str, "MyISAM") == 0))
2634
2717
    can_disable= false;
2635
 
  else if ((my_strcasecmp(&my_charset_utf8_general_ci, tmp->name.str, "MEMORY") == 0))
 
2718
  else if ((my_strcasecmp(&my_charset_latin1, tmp->name.str, "MEMORY") == 0))
2636
2719
    can_disable= false;
2637
2720
  else
2638
2721
    can_disable= true;
2641
2724
  {
2642
2725
    if (!(opts= (my_option*) alloc_root(tmp_root, sizeof(my_option) * count)))
2643
2726
    {
2644
 
      sql_print_error(_("Out of memory for plugin '%s'."), tmp->name.str);
 
2727
      sql_print_error("Out of memory for plugin '%s'.", tmp->name.str);
2645
2728
      return(-1);
2646
2729
    }
2647
 
    memset(opts, 0, sizeof(my_option) * count);
 
2730
    bzero(opts, sizeof(my_option) * count);
2648
2731
 
2649
2732
    if (construct_options(tmp_root, tmp, opts, can_disable))
2650
2733
    {
2651
 
      sql_print_error(_("Bad options for plugin '%s'."), tmp->name.str);
 
2734
      sql_print_error("Bad options for plugin '%s'.", tmp->name.str);
2652
2735
      return(-1);
2653
2736
    }
2654
2737
 
2657
2740
 
2658
2741
    if (error)
2659
2742
    {
2660
 
       sql_print_error(_("Parsing options for plugin '%s' failed."),
 
2743
       sql_print_error("Parsing options for plugin '%s' failed.",
2661
2744
                       tmp->name.str);
2662
2745
       goto err;
2663
2746
    }
2677
2760
      {
2678
2761
        len= tmp->name.length + strlen(o->name) + 2;
2679
2762
        varname= (char*) alloc_root(mem_root, len);
2680
 
        strxmov(varname, tmp->name.str, "-", o->name, NULL);
2681
 
        my_casedn_str(&my_charset_utf8_general_ci, varname);
 
2763
        strxmov(varname, tmp->name.str, "-", o->name, NullS);
 
2764
        my_casedn_str(&my_charset_latin1, varname);
2682
2765
 
2683
2766
        for (p= varname; *p; p++)
2684
2767
          if (*p == '-')
2700
2783
      chain.last->next = NULL;
2701
2784
      if (mysql_add_sys_var_chain(chain.first, NULL))
2702
2785
      {
2703
 
        sql_print_error(_("Plugin '%s' has conflicting system variables"),
 
2786
        sql_print_error("Plugin '%s' has conflicting system variables",
2704
2787
                        tmp->name.str);
2705
2788
        goto err;
2706
2789
      }
2710
2793
  }
2711
2794
 
2712
2795
  if (enabled_saved && global_system_variables.log_warnings)
2713
 
    sql_print_information(_("Plugin '%s' disabled by command line option"),
 
2796
    sql_print_information("Plugin '%s' disabled by command line option",
2714
2797
                          tmp->name.str);
2715
2798
err:
2716
2799
  if (opts)
2725
2808
 
2726
2809
static int option_cmp(my_option *a, my_option *b)
2727
2810
{
2728
 
  return my_strcasecmp(&my_charset_utf8_general_ci, a->name, b->name);
 
2811
  return my_strcasecmp(&my_charset_latin1, a->name, b->name);
2729
2812
}
2730
2813
 
2731
2814
 
2732
 
void my_print_help_inc_plugins(my_option *main_options, uint32_t size)
 
2815
void my_print_help_inc_plugins(my_option *main_options, uint size)
2733
2816
{
2734
2817
  DYNAMIC_ARRAY all_options;
2735
2818
  struct st_plugin_int *p;
2740
2823
  my_init_dynamic_array(&all_options, sizeof(my_option), size, size/4);
2741
2824
 
2742
2825
  if (initialized)
2743
 
    for (uint32_t idx= 0; idx < plugin_array.elements; idx++)
 
2826
    for (uint idx= 0; idx < plugin_array.elements; idx++)
2744
2827
    {
2745
2828
      p= *dynamic_element(&plugin_array, idx, struct st_plugin_int **);
2746
2829
 
2751
2834
      /* Only options with a non-NULL comment are displayed in help text */
2752
2835
      for (;opt->id; opt++)
2753
2836
        if (opt->comment)
2754
 
          insert_dynamic(&all_options, (unsigned char*) opt);
 
2837
          insert_dynamic(&all_options, (uchar*) opt);
2755
2838
    }
2756
2839
 
2757
2840
  for (;main_options->id; main_options++)
2758
 
    insert_dynamic(&all_options, (unsigned char*) main_options);
 
2841
    insert_dynamic(&all_options, (uchar*) main_options);
2759
2842
 
2760
2843
  sort_dynamic(&all_options, (qsort_cmp) option_cmp);
2761
2844
 
2762
2845
  /* main_options now points to the empty option terminator */
2763
 
  insert_dynamic(&all_options, (unsigned char*) main_options);
 
2846
  insert_dynamic(&all_options, (uchar*) main_options);
2764
2847
 
2765
2848
  my_print_help((my_option*) all_options.buffer);
2766
2849
  my_print_variables((my_option*) all_options.buffer);