ksgi

Форк
0
/
kjson_string_write.3 
116 строк · 2.9 Кб
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_WRITE 3
19
.Os
20
.Sh NAME
21
.Nm kjson_string_write
22
.Nd put content data for kcgijson
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_string_write
33
.Fa "const char *buf"
34
.Fa "size_t sz"
35
.Fa "void *arg"
36
.Fc
37
.Sh DESCRIPTION
38
Write binary data
39
.Fa buf
40
of length
41
.Fa sz
42
into a string scope opened with
43
.Xr kjson_string_open 3
44
or
45
.Xr kjson_stringp_open 3
46
to a context
47
.Fa arg ,
48
a
49
.Vt struct kjsonreq
50
initialised with
51
.Xr khtml_open 3
52
and passed as an opaque pointer.
53
If
54
.Fa buf
55
is
56
.Dv NULL
57
or
58
.Fa sz
59
is zero, do nothing and return
60
.Dv KCGI_OK .
61
.Pp
62
All characters are JSON escaped so that content cannot prematurely end
63
its context.
64
.Sh RETURN VALUES
65
Returns an
66
.Ft enum kcgi_err
67
indicating the error state.
68
.Bl -tag -width -Ds
69
.It Dv KCGI_OK
70
Success (not an error).
71
.It Dv KCGI_ENOMEM
72
Internal memory allocation failure.
73
.It Dv KCGI_HUP
74
The output connection has been terminated.
75
For FastCGI connections, the current connection should be released with
76
.Xr khttp_free 3
77
and parse loop reentered.
78
.It Dv KCGI_FORM
79
The connection is still expecting headers with
80
.Xr khttp_head 3 .
81
Indicates that
82
.Xr khttp_body 3
83
did not return with success or was not invoked.
84
For FastCGI connections, the current connection should be released with
85
.Xr khttp_free 3
86
and parse loop reentered.
87
.It Dv KCGI_SYSTEM
88
Internal system error writing to the output stream.
89
.It Dv KCGI_WRITER
90
The incorrect form was used for the current scope, for example, an
91
array-type write within an object.
92
.El
93
.Sh EXAMPLES
94
The following outputs a simple JSON document.
95
It assumes
96
.Va r
97
is a
98
.Vt struct kreq
99
pointer.
100
For brevity, it does not do any error checking.
101
.Bd -literal -offset indent
102
khttp_head(r, kresps[KRESP_STATUS],
103
  "%s", khttps[KHTTP_200]);
104
khttp_head(r, kresps[KRESP_CONTENT_TYPE],
105
  "%s", kmimetypes[KMIME_APP_JSON]);
106
khttp_body(r);
107
kjson_open(&req, r);
108
kjson_string_open(&req);
109
kjson_string_write("hello", 5, &req);
110
kjson_close(&req);
111
.Ed
112
.Sh SEE ALSO
113
.Xr kcgijson 3
114
.Sh AUTHORS
115
Written by
116
.An Kristaps Dzonsons Aq Mt kristaps@bsd.lv .
117

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

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

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

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