| 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_bus_message_open_container" |
| 7 |
xmlns:xi="http://www.w3.org/2001/XInclude"> |
| 8 |
|
| 9 |
<refentryinfo> |
| 10 |
<title>sd_bus_message_open_container</title> |
| 11 |
<productname>systemd</productname> |
| 12 |
</refentryinfo> |
| 13 |
|
| 14 |
<refmeta> |
| 15 |
<refentrytitle>sd_bus_message_open_container</refentrytitle> |
| 16 |
<manvolnum>3</manvolnum> |
| 17 |
</refmeta> |
| 18 |
|
| 19 |
<refnamediv> |
| 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> |
| 24 |
|
| 25 |
<refpurpose>Create and move between containers in D-Bus messages</refpurpose> |
| 26 |
</refnamediv> |
| 27 |
|
| 28 |
<refsynopsisdiv> |
| 29 |
<funcsynopsis> |
| 30 |
<funcsynopsisinfo>#include <systemd/sd-bus.h></funcsynopsisinfo> |
| 31 |
|
| 32 |
<funcprototype> |
| 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> |
| 37 |
</funcprototype> |
| 38 |
|
| 39 |
<funcprototype> |
| 40 |
<funcdef>int sd_bus_message_close_container</funcdef> |
| 41 |
<paramdef>sd_bus_message *<parameter>m</parameter></paramdef> |
| 42 |
</funcprototype> |
| 43 |
|
| 44 |
<funcprototype> |
| 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> |
| 49 |
</funcprototype> |
| 50 |
|
| 51 |
<funcprototype> |
| 52 |
<funcdef>int sd_bus_message_exit_container</funcdef> |
| 53 |
<paramdef>sd_bus_message *<parameter>m</parameter></paramdef> |
| 54 |
</funcprototype> |
| 55 |
</funcsynopsis> |
| 56 |
</refsynopsisdiv> |
| 57 |
|
| 58 |
<refsect1> |
| 59 |
<title>Description</title> |
| 60 |
|
| 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>. |
| 75 |
</para> |
| 76 |
|
| 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> |
| 81 |
|
| 82 |
<para><function>sd_bus_message_enter_container()</function> enters the next container of the message |
| 83 |
<parameter>m</parameter> for reading. It behaves mostly the same as |
| 84 |
<function>sd_bus_message_open_container()</function>. Entering a container allows reading its contents |
| 85 |
with |
| 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> |
| 89 |
|
| 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>. Note that |
| 93 |
<function>sd_bus_message_exit_container()</function> may only be called after iterating through all |
| 94 |
members of the container, i.e. reading or skipping over them. Use |
| 95 |
<citerefentry><refentrytitle>sd_bus_message_skip</refentrytitle><manvolnum>3</manvolnum></citerefentry> |
| 96 |
to skip over fields of a container in order to be able to exit the container with |
| 97 |
<function>sd_bus_message_exit_container()</function> without reading all members.</para> |
| 98 |
</refsect1> |
| 99 |
|
| 100 |
<refsect1> |
| 101 |
<title>Return Value</title> |
| 102 |
|
| 103 |
<para>On success, these functions return a non-negative integer. |
| 104 |
<function>sd_bus_message_open_container()</function> and <function>sd_bus_message_close_container()</function> |
| 105 |
return 0. |
| 106 |
<function>sd_bus_message_enter_container()</function> returns 1 if it successfully opened a new container, and 0 if |
| 107 |
that was not possible because the end of the currently open container or message was reached. |
| 108 |
<function>sd_bus_message_exit_container()</function> returns 1 on success. |
| 109 |
On failure, all of these functions return a negative errno-style error code.</para> |
| 110 |
|
| 111 |
<refsect2> |
| 112 |
<title>Errors</title> |
| 113 |
|
| 114 |
<para>Returned errors may indicate the following problems:</para> |
| 115 |
|
| 116 |
<variablelist> |
| 117 |
<varlistentry> |
| 118 |
<term><constant>-EINVAL</constant></term> |
| 119 |
|
| 120 |
<listitem><para><parameter>m</parameter> or <parameter>contents</parameter> are |
| 121 |
<constant>NULL</constant> or <parameter>type</parameter> is invalid.</para> |
| 122 |
|
| 123 |
<xi:include href="version-info.xml" xpointer="v246"/></listitem> |
| 124 |
</varlistentry> |
| 125 |
|
| 126 |
<varlistentry> |
| 127 |
<term><constant>-EBADMSG</constant></term> |
| 128 |
|
| 129 |
<listitem><para>Message <parameter>m</parameter> has invalid structure.</para> |
| 130 |
|
| 131 |
<xi:include href="version-info.xml" xpointer="v254"/></listitem> |
| 132 |
</varlistentry> |
| 133 |
|
| 134 |
<varlistentry> |
| 135 |
<term><constant>-ENXIO</constant></term> |
| 136 |
|
| 137 |
<listitem><para>Message <parameter>m</parameter> does not have a container of type |
| 138 |
<parameter>type</parameter> at the current position, or the contents do not match |
| 139 |
<parameter>contents</parameter>.</para> |
| 140 |
|
| 141 |
<xi:include href="version-info.xml" xpointer="v254"/></listitem> |
| 142 |
</varlistentry> |
| 143 |
|
| 144 |
<varlistentry> |
| 145 |
<term><constant>-EPERM</constant></term> |
| 146 |
|
| 147 |
<listitem><para>The message <parameter>m</parameter> is already sealed.</para> |
| 148 |
|
| 149 |
<xi:include href="version-info.xml" xpointer="v246"/></listitem> |
| 150 |
</varlistentry> |
| 151 |
|
| 152 |
<varlistentry> |
| 153 |
<term><constant>-ESTALE</constant></term> |
| 154 |
|
| 155 |
<listitem><para>The message <parameter>m</parameter> is in an invalid state.</para> |
| 156 |
|
| 157 |
<xi:include href="version-info.xml" xpointer="v246"/></listitem> |
| 158 |
</varlistentry> |
| 159 |
|
| 160 |
<varlistentry> |
| 161 |
<term><constant>-ENOMEM</constant></term> |
| 162 |
|
| 163 |
<listitem><para>Memory allocation failed.</para> |
| 164 |
|
| 165 |
<xi:include href="version-info.xml" xpointer="v246"/></listitem> |
| 166 |
</varlistentry> |
| 167 |
|
| 168 |
<varlistentry> |
| 169 |
<term><constant>-EBUSY</constant></term> |
| 170 |
|
| 171 |
<listitem><para><function>sd_bus_message_exit_container()</function> was called but there are |
| 172 |
unread members left in the container.</para> |
| 173 |
|
| 174 |
<xi:include href="version-info.xml" xpointer="v247"/></listitem> |
| 175 |
</varlistentry> |
| 176 |
</variablelist> |
| 177 |
</refsect2> |
| 178 |
</refsect1> |
| 179 |
|
| 180 |
<xi:include href="libsystemd-pkgconfig.xml" /> |
| 181 |
|
| 182 |
<refsect1> |
| 183 |
<title>Examples</title> |
| 184 |
|
| 185 |
<example> |
| 186 |
<title>Append an array of strings to a message</title> |
| 187 |
|
| 188 |
<programlisting><xi:include href="sd-bus-container-append.c" parse="text" /></programlisting> |
| 189 |
</example> |
| 190 |
|
| 191 |
<example> |
| 192 |
<title>Read an array of strings from a message</title> |
| 193 |
|
| 194 |
<programlisting><xi:include href="sd-bus-container-read.c" parse="text" /></programlisting> |
| 195 |
</example> |
| 196 |
</refsect1> |
| 197 |
|
| 198 |
<refsect1> |
| 199 |
<title>See Also</title> |
| 200 |
|
| 201 |
<para><simplelist type="inline"> |
| 202 |
<member><citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry></member> |
| 203 |
<member><citerefentry><refentrytitle>sd-bus</refentrytitle><manvolnum>3</manvolnum></citerefentry></member> |
| 204 |
<member><citerefentry><refentrytitle>sd_bus_message_append</refentrytitle><manvolnum>3</manvolnum></citerefentry></member> |
| 205 |
<member><citerefentry><refentrytitle>sd_bus_message_read</refentrytitle><manvolnum>3</manvolnum></citerefentry></member> |
| 206 |
<member><citerefentry><refentrytitle>sd_bus_message_skip</refentrytitle><manvolnum>3</manvolnum></citerefentry></member> |
| 207 |
<member><ulink url="https://dbus.freedesktop.org/doc/dbus-specification.html">The D-Bus specification</ulink></member> |
| 208 |
</simplelist></para> |
| 209 |
</refsect1> |
| 210 |
|
| 211 |
</refentry> |