Granada  1.54.0
Structured layer on top of C++ REST SDK for building server applications in C++. Granada implements sessions, server side plug-in framework, C++ OAuth 2.0 server, data storage access, server script running, server browsing.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
granada::http::session::Session Class Reference

#include <session.h>

Inheritance diagram for granada::http::session::Session:
granada::http::session::MapSession granada::http::session::RedisSession

Public Member Functions

 Session ()
 
 Session (const web::http::http_request &request, web::http::http_response &response)
 
 Session (const web::http::http_request &request)
 
 Session (const std::string &token)
 
virtual ~Session ()
 
virtual void set (const std::string token, const std::time_t update_time)
 
virtual void Open ()
 
virtual void Open (web::http::http_response &response)
 
virtual void Update ()
 
virtual void Close ()
 
virtual const bool IsTimedOut ()
 
virtual const bool IsTimedOut (const long int &extra_seconds)
 
virtual const bool IsValid ()
 
virtual const bool IsGarbage ()
 
virtual const long GetSessionTimeout ()
 
virtual void Write (const std::string &key, const std::string &value)
 
virtual const std::string Read (const std::string &key)
 
virtual void Destroy (const std::string &key)
 
virtual web::json::value to_json ()
 
virtual const std::string & GetToken ()
 
virtual void SetToken (const std::string &token)
 
virtual const std::time_t & GetUpdateTime ()
 
virtual void SetUpdateTime (const std::time_t &update_time)
 
virtual
granada::http::session::SessionRoles
roles ()
 
virtual
granada::http::session::SessionHandler
session_handler ()
 
virtual granada::Functionsclose_callbacks ()
 

Protected Member Functions

virtual void LoadProperties ()
 
virtual const bool LoadSession (const web::http::http_request &request, web::http::http_response &response)
 
virtual const bool LoadSession (const web::http::http_request &request)
 
virtual const bool LoadSession (const std::string &token)
 
virtual const std::string session_data_hash ()
 
virtual const std::string & token_label ()
 
virtual const std::string & application_session_token_support ()
 
virtual const long & application_session_timeout ()
 
virtual const long & session_garbage_extra_timeout ()
 

Protected Attributes

std::string session_token_support_
 
std::string token_
 
std::time_t update_time_
 

Static Protected Attributes

static std::vector< std::string > DEFAULT_SESSIONS_TOKEN_SUPPORT
 
static std::mutex session_exists_mtx_
 
static std::string token_label_
 
static std::string application_session_token_support_
 
static long application_session_timeout_
 
static long session_garbage_extra_timeout_
 

Detailed Description

Abstract Session class that allows to manage session roles. Stores session token in cookies or GET or POST json objects.

Constructor & Destructor Documentation

granada::http::session::Session::Session ( )
inline

Constructor.

granada::http::session::Session::Session ( const web::http::http_request &  request,
web::http::http_response &  response 
)
inline

Constructor. Loads session. Retrieves the token of the session from the HTTP request and loads a session using the session handler. If session does not exist or token is not found a new session is created. If session token is stored in cookies, a cookie will be set in the HTTP response object. This constructor is recommended for sessions that store token in cookie

Parameters
requestHttp request.
responseHttp response.
granada::http::session::Session::Session ( const web::http::http_request &  request)
inline

Constructor. Loads session. Retrieves the token of the session from the HTTP request and loads a session using the session handler. If session does not exist or token is not found a new session is created. This constructor is recommended for sessions that use get and post values.

Parameters
requestHttp request.
granada::http::session::Session::Session ( const std::string &  token)
inline

Constructor. Loads a session with the given token using the session handler. Use this loader if you have the token and you are not using cookies.

Parameters
tokenSession token.
virtual granada::http::session::Session::~Session ( )
inlinevirtual

Destructor

Member Function Documentation

virtual const long& granada::http::session::Session::application_session_timeout ( )
inlineprotectedvirtual

Returns the time in seconds that has to pass since the last session use until the session is usable.

