summaryrefslogtreecommitdiffstats
path: root/upstream/mageia-cauldron/man3/sd_bus_message_open_container.3
blob: f73954cc244c218ab7ebbbe240a9e1dac46140a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
'\" t
.TH "SD_BUS_MESSAGE_OPEN_CONTAINER" "3" "" "systemd 255" "sd_bus_message_open_container"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.\" http://bugs.debian.org/507673
.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.ie \n(.g .ds Aq \(aq
.el       .ds Aq '
.\" -----------------------------------------------------------------
.\" * set default formatting
.\" -----------------------------------------------------------------
.\" disable hyphenation
.nh
.\" disable justification (adjust text to left margin only)
.ad l
.\" -----------------------------------------------------------------
.\" * MAIN CONTENT STARTS HERE *
.\" -----------------------------------------------------------------
.SH "NAME"
sd_bus_message_open_container, sd_bus_message_close_container, sd_bus_message_enter_container, sd_bus_message_exit_container \- Create and move between containers in D\-Bus messages
.SH "SYNOPSIS"
.sp
.ft B
.nf
#include <systemd/sd\-bus\&.h>
.fi
.ft
.HP \w'int\ sd_bus_message_open_container('u
.BI "int sd_bus_message_open_container(sd_bus_message\ *" "m" ", char\ " "type" ", const\ char\ *" "contents" ");"
.HP \w'int\ sd_bus_message_close_container('u
.BI "int sd_bus_message_close_container(sd_bus_message\ *" "m" ");"
.HP \w'int\ sd_bus_message_enter_container('u
.BI "int sd_bus_message_enter_container(sd_bus_message\ *" "m" ", char\ " "type" ", const\ char\ *" "contents" ");"
.HP \w'int\ sd_bus_message_exit_container('u
.BI "int sd_bus_message_exit_container(sd_bus_message\ *" "m" ");"
.SH "DESCRIPTION"
.PP
\fBsd_bus_message_open_container()\fR
appends a new container to the message
\fIm\fR\&. After opening a new container, it can be filled with content using
\fBsd_bus_message_append\fR(3)
and similar functions\&. Containers behave like a stack\&. To nest containers inside each other, call
\fBsd_bus_message_open_container()\fR
multiple times without calling
\fBsd_bus_message_close_container()\fR
in between\&. Each container will be nested inside the previous container\&.
\fItype\fR
represents the container type and should be one of
"r",
"a",
"v"
or
"e"
as described in
\fBsd_bus_message_append\fR(3)\&. Instead of literals, the corresponding constants
\fBSD_BUS_TYPE_STRUCT\fR,
\fBSD_BUS_TYPE_ARRAY\fR,
\fBSD_BUS_TYPE_VARIANT\fR
or
\fBSD_BUS_TYPE_DICT_ENTRY\fR
can also be used\&.
\fIcontents\fR
describes the type of the container\*(Aqs elements and should be a D\-Bus type string following the rules described in
\fBsd_bus_message_append\fR(3)\&.
.PP
\fBsd_bus_message_close_container()\fR
closes the last container opened with
\fBsd_bus_message_open_container()\fR\&. On success, the write pointer of the message
\fIm\fR
is positioned after the closed container in its parent container or in
\fIm\fR
itself if there is no parent container\&.
.PP
\fBsd_bus_message_enter_container()\fR
enters the next container of the message
\fIm\fR
for reading\&. It behaves mostly the same as
\fBsd_bus_message_open_container()\fR\&. Entering a container allows reading its contents with
\fBsd_bus_message_read\fR(3)
and similar functions\&.
\fItype\fR
and
\fIcontents\fR
are the same as in
\fBsd_bus_message_open_container()\fR\&.
.PP
\fBsd_bus_message_exit_container()\fR
exits the scope of the last container entered with
\fBsd_bus_message_enter_container()\fR\&. It behaves mostly the same as
\fBsd_bus_message_close_container()\fR\&. Note that
\fBsd_bus_message_exit_container()\fR
may only be called after iterating through all members of the container, i\&.e\&. reading or skipping over them\&. Use
\fBsd_bus_message_skip\fR(3)
to skip over fields of a container in order to be able to exit the container with
\fBsd_bus_message_exit_container()\fR
without reading all members\&.
.SH "RETURN VALUE"
.PP
On success, these functions return a non\-negative integer\&.
\fBsd_bus_message_open_container()\fR
and
\fBsd_bus_message_close_container()\fR
return 0\&.
\fBsd_bus_message_enter_container()\fR
returns 1 if it successfully opened a new container, and 0 if that was not possible because the end of the currently open container or message was reached\&.
\fBsd_bus_message_exit_container()\fR
returns 1 on success\&. On failure, all of these functions return a negative errno\-style error code\&.
.SS "Errors"
.PP
Returned errors may indicate the following problems:
.PP
\fB\-EINVAL\fR
.RS 4
\fIm\fR
or
\fIcontents\fR
are
\fBNULL\fR
or
\fItype\fR
is invalid\&.
.sp
Added in version 246\&.
.RE
.PP
\fB\-EBADMSG\fR
.RS 4
Message
\fIm\fR
has invalid structure\&.
.sp
Added in version 254\&.
.RE
.PP
\fB\-ENXIO\fR
.RS 4
Message
\fIm\fR
does not have a container of type
\fItype\fR
at the current position, or the contents do not match
\fIcontents\fR\&.
.sp
Added in version 254\&.
.RE
.PP
\fB\-EPERM\fR
.RS 4
The message
\fIm\fR
is already sealed\&.
.sp
Added in version 246\&.
.RE
.PP
\fB\-ESTALE\fR
.RS 4
The message
\fIm\fR
is in an invalid state\&.
.sp
Added in version 246\&.
.RE
.PP
\fB\-ENOMEM\fR
.RS 4
Memory allocation failed\&.
.sp
Added in version 246\&.
.RE
.PP
\fB\-EBUSY\fR
.RS 4
\fBsd_bus_message_exit_container()\fR
was called but there are unread members left in the container\&.
.sp
Added in version 247\&.
.RE
.SH "NOTES"
.PP
Functions described here are available as a shared library, which can be compiled against and linked to with the
\fBlibsystemd\fR\ \&\fBpkg-config\fR(1)
file\&.
.PP
The code described here uses
\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
\fBsetenv\fR(3)
from a parallel thread\&. It is recommended to only do calls to
\fBsetenv()\fR
from an early phase of the program when no other threads have been started\&.
.SH "EXAMPLES"
.PP
\fBExample\ \&1.\ \&Append an array of strings to a message\fR
.sp
.if n \{\
.RS 4
.\}
.nf
/* SPDX\-License\-Identifier: MIT\-0 */

#include <systemd/sd\-bus\&.h>

int append_strings_to_message(sd_bus_message *m, const char *const *arr) {
  int r;

  r = sd_bus_message_open_container(m, \*(Aqa\*(Aq, "s");
  if (r < 0)
    return r;

  for (const char *s = *arr; *s; s++) {
    r = sd_bus_message_append(m, "s", s);
    if (r < 0)
      return r;
  }

  return sd_bus_message_close_container(m);
}
.fi
.if n \{\
.RE
.\}
.PP
\fBExample\ \&2.\ \&Read an array of strings from a message\fR
.sp
.if n \{\
.RS 4
.\}
.nf
/* SPDX\-License\-Identifier: MIT\-0 */

#include <stdio\&.h>

#include <systemd/sd\-bus\&.h>

int read_strings_from_message(sd_bus_message *m) {
  int r;

  r = sd_bus_message_enter_container(m, \*(Aqa\*(Aq, "s");
  if (r < 0)
    return r;

  for (;;) {
    const char *s;

    r = sd_bus_message_read(m, "s", &s);
    if (r < 0)
      return r;
    if (r == 0)
      break;

    printf("%s\en", s);
  }

  return sd_bus_message_exit_container(m);
}
.fi
.if n \{\
.RE
.\}
.SH "SEE ALSO"
.PP
\fBsystemd\fR(1),
\fBsd-bus\fR(3),
\fBsd_bus_message_append\fR(3),
\fBsd_bus_message_read\fR(3),
\fBsd_bus_message_skip\fR(3),
\m[blue]\fBThe D\-Bus specification\fR\m[]\&\s-2\u[1]\d\s+2
.SH "NOTES"
.IP " 1." 4
The D-Bus specification
.RS 4
\%https://dbus.freedesktop.org/doc/dbus-specification.html
.RE