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
30#if HAVE_ZLIB31
32struct buf {33char buf[BUFSIZ];34size_t sz;35};36
37static int38parentwrite(void *ptr, size_t sz, size_t nm, void *dat)39{
40struct buf *buf = dat;41
42if (buf->sz + (sz * nm) + 1 > BUFSIZ)43return(-1);44memcpy(buf->buf + buf->sz, ptr, sz * nm);45buf->sz += sz * nm;46buf->buf[buf->sz] = '\0';47return(sz * nm);48}
49
50static int51parent(CURL *curl)52{
53struct buf buf;54
55memset(&buf, 0, sizeof(struct buf));56curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, parentwrite);57curl_easy_setopt(curl, CURLOPT_HEADERDATA, &buf);58curl_easy_setopt(curl, CURLOPT_URL, "http://localhost:17123/");59curl_easy_setopt(curl, CURLOPT_ENCODING, "gzip");60if (CURLE_OK != curl_easy_perform(curl))61return(0);62return(NULL != strstr(buf.buf, "Content-Encoding: gzip"));63}
64
65static int66child(void)67{
68struct kreq r;69const char *page = "index";70
71if (KCGI_OK != khttp_parse(&r, NULL, 0, &page, 1, 0))72return(0);73
74khttp_head(&r, kresps[KRESP_STATUS],75"%s", khttps[KHTTP_200]);76khttp_head(&r, kresps[KRESP_CONTENT_TYPE],77"%s", kmimetypes[KMIME_TEXT_HTML]);78khttp_body(&r);79khttp_puts(&r, "1234567890");80khttp_free(&r);81return(1);82}
83
84int
85main(int argc, char *argv[])86{
87
88return(regress_cgi(parent, child) ? EXIT_SUCCESS : EXIT_FAILURE);89}
90
91#else92int
93main(int argc, char *argv[])94{
95
96return(EXIT_SUCCESS);97}
98#endif99