~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/loader.cc

  • Committer: Brian Aker
  • Date: 2010-02-04 15:58:21 UTC
  • mfrom: (1280.1.9 build)
  • Revision ID: brian@gaz-20100204155821-bi4txluiivy043sb
Rollup of Brian, Jay

Show diffs side-by-side

added added

removed removed

Lines of Context:
569
569
typedef DECLARE_DRIZZLE_SYSVAR_BASIC(sysvar_str_t, char *);
570
570
typedef DECLARE_DRIZZLE_SessionVAR_BASIC(sessionvar_str_t, char *);
571
571
 
572
 
typedef DECLARE_DRIZZLE_SYSVAR_TYPELIB(sysvar_enum_t, unsigned long);
573
572
typedef DECLARE_DRIZZLE_SessionVAR_TYPELIB(sessionvar_enum_t, unsigned long);
574
 
typedef DECLARE_DRIZZLE_SYSVAR_TYPELIB(sysvar_set_t, uint64_t);
575
573
typedef DECLARE_DRIZZLE_SessionVAR_TYPELIB(sessionvar_set_t, uint64_t);
576
574
 
577
575
typedef DECLARE_DRIZZLE_SYSVAR_SIMPLE(sysvar_int_t, int);
708
706
}
709
707
 
710
708
 
711
 
static int check_func_enum(Session *, drizzle_sys_var *var,
712
 
                           void *save, drizzle_value *value)
713
 
{
714
 
  char buff[STRING_BUFFER_USUAL_SIZE];
715
 
  const char *strvalue= "NULL", *str;
716
 
  TYPELIB *typelib;
717
 
  int64_t tmp;
718
 
  long result;
719
 
  int length;
720
 
 
721
 
  if (var->flags & PLUGIN_VAR_SessionLOCAL)
722
 
    typelib= ((sessionvar_enum_t*) var)->typelib;
723
 
  else
724
 
    typelib= ((sysvar_enum_t*) var)->typelib;
725
 
 
726
 
  if (value->value_type(value) == DRIZZLE_VALUE_TYPE_STRING)
727
 
  {
728
 
    length= sizeof(buff);
729
 
    if (!(str= value->val_str(value, buff, &length)))
730
 
      goto err;
731
 
    if ((result= (long)find_type(typelib, str, length, 1)-1) < 0)
732
 
    {
733
 
      strvalue= str;
734
 
      goto err;
735
 
    }
736
 
  }
737
 
  else
738
 
  {
739
 
    if (value->val_int(value, &tmp))
740
 
      goto err;
741
 
    if (tmp >= typelib->count)
742
 
    {
743
 
      llstr(tmp, buff);
744
 
      strvalue= buff;
745
 
      goto err;
746
 
    }
747
 
    result= (long) tmp;
748
 
  }
749
 
  *(long*)save= result;
750
 
  return 0;
751
 
err:
752
 
  my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), var->name, strvalue);
753
 
  return 1;
754
 
}
755
 
 
756
 
 
757
 
static int check_func_set(Session *, drizzle_sys_var *var,
758
 
                          void *save, drizzle_value *value)
759
 
{
760
 
  char buff[STRING_BUFFER_USUAL_SIZE], *error= 0;
761
 
  const char *strvalue= "NULL", *str;
762
 
  TYPELIB *typelib;
763
 
  uint64_t result;
764
 
  uint32_t error_len;
765
 
  bool not_used;
766
 
  int length;
767
 
 
768
 
  if (var->flags & PLUGIN_VAR_SessionLOCAL)
769
 
    typelib= ((sessionvar_set_t*) var)->typelib;
770
 
  else
771
 
    typelib= ((sysvar_set_t*)var)->typelib;
772
 
 
773
 
  if (value->value_type(value) == DRIZZLE_VALUE_TYPE_STRING)
774
 
  {
775
 
    length= sizeof(buff);
776
 
    if (!(str= value->val_str(value, buff, &length)))
777
 
      goto err;
778
 
    result= find_set(typelib, str, length, NULL,
779
 
                     &error, &error_len, &not_used);
780
 
    if (error_len)
781
 
    {
782
 
      length= min((uint32_t)sizeof(buff), error_len);
783
 
      strncpy(buff, error, length);
784
 
      buff[length]= '\0';
785
 
      strvalue= buff;
786
 
      goto err;
787
 
    }
788
 
  }
789
 
  else
790
 
  {
791
 
    if (value->val_int(value, (int64_t *)&result))
792
 
      goto err;
793
 
    if (unlikely((result >= (1UL << typelib->count)) &&
794
 
                 (typelib->count < sizeof(long)*8)))
795
 
    {
796
 
      llstr(result, buff);
797
 
      strvalue= buff;
798
 
      goto err;
799
 
    }
800
 
  }
801
 
  *(uint64_t*)save= result;
802
 
  return 0;
803
 
err:
804
 
  my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), var->name, strvalue);
