13
13
along with this program; if not, write to the Free Software
14
14
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
16
#include <drizzled/server_includes.h>
17
17
#include <drizzled/gettext.h>
18
18
#include <drizzled/plugin/listen_tcp.h>
19
19
#include <drizzled/plugin/client.h>
20
#include <drizzled/session.h>
21
#include <drizzled/module/option_map.h>
23
21
#include <iostream>
25
#include <boost/program_options.hpp>
27
23
using namespace std;
28
24
using namespace drizzled;
30
namespace po= boost::program_options;
32
26
static bool enabled= false;
33
27
static bool debug_enabled= false;
36
29
class ClientConsole: public plugin::Client
40
33
uint32_t max_column;
41
const std::string &username;
42
const std::string &password;
43
const std::string &db;
46
ClientConsole(const std::string &username_arg,
47
const std::string &password_arg,
48
const std::string &db_arg) :
52
username(username_arg),
53
password(password_arg),
57
42
virtual void printDebug(const char *message)
276
258
class ListenConsole: public plugin::Listen
279
const std::string username;
280
const std::string password;
281
const std::string db;
284
ListenConsole(const std::string &name_arg,
285
const std::string &username_arg,
286
const std::string &password_arg,
287
const std::string &db_arg) :
288
plugin::Listen(name_arg),
289
username(username_arg),
290
password(password_arg),
263
ListenConsole(std::string name_arg)
264
: plugin::Listen(name_arg)
327
300
assert(read(fd, buffer, 1) == 1);
328
return new ClientConsole(username, password, db);
301
return new ClientConsole;
332
static int init(drizzled::module::Context &context)
334
const module::option_map &vm= context.getOptions();
335
const string username(vm.count("username") ? vm["username"].as<string>() : "");
336
const string password(vm.count("password") ? vm["password"].as<string>() : "");
337
const string db(vm.count("db") ? vm["db"].as<string>() : "");
338
context.registerVariable(new sys_var_bool_ptr("enable", &enabled));
339
context.registerVariable(new sys_var_bool_ptr("debug_enable", &debug_enabled));
340
context.registerVariable(new sys_var_const_string_val("username", username));
341
context.registerVariable(new sys_var_const_string_val("password", password));
342
context.registerVariable(new sys_var_const_string_val("db", db));
343
context.add(new ListenConsole("console", username, password, db));
347
static void init_options(drizzled::module::option_context &context)
350
po::value<bool>(&enabled)->default_value(false)->zero_tokens(),
351
N_("Enable the console."));
353
po::value<bool>(&debug_enabled)->default_value(false)->zero_tokens(),
354
N_("Turn on extra debugging."));
357
N_("User to use for auth."));
360
N_("Password to use for auth."));
363
N_("Default database to use."));
366
DRIZZLE_DECLARE_PLUGIN
305
static ListenConsole *listen_obj= NULL;
307
static int init(drizzled::plugin::Registry ®istry)
309
listen_obj= new ListenConsole("console");
310
registry.add(listen_obj);
314
static int deinit(drizzled::plugin::Registry ®istry)
316
registry.remove(listen_obj);
321
static DRIZZLE_SYSVAR_BOOL(enable, enabled, PLUGIN_VAR_NOCMDARG,
322
N_("Enable the console."), NULL, NULL, false);
324
static DRIZZLE_SYSVAR_BOOL(debug, debug_enabled, PLUGIN_VAR_NOCMDARG,
325
N_("Turn on extra debugging."), NULL, NULL, false);
327
static struct st_mysql_sys_var* vars[]= {
328
DRIZZLE_SYSVAR(enable),
329
DRIZZLE_SYSVAR(debug),
333
drizzle_declare_plugin
372
338
"Console Client",
373
339
PLUGIN_LICENSE_BSD,
374
340
init, /* Plugin Init */
375
NULL, /* system variables */
376
init_options /* config options */
341
deinit, /* Plugin Deinit */
342
NULL, /* status variables */
343
vars, /* system variables */
344
NULL /* config options */
378
DRIZZLE_DECLARE_PLUGIN_END;
346
drizzle_declare_plugin_end;