session#

Simple session manager.

The purpose of this session manager is to maintain global states. This library supports multiple sessions, but may also be used when you only want to maintain a single global state. In this case, use session_get_default() instead of session_create().

Creating, freeing and accessing sessions

Session *session_create(const char *session_id)#

Create a new session with given session_id.

Returns:

Pointer to the session or NULL on error.

void session_free(Session *s)#

Free all memory associated with session.

Session *session_get(const char *session_id)#

Retrieve session from session_id.

Returns:

Pointer to the session or NULL if no session exists with this id.

const char *session_get_id(Session *s)#

Retrive session id from session pointer.

Returns:

Session id or NULL on error.

Accessing and setting default session

Useful these functions to maintain a single global state.

Session *session_get_default(void)#

Retrieve default session.

A new default session will transparently be created if it does not already exists.

Returns:

Pointer to default session or NULL on error.

int session_set_default(Session *s)#

Set default session.

It is an error if a default session already exists which differs from s.

Returns:

Non-zero on error.

Setting and accessing global states

Useful these functions to maintain a single global state.

int session_add_state(Session *s, const char *name, void *ptr, void (*free_fun)(void *ptr))#

Add new global state.

Parameters:
  • s – Pointer to session

  • name – A new unique name associated with the state

  • ptr – Pointer to state data

  • free_fun – Pointer to function that free state data

Returns:

Non-zero on error.

int session_remove_state(Session *s, const char *name)#

Remove global state with given name.

name must refer to an existing state.

Returns:

Non-zero on error.

void *session_get_state(Session *s, const char *name)#

Retrieve global state corresponding to name

Returns:

Pointer to global state or NULL if no state with this name exists.

void session_dump(void)#

Dump a listing of all sessions to stdout. For debugging

Typedefs

typedef struct _Session Session#

Opaque session type.