~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/console/console.cc

  • Committer: Brian Aker
  • Date: 2010-06-08 03:51:35 UTC
  • Revision ID: brian@gaz-20100608035135-l66xrjt7xk9d502n
Remove current_session from myisam.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
21
 
23
22
#include <iostream>
24
23
 
25
 
#include <boost/program_options.hpp>
26
 
 
27
24
using namespace std;
28
25
using namespace drizzled;
29
26
 
30
 
namespace po= boost::program_options;
31
 
 
32
27
static bool enabled= false;
33
28
static bool debug_enabled= false;
 
29
static char* user = (char*)"";
 
30
static char* password = (char*)"";
 
31
static char* db = NULL;
34
32
 
35
33
 
36
34
class ClientConsole: public plugin::Client
38
36
  bool is_dead;
39
37
  uint32_t column;
40
38
  uint32_t max_column;
41
 
  const std::string &username;
42
 
  const std::string &password;
43
 
  const std::string &db;
44
39
 
45
40
public:
46
 
  ClientConsole(const std::string &username_arg,
47
 
                const std::string &password_arg,
48
 
                const std::string &db_arg) :
 
41
  ClientConsole():
49
42
    is_dead(false),
50
43
    column(0),
51
 
    max_column(0),
52
 
    username(username_arg),
53
 
    password(password_arg),
54
 
    db(db_arg)
 
44
    max_column(0)
55
45
  {}
56
46
 
57
47
  virtual void printDebug(const char *message)
99
89
  virtual bool authenticate(void)
100
90
  {
101
91
    printDebug("authenticate");
102
 
    session->getSecurityContext().setUser(username);
103
 
    return session->checkUser(password, db);
 
92
    session->getSecurityContext().setUser(user);
 
93
    return session->checkUser(password, strlen(password), db);
104
94
  }
105
95
 
106
96
  virtual bool readCommand(char **packet, uint32_t *packet_length)
199
189
 
200
190
    char buff[MAX_FIELD_WIDTH];
201
191
    String str(buff, sizeof(buff), &my_charset_bin);
202
 
    from->val_str_internal(&str);
 
192
    from->val_str(&str);
203
193
    return store(str.ptr(), str.length());
204
194
  }
205
195
 
274
264
class ListenConsole: public plugin::Listen
275
265
{
276
266
  int pipe_fds[2];
277
 
  const std::string username;
278
 
  const std::string password;
279
 
  const std::string db;
280
267
 
281
268
public:
282
 
  ListenConsole(const std::string &name_arg,
283
 
                const std::string &username_arg,
284
 
                const std::string &password_arg,
285
 
                const std::string &db_arg) :
286
 
    plugin::Listen(name_arg),
287
 
    username(username_arg),
288
 
    password(password_arg),
289
 
    db(db_arg)
 
269
  ListenConsole(std::string name_arg)
 
270
    : plugin::Listen(name_arg)
290
271
  {
291
272
    pipe_fds[0]= -1;
292
273
  }
305
286
    if (debug_enabled)
306
287
      enabled= true;
307
288
 
308
 
    if (not enabled)
 
289
    if (enabled == false)
309
290
      return false;
310
291
 
311
292
    if (pipe(pipe_fds) == -1)
323
304
  {
324
305
    char buffer[1];
325
306
    assert(read(fd, buffer, 1) == 1);
326
 
    return new ClientConsole(username, password, db);
 
307
    return new ClientConsole;
327
308
  }
328
309
};
329
310
 
 
311
static ListenConsole *listen_obj= NULL;
 
312
 
330
313
static int init(drizzled::module::Context &context)
331
314
{
332
 
  const module::option_map &vm= context.getOptions();
333
 
  const string username(vm.count("username") ? vm["username"].as<string>() : "");
334
 
  const string password(vm.count("password") ? vm["password"].as<string>() : "");
335
 
  const string db(vm.count("db") ? vm["db"].as<string>() : "");
336
 
  context.registerVariable(new sys_var_bool_ptr("enable", &enabled));
337
 
  context.registerVariable(new sys_var_bool_ptr("debug_enable", &debug_enabled));
338
 
  context.registerVariable(new sys_var_const_string_val("username", username));
339
 
  context.registerVariable(new sys_var_const_string_val("password", password));
340
 
  context.registerVariable(new sys_var_const_string_val("db", db));
341
 
  context.add(new ListenConsole("console", username, password, db));
 
315
  listen_obj= new ListenConsole("console");
 
316
  context.add(listen_obj);
342
317
  return 0;
343
318
}
344
319
 
345
 
static void init_options(drizzled::module::option_context &context)
346
 
{
347
 
  context("enable",
348
 
          po::value<bool>(&enabled)->default_value(false)->zero_tokens(),
349
 
          N_("Enable the console."));
350
 
  context("debug",
351
 
          po::value<bool>(&debug_enabled)->default_value(false)->zero_tokens(),
352
 
          N_("Turn on extra debugging."));
353
 
  context("username",
354
 
          po::value<string>(),
355
 
          N_("User to use for auth."));
356
 
  context("password",
357
 
          po::value<string>(),
358
 
          N_("Password to use for auth."));
359
 
  context("db",
360
 
          po::value<string>(),
361
 
          N_("Default database to use."));
362
 
}
 
320
static DRIZZLE_SYSVAR_BOOL(enable, enabled, PLUGIN_VAR_NOCMDARG,
 
321
                           N_("Enable the console."), NULL, NULL, false);
 
322
 
 
323
static DRIZZLE_SYSVAR_BOOL(debug, debug_enabled, PLUGIN_VAR_NOCMDARG,
 
324
                           N_("Turn on extra debugging."), NULL, NULL, false);
 
325
static DRIZZLE_SYSVAR_STR(user, user, PLUGIN_VAR_READONLY,
 
326
                          N_("User to use for auth."), NULL, NULL, NULL);
 
327
static DRIZZLE_SYSVAR_STR(password, password, PLUGIN_VAR_READONLY,
 
328
                          N_("Password to use for auth."), NULL, NULL, NULL);
 
329
static DRIZZLE_SYSVAR_STR(db, db, PLUGIN_VAR_READONLY,
 
330
                          N_("Default database to use."), NULL, NULL, NULL);
 
331
 
 
332
static drizzle_sys_var* vars[]= {
 
333
  DRIZZLE_SYSVAR(enable),
 
334
  DRIZZLE_SYSVAR(debug),
 
335
  DRIZZLE_SYSVAR(user),
 
336
  DRIZZLE_SYSVAR(password),
 
337
  DRIZZLE_SYSVAR(db),
 
338
  NULL
 
339
};
363
340
 
364
341
DRIZZLE_DECLARE_PLUGIN
365
342
{
370
347
  "Console Client",
371
348
  PLUGIN_LICENSE_BSD,
372
349
  init,   /* Plugin Init */
373
 
  NULL,   /* system variables */
374
 
  init_options    /* config options */
 
350
  vars,   /* system variables */
 
351
  NULL    /* config options */
375
352
}
376
353
DRIZZLE_DECLARE_PLUGIN_END;