ksgi
1/* $Id$ */
2/*
3* Copyright (c) 2014 Kristaps Dzonsons <kristaps@bsd.lv>
4*
5* Permission to use, copy, modify, and distribute this software for any
6* purpose with or without fee is hereby granted, provided that the above
7* copyright notice and this permission notice appear in all copies.
8*
9* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16*/
17#include "../config.h"18
19#include <stdarg.h>20#include <stdint.h>21#include <stdlib.h>22#include <string.h>23#include <unistd.h>24
25#include <curl/curl.h>26
27#include "../kcgi.h"28#include "regress.h"29
30static int31parent(CURL *curl)32{
33struct curl_slist *slist;34int ret;35
36slist = NULL;37slist = curl_slist_append(slist, "Testing\tfoo:123");38slist = curl_slist_append(slist, "Testing-Test:321");39slist = curl_slist_append(slist, "Test\bing-Test:321");40curl_easy_setopt(curl, CURLOPT_URL, "http://localhost:17123/");41curl_easy_setopt(curl, CURLOPT_HTTPHEADER, slist);42ret = curl_easy_perform(curl);43curl_slist_free_all(slist);44return(CURLE_OK == ret);45}
46
47static int48child(void)49{
50struct kreq r;51const char *page = "index";52size_t i, found1, found2;53
54if (KCGI_OK != khttp_parse(&r, NULL, 0, &page, 1, 0))55return(0);56
57found1 = found2 = 0;58for (i = 0; i < r.reqsz; i++) {59if (0 == strcmp(r.reqs[i].key, "Testing\tfoo"))60found1++;61else if (0 == strcmp(r.reqs[i].key, "Test\bing-Test"))62found1++;63else if (0 == strcmp(r.reqs[i].key, ""))64found1++;65else if (0 == strcmp(r.reqs[i].key, "Testing-Test"))66found2 += 0 == strcmp(r.reqs[i].val, "321");67}68
69if (found1 || 1 != found2)70return(0);71
72khttp_head(&r, kresps[KRESP_STATUS],73"%s", khttps[KHTTP_200]);74khttp_head(&r, kresps[KRESP_CONTENT_TYPE],75"%s", kmimetypes[KMIME_TEXT_HTML]);76khttp_body(&r);77khttp_free(&r);78return(1);79}
80
81int
82main(int argc, char *argv[])83{
84
85return(regress_cgi(parent, child) ? EXIT_SUCCESS : EXIT_FAILURE);86}
87