ksgi

Форк
0
/
kjson_open.3 
109 строк · 2.8 Кб
1
.\"	$Id$
2
.\"
3
.\" Copyright (c) 2020 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
.Dd $Mdocdate$
18
.Dt KJSON_OPEN 3
19
.Os
20
.Sh NAME
21
.Nm kjson_open
22
.Nd open kcgijson context
23
.Sh LIBRARY
24
.Lb libkcgijson
25
.Sh SYNOPSIS
26
.In sys/types.h
27
.In stdarg.h
28
.In stdint.h
29
.In kcgi.h
30
.In kcgijson.h
31
.Ft enum kcgi_err
32
.Fo kjson_open
33
.Fa "struct kjsonreq *req"
34
.Fa "struct kreq *r"
35
.Fc
36
.Sh DESCRIPTION
37
Zeroes and initialises a new context
38
.Fa req
39
with the underlying
40
.Xr kcgi 3
41
context
42
.Fa r
43
as allocated with
44
.Xr khttp_parse 3
45
or
46
.Xr khttp_fcgi_parse 3 .
47
It should only be called after
48
.Xr khttp_body 3 .
49
.Pp
50
The scope open after initialisation is the
51
.Qq root
52
scope, which accepts similar content as arrays such as
53
.Xr kjson_putstring 3
54
instead of
55
.Xr kjson_putstringp 3 .
56
.Pp
57
If
58
.Xr kcgi_writer_disable 3
59
has been called, the process will be killed with an uncatchable signal.
60
.Sh RETURN VALUES
61
Returns an
62
.Ft enum kcgi_err
63
indicating the error state.
64
.Bl -tag -width -Ds
65
.It Dv KCGI_OK
66
Success (not an error).
67
.It Dv KCGI_ENOMEM
68
Internal memory allocation failure.
69
.It Dv KCGI_HUP
70
The output connection has been terminated.
71
For FastCGI connections, the current connection should be released with
72
.Xr khttp_free 3
73
and parse loop reentered.
74
.It Dv KCGI_FORM
75
The connection is still expecting headers with
76
.Xr khttp_head 3 .
77
Indicates that
78
.Xr khttp_body 3
79
did not return with success or was not invoked.
80
For FastCGI connections, the current connection should be released with
81
.Xr khttp_free 3
82
and parse loop reentered.
83
.It Dv KCGI_SYSTEM
84
Internal system error writing to the output stream.
85
.El
86
.Sh EXAMPLES
87
The following outputs a simple JSON page.
88
It assumes
89
.Va r
90
is a
91
.Vt struct kreq
92
pointer.
93
For brevity, it does not do any error checking.
94
.Bd -literal -offset indent
95
khttp_head(r, kresps[KRESP_STATUS],
96
  "%s", khttps[KHTTP_200]);
97
khttp_head(r, kresps[KRESP_CONTENT_TYPE],
98
  "%s", kmimetypes[KMIME_APP_JSON]);
99
khttp_body(r);
100
kjson_open(&req, r);
101
kjson_obj_open(&req);
102
kjson_putstringp(&req, "foo", "bar");
103
kjson_close(&req);
104
.Ed
105
.Sh SEE ALSO
106
.Xr kcgijson 3
107
.Sh AUTHORS
108
Written by
109
.An Kristaps Dzonsons Aq Mt kristaps@bsd.lv .
110

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

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

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

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