Returns
The time in seconds that has to pass since the last session use until the session is usable.
virtual const std::string& granada::http::session::Session::application_session_token_support ( )
inlineprotectedvirtual

Returns where the session token is stored: cookie || query || json by default.

Returns
Where the session token is stored: cookie || query || json by default.
virtual void granada::http::session::Session::Close ( )
virtual

Closes a session deleting it. And call all the close callback functions.

virtual granada::Functions* granada::http::session::Session::close_callbacks ( )
inlinevirtual

Returns a pointer to the collection of functions that are called when closing the session.

Returns
Pointer to the collection of functions that are called when session is closed.

Reimplemented in granada::http::session::MapSession, and granada::http::session::RedisSession.

virtual void granada::http::session::Session::Destroy ( const std::string &  key)
virtual

Destroy session data with given key.

Parameters
keyData key or name.
virtual const long granada::http::session::Session::GetSessionTimeout ( )
virtual

Returns the number of seconds the session is valid before it times out when not used.

Returns
Timeout in seconds.
virtual const std::string& granada::http::session::Session::GetToken ( )
inlinevirtual

Returns the session unique token.

Returns
token
virtual const std::time_t& granada::http::session::Session::GetUpdateTime ( )
inlinevirtual

Returns the last modification time.

Returns
Last modification time.
virtual const bool granada::http::session::Session::IsGarbage ( )
virtual

Returns true if the session is a garbage session, false if it is not. A garbage session is different from a not valid session. A session may not be valid but we still don't want to delete it immediately. Maybe we want to delete it after it has been timed out for three hours or when other conditions are true. This function is called by the functions that "clean" sessions from wherever they are stored.

Returns
true is session is garbage, false if it is not.
virtual const bool granada::http::session::Session::IsTimedOut ( )
virtual

Returns true if the session is timed out, false if it is not.

Returns
true | false.
virtual const bool granada::http::session::Session::IsTimedOut ( const long int &  extra_seconds)
virtual

Returns true if the session is timed out since the given extra seconds, false if it is not.

Parameters
extra_seconds
Returns
true | false
virtual const bool granada::http::session::Session::IsValid ( )
virtual

Returns true if the session is valid, false if it is not. The base session will only check if the session is timed out, but this function may be overriden if we need to add other validity factors.

Returns
true if session is valid, false if it is not.
virtual void granada::http::session::Session::LoadProperties ( )
protectedvirtual

Method that loads the session properties: token label, token support, session timout...

virtual const bool granada::http::session::Session::LoadSession ( const web::http::http_request &  request,
web::http::http_response &  response 
)
protectedvirtual

Loads session. Retrieves the token of the session from the HTTP request and loads a session using the session handler. If session does not exist or token is not found a new session is created. This loader is recommended for sessions that store token in cookie

Parameters
requestHttp request.
responseHttp response.
Returns
True if session has been retrieved or created successfuly.
virtual const bool granada::http::session::Session::LoadSession ( const web::http::http_request &  request)
protectedvirtual

Loads session. Retrieves the token of the session from the HTTP request and loads a session using the session handler. If session does not exist or token is not found a new session is created. This loader is recommended for sessions that use get and post values.

Parameters
requestHttp request.
Returns
True if session has been retrieved or created successfuly.
virtual const bool granada::http::session::Session::LoadSession ( const std::string &  token)
protectedvirtual

Loads a session with the given token using the session handler. Use this loader if you have the token and you are not using cookies.

Parameters
tokenSession token.
Returns
True if session has been retrieved successfuly.
virtual void granada::http::session::Session::Open ( )
virtual

Opens a new session with a unique token.

virtual void granada::http::session::Session::Open ( web::http::http_response &  response)
virtual

Opens a new session with a unique token and if session token support is a cookie it stores the token value in a cookie.

Parameters
responseResponse to store the cookie with the session token.
virtual const std::string granada::http::session::Session::Read ( const std::string &  key)
virtual

Read session data.

Parameters
keyKey or name of the data.
Returns
Data as string.
virtual granada::http::session::SessionRoles* granada::http::session::Session::roles ( )
inlinevirtual

