Menu

[r663]: / framework / trunk / session_interface.h  Maximize  Restore  History

Download this file

107 lines (83 with data), 2.4 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
#ifndef CPPCMS_SESSION_INTERFACE_H
#define CPPCMS_SESSION_INTERFACE_H
#include <boost/noncopyable.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/shared_ptr.hpp>
#include <string>
#include <map>
namespace cppcms {
class session_api;
class worker_thread;
class serializable;
class session_interface : private boost::noncopyable {
struct entry {
std::string value;
bool exposed;
entry(std::string v="",bool exp=false) : value(v) , exposed(exp) {}
bool operator==(entry const &other) const
{
return value==other.value && exposed==other.exposed;
}
bool operator!=(entry const &other) const
{
return !(*this==other);
}
};
typedef std::map<std::string,entry> data_t;
data_t data,data_copy;
worker_thread &worker;
// Cached defaults
int timeout_val_def;
int how_def;
// User Values
int timeout_val;
int how;
// Information from session data
time_t timeout_in;
bool new_session;
int cookie_age();
time_t session_age();
void check();
bool load();
void save();
void update_exposed();
std::string temp_cookie;
boost::shared_ptr<session_api> storage;
void set_session_cookie(int64_t age,std::string const &data,std::string const &key=std::string());
void save_data(data_t const &data,std::string &s);
void load_data(data_t &data,std::string const &s);
public:
session_interface(worker_thread &w);
bool is_set(std::string const &key);
void del(std::string const &key);
std::string &operator[](std::string const &);
template<typename T>
T get(std::string const &key) {
return boost::lexical_cast<T>((*this)[key]);
}
template<typename T>
void set(std::string const &key,T const &val) {
(*this)[key]=boost::lexical_cast<std::string>(val);
}
void get(std::string const &key,serializable &);
void set(std::string const &key,serializable const &);
bool is_exposed(std::string const &key);
void expose(std::string const &key,bool val=true);
void hide(std::string const &key);
void clear();
enum { fixed, renew, browser };
void set_age(int t);
void set_expiration(int h);
void set_age();
void set_expiration();
// Special interface
void set_session_cookie(std::string const &data);
void clear_session_cookie();
std::string get_session_cookie();
void set_api(boost::shared_ptr<session_api>);
void on_start();
void on_end();
worker_thread &get_worker();
};
} // cppcms
#endif
MongoDB Logo MongoDB