~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/module/loader.cc

  • Committer: Monty Taylor
  • Date: 2010-06-19 21:25:32 UTC
  • mfrom: (1627.2.5 build)
  • Revision ID: mordred@inaugust.com-20100619212532-2e4bd11tm4plya7q
Rollup patch featuring: boost::program_options support for plugins, a
valgrind fix, a bugfix for password processing and a few build fixes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
#include <vector>
23
23
#include <map>
24
24
#include <algorithm>
 
25
#include <iostream>
 
26
 
 
27
#include <boost/program_options.hpp>
25
28
 
26
29
#include "drizzled/option.h"
27
30
#include "drizzled/my_hash.h"
31
34
#include "drizzled/module/load_list.h"
32
35
#include "drizzled/module/library.h"
33
36
#include "drizzled/module/registry.h"
 
37
#include "drizzled/module/option_context.h"
34
38
#include "drizzled/sql_parse.h"
35
39
#include "drizzled/show.h"
36
40
#include "drizzled/cursor.h"
49
53
#define RTLD_NOW 1
50
54
#endif
51
55
 
 
56
namespace po=boost::program_options;
 
57
 
52
58
using namespace std;
53
59
 
54
60
/** These exist just to prevent symbols from being optimized out */
1653
1659
  NOTE:
1654
1660
    Requires that a write-lock is held on LOCK_system_variables_hash
1655
1661
*/
1656
 
