ksgi
1/* $Id$ */
2/*
3* Copyright (c) 2015 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 <sys/wait.h>20
21#include <stdarg.h>22#include <stdint.h>23#include <stdlib.h>24#include <unistd.h>25
26#include <curl/curl.h>27
28#include "../kcgi.h"29#include "regress.h"30
31static int32parent(CURL *curl)33{
34
35curl_easy_setopt(curl, CURLOPT_URL,36"http://localhost:17123/");37return(CURLE_OK == curl_easy_perform(curl));38}
39
40static int41child(void)42{
43struct kreq r;44const char *page = "index";45pid_t pid;46
47if (KCGI_OK != khttp_parse(&r, NULL, 0, &page, 1, 0))48return(0);49khttp_head(&r, kresps[KRESP_STATUS],50"%s", khttps[KHTTP_200]);51khttp_head(&r, kresps[KRESP_CONTENT_TYPE],52"%s", kmimetypes[KMIME_TEXT_HTML]);53khttp_body(&r);54khttp_puts(&r, "Hi.\n");55if (-1 == (pid = fork())) {56perror("fork");57return(0);58} else if (0 == pid) {59khttp_child_free(&r);60_exit(EXIT_FAILURE);61}62khttp_puts(&r, "There.\n");63khttp_free(&r);64waitpid(pid, NULL, 0);65return(1);66}
67
68int
69main(int argc, char *argv[])70{
71
72return(regress_cgi(parent, child) ? EXIT_SUCCESS : EXIT_FAILURE);73}
74