805
 
  return 1;
806
 
}
807
 
 
808
 
 
809
709
static void update_func_bool(Session *, drizzle_sys_var *,
810
710
                             void *tgt, const void *save)
811
711
{
953
853
    size= ALIGN_SIZE(sizeof(int));
954
854
    break;
955
855
  case PLUGIN_VAR_LONG:
956
 
  case PLUGIN_VAR_ENUM:
957
856
    size= ALIGN_SIZE(sizeof(long));
958
857
    break;
959
858
  case PLUGIN_VAR_LONGLONG:
960
 
  case PLUGIN_VAR_SET:
961
859
    size= ALIGN_SIZE(sizeof(uint64_t));
962
860
    break;
963
861
  case PLUGIN_VAR_STR:
1154
1052
  return (char **)intern_sys_var_ptr(a_session, offset, true);
1155
1053
}
1156
1054
 
1157
 
static uint64_t *mysql_sys_var_ptr_set(Session* a_session, int offset)
1158
 
{
1159
 
  return (uint64_t *)intern_sys_var_ptr(a_session, offset, true);
1160
 
}
1161
 
 
1162
 
static unsigned long *mysql_sys_var_ptr_enum(Session* a_session, int offset)
1163
 
{
1164
 
  return (unsigned long *)intern_sys_var_ptr(a_session, offset, true);
1165
 
}
1166
 
 
1167
 
 
1168
1055
void plugin_sessionvar_init(Session *session)
1169
1056
{
1170
1057
  session->variables.storage_engine= NULL;
1304
1191
    return SHOW_LONGLONG;
1305
1192
  case PLUGIN_VAR_STR:
1306
1193
    return SHOW_CHAR_PTR;
1307
 
  case PLUGIN_VAR_ENUM:
1308
 
  case PLUGIN_VAR_SET:
1309
 
    return SHOW_CHAR;
1310
1194
  default:
1311
1195
    assert(0);
1312
1196
    return SHOW_UNDEF;
1331
1215
TYPELIB* sys_var_pluginvar::plugin_var_typelib(void)
1332
1216
{
1333
1217
  switch (plugin_var->flags & (PLUGIN_VAR_TYPEMASK | PLUGIN_VAR_SessionLOCAL)) {
1334
 
  case PLUGIN_VAR_ENUM:
1335
 
    return ((sysvar_enum_t *)plugin_var)->typelib;
1336
 
  case PLUGIN_VAR_SET:
1337
 
    return ((sysvar_set_t *)plugin_var)->typelib;
1338
 
  case PLUGIN_VAR_ENUM | PLUGIN_VAR_SessionLOCAL:
 
1218
  case PLUGIN_VAR_SessionLOCAL:
1339
1219
    return ((sessionvar_enum_t *)plugin_var)->typelib;
1340
 
  case PLUGIN_VAR_SET | PLUGIN_VAR_SessionLOCAL:
1341
 
    return ((sessionvar_set_t *)plugin_var)->typelib;
1342
1220
  default:
1343
1221
    return NULL;
1344
1222
  }
1352
1230
 
1353
1231
  result= real_value_ptr(session, type);
1354
1232
 
1355
 
  if ((plugin_var->flags & PLUGIN_VAR_TYPEMASK) == PLUGIN_VAR_ENUM)
1356
 
    result= (unsigned char*) get_type(plugin_var_typelib(), *(ulong*)result);
1357
 
  else if ((plugin_var->flags & PLUGIN_VAR_TYPEMASK) == PLUGIN_VAR_SET)
1358
 
  {
1359
 
    char buffer[STRING_BUFFER_USUAL_SIZE];
1360
 
    String str(buffer, sizeof(buffer), system_charset_info);
1361
 
    TYPELIB *typelib= plugin_var_typelib();
1362
 
    uint64_t mask= 1, value= *(uint64_t*) result;
1363
 
    uint32_t i;
1364
 
 
1365
 
    str.length(0);
1366
 
    for (i= 0; i < typelib->count; i++, mask<<=1)
1367
 
    {
1368
 
      if (!(value & mask))
1369
 
        continue;
1370
 
      str.append(typelib->type_names[i], typelib->type_lengths[i]);
1371
 
      str.append(',');
1372
 
    }
1373
 
 
1374
 
    result= (unsigned char*) "";
1375
 
    if (str.length())
1376
 
      result= (unsigned char*) session->strmake(str.ptr(), str.length()-1);
1377
 
  }
1378
1233
  return result;
1379
1234
}
1380
1235
 
1424
1279
        case PLUGIN_VAR_LONGLONG:
1425
1280
          src= &((sessionvar_uint64_t_t*) plugin_var)->def_val;
1426
1281
          break;
1427
 
        case PLUGIN_VAR_ENUM:
1428
 
          src= &((sessionvar_enum_t*) plugin_var)->def_val;
1429
 
          break;
1430
 
        case PLUGIN_VAR_SET:
1431
 
          src= &((sessionvar_set_t*) plugin_var)->def_val;
1432
 
          break;
1433
1282
        case PLUGIN_VAR_BOOL:
1434
1283
          src= &((sessionvar_bool_t*) plugin_var)->def_val;
1435
1284
          break;
1523
1372
  case PLUGIN_VAR_LONGLONG | PLUGIN_VAR_UNSIGNED:
1524
1373
    OPTION_SET_LIMITS(GET_ULL, options, (sysvar_uint64_t_t*) opt);
1525
1374
    break;
1526
 
  case PLUGIN_VAR_ENUM:
1527
 
    options->var_type= GET_ENUM;
1528
 
    options->typelib= ((sysvar_enum_t*) opt)->typelib;
1529
 
    options->def_value= ((sysvar_enum_t*) opt)->def_val;
1530
 
    options->min_value= options->block_size= 0;
1531
 
    options->max_value= options->typelib->count - 1;
1532
 
    break;
1533
 
  case PLUGIN_VAR_SET:
1534
 
    options->var_type= GET_SET;
1535
 
    options->typelib= ((sysvar_set_t*) opt)->typelib;
1536
 
    options->def_value= ((sysvar_set_t*) opt)->def_val;
1537
 
    options->min_value= options->block_size= 0;
1538
 
    options->max_value= (1UL << options->typelib->count) - 1;
1539
 
    break;
1540
1375
  case PLUGIN_VAR_BOOL:
1541
1376
    options->var_type= GET_BOOL;
1542
1377
    options->def_value= ((sysvar_bool_t*) opt)->def_val;
1565
1400
  case PLUGIN_VAR_LONGLONG | PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_SessionLOCAL:
1566
1401
    OPTION_SET_LIMITS(GET_ULL, options, (sessionvar_uint64_t_t*) opt);
1567
1402
    break;
1568
 
  case PLUGIN_VAR_ENUM | PLUGIN_VAR_SessionLOCAL:
1569
 
    options->var_type= GET_ENUM;
1570
 
    options->typelib= ((sessionvar_enum_t*) opt)->typelib;
1571
 
    options->def_value= ((sessionvar_enum_t*) opt)->def_val;
1572
 
    options->min_value= options->block_size= 0;
1573
 
    options->max_value= options->typelib->count - 1;
1574
 
    break;
1575
 
  case PLUGIN_VAR_SET | PLUGIN_VAR_SessionLOCAL:
1576
 
    options->var_type= GET_SET;
1577
 
    options->typelib= ((sessionvar_set_t*) opt)->typelib;
1578
 
    options->def_value= ((sessionvar_set_t*) opt)->def_val;
1579
 
    options->min_value= options->block_size= 0;
1580
 
    options->max_value= (1UL << options->typelib->count) - 1;
1581
 
    break;
1582
1403
  case PLUGIN_VAR_BOOL | PLUGIN_VAR_SessionLOCAL:
1583
1404
    options->var_type= GET_BOOL;
1584
1405
    options->def_value= ((sessionvar_bool_t*) opt)->def_val;
1690
1511
    case PLUGIN_VAR_STR:
1691
1512
      (((sessionvar_str_t *)opt)->resolve)= mysql_sys_var_ptr_str;
1692
1513
      break;
1693
 
    case PLUGIN_VAR_ENUM:
1694
 
      (((sessionvar_enum_t *)opt)->resolve)= mysql_sys_var_ptr_enum;
1695
 
      break;
1696
 
    case PLUGIN_VAR_SET:
1697
 
      (((sessionvar_set_t *)opt)->resolve)= mysql_sys_var_ptr_set;
1698
 
      break;
1699
1514
    default:
1700
1515
      errmsg_printf(ERRMSG_LVL_ERROR, _("Unknown variable type code 0x%x in plugin '%s'."),
1701
1516
                      opt->flags, plugin_name);
1747
1562
        }
1748
1563
      }
1749
1564
      break;
1750
 
    case PLUGIN_VAR_ENUM:
1751
 
      if (!opt->check)
1752
 
        opt->check= check_func_enum;
1753
 
      if (!opt->update)
1754
 
        opt->update= update_func_long;
1755
 
      break;
1756
 
    case PLUGIN_VAR_SET:
1757
 
      if (!opt->check)
1758
 
        opt->check= check_func_set;
1759
 
      if (!opt->update)
1760
 
        opt->update= update_func_int64_t;
1761
 
      break;
1762
1565
    default:
1763
1566
      errmsg_printf(ERRMSG_LVL_ERROR, _("Unknown variable type code 0x%x in plugin '%s'."),
1764
1567
                      opt->flags, plugin_name);