1 /* $Id$ */
2 /*
3 * Copyright (c) 2017 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
30 static int
parent(CURL * curl)31 parent(CURL *curl)
32 {
33 struct curl_slist *slist;
34 int ret;
35
36 slist = NULL;
37 slist = curl_slist_append(slist, "Testing:123");
38 slist = curl_slist_append(slist, "Testing-Test:321");
39 curl_easy_setopt(curl, CURLOPT_URL, "http://localhost:17123/");
40 curl_easy_setopt(curl, CURLOPT_HTTPHEADER, slist);
41 ret = curl_easy_perform(curl);
42 curl_slist_free_all(slist);
43 return(CURLE_OK == ret);
44 }
45
46 static int
child(void)47 child(void)
48 {
49 struct kreq r;
50 const char *page = "index";
51 struct kfcgi *fcgi;
52 enum kcgi_err er;
53 size_t i, found1, found2;
54
55 if ( ! khttp_fcgi_test())
56 return(0);
57
58 if (KCGI_OK != khttp_fcgi_init(&fcgi, NULL, 0, &page, 1, 0))
59 return(0);
60
61 while (KCGI_OK == (er = khttp_fcgi_parse(fcgi, &r))) {
62 found1 = found2 = 0;
63 for (i = 0; i < r.reqsz; i++) {
64 if (0 == strcmp(r.reqs[i].key, "Testing"))
65 found1 += 0 == strcmp
66 (r.reqs[i].val, "123");
67 else if (0 == strcmp(r.reqs[i].key, "Testing-Test"))
68 found2 += 0 == strcmp
69 (r.reqs[i].val, "321");
70 }
71
72 if (1 != found1 || 1 != found2)
73 return(0);
74
75 khttp_head(&r, kresps[KRESP_STATUS],
76 "%s", khttps[KHTTP_200]);
77 khttp_head(&r, kresps[KRESP_CONTENT_TYPE],
78 "%s", kmimetypes[KMIME_TEXT_HTML]);
79 khttp_body(&r);
80 khttp_free(&r);
81 }
82
83 khttp_free(&r);
84 khttp_fcgi_free(fcgi);
85 return(KCGI_HUP == er ? 1 : 0);
86 }
87
88 int
main(int argc,char * argv[])89 main(int argc, char *argv[])
90 {
91
92 return(regress_fcgi(parent, child) ? EXIT_SUCCESS : EXIT_FAILURE);
93 }
94