18
18
#include <drizzled/plugin/listen_tcp.h>
19
19
#include <drizzled/plugin/client.h>
20
20
#include <drizzled/session.h>
21
#include <drizzled/module/option_map.h>
22
23
#include <iostream>
25
#include <boost/program_options.hpp>
24
27
using namespace std;
25
28
using namespace drizzled;
30
namespace po= boost::program_options;
27
32
static bool enabled= false;
28
33
static bool debug_enabled= false;
29
static char* user = (char*)"";
30
static char* password = (char*)"";
31
static char* db = NULL;
34
static char* username= NULL;
35
static char* password= NULL;
36
static char* db= NULL;
34
39
class ClientConsole: public plugin::Client
311
static ListenConsole *listen_obj= NULL;
313
static int init(drizzled::plugin::Context &context)
321
static int init(drizzled::module::Context &context)
315
listen_obj= new ListenConsole("console");
316
context.add(listen_obj);
323
const module::option_map &vm= context.getOptions();
324
/* duplicating these here means they need to be freed. They're global, so
325
we'll just have the ListenConsole object do it in its destructor */
326
if (vm.count("username"))
327
username= strdup(vm["username"].as<string>().c_str());
329
username= strdup("");
331
if (vm.count("password"))
332
password= strdup(vm["password"].as<string>().c_str());
334
password= strdup("");
337
db= strdup(vm["db"].as<string>().c_str());
341
context.add(new ListenConsole("console"));
320
345
static DRIZZLE_SYSVAR_BOOL(enable, enabled, PLUGIN_VAR_NOCMDARG,
321
346
N_("Enable the console."), NULL, NULL, false);
323
347
static DRIZZLE_SYSVAR_BOOL(debug, debug_enabled, PLUGIN_VAR_NOCMDARG,
324
348
N_("Turn on extra debugging."), NULL, NULL, false);
325
static DRIZZLE_SYSVAR_STR(user, user, PLUGIN_VAR_READONLY,
350
static DRIZZLE_SYSVAR_STR(username, username, PLUGIN_VAR_READONLY,
326
351
N_("User to use for auth."), NULL, NULL, NULL);
327
352
static DRIZZLE_SYSVAR_STR(password, password, PLUGIN_VAR_READONLY,
328
353
N_("Password to use for auth."), NULL, NULL, NULL);
329
354
static DRIZZLE_SYSVAR_STR(db, db, PLUGIN_VAR_READONLY,
330
355
N_("Default database to use."), NULL, NULL, NULL);
357
static void init_options(drizzled::module::option_context &context)
360
po::value<bool>(&enabled)->default_value(false)->zero_tokens(),
361
N_("Enable the console."));
363
po::value<bool>(&debug_enabled)->default_value(false)->zero_tokens(),
364
N_("Turn on extra debugging."));
367
N_("User to use for auth."));
370
N_("Password to use for auth."));
373
N_("Default database to use."));
332
376
static drizzle_sys_var* vars[]= {
333
377
DRIZZLE_SYSVAR(enable),
334
378
DRIZZLE_SYSVAR(debug),
335
DRIZZLE_SYSVAR(user),
379
DRIZZLE_SYSVAR(username),
336
380
DRIZZLE_SYSVAR(password),
337
381
DRIZZLE_SYSVAR(db),