CGI Request Parsing API.
qDecoder supports parsing of
And parsed elements are stored in Q_ENTRY linked-list structure.
[HTML sample] <form action="your_program.cgi"> <input type="text" name="color"> <input type="submit"> </form> [Your Source] Q_ENTRY *req = qCgiRequestParse(NULL, 0); const char *color = req->getStr(req, "color", false); printf("color = %s\n", color); req->free(req);
The sequence of parsing is (1)COOKIE (2)GET (3)POST. Thus if there is a same query name existing in different methods, COOKIE values will be stored first than GET or POST values.
You can parse queries only sent through a particular method. See below sample codes.
Q_ENTRY *req = qCgiRequestParse(NULL, Q_CGI_POST); const char *color = req->getStr(req, "color", false); printf("color = %s\n", color); req->free(req);
If you want to parse only POST and COOKIE methods, you can do that like below.
Q_ENTRY *req = NULL; req = qCgiRequestParse(req, Q_CGI_COOKIE); req = qCgiRequestParse(req, Q_CGI_POST); const char *color = req->getStr(req, "color", false); printf("color = %s\n", color); req->free(req);
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 qCgiRequestSetOption().
Q_ENTRY *req = qCgiRequestSetOption(NULL, true, "/tmp", 86400); req = qCgiRequestParse(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 | |
Q_ENTRY * | qCgiRequestSetOption (Q_ENTRY *request, bool filemode, const char *basepath, int clearold) |
Set request parsing option for file uploading in case of multipart/form-data encoding. | |
Q_ENTRY * | qCgiRequestParse (Q_ENTRY *request, Q_CGI_T method) |
Parse one or more request(COOKIE/GET/POST) queries. | |
char * | qCgiRequestGetQuery (Q_CGI_T method) |
Get raw query string. |
Q_ENTRY* qCgiRequestSetOption | ( | Q_ENTRY * | request, | |
bool | filemode, | |||
const char * | basepath, | |||
int | clearold | |||
) |
Set request parsing option for file uploading in case of multipart/form-data encoding.
request | Q_ENTRY 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. |
Q_ENTRY *req = qCgiRequestSetOption(NULL, true, "/tmp", 86400); req = qCgiRequestParse(req, 0); req->free(req);
Parse one or more request(COOKIE/GET/POST) queries.
request | Q_ENTRY 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_GET and Q_CGI_POST. Q_CGI_ALL or 0 can be used for parsing all of those types. |
Q_ENTRY *req = qCgiRequestParse(NULL, 0); char *name = req->getStr(req, "name", false); if(name != NULL) printf("%s\n", name); req->free(req);
char* qCgiRequestGetQuery | ( | Q_CGI_T | method | ) |
Get raw query string.
method | One of Q_CGI_COOKIE, Q_CGI_GET and Q_CGI_POST. |
char *query = qCgiRequestGetQuery(Q_CGI_GET); if(query != NULL) { printf("%s\n", query); free(query); }