~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to server/sql_plugin.cc

MergingĀ fromĀ Mark.

Show diffs side-by-side

added added

removed removed

Lines of Context:
78
78
  0  /* Auth */
79
79
};
80
80
 
81
 
static const char *plugin_interface_version_sym=
82
 
                   "_mysql_plugin_interface_version_";
83
 
static const char *sizeof_st_plugin_sym=
84
 
                   "_mysql_sizeof_struct_st_plugin_";
85
81
static const char *plugin_declarations_sym= "_mysql_plugin_declarations_";
86
 
static int min_plugin_interface_version= MYSQL_PLUGIN_INTERFACE_VERSION & ~0xFF;
87
82
 
88
83
/* Note that 'int version' must be the first field of every plugin
89
84
   sub-structure (plugin->info).
90
85
*/
91
 
static int min_plugin_info_interface_version[MYSQL_MAX_PLUGIN_TYPE_NUM]=
92
 
{
93
 
  MYSQL_UDF_INTERFACE_VERSION,
94
 
  MYSQL_UDA_INTERFACE_VERSION,
95
 
  MYSQL_HANDLERTON_INTERFACE_VERSION,
96
 
  MYSQL_DAEMON_INTERFACE_VERSION,
97
 
  MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION,
98
 
  MYSQL_AUDIT_INTERFACE_VERSION,
99
 
  MYSQL_LOG_INTERFACE_VERSION,
100
 
  MYSQL_AUTH_INTERFACE_VERSION
101
 
};
102
 
static int cur_plugin_info_interface_version[MYSQL_MAX_PLUGIN_TYPE_NUM]=
103
 
{
104
 
  MYSQL_UDF_INTERFACE_VERSION,
105
 
  MYSQL_UDA_INTERFACE_VERSION,
106
 
  MYSQL_HANDLERTON_INTERFACE_VERSION,
107
 
  MYSQL_DAEMON_INTERFACE_VERSION,
108
 
  MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION,
109
 
  MYSQL_AUDIT_INTERFACE_VERSION,
110
 
  MYSQL_LOG_INTERFACE_VERSION,
111
 
  MYSQL_AUTH_INTERFACE_VERSION
112
 
};
113
86
 
114
87
static bool initialized= 0;
115
88
 
329
302
  if (p->handle)
330
303
    dlclose(p->handle);
331
304
  my_free(p->dl.str, MYF(MY_ALLOW_ZERO_PTR));
332
 
  if (p->version != MYSQL_PLUGIN_INTERFACE_VERSION)
333
 
    my_free((uchar*)p->plugins, MYF(MY_ALLOW_ZERO_PTR));
334
305
}
335
306
 
336
307
 
385
356
      sql_print_error(ER(ER_CANT_OPEN_LIBRARY), dlpath, errno, errmsg);
386
357
    return(0);
387
358
  }
388
 
  /* Determine interface version */
389
 
  if (!(sym= dlsym(plugin_dl.handle, plugin_interface_version_sym)))
390
 
  {
391
 
    free_plugin_mem(&plugin_dl);
392
 
    if (report & REPORT_TO_USER)
393
 
      my_error(ER_CANT_FIND_DL_ENTRY, MYF(0), plugin_interface_version_sym);
394
 
    if (report & REPORT_TO_LOG)
395
 
      sql_print_error(ER(ER_CANT_FIND_DL_ENTRY), plugin_interface_version_sym);
396
 
    return(0);
397
 
  }
398
 
  plugin_dl.version= *(int *)sym;
399
 
  /* Versioning */
400
 
  if (plugin_dl.version < min_plugin_interface_version ||
401
 
      (plugin_dl.version >> 8) > (MYSQL_PLUGIN_INTERFACE_VERSION >> 8))
402
 
  {
403
 
    free_plugin_mem(&plugin_dl);
404
 
    if (report & REPORT_TO_USER)
405
 
      my_error(ER_CANT_OPEN_LIBRARY, MYF(0), dlpath, 0,
406
 
               "plugin interface version mismatch");
407
 
    if (report & REPORT_TO_LOG)
408
 
      sql_print_error(ER(ER_CANT_OPEN_LIBRARY), dlpath, 0,
409
 
                      "plugin interface version mismatch");
410
 
    return(0);
411
 
  }
 
359
 
412
360
  /* Find plugin declarations */
413
361
  if (!(sym= dlsym(plugin_dl.handle, plugin_declarations_sym)))
414
362
  {
420
368
    return(0);
421
369
  }
422
370
 
423
 
  if (plugin_dl.version != MYSQL_PLUGIN_INTERFACE_VERSION)
