Debian Codegraph @

upstream/debian-unstable/man3/sd_bus_message_read.3

raw
1 '\" t
2 .TH "SD_BUS_MESSAGE_READ" "3" "" "systemd 261~rc3" "sd_bus_message_read"
3 .\" -----------------------------------------------------------------
4 .\" * Define some portability stuff
5 .\" -----------------------------------------------------------------
6 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7 .\" http://bugs.debian.org/507673
8 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
9 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10 .ie \n(.g .ds Aq \(aq
11 .el .ds Aq '
12 .\" -----------------------------------------------------------------
13 .\" * set default formatting
14 .\" -----------------------------------------------------------------
15 .\" disable hyphenation
16 .nh
17 .\" disable justification (adjust text to left margin only)
18 .ad l
19 .\" -----------------------------------------------------------------
20 .\" * MAIN CONTENT STARTS HERE *
21 .\" -----------------------------------------------------------------
22 .SH "NAME"
23 sd_bus_message_read, sd_bus_message_readv, sd_bus_message_peek_type \- Read a sequence of values from a message
24 .SH "SYNOPSIS"
25 .sp
26 .ft B
27 .nf
28 #include <systemd/sd\-bus\&.h>
29 .fi
30 .ft
31 .HP \w'int\ sd_bus_message_read('u
32 .BI "int sd_bus_message_read(sd_bus_message\ *" "m" ", const\ char\ *" "types" ", \&.\&.\&.);"
33 .HP \w'int\ sd_bus_message_readv('u
34 .BI "int sd_bus_message_readv(sd_bus_message\ *" "m" ", const\ char\ *" "types" ", va_list\ " "ap" ");"
35 .HP \w'int\ sd_bus_message_peek_type('u
36 .BI "int sd_bus_message_peek_type(sd_bus_message\ *" "m" ", char\ *" "type" ", const\ char\ **" "contents" ");"
37 .SH "DESCRIPTION"
38 .PP
39 \fBsd_bus_message_read()\fR
40 reads a sequence of fields from the D\-Bus message object
41 \fIm\fR
42 and advances the read position in the message\&. The type string
43 \fItypes\fR
44 describes the types of items expected in the message and the field arguments that follow\&. The type string may be
45 \fBNULL\fR
46 or empty, in which case nothing is read\&.
47 .PP
48 The type string is composed of the elements described in
49 \fBsd_bus_message_append\fR(3), i\&.e\&. basic and container types\&. It must contain zero or more single "complete types"\&. The type string is
50 \fBNUL\fR\-terminated\&.
51 .PP
52 For each type specified in the type string, one or more arguments need to be specified after the
53 \fItypes\fR
54 parameter, in the same order\&. The arguments must be pointers to appropriate types (a pointer to
55 \fBint8_t\fR
56 for a
57 "y"
58 in the type string, a pointer to
59 \fBint32_t\fR
60 for an
61 "i", a pointer to
62 \fBconst char*\fR
63 for an
64 "s", \&.\&.\&.) which are set based on the values in the message\&. As an exception, in case of array and variant types, the first argument is an "input" argument that further specifies how the message should be read\&. See the table below for a complete list of allowed arguments and their types\&. Note that, if the basic type is a pointer (e\&.g\&.,
65 \fBconst char *\fR
66 in the case of a string), the argument is a pointer to a pointer, and also the pointer value that is written is only borrowed and the contents must be copied if they are to be used after the end of the message\*(Aqs lifetime\&. If the type is
67 "h"
68 (UNIX file descriptor), the descriptor is not duplicated by this call and the returned descriptor remains in possession of the message object, and needs to be duplicated by the caller in order to keep an open reference to it after the message object is freed\&.
69 .PP
70 Each argument may also be
71 \fBNULL\fR, in which case the value is read and ignored\&.
72 .sp
73 .it 1 an-trap
74 .nr an-no-space-flag 1
75 .nr an-break-flag 1
76 .br
77 .B Table\ \&1.\ \&Item type specifiers
78 .TS
79 allbox tab(:);
80 lB lB lB lB lB.
81 T{
82 Specifier
83 T}:T{
84 Constant
85 T}:T{
86 Description
87 T}:T{
88 Type of the first argument
89 T}:T{
90 Types of the subsequent arguments, if any
91 T}
92 .T&
93 l l l l l
94 l l l l l
95 l l l l l
96 l l l l l
97 l l l l l
98 l l l l l
99 l l l l l
100 l l l l l
101 l l l l l
102 l l l l l
103 l l l l l
104 l l l l l
105 l l l l l
106 l l l l l
107 l l l l l
108 l l l l s
109 l l l ^ ^
110 l l l l l
111 l l l ^ ^.
112 T{
113 "y"
114 T}:T{
115 \fBSD_BUS_TYPE_BYTE\fR
116 T}:T{
117 8\-bit unsigned integer
118 T}:T{
119 \fBuint8_t *\fR
120 T}:T{
121 \ \&
122 T}
123 T{
124 "b"
125 T}:T{
126 \fBSD_BUS_TYPE_BOOLEAN\fR
127 T}:T{
128 boolean
129 T}:T{
130 \fBint *\fR (NB: not \fBbool *\fR)
131 T}:T{
132 \ \&
133 T}
134 T{
135 "n"
136 T}:T{
137 \fBSD_BUS_TYPE_INT16\fR
138 T}:T{
139 16\-bit signed integer
140 T}:T{
141 \fBint16_t *\fR
142 T}:T{
143 \ \&
144 T}
145 T{
146 "q"
147 T}:T{
148 \fBSD_BUS_TYPE_UINT16\fR
149 T}:T{
150 16\-bit unsigned integer
151 T}:T{
152 \fBuint16_t *\fR
153 T}:T{
154 \ \&
155 T}
156 T{
157 "i"
158 T}:T{
159 \fBSD_BUS_TYPE_INT32\fR
160 T}:T{
161 32\-bit signed integer
162 T}:T{
163 \fBint32_t *\fR
164 T}:T{
165 \ \&
166 T}
167 T{
168 "u"
169 T}:T{
170 \fBSD_BUS_TYPE_UINT32\fR
171 T}:T{
172 32\-bit unsigned integer
173 T}:T{
174 \fBuint32_t *\fR
175 T}:T{
176 \ \&
177 T}
178 T{
179 "x"
180 T}:T{
181 \fBSD_BUS_TYPE_INT64\fR
182 T}:T{
183 64\-bit signed integer
184 T}:T{
185 \fBint64_t *\fR
186 T}:T{
187 \ \&
188 T}
189 T{
190 "t"
191 T}:T{
192 \fBSD_BUS_TYPE_UINT64\fR
193 T}:T{
194 64\-bit unsigned integer
195 T}:T{
196 \fBuint64_t *\fR
197 T}:T{
198 \ \&
199 T}
200 T{
201 "d"
202 T}:T{
203 \fBSD_BUS_TYPE_DOUBLE\fR
204 T}:T{
205 IEEE 754 double precision floating\-point
206 T}:T{
207 \fBdouble *\fR
208 T}:T{
209 \ \&
210 T}
211 T{
212 "s"
213 T}:T{
214 \fBSD_BUS_TYPE_STRING\fR
215 T}:T{
216 UTF\-8 string
217 T}:T{
218 \fBconst char **\fR
219 T}:T{
220 \ \&
221 T}
222 T{
223 "o"
224 T}:T{
225 \fBSD_BUS_TYPE_OBJECT_PATH\fR
226 T}:T{
227 D\-Bus object path string
228 T}:T{
229 \fBconst char **\fR
230 T}:T{
231 \ \&
232 T}
233 T{
234 "g"
235 T}:T{
236 \fBSD_BUS_TYPE_SIGNATURE\fR
237 T}:T{
238 D\-Bus signature string
239 T}:T{
240 \fBconst char **\fR
241 T}:T{
242 \ \&
243 T}
244 T{
245 "h"
246 T}:T{
247 \fBSD_BUS_TYPE_UNIX_FD\fR
248 T}:T{
249 UNIX file descriptor
250 T}:T{
251 \fBint *\fR
252 T}:T{
253 \ \&
254 T}
255 T{
256 "a"
257 T}:T{
258 \fBSD_BUS_TYPE_ARRAY\fR
259 T}:T{
260 array
261 T}:T{
262 \fBint\fR, which specifies the expected length \fIn\fR of the array
263 T}:T{
264 \fIn\fR sets of arguments appropriate for the array element type
265 T}
266 T{
267 "v"
268 T}:T{
269 \fBSD_BUS_TYPE_VARIANT\fR
270 T}:T{
271 variant
272 T}:T{
273 signature string
274 T}:T{
275 arguments appropriate for the types specified by the signature
276 T}
277 T{
278 "("
279 T}:T{
280 \fBSD_BUS_TYPE_STRUCT_BEGIN\fR
281 T}:T{
282 array start
283 T}:T{
284 arguments appropriate for the structure elements
285 T}
286 T{
287 ")"
288 T}:T{
289 \fBSD_BUS_TYPE_STRUCT_END\fR
290 T}:T{
291 array end
292 T}::
293 T{
294 "{"
295 T}:T{
296 \fBSD_BUS_TYPE_DICT_ENTRY_BEGIN\fR
297 T}:T{
298 dictionary entry start
299 T}:T{
300 arguments appropriate for the first type in the pair
301 T}:T{
302 arguments appropriate for the second type in the pair
303 T}
304 T{
305 "}"
306 T}:T{
307 \fBSD_BUS_TYPE_DICT_ENTRY_END\fR
308 T}:T{
309 dictionary entry end
310 T}::
311 .TE
312 .sp 1
313 .PP
314 If objects of the specified types are not present at the current position in the message, an error is returned\&.
315 .PP
316 The
317 \fBsd_bus_message_readv()\fR
318 is equivalent to the
319 \fBsd_bus_message_read()\fR, except that it is called with a
320 "va_list"
321 instead of a variable number of arguments\&. This function does not call the
322 \fBva_end()\fR
323 macro\&. Because it invokes the
324 \fBva_arg()\fR
325 macro, the value of
326 \fIap\fR
327 is undefined after the call\&.
328 .PP
329 \fBsd_bus_message_peek_type()\fR
330 determines the type of the next element in
331 \fIm\fR
332 to be read by
333 \fBsd_bus_message_read()\fR
334 or similar functions\&. On success, the type is stored in
335 \fItype\fR, if it is not
336 \fBNULL\fR\&. If the type is a container type, the type of its elements is stored in
337 \fIcontents\fR, if it is not
338 \fBNULL\fR\&. If this function successfully determines the type of the next element in
339 \fIm\fR, it returns a positive integer\&. If there are no more elements to be read, it returns zero\&.
340 .SH "RETURN VALUE"
341 .PP
342 On success, these functions return a non\-negative integer\&. On failure, they return a negative errno\-style error code\&.
343 .SS "Errors"
344 .PP
345 Returned errors may indicate the following problems:
346 .PP
347 \fB\-EINVAL\fR
348 .RS 4
349 Specified type string is invalid or the message parameter is
350 \fBNULL\fR\&.
351 .RE
352 .PP
353 \fB\-ENXIO\fR
354 .RS 4
355 The message does not contain the specified type at current position\&.
356 .RE
357 .PP
358 \fB\-EBADMSG\fR
359 .RS 4
360 The message cannot be parsed\&.
361 .RE
362 .PP
363 \fB\-EBUSY\fR
364 .RS 4
365 When reading from a container, this error will be returned if unread elements are left in the container\&.
366 .sp
367 Added in version 251\&.
368 .RE
369 .SH "NOTES"
370 .PP
371 Functions described here are available as a shared library, which can be compiled against and linked to with the
372 \fBlibsystemd\fR\ \&\fBpkg-config\fR(1)
373 file\&.
374 .PP
375 The code described here uses
376 \fBgetenv\fR(3), which is declared to be not multi\-thread\-safe\&. This means that the code calling the functions described here must not call
377 \fBsetenv\fR(3)
378 from a parallel thread\&. It is recommended to only do calls to
379 \fBsetenv()\fR
380 from an early phase of the program when no other threads have been started\&.
381 .SH "EXAMPLES"
382 .PP
383 Read a single basic type (a 64\-bit integer):
384 .sp
385 .if n \{\
386 .RS 4
387 .\}
388 .nf
389 sd_bus_message *m;
390 int64_t x;
391
392 sd_bus_message_read(m, "x", &x);
393 .fi
394 .if n \{\
395 .RE
396 .\}
397 .PP
398 Read a boolean value:
399 .sp
400 .if n \{\
401 .RS 4
402 .\}
403 .nf
404 sd_bus_message *m;
405 int x; /* Do not use C99 "bool" type here, it is typically smaller
406 in memory and would cause memory corruption */
407
408 sd_bus_message_read(m, "b", &x);
409 .fi
410 .if n \{\
411 .RE
412 .\}
413 .PP
414 Read all types of integers:
415 .sp
416 .if n \{\
417 .RS 4
418 .\}
419 .nf
420 uint8_t y;
421 int16_t n;
422 uint16_t q;
423 int32_t i;
424 uint32_t u;
425 int64_t x;
426 uint64_t t;
427 double d;
428
429 sd_bus_message_read(m, "ynqiuxtd", &y, &n, &q, &i, &u, &x, &t, &d);
430 .fi
431 .if n \{\
432 .RE
433 .\}
434 .PP
435 Read a structure composed of a string and a D\-Bus path:
436 .sp
437 .if n \{\
438 .RS 4
439 .\}
440 .nf
441 const char *s, *p;
442
443 sd_bus_message_read(m, "(so)", &s, &p);
444 .fi
445 .if n \{\
446 .RE
447 .\}
448 .PP
449 Read a variant, with the real type "gt" (signature, unsigned integer):
450 .sp
451 .if n \{\
452 .RS 4
453 .\}
454 .nf
455 const char *s;
456 uint64_t *v;
457
458 sd_bus_message_read(m, "v", "gt", &s, &v);
459 .fi
460 .if n \{\
461 .RE
462 .\}
463 .PP
464 Read a dictionary containing three pairs of type {integer=>string}:
465 .sp
466 .if n \{\
467 .RS 4
468 .\}
469 .nf
470 int i, j, k;
471 const char *s, *t, *u;
472
473 sd_bus_message_read(m, "a{is}", 3, &i, &s, &j, &t, &k, &u);
474 .fi
475 .if n \{\
476 .RE
477 .\}
478 .PP
479 Read a single file descriptor, and duplicate it in order to keep it open after the message is freed\&.
480 .sp
481 .if n \{\
482 .RS 4
483 .\}
484 .nf
485 sd_bus_message *m;
486 int fd, fd_copy;
487
488 sd_bus_message_read(m, "h", &fd);
489 fd_copy = fcntl(fd, FD_DUPFD_CLOEXEC, 3);
490 .fi
491 .if n \{\
492 .RE
493 .\}
494 .SH "HISTORY"
495 .PP
496 \fBsd_bus_message_read()\fR
497 and
498 \fBsd_bus_message_readv()\fR
499 were added in version 240\&.
500 .PP
501 \fBsd_bus_message_peek_type()\fR
502 was added in version 246\&.
503 .SH "SEE ALSO"
504 .PP
505 \fBsystemd\fR(1), \fBsd-bus\fR(3), \fBsd_bus_message_read_basic\fR(3), \fBsd_bus_message_skip\fR(3), \fBsd_bus_message_append\fR(3), \fBsd_bus_message_enter_container\fR(3)