qDecoder API Reference

Functions
qcgires.c File Reference

Detailed Description

CGI Response API.

Functions

bool qcgires_setcookie (qentry_t *request, const char *name, const char *value, int expire, const char *path, const char *domain, bool secure)
 Set cookie. More...
 
bool qcgires_removecookie (qentry_t *request, const char *name, const char *path, const char *domain, bool secure)
 Remove cookie. More...
 
bool qcgires_setcontenttype (qentry_t *request, const char *mimetype)
 Set responding content-type. More...
 
const char * qcgires_getcontenttype (qentry_t *request)
 Get content-type. More...
 
bool qcgires_redirect (qentry_t *request, const char *uri)
 Send redirection header. More...
 
int qcgires_download (qentry_t *request, const char *filepath, const char *mimetype)
 Force to send(download) file to client in accordance with given mime type. More...
 
void qcgires_error (qentry_t *request, char *format,...)
 Print out HTML error page and exit program. More...
 

Function Documentation

bool qcgires_setcookie ( qentry_t request,
const char *  name,
const char *  value,
int  expire,
const char *  path,
const char *  domain,
bool  secure 
)

Set cookie.

Parameters
requesta pointer of request structure
namecookie name
valuecookie value
expireexpire related time in seconds (0 means end of session)
pathcookie path (NULL can current path)
domaincookie domain (NULL means current domain)
securesecure flag
Returns
true in case of success, otherwise returns false
// Apply cookie in the current domain and directory for 1 day.
qcgires_setcookie(req, "NAME", "VALUE", 86400, NULL, NULL, false);
// Apply cookie to the "/" directory of "*.qdecoder.org" until the
// browser is closed.
qcgires_setcookie(req, name, value, 0, "/", ".qdecoder.org", false);
// As for the followings, cookies will be set up only when security
// requirements are satisfied.
qcgires_setcookie(req, name, value, 0, NULL, NULL, true);
bool qcgires_removecookie ( qentry_t request,
const char *  name,
const char *  path,
const char *  domain,
bool  secure 
)

Remove cookie.

Parameters
requesta pointer of request structure
namecookie name
pathcookie path
domaincookie domain
securesecure flag
Returns
true in case of success, otherwise returns false
qcgires_setcookie(req, "NAME", "VALUE", 0, NULL, NULL, NULL);
qcgires_removecookie(req, "NAME", NULL, NULL, NULL);
qcgires_setcookie(req, "NAME", "VALUE", 0, "/", "www.qdecoder.org", NULL);
qcgires_removecookie(req, "NAME", "/", "www.qdecoder.org", NULL);
bool qcgires_setcontenttype ( qentry_t request,
const char *  mimetype 
)

Set responding content-type.

Parameters
requesta pointer of request structure
mimetypemimetype
Returns
true in case of success, otherwise returns false
qcgires_setcontenttype(req, "text/html");
const char* qcgires_getcontenttype ( qentry_t request)

Get content-type.

Parameters
requesta pointer of request structure
Returns
a pointer of mimetype string in case of success, otherwise returns NULL
qcgires_setcontenttype(req, "text/html");
bool qcgires_redirect ( qentry_t request,
const char *  uri 
)

Send redirection header.

Parameters
requesta pointer of request structure
urinew URI
Returns
true in case of success, otherwise returns false
qcgires_redirect(req, "http://www.qdecoder.org/");
int qcgires_download ( qentry_t request,
const char *  filepath,
const char *  mimetype 
)

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

Parameters
requesta pointer of request structure
filepathfile to send
mimetypemimetype. NULL can be used for "application/octet-stream".
Returns
the number of bytes sent. otherwise(file not found) returns -1.
Note
Do not call qcgires_getcontenttype() 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 qcgires_error ( qentry_t request,
char *  format,
  ... 
)

Print out HTML error page and exit program.

Parameters
requesta pointer of request structure
formaterror message
Returns
none
qcgires_error(req, "Error: can't find userid.");