Returns a pointer to the roles of a session.

Returns
Pointer to the roles of the session.

Reimplemented in granada::http::session::MapSession, and granada::http::session::RedisSession.

virtual const std::string granada::http::session::Session::session_data_hash ( )
inlineprotectedvirtual

Returns the key to identify the session data in the cache.

virtual const long& granada::http::session::Session::session_garbage_extra_timeout ( )
inlineprotectedvirtual

Returns the number of seconds that needs to pass after a session is timed out to be considered garbage.

virtual granada::http::session::SessionHandler* granada::http::session::Session::session_handler ( )
inlinevirtual

Returns the pointer of Session Handler that manages the session.

Returns
Session Handler.

Reimplemented in granada::http::session::MapSession, and granada::http::session::RedisSession.

virtual void granada::http::session::Session::set ( const std::string  token,
const std::time_t  update_time 
)
inlinevirtual

Set the value of the sessions, may be overriden in case we want to make other actions.

Parameters
tokenSession token.
update_timeSession update time.
virtual void granada::http::session::Session::SetToken ( const std::string &  token)
inlinevirtual

Sets the session unique token.

virtual void granada::http::session::Session::SetUpdateTime ( const std::time_t &  update_time)
inlinevirtual

Sets the last modification time.

virtual web::json::value granada::http::session::Session::to_json ( )
virtual

Returns the session in a JSON object format.

Returns
Session in form of JSON object. Example:
{
"token" : "cc9sKWG6PbhwyhP3EuBq8Fgve7ZycsRplduswcKIDwDuyrQ2jySsYG1v7gq1Vecf",
"update_time" : "6346464"
"timeout" : "123456789"
}
virtual const std::string& granada::http::session::Session::token_label ( )
inlineprotectedvirtual

Returns the label of the token. It is used for example when a token has to be extracted from a cookie.

Returns
Label of the token.
virtual void granada::http::session::Session::Update ( )
virtual

Updates a session, updating the session update time to now and saving it. That means the session will timeout in now + timeout. It will keep the session alive.

virtual void granada::http::session::Session::Write ( const std::string &  key,
const std::string &  value 
)
virtual

Write session data.

Parameters
keyKey or name of the data.
valueData as string.

Member Data Documentation

long granada::http::session::Session::application_session_timeout_
staticprotected

Time in seconds that has to pass since the last session use until the session is usable. This value is taken from the "session_timeout" property of the server.conf file. If no value is indicated the value will be taken from the "session_timeout" property in defaults.dat

std::string granada::http::session::Session::application_session_token_support_
staticprotected

Where the session token is stored: cookie || query || json by default. This value is taken from the "session_token_support" property of the server.conf file. If no value is indicated the value will be taken from the "session_token_support" property in defaults.dat

std::vector<std::string> granada::http::session::Session::DEFAULT_SESSIONS_TOKEN_SUPPORT
staticprotected

Default token support, cookie || query || json. Where the token will be stored-retrieved in the client-side. This default value is taken in case "session_token_support" property is not found.

std::mutex granada::http::session::Session::session_exists_mtx_
staticprotected

Mutex used when performing an action after checking that a session exists, for example when opening a session.

long granada::http::session::Session::session_garbage_extra_timeout_
staticprotected

Number of seconds that needs to pass after a session is timed out to be considered garbage. in the "session_garbage_extra_timeout" property If no property indicated, it will take default_numbers::session_session_garbage_extra_timeout.

std::string granada::http::session::Session::session_token_support_
protected

Where the session token is stored: cookie || query || json for this session. It can be different from the application_session_token_support_

std::string granada::http::session::Session::token_
protected

Session token: Unique identifier of the session.

std::string granada::http::session::Session::token_label_
staticprotected

The name of the cookie or the key where the token value is stored. This value is taken from the "session_token_label" property of the server.conf file. If no value is indicated the value will be taken from the "session_token_label" property in defaults.dat

std::time_t granada::http::session::Session::update_time_
protected

Last time we have used the session.


The documentation for this class was generated from the following file: