Drizzled Public API Documentation

module.cc
00001 /* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright 2011 Daniel Nichter
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; version 2 of the License.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018  */
00019 
00020 #include <config.h>
00021 #include <drizzled/item.h>
00022 #include <drizzled/plugin.h>
00023 #include <drizzled/module/option_map.h>
00024 #include <boost/program_options.hpp>
00025 #include "auth_schema.h"
00026 
00027 namespace po= boost::program_options;
00028 
00029 using namespace std;
00030 
00031 namespace drizzle_plugin {
00032 namespace auth_schema {
00033 
00037 static AuthSchema *auth_schema= NULL;
00038 
00039 static bool update_table(Session*, set_var* var)
00040 {
00041   if (not var->value->str_value.empty())
00042     return auth_schema->setTable(var->value->str_value.data());
00043   errmsg_printf(error::ERROR, _("auth_schema table cannot be NULL"));
00044   return true; // error
00045 }
00046 
00047 static void init_options(module::option_context &context)
00048 {
00049   auth_schema= new AuthSchema(true);
00050 
00051   context("table",
00052     po::value<string>(&auth_schema->sysvar_table)->default_value("auth.users"),
00053     N_("Database-qualified auth table name"));
00054 }
00055 
00056 static int init(module::Context &context)
00057 {
00058   const module::option_map &vm= context.getOptions();
00059 
00060   if (not vm["table"].as<string>().empty())
00061     auth_schema->setTable(vm["table"].as<string>());
00062 
00063   context.add(auth_schema);
00064   context.registerVariable(new sys_var_bool_ptr("enabled", &auth_schema->sysvar_enabled));
00065   context.registerVariable(new sys_var_std_string("table", auth_schema->sysvar_table, NULL, &update_table));
00066 
00067   return 0;
00068 }
00069 
00070 } /* end namespace drizzle_plugin::auth_schema */
00071 } /* end namespace drizzle_plugin */
00072 
00073 DRIZZLE_PLUGIN(
00074   drizzle_plugin::auth_schema::init,
00075   NULL,
00076   drizzle_plugin::auth_schema::init_options
00077 );