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_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. | |
qentry_t * | qcgireq_parse (qentry_t *request, Q_CGI_T method) |
Parse one or more request(COOKIE/POST/GET) queries. | |
char * | qcgireq_getquery (Q_CGI_T method) |
Get raw query string. |
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.
request | qentry_t container pointer that options will be set. NULL can be used to create a new container. | |
filemode | false for parsing in memory, true for storing attached files into file-system directly. | |
basepath | the base path where the uploaded files are located. Set to NULL if filemode is false. | |
clearold | saved files older than this seconds will be removed automatically. Set to 0 to disable. |
qentry_t *req = qcgireq_setoption(NULL, true, "/tmp", 86400); req = qcgireq_parse(req, 0); req->free(req);
Parse one or more request(COOKIE/POST/GET) queries.
request | qentry_t container pointer that parsed key/value pairs will be stored. NULL can be used to create a new container. | |
method | Target 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. |
qentry_t *req = qcgireq_parse(NULL, 0);
qentry_t *req = qcgireq_parse(req, Q_CGI_COOKIE | Q_CGI_POST);
char* qcgireq_getquery | ( | Q_CGI_T | method | ) |
Get raw query string.
method | One of Q_CGI_COOKIE, Q_CGI_POST or Q_CGI_GET. |
char *query = qcgireq_getquery(Q_CGI_GET); if(query != NULL) { printf("%s\n", query); free(query); }