libonion
|
Data Structures | |
struct | onion_sessions_t |
Storage for all sessions knownThis is a simple storage for sessions. More... |
Functions | |
void | onion_sessions_save (onion_sessions *sessions, const char *sessionId, onion_dict *data) |
Ensures the content of the dict is saved to that sessionOn memory backend does nothing, on other backends may do the marshalling. | |
onion_sessions * | onion_sessions_mem_new () |
Creates a inmem backend for sessionsThis is the default and less interesting of the session backends. | |
onion_sessions * | onion_sessions_redis_new (const char *server_ip, int port) |
Creates a redis backend for sessions. | |
onion_sessions * | onion_sessions_sqlite3_new (const char *database_filename) |
Creates a sqlite backend for sessions. | |
char * | onion_sessions_t::onion_sessions_generate_id () |
Generates a unique id. | |
onion_sessions * | onion_sessions_t::onion_sessions_new () |
Creates a sessions data object, which keeps all sessions in memory. | |
void | onion_sessions_t::onion_sessions_free (onion_sessions *sessions) |
Frees the memory used by sessions. | |
char * | onion_sessions_t::onion_sessions_create (onion_sessions *sessions) |
Creates a new session and returns the sessionId. | |
onion_dict * | onion_sessions_t::onion_sessions_get (onion_sessions *sessions, const char *sessionId) |
Returns a session dictionary. |
char * onion_sessions_create | ( | onion_sessions * | sessions | ) |
Creates a new session and returns the sessionId.
References ONION_DEBUG, onion_dict_t::onion_dict_free(), onion_dict_t::onion_dict_new(), onion_sessions_t::onion_sessions_generate_id(), and onion_sessions_t::save.
Referenced by onion_request_t::onion_request_get_session_dict().
void onion_sessions_free | ( | onion_sessions * | sessions | ) |
Frees the memory used by sessions.
References onion_sessions_t::free, and onion_random_free().
Referenced by onion_free(), and onion_set_session_backend().
char * onion_sessions_generate_id | ( | ) |
Generates a unique id.
This unique id is also dificult to guess, so that blind guessing will not work.
Just now random 32 bytes string with alphanum chars. Not really safe as using simple C rand.
The memory is malloc'ed and will be freed somewhere.
References onion_low_scalar_malloc(), and onion_random_generate().
Referenced by onion_sessions_t::onion_sessions_create().
onion_dict * onion_sessions_get | ( | onion_sessions * | sessions, |
const char * | sessionId | ||
) |
Returns a session dictionary.
It returns a dupped (ref counter ++) version of the dict. All modifications are straight here, but user (normally onion_request) must dereference it.. as it really do.
This is this way to prevent a thread removing the dict, whilst others are using it. to really remove the dict, call onion_sessions_remove, which will remove the reference here, which is the only one which should stay across thread lifetimes.
The sessionId is the session as asked by the client. If it does not exist it returns NULL, and onion_sessions_create has to be used. It used to reuse the sessionId if it doe snot exist, but that looks like an insecure pattern.
References onion_sessions_t::get.
Referenced by onion_request_t::onion_request_get_session_dict(), and onion_request_t::onion_request_guess_session_id().
onion_sessions* onion_sessions_mem_new | ( | ) |
Creates a inmem backend for sessionsThis is the default and less interesting of the session backends.
References onion_sessions_t::data, onion_sessions_t::free, onion_sessions_t::get, onion_dict_t::onion_dict_new(), onion_low_malloc(), onion_random_init(), and onion_sessions_t::save.
Referenced by onion_sessions_t::onion_sessions_new().
onion_sessions * onion_sessions_new | ( | ) |
Creates a sessions data object, which keeps all sessions in memory.
TODO: Make it also to allow persistent storage: for example if sqlite is available.
References onion_sessions_mem_new().
Referenced by onion_new().
onion_sessions* onion_sessions_redis_new | ( | const char * | server_ip, |
int | port | ||
) |
Creates a redis backend for sessions.
References onion_session_redis_t::context, onion_sessions_t::data, onion_sessions_t::free, onion_sessions_t::get, ONION_ERROR, onion_low_malloc(), onion_random_init(), onion_sessions_redis_save(), pthread_mutex_init, and onion_sessions_t::save.
void onion_sessions_save | ( | onion_sessions * | sessions, |
const char * | sessionId, | ||
onion_dict * | data | ||
) |
Ensures the content of the dict is saved to that sessionOn memory backend does nothing, on other backends may do the marshalling.
Store session.
References onion_sessions_t::save.
Referenced by onion_request_t::onion_request_clean(), and onion_request_t::onion_request_free().
onion_sessions* onion_sessions_sqlite3_new | ( | const char * | database_filename | ) |
Creates a sqlite backend for sessions.
References onion_sessions_t::data, onion_session_sqlite3_t::db, onion_sessions_t::free, onion_session_sqlite3_t::get, onion_sessions_t::get, ONION_ERROR, onion_low_malloc(), onion_random_init(), onion_sessions_sqlite3_save(), pthread_mutex_init, onion_session_sqlite3_t::save, and onion_sessions_t::save.