~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/console/console.cc

  • Committer: Brian Aker
  • Date: 2009-12-03 04:18:00 UTC
  • mto: (1237.3.3 push)
  • mto: This revision was merged to the branch mainline in revision 1238.
  • Revision ID: brian@gaz-20091203041800-rxbans14m0bo0xcs
Final move of index flags up to Engine (new interface still needed).

Show diffs side-by-side

added added

removed removed

Lines of Context:
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 */
15
15
 
16
 
#include "config.h"
 
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>
22
20
 
23
21
#include <iostream>
24
22
 
25
 
#include <boost/program_options.hpp>
26
 
 
27
23
using namespace std;
28
24
using namespace drizzled;
29
25
 
30
 
namespace po= boost::program_options;
31
 
 
32
26
static bool enabled= false;
33
27
static bool debug_enabled= false;
34
28
 
35
 
 
36
29
class ClientConsole: public plugin::Client
37
30
{
38
31
  bool is_dead;
39
32
  uint32_t column;
40
33
  uint32_t max_column;
41
 
  const std::string &username;
42
 
  const std::string &password;
43
 
  const std::string &db;
44
34
 
45
35
public:
46
 
  ClientConsole(const std::string &username_arg,
47
 
                const std::string &password_arg,
48
 
                const std::string &db_arg) :
 
36
  ClientConsole():
49
37
    is_dead(false),
50
38
    column(0),
51
 
    max_column(0),
52
 
    username(username_arg),
53
 
    password(password_arg),
54
 
    db(db_arg)
 
39
    max_column(0)
55
40
  {}
56
41
 
57
42
  virtual void printDebug(const char *message)
99
84
  virtual bool authenticate(void)
100
85
  {
101
86
    printDebug("authenticate");
102
 
    identifier::User::shared_ptr user= identifier::User::make_shared();
103
 
    user->setUser(username);
104
 
    session->setUser(user);
105
 
    return session->checkUser(password, db);
 
87
    return true;
106
88
  }
107
89
 
108
90
  virtual bool readCommand(char **packet, uint32_t *packet_length)
201
183
 
202
184
    char buff[MAX_FIELD_WIDTH];
203
185
    String str(buff, sizeof(buff), &my_charset_bin);
204
 
    from->val_str_internal(&str);
 
186
    from->val_str(&str);
205
187
    return store(str.ptr(), str.length());
206
188
  }
207
189
 
276
258
class ListenConsole: public plugin::Listen
277
259
{
278
260
  int pipe_fds[2];
279
 
  const std::string username;
280
 
  const std::string password;
281
 
  const std::string db;
282
261
 
283
262
public:
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),
291
 
    db(db_arg)
 
263
  ListenConsole(std::string name_arg)
 
264
    : plugin::Listen(name_arg)
292
265
  {
293
266
    pipe_fds[0]= -1;
294
267
  }
307
280
    if (debug_enabled)
308
281
      enabled= true;
309
282
 
310
 
    if (not enabled)
 
283
    if (enabled == false)
311
284
      return false;
312
285
 
313
286
    if (pipe(pipe_fds) == -1)
325
298
  {
326
299
    char buffer[1];
327
300
    assert(read(fd, buffer, 1) == 1);
328
 
    return new ClientConsole(username, password, db);
 
301
    return new ClientConsole;
329
302
  }
330
303
};
331
304
 
332
 
static int init(drizzled::module::Context &context)
333
 
{
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));
344
 
  return 0;
345
 
}
346
 
 
347
 
static void init_options(drizzled::module::option_context &context)
348
 
{
349
 
  context("enable",
350
 
          po::value<bool>(&enabled)->default_value(false)->zero_tokens(),
351
 
          N_("Enable the console."));
352
 
  context("debug",
353
 
          po::value<bool>(&debug_enabled)->default_value(false)->zero_tokens(),
354
 
          N_("Turn on extra debugging."));
355
 
  context("username",
356
 
          po::value<string>(),
357
 
          N_("User to use for auth."));
358
 
  context("password",
359
 
          po::value<string>(),
360
 
          N_("Password to use for auth."));
361
 
  context("db",
362
 
          po::value<string>(),
363
 
          N_("Default database to use."));
364
 
}
365
 
 
366
 
DRIZZLE_DECLARE_PLUGIN
367
 
{
368
 
  DRIZZLE_VERSION_ID,
 
305
static ListenConsole *listen_obj= NULL;
 
306
 
 
307
static int init(drizzled::plugin::Registry &registry)
 
308
{
 
309
  listen_obj= new ListenConsole("console");
 
310
  registry.add(listen_obj);
 
311
  return 0;
 
312
}
 
313
 
 
314
static int deinit(drizzled::plugin::Registry &registry)
 
315
{
 
316
  registry.remove(listen_obj);
 
317
  delete listen_obj;
 
318
  return 0;
 
319
}
 
320
 
 
321
static DRIZZLE_SYSVAR_BOOL(enable, enabled, PLUGIN_VAR_NOCMDARG,
 
322
                           N_("Enable the console."), NULL, NULL, false);
 
323
 
 
324
static DRIZZLE_SYSVAR_BOOL(debug, debug_enabled, PLUGIN_VAR_NOCMDARG,
 
325
                           N_("Turn on extra debugging."), NULL, NULL, false);
 
326
 
 
327
static struct st_mysql_sys_var* vars[]= {
 
328
  DRIZZLE_SYSVAR(enable),
 
329
  DRIZZLE_SYSVAR(debug),
 
330
  NULL
 
331
};
 
332
 
 
333
drizzle_declare_plugin
 
334
{
369
335
  "console",
370
336
  "0.1",
371
337
  "Eric Day",
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 */
377
345
}
378
 
DRIZZLE_DECLARE_PLUGIN_END;
 
346
drizzle_declare_plugin_end;