# qDecoder API Reference

- Main Page
- Data Structures
- Files

- File List
- Globals

Macros | Functions
qcgisess.c File Reference

## Detailed Description

CGI Session API.

## Macros
#define | SESSION_DEFAULT_REPOSITORY "/tmp"
#define | SESSION_ID "QSESSIONID"
#define | SESSION_PREFIX "qsession-"
#define | SESSION_STORAGE_EXTENSION ".properties"
#define | SESSION_TIMEOUT_EXTENSION ".expire"
#define | SESSION_TIMETOCLEAR_FILENAME "qsession-timetoclear"
#define | SESSION_DEFAULT_TIMEOUT_INTERVAL (30 * 60)

## Functions
qentry_t * | qcgisess_init (qentry_t *request, const char *dirpath)
| Initialize session.
bool | qcgisess_settimeout (qentry_t *session, time_t seconds)
| Set the auto-expiration seconds about user session.
const char * | qcgisess_getid (qentry_t *session)
| Get user session id.
time_t | qcgisess_getcreated (qentry_t *session)
| Get user session created time.
bool | qcgisess_save (qentry_t *session)
| Update session data.
bool | qcgisess_destroy (qentry_t *session)
| Destroy user session.

## Function Documentation

qentry_t* qcgisess_init | ( | qentry_t * | request,
|  | const char * | dirpath
| ) |  |

Initialize session.

Parameters

  request | a pointer of request structure returned by qcgireq_parse()
  dirpath | directory path where session data will be kept

Returns
  a pointer of malloced session data list (qentry_t type)

Note
  The returned qentry_t list must be de-allocated by calling qentry_t->free(). And if you want to append or remove some user session data, use qentry_t->*() functions then finally call qcgisess_save() to store updated session data.

bool qcgisess_settimeout | ( | qentry_t * | session,
|  | time_t | seconds
| ) |  |

Set the auto-expiration seconds about user session.

Parameters

  session | a pointer of session structure
  seconds | expiration seconds

Returns
  true if successful, otherwise returns false

Note
  Default timeout is defined as SESSION_DEFAULT_TIMEOUT_INTERVAL. 1800 seconds

const char* qcgisess_getid | ( | qentry_t * | session | ) |

Get user session id.

Parameters

  session | a pointer of session structure

Returns
  a pointer of session identifier

Note
  Do not free manually

time_t qcgisess_getcreated | ( | qentry_t * | session | ) |

Get user session created time.

Parameters

  session | a pointer of session structure

Returns
  user session created time in UTC time seconds

bool qcgisess_save | ( | qentry_t * | session | ) |

Update session data.

Parameters

  session | a pointer of session structure

Returns
  true if successful, otherwise returns false

bool qcgisess_destroy | ( | qentry_t * | session | ) |

Destroy user session.

Parameters

  session | a pointer of session structure

Returns
  true if successful, otherwise returns false

Note
  If you only want to de-allocate session structure, just call qentry_t->free(). This will remove all user session data permanantely and also free the session structure.