The qDecoder Project

qCgiResponse.c File Reference

CGI Cookie Handling API. More…


Functions

bool qCgiResponseSetCookie (Q_ENTRY *request, const char *name, const char *value, int expire, const char *path, const char *domain, bool secure)
 Set cookie.
bool qCgiResponseRemoveCookie (Q_ENTRY *request, const char *name, const char *path, const char *domain, bool secure)
 Remove cookie.
bool qCgiResponseSetContentType (Q_ENTRY *request, const char *mimetype)
 Set responding content-type.
const char * qCgiResponseGetContentType (Q_ENTRY *request)
 Get content-type.
bool qCgiResponseRedirect (Q_ENTRY *request, const char *uri)
 Send redirection header.
int qCgiResponseDownload (Q_ENTRY *request, const char *filepath, const char *mimetype)
 Force to send(download) file to client in accordance with given mime type.
void qCgiResponseError (Q_ENTRY *request, char *format,…)
 Generate and print out HTML error page.


Detailed Description

CGI Cookie Handling API.


Function Documentation

bool qCgiResponseSetCookie ( Q_ENTRY request,
const char *  name,
const char *  value,
int  expire,
const char *  path,
const char *  domain,
bool  secure 
)

Set cookie.

Parameters:
request a pointer of request structure
name cookie name
value cookie value
expire expire related time in seconds (0 means end of session)
path cookie path (NULL can current path)
domain cookie domain (NULL means current domain)
secure secure flag
Returns:
true in case of success, otherwise returns false
   // Apply cookie in the current domain and directory for 1 day.
   qCgiResponseSetCookie(req, "NAME", "qDecoder", 86400, NULL, NULL, false);
   // Apply cookie to the "/" directory of "*.qdecoder.org" until the
   // browser is closed.
   qCgiResponseSetCookie(req, name, value, 0, "/", ".qdecoder.org", false);
   // As for the followings, cookies will be set up only when security
   // requirements are satisfied.
   qCgiResponseSetCookie(req, name, value, 0, NULL, NULL, true);

bool qCgiResponseRemoveCookie ( Q_ENTRY request,
const char *  name,
const char *  path,
const char *  domain,
bool  secure 
)

Remove cookie.

Parameters:
request a pointer of request structure
name cookie name
path cookie path
domain cookie domain
secure secure flag
Returns:
true in case of success, otherwise returns false
   qCgiResponseSetCookie(req, "NAME", "VALUE", 0, NULL, NULL, NULL);
   qCgiResponseRemoveCookie(req, "NAME", NULL, NULL, NULL);
   qCgiResponseSetCookie(req, "NAME", "VALUE", 0, "/", "www.qdecoder.org", NULL);
   qCgiResponseRemoveCookie(req, "NAME", "/", "www.qdecoder.org", NULL);

bool qCgiResponseSetContentType ( Q_ENTRY request,
const char *  mimetype 
)

Set responding content-type.

Parameters:
request a pointer of request structure
mimetype mimetype
Returns:
true in case of success, otherwise returns false
   qCgiResponseSetContentType(req, "text/html");

const char* qCgiResponseGetContentType ( Q_ENTRY request  ) 

Get content-type.

Parameters:
request a pointer of request structure
Returns:
a pointer of mimetype string in case of success, otherwise returns NULL
   qCgiResponseSetContentType(req, "text/html");

bool qCgiResponseRedirect ( Q_ENTRY request,
const char *  uri 
)

Send redirection header.

Parameters:
request a pointer of request structure
uri new URI
Returns:
true in case of success, otherwise returns false

int qCgiResponseDownload ( Q_ENTRY request,
const char *  filepath,
const char *  mimetype 
)

Force to send(download) file to client in accordance with given mime type.

Parameters:
request a pointer of request structure
filepath file to send
mimetype mimetype. NULL can be used for “application/octet-stream” mimetype.
Returns:
the number of bytes sent. otherwise(file not found) returns -1.
Note:
Do not call qCgiResponseGetContentType() before. The results of this function are the same as those acquired when the corresponding files are directly linked to the Web. But this is especially useful in preprocessing files to be downloaded only with user certification and in enabling downloading those files, which cannot be opend on the Web, only through specific programs.

void qCgiResponseError ( Q_ENTRY request,
char *  format,
   
)

Generate and print out HTML error page.

Parameters:
request a pointer of request structure
format error message
Returns:
none
   qCgiResponseError(req, "Error: can't find userid.");


[Home] [About] [Examples] [Changes] [Download] [SVN Repository] [Install] [Reference]