Apache HTTPD
Macros | Functions | Variables
mod_session.c File Reference
#include "mod_session.h"
#include "apr_lib.h"
#include "apr_strings.h"
#include "util_filter.h"
#include "http_log.h"
#include "http_request.h"
#include "http_protocol.h"

Go to the source code of this file.

Macros

#define SESSION_EXPIRY   "expiry"
 
#define HTTP_SESSION   "HTTP_SESSION"
 

Functions

void ap_hook_session_load (ap_HOOK_session_load_t *pf, const char *const *aszPre, const char *const *aszSucc, int nOrder)
 
apr_array_header_tap_hook_get_session_load (void)
 
int ap_run_session_load (request_rec *r, session_rec **z)
 
void ap_hook_session_save (ap_HOOK_session_save_t *pf, const char *const *aszPre, const char *const *aszSucc, int nOrder)
 
apr_array_header_tap_hook_get_session_save (void)
 
int ap_run_session_save (request_rec *r, session_rec *z)
 
void ap_hook_session_encode (ap_HOOK_session_encode_t *pf, const char *const *aszPre, const char *const *aszSucc, int nOrder)
 
apr_array_header_tap_hook_get_session_encode (void)
 
int ap_run_session_encode (request_rec *r, session_rec *z)
 
void ap_hook_session_decode (ap_HOOK_session_decode_t *pf, const char *const *aszPre, const char *const *aszSucc, int nOrder)
 
apr_array_header_tap_hook_get_session_decode (void)
 
int ap_run_session_decode (request_rec *r, session_rec *z)
 
static int session_identity_encode (request_rec *r, session_rec *z)
 
static int session_identity_decode (request_rec *r, session_rec *z)
 
static int session_fixups (request_rec *r)
 
static int session_included (request_rec *r, session_dir_conf *conf)
 
static apr_status_t ap_session_load (request_rec *r, session_rec **z)
 
static apr_status_t ap_session_save (request_rec *r, session_rec *z)
 
static apr_status_t ap_session_get (request_rec *r, session_rec *z, const char *key, const char **value)
 
static apr_status_t ap_session_set (request_rec *r, session_rec *z, const char *key, const char *value)
 
static int identity_count (void *v, const char *key, const char *val)
 
static int identity_concat (void *v, const char *key, const char *val)
 
static apr_status_t session_output_filter (ap_filter_t *f, apr_bucket_brigade *in)
 
static void session_insert_output_filter (request_rec *r)
 
static void * create_session_dir_config (apr_pool_t *p, char *dummy)
 
static void * merge_session_dir_config (apr_pool_t *p, void *basev, void *addv)
 
static const charset_session_enable (cmd_parms *parms, void *dconf, int flag)
 
static const charset_session_maxage (cmd_parms *parms, void *dconf, const char *arg)
 
static const charset_session_header (cmd_parms *parms, void *dconf, const char *arg)
 
static const charset_session_env (cmd_parms *parms, void *dconf, int flag)
 
static const charadd_session_include (cmd_parms *cmd, void *dconf, const char *f)
 
static const charadd_session_exclude (cmd_parms *cmd, void *dconf, const char *f)
 
static const charset_session_expiry_update (cmd_parms *parms, void *dconf, const char *arg)
 
static void register_hooks (apr_pool_t *p)
 

Variables

struct { 
 
   apr_array_header_t *   link_session_load 
 
   apr_array_header_t *   link_session_save 
 
   apr_array_header_t *   link_session_encode 
 
