#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <dirent.h>
#include "qDecoder.h"
#include "qInternal.h"
Go to the source code of this file.
Defines | |
#define | _Q_MULTIPART_CHUNK_SIZE |
FunctionsTitleTestFour | |
char * | qCgiRequestGetQueryString (const char *query_type) |
Q_ENTRY * | qCgiRequestParse (Q_ENTRY *request) |
Q_ENTRY * | qCgiRequestParseCookies (Q_ENTRY *request) |
Q_ENTRY * | qCgiRequestParseOption (bool filemode, const char *basepath, int clearold) |
Q_ENTRY * | qCgiRequestParseQueries (Q_ENTRY *request, const char *method) |
qDecoder supports parsing
[HTML sample] <form action="your_program.cgi"> <input type="text" name="color"> <input type="submit"> </form> [Your Source] Q_ENTRY *req = qCgiRequestParse(NULL); const char *color = qEntryGetStr(req, "color"); printf("color = %s\n", color); qEntryFree(req);
The storing sequence is (1)COOKIE (2)GET (3)POST. Thus if same query names (which are sent by different method) exist, COOKIE query will be returned.
If you would like to get POST queries only. See below sample codes.
Q_ENTRY *req = qCgiRequestParseQueries(NULL, "POST"); const char *color = qEntryGetStr(req, "color"); printf("color = %s\n", color);
If you would like to get POST and COOKIE queries only. See below sample codes.
Q_ENTRY *req = NULL; req = qCgiRequestParseCookies(req); req = qCgiRequestParseQueries(req, "POST"); const char *color = qEntryGetStr(req, "color"); printf("color = %s\n", color); qEntryFree(req);
In case of multipart/form-data encoding(used for file uploading), qDecoder supports 2 modes for handling file uploading. I just made a name for that.
Q_ENTRY *req = qCgiRequestParseOption(true, "/tmp", 86400); req = qCgiRequestParse(req); (...your codes here...) qEntryFree(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_7b91698bc6d6ac7eaac93e71ce729b7c/1-hello.xls
binary.filename = hello.xls
binary.length = 3292
binary.contenttype = application/vnd.ms-excel
binary.savepath = tmp/Q_7b91698bc6d6ac7eaac93e71ce729b7c/1-hello.xls
If you want to activate progress mode. Please follow below steps
[HTML sample] <script language="JavaScript" src="/_(SOME_PATH)_/qDecoder-upload/qDecoder-upload.js"></script> <form method="post" action="your_program.cgi" enctype="multipart/form-data" onSubmit="return Q_UPLOAD(this);"> <input type="hidden" name="Q_UPLOAD_ID" value=""> Input text: <input type="text" name="text"> <br>Select file: <input type="file" name="binary1"> <br>Another file: <input type="file" name="binary2"> <br><input type="submit"> </form> [Code sample] int main(...) { // if you use "progress mode", this codes should be located at // the first line in main(). Q_ENTRY *req = qCgiRequestParseOption(true, "/tmp", 86400); req = qCgiRequestParse(req); (...your codes here...) qEntryFree(req); }
Definition in file qCgiRequest.c.