Apache HTTPD
Classes | Macros | Functions | Variables
mod_session_dbd.c File Reference
#include "mod_session.h"
#include "apr_lib.h"
#include "apr_strings.h"
#include "http_log.h"
#include "util_cookies.h"
#include "apr_dbd.h"
#include "mod_dbd.h"
#include "mpm_common.h"

Go to the source code of this file.

Classes

struct  session_dbd_dir_conf
 

Macros

#define MOD_SESSION_DBD   "mod_session_dbd"
 

Functions

static apr_status_t dbd_init (request_rec *r, const char *query, ap_dbd_t **dbdp, apr_dbd_prepared_t **statementp)
 
static apr_status_t dbd_load (apr_pool_t *p, request_rec *r, const char *key, const char **val)
 
static apr_status_t session_dbd_load (request_rec *r, session_rec **z)
 
static apr_status_t dbd_save (request_rec *r, const char *oldkey, const char *newkey, const char *val, apr_int64_t expiry)
 
static apr_status_t dbd_remove (request_rec *r, const char *key)
 
static apr_status_t dbd_clean (apr_pool_t *p, server_rec *s)
 
static apr_status_t session_dbd_save (request_rec *r, session_rec *z)
 
static int session_dbd_monitor (apr_pool_t *p, server_rec *s)
 
static void * create_session_dbd_dir_config (apr_pool_t *p, char *dummy)
 
static void * merge_session_dbd_dir_config (apr_pool_t *p, void *basev, void *addv)
 
static const charcheck_string (cmd_parms *cmd, const char *string)
 
static const charset_dbd_peruser (cmd_parms *parms, void *dconf, int flag)
 
static const charset_dbd_cookie_remove (cmd_parms *parms, void *dconf, int flag)
 
static const charset_cookie_name (cmd_parms *cmd, void *config, const char *args)
 
static const charset_cookie_name2 (cmd_parms *cmd, void *config, const char *args)
 
static void register_hooks (apr_pool_t *p)
 

Variables

static ap_dbd_t *(* session_dbd_acquire_fn )(request_rec *) = NULL
 
static void(* session_dbd_prepare_fn )(server_rec *, const char *, const char *) = NULL
 
static const command_rec session_dbd_cmds []
 
static int *const aplog_module_index = &( session_dbd_module.module_index)
 

Macro Definition Documentation

◆ MOD_SESSION_DBD

#define MOD_SESSION_DBD   "mod_session_dbd"

Definition at line 26 of file mod_session_dbd.c.

Function Documentation

◆ check_string()

static const char * check_string ( cmd_parms cmd,
const char string 
)
static

Sanity check a given string that it exists, is not empty, and does not contain special characters.

Definition at line 536 of file mod_session_dbd.c.

◆ create_session_dbd_dir_config()

static void * create_session_dbd_dir_config ( apr_pool_t p,
char dummy 
)
static

Definition at line 493 of file mod_session_dbd.c.

◆ dbd_clean()

static apr_status_t dbd_clean ( apr_pool_t p,
server_rec s 
)
static

Clean out expired sessions.

TODO: We need to figure out a way to clean out expired sessions from the database. The monitor hook doesn't help us that much, as we have no handle into the server, and so we need to come up with a way to do this safely.

Definition at line 383 of file mod_session_dbd.c.

◆ dbd_init()

static apr_status_t dbd_init ( request_rec r,
const char query,
ap_dbd_t **  dbdp,
apr_dbd_prepared_t **  statementp 
)
static

Initialise the database.

If the mod_dbd module is missing, this method will return APR_EGENERAL.

Definition at line 59 of file mod_session_dbd.c.

◆ dbd_load()

static apr_status_t dbd_load ( apr_pool_t p,
request_rec r,
const char key,
const char **  val 
)
static

Load the session by the key specified.

The session value is allocated using the passed apr_pool_t.

Definition at line 100 of file mod_session_dbd.c.

◆ dbd_remove()

static apr_status_t dbd_remove ( request_rec r,
const char key 
)
static

Remove the session by the key specified.

Definition at line 339 of file mod_session_dbd.c.

◆ dbd_save()

static apr_status_t dbd_save ( request_rec r,
const char oldkey,
const char newkey,
const char val,
apr_int64_t  expiry 
)
static

Save the session by the key specified.

Definition at line 258 of file mod_session_dbd.c.

◆ merge_session_dbd_dir_config()

static void * merge_session_dbd_dir_config ( apr_pool_t p,
void *  basev,
void *  addv 
)
static

Definition at line 508 of file mod_session_dbd.c.

◆ register_hooks()

static void register_hooks ( apr_pool_t p)
static

Definition at line 623 of file mod_session_dbd.c.

◆ session_dbd_load()

static apr_status_t session_dbd_load ( request_rec r,
session_rec **  z 
)
static

Load the session by firing off a dbd query.

If the session is anonymous, the session key will be extracted from the cookie specified. Failing that, the session key will be extracted from the GET parameters.

If the session is keyed by the username, the session will be extracted by that.