   apr_array_header_t *   link_session_decode 
 
_hooks 
 
static const command_rec session_cmds []
 
static int *const aplog_module_index = &( session_module.module_index)
 

Macro Definition Documentation

◆ HTTP_SESSION

#define HTTP_SESSION   "HTTP_SESSION"

Definition at line 26 of file mod_session.c.

◆ SESSION_EXPIRY

#define SESSION_EXPIRY   "expiry"

Definition at line 25 of file mod_session.c.

Function Documentation

◆ add_session_exclude()

static const char * add_session_exclude ( cmd_parms cmd,
void *  dconf,
const char f 
)
static

Definition at line 637 of file mod_session.c.

◆ add_session_include()

static const char * add_session_include ( cmd_parms cmd,
void *  dconf,
const char f 
)
static

Definition at line 627 of file mod_session.c.

◆ ap_session_get()

static apr_status_t ap_session_get ( request_rec r,
session_rec z,
const char key,
const char **  value 
)
static

Get a particular value from the session.

Parameters
rThe current request.
zThe current session. If this value is NULL, the session will be looked up in the request, created if necessary, and saved to the request notes.
keyThe key to get.
valueThe buffer to write the value to.

< Module has handled this stage.

Definition at line 267 of file mod_session.c.

◆ ap_session_load()

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

Load the session.

If the session doesn't exist, a blank one will be created.

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

< Module declines to handle

< Module has handled this stage.

< Module has handled this stage.

Definition at line 91 of file mod_session.c.

◆ ap_session_save()

static apr_status_t ap_session_save ( request_rec r,
session_rec z 
)
static

Save the session.

In most implementations the session is only saved if the dirty flag is true. This prevents the session being saved unnecessarily.

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

< Module has handled this stage.

< Module declines to handle

< Module has handled this stage.

Definition at line 180 of file mod_session.c.

◆ ap_session_set()

static apr_status_t ap_session_set ( request_rec r,
session_rec z,
const char key,
const char value 
)
static

Set a particular value to the session.

Using this method ensures that the dirty flag is set correctly, so that the session can be saved efficiently.

Parameters
rThe current request.
zThe current session. If this value is NULL, the session will be looked up in the request, created if necessary, and saved to the request notes.
keyThe key to set. The existing key value will be replaced.
valueThe value to set.

Definition at line 296 of file mod_session.c.

◆ create_session_dir_config()

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

Definition at line 547 of file mod_session.c.

◆ identity_concat()

static int identity_concat ( void *  v,
const char key,
const char val 
)
static

Definition at line 326 of file mod_session.c.

◆ identity_count()

static int identity_count ( void *  v,
const char key,
const char val 
)
static

Definition at line 318 of file mod_session.c.

◆ merge_session_dir_config()

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

Definition at line 558 of file mod_session.c.

◆ register_hooks()

static void register_hooks ( apr_pool_t p)
static

Definition at line 683 of file mod_session.c.

◆ session_fixups()

static int session_fixups ( request_rec r)
static

Fixups hook.

Load the session within a fixup - this ensures that the session is properly loaded prior to the handler being called.

The fixup is also responsible for injecting the session into the CGI environment, should the admin have configured it so.

Parameters
rThe request

< Module has handled this stage.

Definition at line 518 of file mod_session.c.

◆ session_identity_decode()

static apr_status_t session_identity_decode ( request_rec r,
session_rec z 
)
static

Default identity decoding for the session.

By default, the name value pairs in the session are URLEncoded, separated by equals, and then in turn separated by ampersand, in the format of an html form.

This was chosen to make it easy for external code to unpack a session, should there be a need to do so.

This function reverses that process, and populates the session table.

Name / value pairs that are not encoded properly are ignored.

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

< Module has handled this stage.

< Module has handled this stage.

Definition at line 391 of file mod_session.c.

◆ session_identity_encode()

static apr_status_t session_identity_encode ( request_rec r,
session_rec z 
)
static

Default identity encoding for the session.

By default, the name value pairs in the session are URLEncoded, separated by equals, and then in turn separated by ampersand, in the format of an html form.

This was chosen to make it easy for external code to unpack a session, should there be a need to do so.

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

< Module has handled this stage.

Definition at line 357 of file mod_session.c.

◆ session_included()

static int session_included ( request_rec r,
session_dir_conf conf 
)
static

Should the session be included within this URL.

This function tests whether a session is valid for this URL. It uses the include and exclude arrays to determine whether they should be included.

Definition at line 53 of file mod_session.c.

◆ session_insert_output_filter()

static void session_insert_output_filter ( request_rec r)
static

Insert the output filter.

Definition at line 502 of file mod_session.c.

◆ session_output_filter()

static apr_status_t session_output_filter ( ap_filter_t f,
apr_bucket_brigade in 
)
static

Ensure any changes to the session are committed.

This is done in an output filter so that our options for where to store the session can include storing the session within a cookie: As an HTTP header, the cookie must be set before the output is written, but after the handler is run.

NOTE: It is possible for internal redirects to cause more than one request to be present, and each request might have a session defined. We need to go through each session in turn, and save each one.

The same session might appear in more than one request. The first attempt to save the session will be called

Definition at line 447 of file mod_session.c.

◆ set_session_enable()

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

Definition at line 584 of file mod_session.c.

◆ set_session_env()

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

Definition at line 617 of file mod_session.c.

◆ set_session_expiry_update()

static const char * set_session_expiry_update ( cmd_parms parms,
void *  dconf,
const char arg 
)
static

Definition at line 648 of file mod_session.c.

◆ set_session_header()

static const char * set_session_header ( cmd_parms parms,
void *  dconf,
const char arg 
)
static

Definition at line 606 of file mod_session.c.

◆ set_session_maxage()

static const char * set_session_maxage ( cmd_parms parms,
void *  dconf,
const char arg 
)
static

Definition at line 595 of file mod_session.c.

Variable Documentation

◆ [struct]

struct { ... } _hooks

◆ aplog_module_index

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

Definition at line 702 of file mod_session.c.

◆ link_session_decode

apr_array_header_t* link_session_decode

Definition at line 33 of file mod_session.c.

◆ link_session_encode

apr_array_header_t* link_session_encode

Definition at line 33 of file mod_session.c.

◆ link_session_load

apr_array_header_t* link_session_load

Definition at line 33 of file mod_session.c.

◆ link_session_save

apr_array_header_t* link_session_save

Definition at line 33 of file mod_session.c.

◆ session_cmds

const command_rec session_cmds[]
static
Initial value:
=
{
{ "Session" , set_session_enable , NULL , 128 | 8 , FLAG, "on if a session should be maintained for these URLs" },
{ "SessionMaxAge" , set_session_maxage , NULL , 128 | 8 , TAKE1, "length of time for which a session should be valid. Zero to disable" },
{ "SessionHeader" , set_session_header , NULL , 128 | 8 , TAKE1, "output header, if present, whose contents will be injected into the session." },
{ "SessionEnv" , set_session_env , NULL , 128 | 8 , FLAG, "on if a session should be written to the CGI environment. Defaults to off" },
{ "SessionInclude" , add_session_include , NULL , 128 | 8 , TAKE1, "URL prefixes to include in the session. Defaults to all URLs" },
{ "SessionExclude" , add_session_exclude , NULL , 128 | 8 , TAKE1, "URL prefixes to exclude from the session. Defaults to no URLs" },
{ "SessionExpiryUpdateInterval" , set_session_expiry_update , NULL , 128 | 8 , TAKE1, "time interval for which a session's expiry time may change " "without having to be rewritten. Zero to disable" },
{NULL}
}
@ TAKE1
Definition http_config.h:51
@ FLAG
Definition http_config.h:59
static const char * add_session_exclude(cmd_parms *cmd, void *dconf, const char *f)
static const char * set_session_env(cmd_parms *parms, void *dconf, int flag)
static const char * set_session_enable(cmd_parms *parms, void *dconf, int flag)
static const char * set_session_expiry_update(cmd_parms *parms, void *dconf, const char *arg)
static const char * set_session_maxage(cmd_parms *parms, void *dconf, const char *arg)
static const char * set_session_header(cmd_parms *parms, void *dconf, const char *arg)
static const char * add_session_include(cmd_parms *cmd, void *dconf, const char *f)
return NULL
Definition mod_so.c:359

Definition at line 663 of file mod_session.c.