3
* Copyright (c) 2020 Kristaps Dzonsons <kristaps@bsd.lv>
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.
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.
31
#include "../kcgihtml.h"
35
"<!DOCTYPE html><html><body></body></html>"
38
bufcb(void *contents, size_t sz, size_t nm, void *dat)
40
struct kcgi_buf *buf = dat;
42
if (kcgi_buf_write(contents, nm * sz, buf) != KCGI_OK)
53
memset(&buf, 0, sizeof(struct kcgi_buf));
55
curl_easy_setopt(curl, CURLOPT_URL,
56
"http://localhost:17123/index.html");
57
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, bufcb);
58
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buf);
59
if (curl_easy_perform(curl) != CURLE_OK) {
60
warnx("curl_easy_perform");
63
if (!(rc = strcmp(buf.buf, EXPECT) == 0))
64
warnx("content test failure: %s", buf.buf);
74
const char *page[] = { "index" };
77
if (khttp_parse(&r, NULL, 0, page, 1, 0) != KCGI_OK) {
80
} else if (r.page != 0 || r.mime != KMIME_TEXT_HTML)
85
if (khttp_head(&r, kresps[KRESP_STATUS],
86
"%s", khttps[KHTTP_200]) != KCGI_OK) {
89
} else if (khttp_head(&r, kresps[KRESP_CONTENT_TYPE],
90
"%s", kmimetypes[r.mime]) != KCGI_OK) {
93
} else if (khttp_body(&r) != KCGI_OK) {
98
if (khtml_open(&req, &r, 0) != KCGI_OK) {
103
kcgi_writer_disable(&r);
105
if (khtml_elem(&req, KELEM_DOCTYPE) != KCGI_OK ||
106
khtml_elem(&req, KELEM_HTML) != KCGI_OK ||
107
khtml_elem(&req, KELEM_BODY) != KCGI_OK) {
112
if (khtml_puts(&req, NULL) != KCGI_OK ||
113
khtml_printf(&req, NULL) != KCGI_OK ||
114
khtml_write(NULL, 9, &req) != KCGI_OK ||
115
khtml_write("abcdef", 0, &req) != KCGI_OK) {
116
warnx("khtml_puts/write");
120
if (khtml_close(&req) != KCGI_OK) {
121
warnx("khtml_close");
132
main(int argc, char *argv[])
135
return regress_cgi(parent, child) ?
136
EXIT_SUCCESS : EXIT_FAILURE;