Debian Codegraph @

man/sd_json_dispatch_string.xml

raw
1 <?xml version='1.0'?>
2 <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
3 "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
4 <!-- SPDX-License-Identifier: LGPL-2.1-or-later -->
5
6 <refentry id="sd_json_dispatch_string" xmlns:xi="http://www.w3.org/2001/XInclude">
7
8 <refentryinfo>
9 <title>sd_json_dispatch_string</title>
10 <productname>systemd</productname>
11 </refentryinfo>
12
13 <refmeta>
14 <refentrytitle>sd_json_dispatch_string</refentrytitle>
15 <manvolnum>3</manvolnum>
16 </refmeta>
17
18 <refnamediv>
19 <refname>sd_json_dispatch_string</refname>
20 <refname>sd_json_dispatch_const_string</refname>
21 <refname>sd_json_dispatch_strv</refname>
22 <refname>sd_json_dispatch_stdbool</refname>
23 <refname>sd_json_dispatch_intbool</refname>
24 <refname>sd_json_dispatch_tristate</refname>
25 <refname>sd_json_dispatch_variant</refname>
26 <refname>sd_json_dispatch_variant_noref</refname>
27 <refname>sd_json_dispatch_int64</refname>
28 <refname>sd_json_dispatch_int32</refname>
29 <refname>sd_json_dispatch_int16</refname>
30 <refname>sd_json_dispatch_int8</refname>
31 <refname>sd_json_dispatch_uint64</refname>
32 <refname>sd_json_dispatch_uint32</refname>
33 <refname>sd_json_dispatch_uint16</refname>
34 <refname>sd_json_dispatch_uint8</refname>
35 <refname>sd_json_dispatch_double</refname>
36 <refname>sd_json_dispatch_uid_gid</refname>
37 <refname>sd_json_dispatch_id128</refname>
38 <refname>sd_json_dispatch_signal</refname>
39 <refname>sd_json_dispatch_unsupported</refname>
40
41 <refpurpose>Decode JSON variant values and write them to the specified memory</refpurpose>
42 </refnamediv>
43
44 <refsynopsisdiv>
45 <funcsynopsis>
46 <funcsynopsisinfo>#include &lt;systemd/sd-varlink.h&gt;</funcsynopsisinfo>
47
48 <funcprototype>
49 <funcdef>int <function>sd_json_dispatch_string</function></funcdef>
50 <paramdef>const char *<parameter>name</parameter></paramdef>
51 <paramdef>sd_json_variant *<parameter>variant</parameter></paramdef>
52 <paramdef>sd_dispatch_flags <parameter>flags</parameter></paramdef>
53 <paramdef>void *<parameter>userdata</parameter></paramdef>
54 </funcprototype>
55
56 <funcprototype>
57 <funcdef>int <function>sd_json_dispatch_const_string</function></funcdef>
58 <paramdef>const char *<parameter>name</parameter></paramdef>
59 <paramdef>sd_json_variant *<parameter>variant</parameter></paramdef>
60 <paramdef>sd_dispatch_flags <parameter>flags</parameter></paramdef>
61 <paramdef>void *<parameter>userdata</parameter></paramdef>
62 </funcprototype>
63
64 <funcprototype>
65 <funcdef>int <function>sd_json_dispatch_strv</function></funcdef>
66 <paramdef>const char *<parameter>name</parameter></paramdef>
67 <paramdef>sd_json_variant *<parameter>variant</parameter></paramdef>
68 <paramdef>sd_dispatch_flags <parameter>flags</parameter></paramdef>
69 <paramdef>void *<parameter>userdata</parameter></paramdef>
70 </funcprototype>
71
72 <funcprototype>
73 <funcdef>int <function>sd_json_dispatch_stdbool</function></funcdef>
74 <paramdef>const char *<parameter>name</parameter></paramdef>
75 <paramdef>sd_json_variant *<parameter>variant</parameter></paramdef>
76 <paramdef>sd_dispatch_flags <parameter>flags</parameter></paramdef>
77 <paramdef>void *<parameter>userdata</parameter></paramdef>
78 </funcprototype>
79
80 <funcprototype>
81 <funcdef>int <function>sd_json_dispatch_intbool</function></funcdef>
82 <paramdef>const char *<parameter>name</parameter></paramdef>
83 <paramdef>sd_json_variant *<parameter>variant</parameter></paramdef>
84 <paramdef>sd_dispatch_flags <parameter>flags</parameter></paramdef>
85 <paramdef>void *<parameter>userdata</parameter></paramdef>
86 </funcprototype>
87
88 <funcprototype>
89 <funcdef>int <function>sd_json_dispatch_tristate</function></funcdef>
90 <paramdef>const char *<parameter>name</parameter></paramdef>
91 <paramdef>sd_json_variant *<parameter>variant</parameter></paramdef>
92 <paramdef>sd_dispatch_flags <parameter>flags</parameter></paramdef>
93 <paramdef>void *<parameter>userdata</parameter></paramdef>
94 </funcprototype>
95
96 <funcprototype>
97 <funcdef>int <function>sd_json_dispatch_variant</function></funcdef>
98 <paramdef>const char *<parameter>name</parameter></paramdef>
99 <paramdef>sd_json_variant *<parameter>variant</parameter></paramdef>
100 <paramdef>sd_dispatch_flags <parameter>flags</parameter></paramdef>
101 <paramdef>void *<parameter>userdata</parameter></paramdef>
102 </funcprototype>
103
104 <funcprototype>
105 <funcdef>int <function>sd_json_dispatch_variant_noref</function></funcdef>
106 <paramdef>const char *<parameter>name</parameter></paramdef>
107 <paramdef>sd_json_variant *<parameter>variant</parameter></paramdef>
108 <paramdef>sd_dispatch_flags <parameter>flags</parameter></paramdef>
109 <paramdef>void *<parameter>userdata</parameter></paramdef>
110 </funcprototype>
111
112 <funcprototype>
113 <funcdef>int <function>sd_json_dispatch_int64</function></funcdef>
114 <paramdef>const char *<parameter>name</parameter></paramdef>
115 <paramdef>sd_json_variant *<parameter>variant</parameter></paramdef>
116 <paramdef>sd_dispatch_flags <parameter>flags</parameter></paramdef>
117 <paramdef>void *<parameter>userdata</parameter></paramdef>
118 </funcprototype>
119
120 <funcprototype>
121 <funcdef>int <function>sd_json_dispatch_int32</function></funcdef>
122 <paramdef>const char *<parameter>name</parameter></paramdef>
123 <paramdef>sd_json_variant *<parameter>variant</parameter></paramdef>
124 <paramdef>sd_dispatch_flags <parameter>flags</parameter></paramdef>
125 <paramdef>void *<parameter>userdata</parameter></paramdef>
126 </funcprototype>
127
128 <funcprototype>
129 <funcdef>int <function>sd_json_dispatch_int16</function></funcdef>
130 <paramdef>const char *<parameter>name</parameter></paramdef>
131 <paramdef>sd_json_variant *<parameter>variant</parameter></paramdef>
132 <paramdef>sd_dispatch_flags <parameter>flags</parameter></paramdef>
133 <paramdef>void *<parameter>userdata</parameter></paramdef>
134 </funcprototype>
135
136 <funcprototype>
137 <funcdef>int <function>sd_json_dispatch_int8</function></funcdef>
138 <paramdef>const char *<parameter>name</parameter></paramdef>
139 <paramdef>sd_json_variant *<parameter>variant</parameter></paramdef>
140 <paramdef>sd_dispatch_flags <parameter>flags</parameter></paramdef>
141 <paramdef>void *<parameter>userdata</parameter></paramdef>
142 </funcprototype>
143
144 <funcprototype>
145 <funcdef>int <function>sd_json_dispatch_uint64</function></funcdef>
146 <paramdef>const char *<parameter>name</parameter></paramdef>
147 <paramdef>sd_json_variant *<parameter>variant</parameter></paramdef>
148 <paramdef>sd_dispatch_flags <parameter>flags</parameter></paramdef>
149 <paramdef>void *<parameter>userdata</parameter></paramdef>
150 </funcprototype>
151
152 <funcprototype>
153 <funcdef>int <function>sd_json_dispatch_uint32</function></funcdef>
154 <paramdef>const char *<parameter>name</parameter></paramdef>
155 <paramdef>sd_json_variant *<parameter>variant</parameter></paramdef>
156 <paramdef>sd_dispatch_flags <parameter>flags</parameter></paramdef>
157 <paramdef>void *<parameter>userdata</parameter></paramdef>
158 </funcprototype>
159
160 <funcprototype>
161 <funcdef>int <function>sd_json_dispatch_uint16</function></funcdef>
162 <paramdef>const char *<parameter>name</parameter></paramdef>
163 <paramdef>sd_json_variant *<parameter>variant</parameter></paramdef>
164 <paramdef>sd_dispatch_flags <parameter>flags</parameter></paramdef>
165 <paramdef>void *<parameter>userdata</parameter></paramdef>
166 </funcprototype>
167
168 <funcprototype>
169 <funcdef>int <function>sd_json_dispatch_uint8</function></funcdef>
170 <paramdef>const char *<parameter>name</parameter></paramdef>
171 <paramdef>sd_json_variant *<parameter>variant</parameter></paramdef>
172 <paramdef>sd_dispatch_flags <parameter>flags</parameter></paramdef>
173 <paramdef>void *<parameter>userdata</parameter></paramdef>
174 </funcprototype>
175
176 <funcprototype>
177 <funcdef>int <function>sd_json_dispatch_double</function></funcdef>
178 <paramdef>const char *<parameter>name</parameter></paramdef>
179 <paramdef>sd_json_variant *<parameter>variant</parameter></paramdef>
180 <paramdef>sd_dispatch_flags <parameter>flags</parameter></paramdef>
181 <paramdef>void *<parameter>userdata</parameter></paramdef>
182 </funcprototype>
183
184 <funcprototype>
185 <funcdef>int <function>sd_json_dispatch_uid_gid</function></funcdef>
186 <paramdef>const char *<parameter>name</parameter></paramdef>
187 <paramdef>sd_json_variant *<parameter>variant</parameter></paramdef>
188 <paramdef>sd_dispatch_flags <parameter>flags</parameter></paramdef>
189 <paramdef>void *<parameter>userdata</parameter></paramdef>
190 </funcprototype>
191
192 <funcprototype>
193 <funcdef>int <function>sd_json_dispatch_id128</function></funcdef>
194 <paramdef>const char *<parameter>name</parameter></paramdef>
195 <paramdef>sd_json_variant *<parameter>variant</parameter></paramdef>
196 <paramdef>sd_dispatch_flags <parameter>flags</parameter></paramdef>
197 <paramdef>void *<parameter>userdata</parameter></paramdef>
198 </funcprototype>
199
200 <funcprototype>
201 <funcdef>int <function>sd_json_dispatch_signal</function></funcdef>
202 <paramdef>const char *<parameter>name</parameter></paramdef>
203 <paramdef>sd_json_variant *<parameter>variant</parameter></paramdef>
204 <paramdef>sd_dispatch_flags <parameter>flags</parameter></paramdef>
205 <paramdef>void *<parameter>userdata</parameter></paramdef>
206 </funcprototype>
207
208 <funcprototype>
209 <funcdef>int <function>sd_json_dispatch_unsupported</function></funcdef>
210 <paramdef>const char *<parameter>name</parameter></paramdef>
211 <paramdef>sd_json_variant *<parameter>variant</parameter></paramdef>
212 <paramdef>sd_dispatch_flags <parameter>flags</parameter></paramdef>
213 <paramdef>void *<parameter>userdata</parameter></paramdef>
214 </funcprototype>
215 </funcsynopsis>
216 </refsynopsisdiv>
217
218 <refsect1>
219 <title>Description</title>
220
221 <para>The various functions described here are intended for use in the
222 <type>sd_json_dispatch_field</type> structure arrays the
223 <citerefentry><refentrytitle>sd_json_dispatch</refentrytitle><manvolnum>3</manvolnum></citerefentry> and
224 <citerefentry><refentrytitle>sd_varlink_dispatch</refentrytitle><manvolnum>3</manvolnum></citerefentry>
225 functions accept; they decode the provided JSON variant object's value, and write it to the memory
226 indicated by the <parameter>userdata</parameter> pointer. The <parameter>name</parameter> parameter
227 contains the field name (in the JSON object it is contained in) of the value being decoded. For details
228 on the <parameter>flags</parameter> parameter see the <function>sd_json_dispatch()</function>
229 documentation.</para>
230
231 <para>Note that all these functions not only accept the native JSON type they are intended for, but also
232 accept null JSON values, in which case they assign an appropriate invalid/unset/null value, as
233 appropriate for the type (for details see below).</para>
234
235 <para><function>sd_json_dispatch_string()</function> decodes a JSON string value, and allocates a
236 <constant>NUL</constant> terminated copy in dynamic memory. The <parameter>userdata</parameter> pointer
237 must point to a pointer to a string, which is freed if non-<constant>NULL</constant>, and then replaced
238 by the newly allocated one. If a JSON null value is passed, the existing string is freed and
239 <constant>NULL</constant> is assigned.</para>
240
241 <para><function>sd_json_dispatch_const_string()</function> is very similar to
242 <function>sd_json_dispatch_string()</function>, but does not allocate a string in dynamic
243 memory. Instead, it just writes a pointer into the JSON object into the indicated memory (or
244 <constant>NULL</constant> in case a JSON null object is passed). The memory remains valid only as long as
245 the indicated variant object is kept allocated (which can happen via direct reference, or via an indirect
246 one via an object that references the specified variant). The memory <parameter>userdata</parameter>
247 points to on input is <emphasis>not</emphasis> freed before the new value is assigned.</para>
248
249 <para><function>sd_json_dispatch_stdbool()</function> and <function>sd_json_dispatch_intbool()</function>
250 decode JSON boolean values and write them to the indicated memory. The former expects a variable of the
251 C99 <type>bool</type> type in the indicated memory, the latter an <type>int</type> (which will only
252 receive the values 0 and 1). The JSON null value is treated equivalent to a JSON false.</para>
253
254 <para><function>sd_json_dispatch_tristate()</function> is very similar
255 to<function>sd_json_dispatch_intbool()</function>, but will assign -1 if a JSON null value is passed. Or
256 in other words, the integer will have a value &gt; 0, == 0 or &lt; 0, for the cases true, false or
257 invalid/unset/null.</para>
258
259 <para><function>sd_json_dispatch_variant()</function> takes an additional reference to the passed JSON
260 object (via <function>sd_json_variant_ref()</function>) and writes the pointer to the indicated
261 memory. No decoding is done. If the indicated pointer is non-<constant>NULL</constant> on input it is
262 freed (via <function>sd_json_variant_unref()</function>) before the new pointer is written.</para>
263
264 <para><function>sd_json_dispatch_variant_noref()</function> is similar, but does <emphasis>not</emphasis>
265 take a new reference to the JSON variant object. The pointer hence only remains valid as long as the
266 original object stays referenced. If the indicated pointer is non-<constant>NULL</constant> on input it
267 is <emphasis>not</emphasis> freed before the new pointer is written.</para>
268
269 <para>The <function>sd_json_dispatch_int64()</function>, <function>sd_json_dispatch_int32()</function>,
270 <function>sd_json_dispatch_int16()</function>, <function>sd_json_dispatch_int8()</function>,
271 <function>sd_json_dispatch_uint64()</function>, <function>sd_json_dispatch_uint32()</function>,
272 <function>sd_json_dispatch_uint16()</function> and <function>sd_json_dispatch_uint8()</function>
273 functions decode a JSON integer value, and write the value to the indicated memory. The function names
274 indicate the word width and signedness of the integers being parsed. If the JSON null value is passed the
275 functions for the unsigned integer types will assign the maximum value the type takes
276 (i.e. <constant>UINT64_MAX</constant>, <constant>UINT32_MAX</constant> …), and the signed versions assign
277 -1. Instead of a JSON integer value these functions also accept JSON strings that contain formatted
278 decimal numbers, in order to improve compatibility for encoding integer values that cannot be represented
279 in 64bit double precision floating point numbers in other programming languages that encode JSON numerals
280 this way.</para>
281
282 <para>The <function>sd_json_dispatch_double()</function> function decodes a 64bit double precision
283 floating point number. If a JSON null value is passed, assigns NaN.</para>
284
285 <para>The <function>sd_json_dispatch_uid_gid()</function> function is similar to
286 <function>sd_json_dispatch_uint32()</function>, and is intended to decode 32bit UNIX UID/GID numbers, as
287 used on Linux. It will decode a JSON null value as 4294967295 (i.e. <literal>(uid_t) -1</literal>), and
288 will refuse the values 65535 and 4294967295 when passed as JSON numerals (i.e. both the 16bit and 32bit
289 "invalid" UID/GID, as these values have special meaning for various UNIX syscalls, on different OSes and
290 file systems).</para>
291
292 <para><function>sd_json_dispatch_id128()</function> decodes a 128bit ID formatted as a JSON string. It
293 supports both RFC9562 UUID formatting, as well as 64 hexadecimal characters without separators, the same
294 way as
295 <citerefentry><refentrytitle>sd_id128_from_string</refentrytitle><manvolnum>3</manvolnum></citerefentry>. If
296 the JSON null value is passed, the all-zero ID is assigned.</para>
297
298 <para><function>sd_json_dispatch_signal()</function> decodes a UNIX process signal specification. It
299 expects either an JSON string containing a signal name such as <literal>SIGINT</literal> or
300 <literal>SIGTERM</literal>, or an unsigned JSON integer value with the signal number (in the Linux
301 definition). The indicated memory must point to an <type>int</type> variable to write the signal number
302 to. If the JSON null value is passed a negative value will be written to the memory.</para>
303
304 <para><function>sd_json_dispatch_unsupported()</function> will always fail with the
305 -<constant>EINVAL</constant> error.</para>
306 </refsect1>
307
308 <refsect1>
309 <title>Return Value</title>
310
311 <para>On success, these functions return a non-negative integer. On failure, they return a negative
312 errno-style error code.</para>
313
314 <refsect2>
315 <title>Errors</title>
316
317 <para>Returned errors may indicate the following problems:</para>
318
319 <variablelist>
320 <varlistentry>
321 <term><constant>-EINVAL</constant></term>
322
323 <listitem><para>An argument is invalid.</para></listitem>
324 </varlistentry>
325
326 <varlistentry>
327 <term><constant>-ENOMEM</constant></term>
328
329 <listitem><para>Memory allocation failed.</para></listitem>
330 </varlistentry>
331 </variablelist>
332 </refsect2>
333 </refsect1>
334
335 <xi:include href="libsystemd-pkgconfig.xml" />
336
337 <refsect1>
338 <title>History</title>
339 <para>
340 <function>sd_json_dispatch_string()</function>, <function>sd_json_dispatch_const_string()</function>,
341 <function>sd_json_dispatch_strv()</function>, <function>sd_json_dispatch_stdbool()</function>,
342 <function>sd_json_dispatch_intbool()</function>, <function>sd_json_dispatch_tristate()</function>,
343 <function>sd_json_dispatch_variant()</function>, <function>sd_json_dispatch_variant_noref()</function>,
344 <function>sd_json_dispatch_int64()</function>, <function>sd_json_dispatch_int32()</function>,
345 <function>sd_json_dispatch_int16()</function>, <function>sd_json_dispatch_int8()</function>,
346 <function>sd_json_dispatch_uint64()</function>, <function>sd_json_dispatch_uint32()</function>,
347 <function>sd_json_dispatch_uint16()</function>, <function>sd_json_dispatch_uint8()</function>,
348 <function>sd_json_dispatch_double()</function>, <function>sd_json_dispatch_uid_gid()</function>,
349 <function>sd_json_dispatch_id128()</function>, <function>sd_json_dispatch_signal()</function>,
350 <function>sd_json_dispatch_unsupported()</function> were added in version 257.</para>
351 </refsect1>
352
353 <refsect1>
354 <title>See Also</title>
355
356 <para><simplelist type="inline">
357 <member><citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry></member>
358 <member><citerefentry><refentrytitle>sd-json</refentrytitle><manvolnum>3</manvolnum></citerefentry></member>
359 <member><citerefentry><refentrytitle>sd-varlink</refentrytitle><manvolnum>3</manvolnum></citerefentry></member>
360 <member><citerefentry><refentrytitle>sd_json_dispatch</refentrytitle><manvolnum>3</manvolnum></citerefentry></member>
361 <member><citerefentry><refentrytitle>sd_variant_dispatch</refentrytitle><manvolnum>3</manvolnum></citerefentry></member>
362 </simplelist></para>
363 </refsect1>
364 </refentry>