qDecoder API Reference

Functions
qcgireq.c File Reference

Detailed Description

CGI Request Parsing API.

qDecoder supports parsing of

And parsed elements are stored in qentry_t linked-list structure.

[HTML sample]
<form action="your_program.cgi">
<input type="text" name="color">
<input type="submit">
</form>
[Your Source]
qentry_t *req = qcgireq_parse(NULL, 0); // 0 is equivalent to Q_CGI_ALL.
qcgires_setcontenttype(req, "text/plain");
char *color = req->getstr(req, "color", false);
if (color != NULL) {
printf("Color = %s\n", color);
}
req->free(req);

The order of parsing sequence is (1)COOKIE (2)POST (3)GET. Thus if there is a same query name existing in different methods, COOKIE values will be stored first than POST, GET values will be added at the very last into a qentry linked-list.

Below is an example to parse only two given methods. Please note that when multiple methods are specified, it'll be parsed in the order of COOKIE, POST and GET.

qentry_t *req = qcgireq_parse(req, Q_CGI_COOKIE | Q_CGI_POST);

To change the order of parsing sequence, you can call qcgireq_parse() multiple times in the order that you want as below.

qentry_t *req;
req = qcgireq_parse(req, Q_CGI_POST);
req = qcgireq_parse(req, Q_CGI_GET);
req = qcgireq_parse(req, Q_CGI_COOKIE);

In terms of multipart/form-data encoding(used for file uploading), qDecoder can handle that in two different ways internally.

You can switch to file mode by calling qcgireq_setoption().

qentry_t *req = qcgireq_setoption(NULL, true, "/tmp", 86400);
req = qcgireq_parse(req, 0);
(...your codes here...)
req->free(req);

Basically, when file is uploaded qDecoder store it's meta information like below.

[default mode example]
binary = (...binary data...)
binary.filename = hello.xls
binary.length = 3292
binary.contenttype = application/vnd.ms-excel
[file mode example]
binary = tmp/q_wcktIq
binary.length = 60014
binary.filename = hello.xls
binary.contenttype = application/vnd.ms-excel
binary.savepath = tmp/q_wcktIq

Functions

qentry_tqcgireq_setoption (qentry_t *request, bool filemode, const char *basepath, int clearold)
 Set request parsing option for file uploading in case of multipart/form-data encoding. More...
 
qentry_tqcgireq_parse (qentry_t *request, Q_CGI_T method)
 Parse one or more request(COOKIE/POST/GET) queries. More...
 
char * qcgireq_getquery (Q_CGI_T method)
 Get raw query string. More...
 

Function Documentation

qentry_t* qcgireq_setoption ( qentry_t request,
bool  filemode,
const char *  basepath,
int  clearold 
)

Set request parsing option for file uploading in case of multipart/form-data encoding.

Parameters
requestqentry_t container pointer that options will be set. NULL can be used to create a new container.
filemodefalse for parsing in memory, true for storing attached files into file-system directly.
basepaththe base path where the uploaded files are located. Set to NULL if filemode is false.
clearoldsaved files older than this seconds will be removed automatically. Set to 0 to disable.
Returns
qentry_t container pointer, otherwise returns NULL.
Note
This method should be called before calling qcgireq_parse().
qentry_t *req = qcgireq_setoption(NULL, true, "/tmp", 86400);
req = qcgireq_parse(req, 0);
req->free(req);
qentry_t* qcgireq_parse ( qentry_t request,
Q_CGI_T  method 
)

Parse one or more request(COOKIE/POST/GET) queries.

Parameters
requestqentry_t container pointer that parsed key/value pairs will be stored. NULL can be used to create a new container.
methodTarget mask consists of one or more of Q_CGI_COOKIE, Q_CGI_POST and Q_CGI_GET. Q_CGI_ALL or 0 can be used for parsing all of those types.
Returns
qentry_t* handle if successful, NULL if there was insufficient memory to allocate a new object.
qentry_t *req = qcgireq_parse(NULL, 0);
qentry_t *req = qcgireq_parse(req, Q_CGI_COOKIE | Q_CGI_POST);
Note
When multiple methods are specified, it'll be parsed in the order of (1)COOKIE, (2)POST (3)GET unless you call it separately multiple times.
char* qcgireq_getquery ( Q_CGI_T  method)

Get raw query string.

Parameters
methodOne of Q_CGI_COOKIE, Q_CGI_POST or Q_CGI_GET.
Returns
malloced query string otherwise returns NULL;
char *query = qcgireq_getquery(Q_CGI_GET);
if(query != NULL) {
printf("%s\n", query);
free(query);
}