static int test_plugin_options(memory::Root *tmp_root, module::Module *tmp,
 
1662
static int test_plugin_options(memory::Root *module_root,
 
1663
                               module::Module *test_module,
1657
1664
                               int *argc, char **argv)
1658
1665
{
1659
1666
  struct sys_var_chain chain= { NULL, NULL };
1664
1671
  struct st_bookmark *var;
1665
1672
  uint32_t len, count= EXTRA_OPTIONS;
1666
1673
 
1667
 
  for (opt= tmp->getManifest().system_vars; opt && *opt; opt++)
 
1674
  if (test_module->getManifest().init_options != NULL)
 
1675
  {
 
1676
    cout << "Calling init_options: " << test_module->getName() << endl;
 
1677
    po::options_description module_options("Options used by plugins");
 
1678
    module::option_context opt_ctx(test_module->getName(),
 
1679
                                   module_options.add_options());
 
1680
    test_module->getManifest().init_options(opt_ctx);
 
1681
 
 
1682
    po::variables_map vm;
 
1683
 
 
1684
    po::parsed_options parsed= po::command_line_parser(*argc, argv).
 
1685
      options(module_options).allow_unregistered().run();
 
1686
 
 
1687
    po::store(parsed, vm);
 
1688
 
 
1689
    vector<string> to_pass_further= po::collect_unrecognized(parsed.options,
 
1690
                                                             po::include_positional);
 
1691
 
 
1692
 
 
1693
    /* Copy the left over options back into argv for further processing.
 
1694
       Once the core is using program options, this whole thing will be done
 
1695
       differently.
 
1696
     */
 
1697
    for (vector<string>::iterator iter= to_pass_further.begin();
 
1698
         iter != to_pass_further.end();
 
1699
         ++iter)
 
1700
    {
 
1701
      size_t pos= iter-to_pass_further.begin()+1;
 
1702
      memcpy(argv[pos], (*iter).c_str(), (*iter).size()+1);
 
1703
      cout << "arg: *" << argv[pos] << "*" << endl;
 
1704
    }
 
1705
    *argc= to_pass_further.size() + 1;
 
1706
 
 
1707
    po::notify(vm);
 
1708
  }
 
1709
  else
 
1710
  {
 
1711
 
 
1712
  for (opt= test_module->getManifest().system_vars; opt && *opt; opt++)
 
1713
  {
1668
1714
    count++;
1669
 
 
 
1715
  }
1670
1716
 
1671
1717
  if (count > EXTRA_OPTIONS || (*argc > 1))
1672
1718
  {
1673
 
    if (!(opts= (option*) tmp_root->alloc_root(sizeof(option) * count)))
 
1719
    if (!(opts= (option*) module_root->alloc_root(sizeof(option) * count)))
1674
1720
    {
1675
 
      errmsg_printf(ERRMSG_LVL_ERROR, _("Out of memory for plugin '%s'."), tmp->getName().c_str());
 
1721
      errmsg_printf(ERRMSG_LVL_ERROR,
 
1722
                    _("Out of memory for plugin '%s'."),
 
1723
                    test_module->getName().c_str());
1676
1724
      return(-1);
1677
1725
    }
1678
1726
    memset(opts, 0, sizeof(option) * count);
1679
1727
 
1680
 
    if (construct_options(tmp_root, tmp, opts))
 
1728
    if (construct_options(module_root, test_module, opts))
1681
1729
    {
1682
 
      errmsg_printf(ERRMSG_LVL_ERROR, _("Bad options for plugin '%s'."), tmp->getName().c_str());
 
1730
      errmsg_printf(ERRMSG_LVL_ERROR,
 
1731
                    _("Bad options for plugin '%s'."),
 
1732
                    test_module->getName().c_str());
1683
1733
      return(-1);
1684
1734
    }
1685
1735
 
1688
1738
 
1689
1739
    if (error)
1690
1740
    {
1691
 
       errmsg_printf(ERRMSG_LVL_ERROR, _("Parsing options for plugin '%s' failed."),
1692
 
                       tmp->getName().c_str());
1693
 
       goto err;
 
1741
      errmsg_printf(ERRMSG_LVL_ERROR,
 
1742
                    _("Parsing options for plugin '%s' failed."),
 
1743
                    test_module->getName().c_str());
 
1744
      goto err;
1694
1745
    }
1695
1746
  }
 
1747
  }
1696
1748
 
1697
1749
  error= 1;
1698
1750
 
1699
1751
  {
1700
 
    for (opt= tmp->getManifest().system_vars; opt && *opt; opt++)
 
1752
    for (opt= test_module->getManifest().system_vars; opt && *opt; opt++)
1701
1753
    {
1702
1754
      sys_var *v;
1703
1755
      if (((o= *opt)->flags & PLUGIN_VAR_NOSYSVAR))
1704
1756
        continue;
1705
1757
 
1706
 
      if ((var= find_bookmark(tmp->getName(), o->name, o->flags)))
 
1758
      if ((var= find_bookmark(test_module->getName(), o->name, o->flags)))
 
1759
      {
1707
1760
        v= new sys_var_pluginvar(var->key + 1, o);
 
1761
      }
1708
1762
      else
1709
1763
      {
1710
 
        len= tmp->getName().length() + strlen(o->name) + 2;
1711
 
        string vname(tmp->getName());
 
1764
        len= test_module->getName().length() + strlen(o->name) + 2;
 
1765
        string vname(test_module->getName());
1712
1766
        vname.push_back('-');
1713
1767
        vname.append(o->name);
1714
1768
        transform(vname.begin(), vname.end(), vname.begin(), ::tolower);
1737
1791
      chain.last->setNext(NULL);
1738
1792
      if (mysql_add_sys_var_chain(chain.first, NULL))
1739
1793
      {
1740
 
        errmsg_printf(ERRMSG_LVL_ERROR, _("Plugin '%s' has conflicting system variables"),
1741
 
                        tmp->getName().c_str());
 
1794
        errmsg_printf(ERRMSG_LVL_ERROR,
 
1795
                      _("Plugin '%s' has conflicting system variables"),
 
1796
                      test_module->getName().c_str());
1742
1797
        goto err;
1743
1798
      }
1744
 
      tmp->system_vars= chain.first;
 
1799
      test_module->system_vars= chain.first;
1745
1800
    }
1746
1801
    return(0);
1747
1802
  }