ksgi

Форк
0
/
test-json-controlchars.c 
99 строк · 2.3 Кб
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 <string.h>
23
#include <unistd.h>
24

25
#include <curl/curl.h>
26

27
#include "../kcgi.h"
28
#include "../kcgijson.h"
29
#include "regress.h"
30

31
static size_t
32
bufcb(void *contents, size_t sz, size_t nm, void *dat)
33
{
34
	struct kcgi_buf	*buf = dat;
35

36
	if (KCGI_OK != kcgi_buf_write(contents, nm * sz, buf))
37
		return 0;
38
	return nm * sz;
39
}
40

41
static int
42
parent(CURL *curl)
43
{
44
	struct kcgi_buf	 buf;
45
	int		 rc;
46

47
	memset(&buf, 0, sizeof(struct kcgi_buf));
48

49
	curl_easy_setopt(curl, CURLOPT_URL, 
50
		"http://localhost:17123/index.json");
51
	curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, bufcb);
52
	curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buf);
53
	if (CURLE_OK != curl_easy_perform(curl))
54
		return 0;
55

56
	rc = 0 == strcmp(buf.buf, "{\"für\": \"für\"}");
57
	free(buf.buf);
58
	return rc;
59
}
60

61
static int
62
child(void)
63
{
64
	struct kreq	 r;
65
	struct kjsonreq	 req;
66
	const char 	*page[] = { "index" };
67
	int		 rc = 0;
68

69
	if (KCGI_OK != khttp_parse(&r, NULL, 0, page, 1, 0))
70
		return(0);
71
	if (r.page)
72
		goto out;
73
	if (KMIME_APP_JSON != r.mime)
74
		goto out;
75

76
	rc = 1;
77
	khttp_head(&r, kresps[KRESP_STATUS], 
78
		"%s", khttps[KHTTP_200]);
79
	khttp_head(&r, kresps[KRESP_CONTENT_TYPE], 
80
		"%s", kmimetypes[r.mime]);
81
	khttp_body(&r);
82

83
	kjson_open(&req, &r);
84
	kjson_obj_open(&req);
85
	kjson_putstringp(&req, "für", "für");
86
	kjson_obj_close(&req);
87
	kjson_close(&req);
88
out:
89
	khttp_free(&r);
90
	return(rc);
91
}
92

93
int
94
main(int argc, char *argv[])
95
{
96

97
	return(regress_cgi(parent, child) ? 
98
		EXIT_SUCCESS : EXIT_FAILURE);
99
}
100

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.