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
#include <drizzled/plugin/catalog.h>
25
21
#include <iostream>
27
#include <boost/program_options.hpp>
29
23
using namespace std;
30
24
using namespace drizzled;
32
namespace po= boost::program_options;
34
26
static bool enabled= false;
35
27
static bool debug_enabled= false;
38
29
class ClientConsole: public plugin::Client
42
33
uint32_t max_column;
43
const std::string &username;
44
const std::string &password;
45
const std::string &schema;
46
const std::string &_catalog;
49
ClientConsole(const std::string &username_arg,
50
const std::string &password_arg,
51
const std::string &schema_arg,
52
const std::string &catalog_arg) :
56
username(username_arg),
57
password(password_arg),
62
42
virtual void printDebug(const char *message)
65
45
cout << "CONSOLE: " << message << endl;
68
catalog::Instance::shared_ptr catalog()
70
identifier::Catalog identifier(_catalog);
71
catalog::Instance::shared_ptr tmp= plugin::Catalog::getInstance(identifier);
74
std::cerr << "Invalid catalog '" << identifier << "', resorting to 'local' catalog" << std::endl;
79
48
virtual int getFileDescriptor(void)
81
50
printDebug("getFileDescriptor");
151
116
while (cin.eof() == false && cin.fail() == true);
153
if ((*packet_length == 1 && cin.eof() == true) or
154
not strncasecmp(*packet + 1, "quit", 4) or
155
not strncasecmp(*packet + 1, "exit", 4) or
156
not strncasecmp(*packet + 1, "shutdown", sizeof("shutdown") -1))
118
if ((*packet_length == 1 && cin.eof() == true) ||
119
!strncasecmp(*packet + 1, "quit", 4) ||
120
!strncasecmp(*packet + 1, "exit", 4))
159
123
*packet_length= 1;
160
124
(*packet)[0]= COM_SHUTDOWN;
291
253
printDebug("wasAborted");
301
258
class ListenConsole: public plugin::Listen
304
const std::string username;
305
const std::string password;
306
const std::string schema;
307
const std::string _catalog;
310
ListenConsole(const std::string &name_arg,
311
const std::string &username_arg,
312
const std::string &password_arg,
313
const std::string &schema_arg,
314
const std::string &catalog_arg) :
315
plugin::Listen(name_arg),
316
username(username_arg),
317
password(password_arg),
319
_catalog(catalog_arg)
263
ListenConsole(std::string name_arg)
264
: plugin::Listen(name_arg)
355
300
assert(read(fd, buffer, 1) == 1);
357
return new ClientConsole(username, password, schema, _catalog);
301
return new ClientConsole;
361
static int init(drizzled::module::Context &context)
363
const module::option_map &vm= context.getOptions();
364
const string username(vm.count("username") ? vm["username"].as<string>() : "");
365
const string password(vm.count("password") ? vm["password"].as<string>() : "");
366
const string schema(vm.count("schema") ? vm["schema"].as<string>() : "");
368
const std::string catalog(vm.count("catalog") ? vm["catalog"].as<string>() : "LOCAL");
370
context.add(new ListenConsole("console", username, password, schema, catalog));
375
static void init_options(drizzled::module::option_context &context)
378
po::value<bool>(&enabled)->default_value(false)->zero_tokens(),
379
N_("Enable the console."));
381
po::value<bool>(&debug_enabled)->default_value(false)->zero_tokens(),
382
N_("Turn on extra debugging."));
385
N_("User to use for auth."));
388
N_("Password to use for auth."));
391
N_("Default catalog to use."));
394
N_("Default schema to use."));
397
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
403
338
"Console Client",
404
339
PLUGIN_LICENSE_BSD,
405
340
init, /* Plugin Init */
407
init_options /* config options */
341
deinit, /* Plugin Deinit */
342
NULL, /* status variables */
343
vars, /* system variables */
344
NULL /* config options */
409
DRIZZLE_DECLARE_PLUGIN_END;
346
drizzle_declare_plugin_end;