8 #ifndef CPPCMS_SESSION_INTERFACE_H
9 #define CPPCMS_SESSION_INTERFACE_H
11 #include <cppcms/defs.h>
12 #include <booster/noncopyable.h>
13 #include <booster/hold_ptr.h>
14 #include <booster/shared_ptr.h>
15 #include <cppcms/cstdint.h>
16 #include <cppcms/cppcms_error.h>
17 #include <cppcms/serialization_classes.h>
80 bool is_set(std::string
const &key);
84 void erase(std::string
const &key);
93 bool is_exposed(std::string
const &key);
98 void expose(std::string
const &key,
bool val=
true);
102 void hide(std::string
const &key);
108 std::string &operator[](std::string
const &key);
112 void set(std::string
const &key,std::string
const &v);
118 std::string
get(std::string
const &key);
123 std::string
get(std::string
const &key,std::string
const &default_value);
135 T
get(std::string
const &key)
137 std::istringstream ss(
get(key));
138 ss.imbue(std::locale::classic());
141 if(ss.fail() || !ss.eof())
142 throw std::bad_cast();
152 void set(std::string
const &key,T
const &value)
154 std::ostringstream ss;
155 ss.imbue(std::locale::classic());
165 template<
typename Serializable>
166 void store_data(std::string
const &key,Serializable
const &
object)
181 template<
typename Serializable>
184 std::string buffer=
get(key);
219 void expiration(
int h);
223 void default_expiration();
236 void on_server(
bool srv);
249 void set_session_cookie(std::string
const &data);
255 void clear_session_cookie();
262 std::string get_session_cookie();
290 void reset_session();
300 bool validate_csrf_token(std::string
const &str);
309 void validate_request_origin();
325 void request_origin_validation_is_required(
bool required);
331 std::string get_csrf_token();
336 std::string get_csrf_token_cookie_name();
346 typedef std::map<std::string,entry> data_type;
347 data_type data_,data_copy_;
351 int timeout_val_def_;
361 uint32_t new_session_ : 1;
363 uint32_t on_server_ : 1;
364 uint32_t loaded_ : 1;
366 uint32_t csrf_checked_ : 1;
367 uint32_t csrf_do_validation_ : 1;
368 uint32_t csrf_validation_ : 1;
369 uint32_t reserved_ : 24;
371 std::string temp_cookie_;
380 time_t session_age();
383 void update_exposed(
bool);
386 void set_session_cookie(int64_t age,std::string
const &data,std::string
const &key=std::string());
388 void save_data(std::map<std::string,entry>
const &data,std::string &s);
389 void load_data(std::map<std::string,entry> &data,std::string
const &s);
390 std::string generate_csrf_token();
Once the session is created it will expire in age() second from the moment it created.
Definition: session_interface.h:192
void set(std::string const &key, T const &value)
Definition: session_interface.h:152
Exception thrown by CppCMS framework.
Definition: cppcms_error.h:22
This exception is thrown when CSRF attempt is suspected:
Definition: session_interface.h:36
This class provides an access to an application for session management.
Definition: session_interface.h:69
static void load(std::string const &serialized_object, Object &real_object)
context is a central class that holds all specific connection related information. It encapsulates CGI request and response, cache, session and locale information
Definition: http_context.h:45
this class represents all HTTP/CGI response related API, generation of output content and HTTP header...
Definition: http_response.h:31
request_forgery_error()
Create an exception object.
Definition: session_interface.h:39
void store_data(std::string const &key, Serializable const &object)
Definition: session_interface.h:166
void fetch_data(std::string const &key, Serializable &object)
Definition: session_interface.h:182
This class makes impossible to copy any class derived from this one.
Definition: noncopyable.h:15
static void save(Object const &real_object, std::string &serialized_object)
This class represents all information related to the HTTP/CGI request.
Definition: http_request.h:34