~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/auth_schema/module.cc

  • Committer: Daniel Nichter
  • Date: 2011-09-26 01:40:03 UTC
  • mto: This revision was merged to the branch mainline in revision 2437.
  • Revision ID: daniel@percona.com-20110926014003-5q2prdqcl84v583m
auth_schema (auth_db) working prototype.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
 
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
 
3
 *
 
4
 *  Copyright 2011 Daniel Nichter
 
5
 *
 
6
 *  This program is free software; you can redistribute it and/or modify
 
7
 *  it under the terms of the GNU General Public License as published by
 
8
 *  the Free Software Foundation; version 2 of the License.
 
9
 *
 
10
 *  This program is distributed in the hope that it will be useful,
 
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 *  GNU General Public License for more details.
 
14
 *
 
15
 *  You should have received a copy of the GNU General Public License
 
16
 *  along with this program; if not, write to the Free Software
 
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
18
 */
 
19
 
 
20
#include <config.h>
 
21
#include <boost/program_options.hpp>
 
22
#include <drizzled/plugin.h>
 
23
#include <drizzled/item.h>
 
24
#include <drizzled/module/option_map.h>
 
25
#include "auth_schema.h"
 
26
 
 
27
namespace po= boost::program_options;
 
28
 
 
29
using namespace std;
 
30
using namespace drizzled;
 
31
 
 
32
namespace auth_schema {
 
33
 
 
34
bool update_table(Session *, set_var *var);
 
35
 
 
36
static drizzled::plugin::AuthSchema *auth_schema= NULL;
 
37
 
 
38
bool update_table(Session *, set_var *var)
 
39
{
 
40
  return auth_schema->setTable(var->value->str_value.ptr());
 
41
}
 
42
 
 
43
static void init_options(drizzled::module::option_context &context)
 
44
{
 
45
  auth_schema= new drizzled::plugin::AuthSchema();
 
46
 
 
47
  context("table",
 
48
    po::value<string>(&auth_schema->_table)->default_value("auth.users"),
 
49
    N_("Database-qualified auth table name"));
 
50
}
 
51
 
 
52
static int init(module::Context &context)
 
53
{
 
54
  const module::option_map &vm= context.getOptions();
 
55
 
 
56
  if (not vm["table"].as<string>().empty())
 
57
    auth_schema->setTable(vm["table"].as<string>().c_str());
 
58
 
 
59
  context.add(auth_schema);
 
60
 
 
61
  context.registerVariable(
 
62
    new sys_var_std_string("table", auth_schema->_table, NULL, &update_table));
 
63
 
 
64
  return 0;
 
65
}
 
66
 
 
67
} /* namespace auth_schema */
 
68
 
 
69
DRIZZLE_PLUGIN(auth_schema::init, NULL, auth_schema::init_options);