424
 
  {
425
 
    int i;
426
 
    uint sizeof_st_plugin;
427
 
    struct st_mysql_plugin *old, *cur;
428
 
    char *ptr= (char *)sym;
429
 
 
430
 
    if ((sym= dlsym(plugin_dl.handle, sizeof_st_plugin_sym)))
431
 
      sizeof_st_plugin= *(int *)sym;
432
 
    else
433
 
    {
434
 
#ifdef ERROR_ON_NO_SIZEOF_PLUGIN_SYMBOL
435
 
      free_plugin_mem(&plugin_dl);
436
 
      if (report & REPORT_TO_USER)
437
 
        my_error(ER_CANT_FIND_DL_ENTRY, MYF(0), sizeof_st_plugin_sym);
438
 
      if (report & REPORT_TO_LOG)
439
 
        sql_print_error(ER(ER_CANT_FIND_DL_ENTRY), sizeof_st_plugin_sym);
440
 
      return(0);
441
 
#else
442
 
      /*
443
 
        When the following assert starts failing, we'll have to switch
444
 
        to the upper branch of the #ifdef
445
 
      */
446
 
      assert(min_plugin_interface_version == 0);
447
 
      sizeof_st_plugin= (int)offsetof(struct st_mysql_plugin, version);
448
 
#endif
449
 
    }
450
 
 
451
 
    for (i= 0;
452
 
         ((struct st_mysql_plugin *)(ptr+i*sizeof_st_plugin))->info;
453
 
         i++)
454
 
      /* no op */;
455
 
 
456
 
    cur= (struct st_mysql_plugin*)
457
 
          my_malloc(i*sizeof(struct st_mysql_plugin), MYF(MY_ZEROFILL|MY_WME));
458
 
    if (!cur)
459
 
    {
460
 
      free_plugin_mem(&plugin_dl);
461
 
      if (report & REPORT_TO_USER)
462
 
        my_error(ER_OUTOFMEMORY, MYF(0), plugin_dl.dl.length);
463
 
      if (report & REPORT_TO_LOG)
464
 
        sql_print_error(ER(ER_OUTOFMEMORY), plugin_dl.dl.length);
465
 
      return(0);
466
 
    }
467
 
    /*
468
 
      All st_plugin fields not initialized in the plugin explicitly, are
469
 
      set to 0. It matches C standard behaviour for struct initializers that
470
 
      have less values than the struct definition.
471
 
    */
472
 
    for (i=0;
473
 
         (old=(struct st_mysql_plugin *)(ptr+i*sizeof_st_plugin))->info;
474
 
         i++)
475
 
      memcpy(cur+i, old, min(sizeof(cur[i]), sizeof_st_plugin));
476
 
 
477
 
    sym= cur;
478
 
  }
479
371
  plugin_dl.plugins= (struct st_mysql_plugin *)sym;
480
372
 
481
373
  /* Duplicate and convert dll name */
679
571
  if (! (tmp.plugin_dl= plugin_dl_add(dl, report)))
680
572
    return(true);
681
573
  /* Find plugin by name */
682
 
  for (plugin= tmp.plugin_dl->plugins; plugin->info; plugin++)
 
574
  for (plugin= tmp.plugin_dl->plugins; plugin->name; plugin++)
683
575
  {
684
576
    uint name_len= strlen(plugin->name);
685
577
    if (plugin->type >= 0 && plugin->type < MYSQL_MAX_PLUGIN_TYPE_NUM &&
689
581
                       name_len))
690
582
    {
691
583
      struct st_plugin_int *tmp_plugin_ptr;
692
 
      if (*(int*)plugin->info <
693
 
          min_plugin_info_interface_version[plugin->type] ||
694
 
          ((*(int*)plugin->info) >> 8) >
695
 
          (cur_plugin_info_interface_version[plugin->type] >> 8))
696
 
      {
697
 
        char buf[256];
698
 
        strxnmov(buf, sizeof(buf) - 1, "API version for ",
699
 
                 plugin_type_names[plugin->type].str,
700
 
                 " plugin is too different", NullS);
701
 
        if (report & REPORT_TO_USER)
702
 
          my_error(ER_CANT_OPEN_LIBRARY, MYF(0), dl->str, 0, buf);
703
 
        if (report & REPORT_TO_LOG)
704
 
          sql_print_error(ER(ER_CANT_OPEN_LIBRARY), dl->str, 0, buf);
705
 
        goto err;
706
 
      }
 
584
 
707
585
      tmp.plugin= plugin;
708
586
      tmp.name.str= (char *)plugin->name;
709
587
      tmp.name.length= name_len;
1027
905
  */
1028
906
  for (builtins= mysqld_builtins; *builtins; builtins++)
1029
907
  {
1030
 
    for (plugin= *builtins; plugin->info; plugin++)
 
908
    for (plugin= *builtins; plugin->name; plugin++)
1031
909
    {
1032
910
      bzero(&tmp, sizeof(tmp));
1033
911
      tmp.plugin= plugin;
1175
1053
        dl= name;
1176
1054
        if ((plugin_dl= plugin_dl_add(&dl, REPORT_TO_LOG)))
1177
1055
        {
1178
 
          for (plugin= plugin_dl->plugins; plugin->info; plugin++)
 
1056
          for (plugin= plugin_dl->plugins; plugin->name; plugin++)
1179
1057
          {
1180
1058
            name.str= (char *) plugin->name;
1181
1059
            name.length= strlen(name.str);