2 <!DOCTYPE refentry PUBLIC
"-//OASIS//DTD DocBook XML V4.5//EN"
3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
4 <!-- SPDX-License-Identifier: LGPL-2.1+ -->
6 <refentry id=
"sd_bus_message_open_container"
7 xmlns:
xi=
"http://www.w3.org/2001/XInclude">
10 <title>sd_bus_message_open_container
</title>
11 <productname>systemd
</productname>
15 <refentrytitle>sd_bus_message_open_container
</refentrytitle>
16 <manvolnum>3</manvolnum>
20 <refname>sd_bus_message_open_container
</refname>
21 <refname>sd_bus_message_close_container
</refname>
22 <refname>sd_bus_message_enter_container
</refname>
23 <refname>sd_bus_message_exit_container
</refname>
25 <refpurpose>Create and move between containers in D-Bus messages
</refpurpose>
30 <funcsynopsisinfo>#include
<systemd/sd-bus.h
></funcsynopsisinfo>
33 <funcdef>int sd_bus_message_open_container
</funcdef>
34 <paramdef>sd_bus_message *
<parameter>m
</parameter></paramdef>
35 <paramdef>char
<parameter>type
</parameter></paramdef>
36 <paramdef>const char *
<parameter>contents
</parameter></paramdef>
40 <funcdef>int sd_bus_message_close_container
</funcdef>
41 <paramdef>sd_bus_message *
<parameter>m
</parameter></paramdef>
45 <funcdef>int sd_bus_message_enter_container
</funcdef>
46 <paramdef>sd_bus_message *
<parameter>m
</parameter></paramdef>
47 <paramdef>char
<parameter>type
</parameter></paramdef>
48 <paramdef>const char *
<parameter>contents
</parameter></paramdef>
52 <funcdef>int sd_bus_message_exit_container
</funcdef>
53 <paramdef>sd_bus_message *
<parameter>m
</parameter></paramdef>
59 <title>Description
</title>
61 <para><function>sd_bus_message_open_container()
</function> appends a new container to the message
62 <parameter>m
</parameter>. After opening a new container, it can be filled with content using
63 <citerefentry><refentrytitle>sd_bus_message_append
</refentrytitle><manvolnum>3</manvolnum></citerefentry>
64 and similar functions. Containers behave like a stack. To nest containers inside each other, call
65 <function>sd_bus_message_open_container()
</function> multiple times without calling
66 <function>sd_bus_message_close_container()
</function> in between. Each container will be nested inside the
67 previous container.
<parameter>type
</parameter> represents the container type and should be one of
68 <literal>r
</literal>,
<literal>a
</literal>,
<literal>v
</literal> or
<literal>e
</literal> as described in
69 <citerefentry><refentrytitle>sd_bus_message_append
</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
70 Instead of literals, the corresponding constants
<constant>SD_BUS_TYPE_STRUCT
</constant>,
71 <constant>SD_BUS_TYPE_ARRAY
</constant>,
<constant>SD_BUS_TYPE_VARIANT
</constant> or
72 <constant>SD_BUS_TYPE_DICT_ENTRY
</constant> can also be used.
<parameter>contents
</parameter> describes
73 the type of the container's elements and should be a D-Bus type string following the rules described in
74 <citerefentry><refentrytitle>sd_bus_message_append
</refentrytitle><manvolnum>3</manvolnum></citerefentry>.
77 <para><function>sd_bus_message_close_container()
</function> closes the last container opened with
78 <function>sd_bus_message_open_container()
</function>. On success, the write pointer of the message
79 <parameter>m
</parameter> is positioned after the closed container in its parent container or in
80 <parameter>m
</parameter> itself if there is no parent container.
</para>
82 <para><function>sd_bus_message_enter_container()
</function> enters the next container of the message
83 <parameter>m
</parameter>. It behaves mostly the same as
84 <function>sd_bus_message_open_container()
</function>. Entering a container allows reading its contents
86 <citerefentry><refentrytitle>sd_bus_message_read
</refentrytitle><manvolnum>3</manvolnum></citerefentry>
87 and similar functions.
<parameter>type
</parameter> and
<parameter>contents
</parameter> are the same as in
88 <function>sd_bus_message_open_container()
</function>.
</para>
90 <para><function>sd_bus_message_exit_container()
</function> exits the scope of the last container entered
91 with
<function>sd_bus_message_enter_container()
</function>. It behaves mostly the same as
92 <function>sd_bus_message_close_container()
</function>.
</para>
96 <title>Return Value
</title>
98 <para>On success, these functions return a non-negative integer. On failure, they return a negative
99 errno-style error code.
</para>
102 <title>Errors
</title>
104 <para>Returned errors may indicate the following problems:
</para>
108 <term><constant>-EINVAL
</constant></term>
110 <listitem><para><parameter>m
</parameter> or
<parameter>contents
</parameter> are
111 <constant>NULL
</constant> or
<parameter>type
</parameter> is invalid.
</para></listitem>
115 <term><constant>-EPERM
</constant></term>
117 <listitem><para>The message
<parameter>m
</parameter> is already sealed.
</para></listitem>
121 <term><constant>-ESTALE
</constant></term>
123 <listitem><para>The message
<parameter>m
</parameter> is in an invalid state.
</para></listitem>
127 <term><constant>-ENOMEM
</constant></term>
129 <listitem><para>Memory allocation failed.
</para></listitem>
135 <xi:include href=
"libsystemd-pkgconfig.xml" />
138 <title>Examples
</title>
141 <title>Append an array of strings to a message
</title>
143 <programlisting><xi:include href=
"sd-bus-container-append.c" parse=
"text" /></programlisting>
147 <title>Read an array of strings from a message
</title>
149 <programlisting><xi:include href=
"sd-bus-container-read.c" parse=
"text" /></programlisting>
154 <title>See Also
</title>
157 <citerefentry><refentrytitle>systemd
</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
158 <citerefentry><refentrytitle>sd-bus
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
159 <citerefentry><refentrytitle>sd_bus_message_append
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
160 <citerefentry><refentrytitle>sd_bus_message_read
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
161 <ulink url=
"https://dbus.freedesktop.org/doc/dbus-specification.html">The D-Bus specification
</ulink>