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.
18
.Dt KJSON_STRING_OPEN 3
21
.Nm kjson_string_open ,
23
.Nd open string scope for kcgijson
34
.Fa "struct kjsonreq *req"
38
.Fa "struct kjsonreq *req"
42
Open an string scope in a context
47
.Xr kjson_string_close 3
50
String scopes are open strings that may be filled in with further
51
.Xr kjson_string_puts 3
56
form is for array scopes, while
65
.Fn kjson_stringp_open ,
66
is equivalent to calling
67
.Fn kjson_string_open .
71
indicating the error state.
74
Success (not an error).
76
Internal memory allocation failure, including reaching the maximum
77
number of possible JSON scopes.
79
The output connection has been terminated.
80
For FastCGI connections, the current connection should be released with
82
and parse loop reentered.
84
The connection is still expecting headers with
88
did not return with success or was not invoked.
89
For FastCGI connections, the current connection should be released with
91
and parse loop reentered.
93
Internal system error writing to the output stream.
95
The incorrect form was used for the current scope, for example, an
96
array-type write within an object.
99
The following outputs a simple JSON document.
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]);
113
kjson_string_open(&req);
114
kjson_string_puts(&req, "Hello, ");
115
kjson_string_puts(&req, "world.");
122
.An Kristaps Dzonsons Aq Mt kristaps@bsd.lv .