If no session is found, an empty session will be created.

On success, this returns OK.

< Module declines to handle

< Module has handled this stage.

< Module declines to handle

< Module has handled this stage.

Definition at line 167 of file mod_session_dbd.c.

◆ session_dbd_monitor()

static int session_dbd_monitor ( apr_pool_t p,
server_rec s 
)
static

This function performs housekeeping on the database, deleting expired sessions.

< Module has handled this stage.

Definition at line 485 of file mod_session_dbd.c.

◆ session_dbd_save()

static apr_status_t session_dbd_save ( request_rec r,
session_rec z 
)
static

Save the session by firing off a dbd query.

If the session is anonymous, save the session and write a cookie containing the uuid.

If the session is keyed to the username, save the session using the username as a key.

On success, this method will return APR_SUCCESS.

Parameters
rThe request pointer.
zA pointer to where the session will be written.

< Module has handled this stage.

< Module has handled this stage.

< Module declines to handle

Definition at line 404 of file mod_session_dbd.c.

◆ set_cookie_name()

static const char * set_cookie_name ( cmd_parms cmd,
void *  config,
const char args 
)
static

Definition at line 568 of file mod_session_dbd.c.

◆ set_cookie_name2()

static const char * set_cookie_name2 ( cmd_parms cmd,
void *  config,
const char args 
)
static

Definition at line 583 of file mod_session_dbd.c.

◆ set_dbd_cookie_remove()

static const char * set_dbd_cookie_remove ( cmd_parms parms,
void *  dconf,
int  flag 
)
static

Definition at line 558 of file mod_session_dbd.c.

◆ set_dbd_peruser()

static const char * set_dbd_peruser ( cmd_parms parms,
void *  dconf,
int  flag 
)
static

Definition at line 547 of file mod_session_dbd.c.

Variable Documentation

◆ aplog_module_index

int* const aplog_module_index = &( session_dbd_module.module_index)
static

Definition at line 630 of file mod_session_dbd.c.

◆ session_dbd_acquire_fn

ap_dbd_t *(* session_dbd_acquire_fn) (request_rec *) ( request_rec ) = NULL
static

Definition at line 51 of file mod_session_dbd.c.

◆ session_dbd_cmds

const command_rec session_dbd_cmds[]
static
Initial value:
=
{
{ "SessionDBDSelectLabel" , ap_set_string_slot , (void *) ((long) (((char *) (&((( session_dbd_dir_conf * )NULL)-> selectlabel ))) - ((char *) NULL))) , 128 | 8 , TAKE1, "Query label used to select a new session" },
{ "SessionDBDInsertLabel" , ap_set_string_slot , (void *) ((long) (((char *) (&((( session_dbd_dir_conf * )NULL)-> insertlabel ))) - ((char *) NULL))) , 128 | 8 , TAKE1, "Query label used to insert a new session" },
{ "SessionDBDUpdateLabel" , ap_set_string_slot , (void *) ((long) (((char *) (&((( session_dbd_dir_conf * )NULL)-> updatelabel ))) - ((char *) NULL))) , 128 | 8 , TAKE1, "Query label used to update an existing session" },
{ "SessionDBDDeleteLabel" , ap_set_string_slot , (void *) ((long) (((char *) (&((( session_dbd_dir_conf * )NULL)-> deletelabel ))) - ((char *) NULL))) , 128 | 8 , TAKE1, "Query label used to delete an existing session" },
{ "SessionDBDPerUser" , set_dbd_peruser , NULL , 128 | 8 , FLAG, "Save the session per user" },
{ "SessionDBDCookieRemove" , set_dbd_cookie_remove , NULL , 128 | 8 , FLAG, "Remove the session cookie after session load. On by default." },
{ "SessionDBDCookieName" , set_cookie_name , NULL , 128 | 8 , RAW_ARGS, "The name of the RFC2109 cookie carrying the session key" },
{ "SessionDBDCookieName2" , set_cookie_name2 , NULL , 128 | 8 , RAW_ARGS, "The name of the RFC2965 cookie carrying the session key" },
{NULL}
}
const char * ap_set_string_slot(cmd_parms *cmd, void *struct_ptr, const char *arg)
Definition config.c:1469
@ RAW_ARGS
Definition http_config.h:50
@ TAKE1
Definition http_config.h:51
@ FLAG
Definition http_config.h:59
static const char * set_dbd_peruser(cmd_parms *parms, void *dconf, int flag)
static const char * set_cookie_name2(cmd_parms *cmd, void *config, const char *args)
static const char * set_dbd_cookie_remove(cmd_parms *parms, void *dconf, int flag)
static const char * set_cookie_name(cmd_parms *cmd, void *config, const char *args)
return NULL
Definition mod_so.c:359

Definition at line 598 of file mod_session_dbd.c.

◆ session_dbd_prepare_fn

void(* session_dbd_prepare_fn) (server_rec *, const char *, const char *) ( server_rec ,
const char ,
const char  
) = NULL
static

Definition at line 52 of file mod_session_dbd.c.