~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/session.h

  • Committer: Monty Taylor
  • Date: 2010-12-02 22:51:54 UTC
  • mto: (1975.1.1 build)
  • mto: This revision was merged to the branch mainline in revision 1976.
  • Revision ID: mordred@inaugust.com-20101202225154-h54ifmga9x6cckgs
Refactored syslog module and changed it to use sys_var directly.

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
#include "drizzled/util/storable.h"
38
38
#include "drizzled/my_hash.h"
39
39
#include "drizzled/pthread_globals.h"
 
40
 
40
41
#include <netdb.h>
41
42
#include <sys/time.h>
42
43
#include <sys/resource.h>
43
44
 
44
 
#include <algorithm>
 
45
#include <map>
 
46
#include <string>
45
47
#include <bitset>
46
48
#include <deque>
47
 
#include <map>
48
 
#include <string>
49
49
 
50
 
#include "drizzled/identifier.h"
 
50
#include "drizzled/security_context.h"
51
51
#include "drizzled/open_tables_state.h"
52
52
#include "drizzled/internal_error_handler.h"
53
53
#include "drizzled/diagnostics_area.h"
59
59
#include <boost/thread/mutex.hpp>
60
60
#include <boost/thread/shared_mutex.hpp>
61
61
#include <boost/thread/condition_variable.hpp>
62
 
#include <boost/make_shared.hpp>
63
 
 
64
62
 
65
63
#define MIN_HANDSHAKE_SIZE      6
66
64
 
418
416
 
419
417
  void resetQueryString()
420
418
  {
421
 
    query.reset();
422
 
    _state.reset();
 
419
    return query.reset(new std::string);
423
420
  }
424
421
 
425
422
  /*
431
428
  {
432
429
    QueryString tmp_string(getQueryString());
433
430
 
434
 
    assert(tmp_string);
435
 
    if (not tmp_string)
436
 
    {
437
 
      length= 0;
438
 
      return 0;
439
 
    }
440
 
 
441
431
    length= tmp_string->length();
442
432
    char *to_return= strmake(tmp_string->c_str(), tmp_string->length());
443
433
    return to_return;
444
434
  }
445
435
 
446
 
  class State {
447
 
    std::vector <char> _query;
448
 
 
449
 
  public:
450
 
    typedef boost::shared_ptr<State> const_shared_ptr;
451
 
 
452
 
    State(const char *in_packet, size_t in_packet_length)
453
 
    {
454
 
      if (in_packet_length)
455
 
      {
456
 
        size_t minimum= std::min(in_packet_length, static_cast<size_t>(PROCESS_LIST_WIDTH));
457
 
        _query.resize(minimum + 1);
458
 
        memcpy(&_query[0], in_packet, minimum);
459
 
      }
460
 
      else
461
 
      {
462
 
        _query.resize(0);
463
 
      }
464
 
    }
465
 
 
466
 
    const char *query() const
467
 
    {
468
 
      if (_query.size())
469
 
        return &_query[0];
470
 
 
471
 
      return "";
472
 
    }
473
 
 
474
 
    const char *query(size_t &size) const
475
 
    {
476
 
      if (_query.size())
477
 
      {
478
 
        size= _query.size() -1;
479
 
        return &_query[0];
480
 
      }
481
 
 
482
 
      size= 0;
483
 
      return "";
484
 
    }
485
 
  protected:
486
 
    friend class Session;
487
 
    typedef boost::shared_ptr<State> shared_ptr;
488
 
  };
489
 
private:
490
 
  State::shared_ptr  _state; 
491
 
public:
492
 
 
493
 
  State::const_shared_ptr state()
494
 
  {
495
 
    return _state;
496
 
  }
497
 
 
498
436
  /**
499
437
    Name of the current (default) database.
500
438
 
507
445
    the Session of that thread); that thread is (and must remain, for now) the
508
446
    only responsible for freeing this member.
509
447
  */
510
 
private:
511
 
  util::string::shared_ptr _schema;
512
 
public:
 
448
  std::string db;
513
449
 
514
 
  util::string::const_shared_ptr schema() const
 
450
  const std::string &getSchema() const
515
451
  {
516
 
    if (_schema)
517
 
      return _schema;
518
 
 
519
 
    return util::string::const_shared_ptr(new std::string(""));
 
452
    return db;
520
453
  }
521
454
  std::string catalog;
522
455
  /* current cache key */
567
500
  char *thread_stack;
568
501
 
569
502
private:
570
 
  identifier::User::shared_ptr security_ctx;
 
503
  SecurityContext security_ctx;
571
504
 
572
505
  int32_t scoreboard_index;
573
506
 
576
509
    assert(this->dbug_sentry == Session_SENTRY_MAGIC);
577
510
  }
578
511
public:
579
 
  identifier::User::const_shared_ptr user() const
 
512
  const SecurityContext& getSecurityContext() const
580
513
  {
581
 
    if (security_ctx)
582
 
      return security_ctx;
583
 
 
584
 
    return identifier::User::const_shared_ptr();
 
514
    return security_ctx;
585
515
  }
586
516
 
587
 
  void setUser(identifier::User::shared_ptr arg)
 
517
  SecurityContext& getSecurityContext()
588
518
  {
589
 
    security_ctx= arg;
 
519
    return security_ctx;
590
520
  }
591
521
 
592
522
  int32_t getScoreboardIndex()
934
864
    return &_killed;
935
865
  }
936
866
 
937
 
  bool is_admin_connection;
938
867
  bool some_tables_deleted;
939
868
  bool no_errors;
940
869
  bool password;
1380
1309
    database usually involves other actions, like switching other database
1381
1310
    attributes including security context. In the future, this operation
1382
1311
    will be made private and more convenient interface will be provided.
 
1312
 
 
1313
    @return Operation status
 
1314
      @retval false Success
 
1315
      @retval true  Out-of-memory error
1383
1316
  */
1384
 
  void set_db(const std::string &new_db);
 
1317
  bool set_db(const std::string &new_db);
1385
1318
 
1386
1319
  /*
1387
1320
    Copy the current database to the argument. Use the current arena to