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.2/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 them. Use 95 <citerefentry><refentrytitle>sd_bus_message_skip</refentrytitle><manvolnum>3</manvolnum></citerefentry> 96 to skip over felds 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></listitem> 122 </varlistentry> 123 124 <varlistentry> 125 <term><constant>-EPERM</constant></term> 126 127 <listitem><para>The message <parameter>m</parameter> is already sealed.</para></listitem> 128 </varlistentry> 129 130 <varlistentry> 131 <term><constant>-ESTALE</constant></term> 132 133 <listitem><para>The message <parameter>m</parameter> is in an invalid state.</para></listitem> 134 </varlistentry> 135 136 <varlistentry> 137 <term><constant>-ENOMEM</constant></term> 138 139 <listitem><para>Memory allocation failed.</para></listitem> 140 </varlistentry> 141 142 <varlistentry> 143 <term><constant>-EBUSY</constant></term> 144 145 <listitem><para><function>sd_bus_message_exit_container()</function> was called but there are 146 unread members left in the container.</para></listitem> 147 </varlistentry> 148 </variablelist> 149 </refsect2> 150 </refsect1> 151 152 <xi:include href="libsystemd-pkgconfig.xml" /> 153 154 <refsect1> 155 <title>Examples</title> 156 157 <example> 158 <title>Append an array of strings to a message</title> 159 160 <programlisting><xi:include href="sd-bus-container-append.c" parse="text" /></programlisting> 161 </example> 162 163 <example> 164 <title>Read an array of strings from a message</title> 165 166 <programlisting><xi:include href="sd-bus-container-read.c" parse="text" /></programlisting> 167 </example> 168 </refsect1> 169 170 <refsect1> 171 <title>See Also</title> 172 173 <para> 174 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>, 175 <citerefentry><refentrytitle>sd-bus</refentrytitle><manvolnum>3</manvolnum></citerefentry>, 176 <citerefentry><refentrytitle>sd_bus_message_append</refentrytitle><manvolnum>3</manvolnum></citerefentry>, 177 <citerefentry><refentrytitle>sd_bus_message_read</refentrytitle><manvolnum>3</manvolnum></citerefentry>, 178 <citerefentry><refentrytitle>sd_bus_message_skip</refentrytitle><manvolnum>3</manvolnum></citerefentry>, 179 <ulink url="https://dbus.freedesktop.org/doc/dbus-specification.html">The D-Bus specification</ulink> 180 </para> 181 </refsect1> 182 183</refentry> 184