ksgi

Форк
0
/
kjson_string_open.3 
122 строки · 3.1 Кб
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_STRING_OPEN 3
19
.Os
20
.Sh NAME
21
.Nm kjson_string_open ,
22
.Nm kjson_stringp_open
23
.Nd open string scope for kcgijson
24
.Sh LIBRARY
25
.Lb libkcgijson
26
.Sh SYNOPSIS
27
.In sys/types.h
28
.In stdarg.h
29
.In stdint.h
30
.In kcgi.h
31
.In kcgijson.h
32
.Ft enum kcgi_err
33
.Fo kjson_string_open
34
.Fa "struct kjsonreq *req"
35
.Fc
36
.Ft enum kcgi_err
37
.Fo kjson_stringp_open
38
.Fa "struct kjsonreq *req"
39
.Fa "const char *name"
40
.Fc
41
.Sh DESCRIPTION
42
Open an string scope in a context
43
.Fa req
44
initialised with
45
.Xr khtml_open 3 .
46
Scopes are closed with
47
.Xr kjson_string_close 3
48
or
49
.Xr kjson_close 3 .
50
String scopes are open strings that may be filled in with further
51
.Xr kjson_string_puts 3
52
and family functions.
53
.Pp
54
The
55
.Fn kjson_string_open
56
form is for array scopes, while
57
.Fn kjson_stringp_open
58
for objects.
59
.Pp
60
Passing a
61
.Dv NULL
62
value to
63
.Fa name
64
for
65
.Fn kjson_stringp_open ,
66
is equivalent to calling
67
.Fn kjson_string_open .
68
.Sh RETURN VALUES
69
Returns an
70
.Ft enum kcgi_err
71
indicating the error state.
72
.Bl -tag -width -Ds
73
.It Dv KCGI_OK
74
Success (not an error).
75
.It Dv KCGI_ENOMEM
76
Internal memory allocation failure, including reaching the maximum
77
number of possible JSON scopes.
78
.It Dv KCGI_HUP
79
The output connection has been terminated.
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_FORM
84
The connection is still expecting headers with
85
.Xr khttp_head 3 .
86
Indicates that
87
.Xr khttp_body 3
88
did not return with success or was not invoked.
89
For FastCGI connections, the current connection should be released with
90
.Xr khttp_free 3
91
and parse loop reentered.
92
.It Dv KCGI_SYSTEM
93
Internal system error writing to the output stream.
94
.It Dv KCGI_WRITER
95
The incorrect form was used for the current scope, for example, an
96
array-type write within an object.
97
.El
98
.Sh EXAMPLES
99
The following outputs a simple JSON document.
100
It assumes
101
.Va r
102
is a
103
.Vt struct kreq
104
pointer.
105
For brevity, it does not do any error checking.
106
.Bd -literal -offset indent
107
khttp_head(r, kresps[KRESP_STATUS],
108
  "%s", khttps[KHTTP_200]);
109
khttp_head(r, kresps[KRESP_CONTENT_TYPE],
110
  "%s", kmimetypes[KMIME_APP_JSON]);
111
khttp_body(r);
112
kjson_open(&req, r);
113
kjson_string_open(&req);
114
kjson_string_puts(&req, "Hello, ");
115
kjson_string_puts(&req, "world.");
116
kjson_close(&req);
117
.Ed
118
.Sh SEE ALSO
119
.Xr kcgijson 3
120
.Sh AUTHORS
121
Written by
122
.An Kristaps Dzonsons Aq Mt kristaps@bsd.lv .
123

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

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

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

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