int main(void) { // Parse (GET/COOKIE/POST) queries. Q_ENTRY *req = qCgiRequestParse(NULL, 0); const char *mode = req->getStr(req, "mode", false); const char *name = req->getStr(req, "cname", false); const char *value = req->getStr(req, "cvalue", false); if (mode == NULL) { // View Cookie qCgiResponseSetContentType(req, "text/plain"); printf("Total %d entries\n", req->getNum(req)); req->print(req, stdout, true); } else if (!strcmp(mode, "set")) { // Set Cookie if (name == NULL || value == NULL) qCgiResponseError(req, "Query not found"); if (strlen(name) == 0) qCgiResponseError(req, "Empty cookie name can not be stored."); qCgiResponseSetCookie(req, name, value, 0, NULL, NULL, false); qCgiResponseSetContentType(req, "text/html"); printf("Cookie('%s'='%s') entry is stored.<br>Click <a href='cookie.cgi'>here</a> to view your cookies\n", name, value); } else if (!strcmp(mode, "remove")) { // Remove Cookie if (name == NULL) qCgiResponseError(req, "Query not found"); if (!strcmp(name, "")) qCgiResponseError(req, "Empty cookie name can not be removed."); qCgiResponseRemoveCookie(req, name, NULL, NULL, false); qCgiResponseSetContentType(req, "text/html"); printf("Cookie('%s') entry is removed.<br>Click <a href='cookie.cgi'>here</a> to view your cookies\n", name); } else { qCgiResponseError(req, "Unknown mode."); } req->free(req); return 0; }
void pair_client_site(struct sitereq *site) { Q_ENTRY *req = site->req; char *localid_req = (char *)req->getStr(req, "localid", false); char *okbox = (char *)req->getStr(req, "okbox", false); if(site->localid){ printf("<h3>Boksen er tilknyttet installations-ID:</h3><h2>%s</h2>", site->localid); return; } if(!site->socket_rp){ pair_client_error("Fejl i lokal forbindelse", NULL, SOLVE_INTERNET); return; } if((localid_req)&&(okbox)&&(strcmp(okbox,"checked")==0)) pair_client_set(site->socket_rp, localid_req); else if (localid_req) pair_client_check(site->socket_rp, localid_req); else pair_client_start(); }
int main(void) { // Parse queries. Q_ENTRY *req = qCgiRequestParse(NULL, 0); // get queries const char *text = req->getStr(req, "text", false); const char *filedata = req->getStr(req, "binary", false); int filelength = req->getInt(req, "binary.length"); const char *filename = req->getStr(req, "binary.filename", false); const char *contenttype = req->getStr(req, "binary.contenttype", false); // check queries if (text == NULL) qCgiResponseError(req, "Invalid usages."); if (filename == NULL || filelength == 0) qCgiResponseError(req, "Select file, please."); char filepath[1024]; sprintf(filepath, "%s/%s", BASEPATH, filename); if (savefile(filepath, filedata, filelength) < 0) { qCgiResponseError(req, "File(%s) open fail. Please make sure CGI or directory has right permission.", filepath); } // result out qCgiResponseSetContentType(req, "text/html"); printf("You entered: <b>%s</b>\n", text); printf("<br><a href=\"%s\">%s</a> (%d bytes, %s) saved.", filepath, filename, filelength, contenttype); // dump printf("\n<p><hr>--[ DUMP INTERNAL DATA STRUCTURE ]--\n<pre>"); req->print(req, stdout, false); printf("\n</pre>\n"); // de-allocate req->free(req); return 0; }