ksgi
1/* $Id$ */
2/*
3* Copyright (c) 2018 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 <unistd.h>23
24#include <curl/curl.h>25
26#include "../kcgi.h"27#include "regress.h"28
29static int30parent1(CURL *curl)31{
32
33curl_easy_setopt(curl, CURLOPT_URL,34"http://localhost:17123/index1.html");35return CURLE_OK == curl_easy_perform(curl);36}
37
38static int39parent2(CURL *curl)40{
41
42curl_easy_setopt(curl, CURLOPT_URL,43"http://localhost:17123/index2.html");44return CURLE_OK == curl_easy_perform(curl);45}
46
47static int48child1(void)49{
50struct kreq r;51const char *page[] = { "index1", "index2" };52struct kfcgi *fcgi;53enum kcgi_err er;54
55if ( ! khttp_fcgi_test())56return 0;57if (KCGI_OK != khttp_fcgi_init(&fcgi, NULL, 0, page, 2, 1))58return 0;59
60while (KCGI_OK == (er = khttp_fcgi_parse(fcgi, &r))) {61if (0 != r.page) {62khttp_free(&r);63khttp_fcgi_free(fcgi);64return 0;65}66khttp_head(&r, kresps[KRESP_STATUS],67"%s", khttps[KHTTP_200]);68khttp_head(&r, kresps[KRESP_CONTENT_TYPE],69"%s", kmimetypes[KMIME_TEXT_HTML]);70khttp_body(&r);71khttp_free(&r);72}73
74khttp_free(&r);75khttp_fcgi_free(fcgi);76return KCGI_HUP == er ? 1 : 0;77}
78
79static int80child2(void)81{
82struct kreq r;83const char *page[] = { "index1", "index2" };84struct kfcgi *fcgi;85enum kcgi_err er;86
87if ( ! khttp_fcgi_test())88return 0;89if (KCGI_OK != khttp_fcgi_init(&fcgi, NULL, 0, page, 2, 0))90return 0;91
92while (KCGI_OK == (er = khttp_fcgi_parse(fcgi, &r))) {93if (1 != r.page) {94khttp_free(&r);95khttp_fcgi_free(fcgi);96return 0;97}98khttp_head(&r, kresps[KRESP_STATUS],99"%s", khttps[KHTTP_200]);100khttp_head(&r, kresps[KRESP_CONTENT_TYPE],101"%s", kmimetypes[KMIME_TEXT_HTML]);102khttp_body(&r);103khttp_free(&r);104}105
106khttp_free(&r);107khttp_fcgi_free(fcgi);108return KCGI_HUP == er ? 1 : 0;109}
110
111int
112main(int argc, char *argv[])113{
114
115if ( ! regress_fcgi(parent1, child1))116return EXIT_FAILURE;117return regress_fcgi(parent2, child2) ?118EXIT_SUCCESS : EXIT_FAILURE;119}
120