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> 21 #include <booster/auto_ptr_inc.h> 27 struct cached_settings;
72 virtual void set_cookie(
http::cookie const &updated_cookie) = 0;
76 virtual std::string get_session_cookie(std::string
const &name) = 0;
80 virtual std::set<std::string> get_cookie_names() = 0;
130 bool is_set(std::string
const &key);
134 void erase(std::string
const &key);
143 bool is_exposed(std::string
const &key);
148 void expose(std::string
const &key,
bool val=
true);
152 void hide(std::string
const &key);
158 std::string &operator[](std::string
const &key);
162 void set(std::string
const &key,std::string
const &v);
168 std::string
get(std::string
const &key);
173 std::string
get(std::string
const &key,std::string
const &default_value);
185 T
get(std::string
const &key)
187 std::istringstream ss(
get(key));
188 ss.imbue(std::locale::classic());
191 if(ss.fail() || !ss.eof())
202 void set(std::string
const &key,T
const &value)
204 std::ostringstream ss;
205 ss.imbue(std::locale::classic());
215 template<
typename Serializable>
216 void store_data(std::string
const &key,Serializable
const &
object)
231 template<
typename Serializable>
234 std::string buffer=
get(key);
269 void expiration(
int h);
273 void default_expiration();
286 void on_server(
bool srv);
299 void set_session_cookie(std::string
const &data);
305 void clear_session_cookie();
312 std::string get_session_cookie();
349 void reset_session();
359 bool validate_csrf_token(std::string
const &str);
368 void validate_request_origin();
384 void request_origin_validation_is_required(
bool required);
390 std::string get_csrf_token();
395 std::string get_csrf_token_cookie_name();
401 std::string session_cookie_name();
407 std::set<std::string> key_set();
414 impl::cached_settings
const &cached_settings();
418 typedef std::map<std::string,entry> data_type;
419 data_type data_,data_copy_;
423 int timeout_val_def_;
433 uint32_t new_session_ : 1;
435 uint32_t on_server_ : 1;
436 uint32_t loaded_ : 1;
438 uint32_t csrf_checked_ : 1;
439 uint32_t csrf_do_validation_ : 1;
440 uint32_t csrf_validation_ : 1;
441 uint32_t reserved_ : 24;
443 std::string temp_cookie_;
452 time_t session_age();
455 void update_exposed(
bool);
458 void set_session_cookie(int64_t age,std::string
const &data,std::string
const &key=std::string());
460 void save_data(std::map<std::string,entry>
const &data,std::string &s);
461 void load_data(std::map<std::string,entry> &data,std::string
const &s);
462 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:242
Exception thrown by CppCMS framework.
Definition: cppcms_error.h:22
This exception is thrown when CSRF attempt is suspected:
Definition: session_interface.h:42
This class provides an access to an application for session management.
Definition: session_interface.h:107
This is the namespace where all CppCMS functionality is placed.
Definition: application.h:19
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:47
Definition: session_interface.h:66
This class provides an access to session management backends an allow customization.
Definition: session_pool.h:35
this class represents all HTTP/CGI response related API, generation of output content and HTTP header...
Definition: http_response.h:36
Same as std::bad_cast but records stack trace.
Definition: backtrace.h:151
request_forgery_error()
Create an exception object.
Definition: session_interface.h:45
void store_data(std::string const &key, Serializable const &object)
Definition: session_interface.h:216
void fetch_data(std::string const &key, Serializable &object)
Definition: session_interface.h:232
Class that represents single HTTP Cookie Generally used in context of http::request and http::respons...
Definition: http_cookie.h:27
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:37