]> git.ipfire.org Git - thirdparty/systemd.git/blame - man/sd_bus_path_encode.xml
man: fix reference to sd_bus_add_fallback_vtable
[thirdparty/systemd.git] / man / sd_bus_path_encode.xml
CommitLineData
514094f9 1<?xml version='1.0'?>
3a54a157
ZJS
2<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
0307f791 4<!-- SPDX-License-Identifier: LGPL-2.1+ -->
a6278b88 5
7647c01d 6<refentry id="sd_bus_path_encode" xmlns:xi="http://www.w3.org/2001/XInclude">
a6278b88
LP
7
8 <refentryinfo>
9 <title>sd_bus_path_encode</title>
10 <productname>systemd</productname>
a6278b88
LP
11 </refentryinfo>
12
13 <refmeta>
14 <refentrytitle>sd_bus_path_encode</refentrytitle>
15 <manvolnum>3</manvolnum>
16 </refmeta>
17
18 <refnamediv>
19 <refname>sd_bus_path_encode</refname>
dfb815c3 20 <refname>sd_bus_path_encode_many</refname>
a6278b88 21 <refname>sd_bus_path_decode</refname>
dfb815c3 22 <refname>sd_bus_path_decode_many</refname>
a6278b88
LP
23
24 <refpurpose>Convert an external identifier into an object path and back</refpurpose>
25 </refnamediv>
26
27 <refsynopsisdiv>
28 <funcsynopsis>
29 <funcsynopsisinfo>#include &lt;systemd/sd-bus.h&gt;</funcsynopsisinfo>
30
31 <funcprototype>
32 <funcdef>int <function>sd_bus_path_encode</function></funcdef>
33 <paramdef>const char *<parameter>prefix</parameter></paramdef>
34 <paramdef>const char *<parameter>external_id</parameter></paramdef>
35 <paramdef>char **<parameter>ret_path</parameter></paramdef>
36 </funcprototype>
37
dfb815c3
DH
38 <funcprototype>
39 <funcdef>int <function>sd_bus_path_encode_many</function></funcdef>
40 <paramdef>char **<parameter>out</parameter></paramdef>
41 <paramdef>const char *<parameter>path_template</parameter></paramdef>
1eecafb8 42 <paramdef>…</paramdef>
dfb815c3
DH
43 </funcprototype>
44
a6278b88
LP
45 <funcprototype>
46 <funcdef>int <function>sd_bus_path_decode</function></funcdef>
a6278b88 47 <paramdef>const char *<parameter>path</parameter></paramdef>
53d68375 48 <paramdef>const char *<parameter>prefix</parameter></paramdef>
a6278b88
LP
49 <paramdef>char **<parameter>ret_external_id</parameter></paramdef>
50 </funcprototype>
dfb815c3
DH
51
52 <funcprototype>
53 <funcdef>int <function>sd_bus_path_decode_many</function></funcdef>
54 <paramdef>const char *<parameter>path</parameter></paramdef>
55 <paramdef>const char *<parameter>path_template</parameter></paramdef>
1eecafb8 56 <paramdef>…</paramdef>
dfb815c3 57 </funcprototype>
a6278b88
LP
58 </funcsynopsis>
59 </refsynopsisdiv>
60
61 <refsect1>
62 <title>Description</title>
63
64 <para><function>sd_bus_path_encode()</function> and
65 <function>sd_bus_path_decode()</function> convert external
66 identifier strings into object paths and back. These functions are
67 useful to map application-specific string identifiers of any kind
68 into bus object paths in a simple, reversible and safe way.</para>
69
70 <para><function>sd_bus_path_encode()</function> takes a bus path
71 prefix and an external identifier string as arguments, plus a
72 place to store the returned bus path string. The bus path prefix
73 must be a valid bus path, starting with a slash
b8bde116
JE
74 <literal>/</literal>, and not ending in one. The external
75 identifier string may be in any format, may be the empty string,
76 and has no restrictions on the charset — however, it must
a6278b88
LP
77 always be <constant>NUL</constant>-terminated. The returned string
78 will be the concatenation of the bus path prefix plus an escaped
79 version of the external identifier string. This operation may be
cfe8ee46 80 reversed with <function>sd_bus_path_decode()</function>. It is
b8bde116 81 recommended to only use external identifiers that generally
a6278b88 82 require little escaping to be turned into valid bus path
b8bde116 83 identifiers (for example, by sticking to a 7-bit ASCII character
a6278b88
LP
84 set), in order to ensure the resulting bus path is still short and
85 easily processed.</para>
86
87 <para><function>sd_bus_path_decode()</function> reverses the
88 operation of <function>sd_bus_path_encode()</function> and thus
89 regenerates an external identifier string from a bus path. It
90 takes a bus path and a prefix string, plus a place to store the
91 returned external identifier string. If the bus path does not
92 start with the specified prefix, 0 is returned and the returned
b8bde116 93 string is set to <constant>NULL</constant>. Otherwise, the
a6278b88
LP
94 string following the prefix is unescaped and returned in the
95 external identifier string.</para>
96
dca348bc 97 <para>The escaping used will replace all characters which are
b8bde116 98 invalid in a bus object path by <literal>_</literal>, followed by a
a6278b88
LP
99 hexadecimal value. As a special case, the empty string will be
100 replaced by a lone <literal>_</literal>.</para>
dfb815c3
DH
101
102 <para><function>sd_bus_path_encode_many()</function> works like
103 its counterpart <function>sd_bus_path_encode()</function>, but
b938cb90 104 takes a path template as argument and encodes multiple labels
dfb815c3
DH
105 according to its embedded directives. For each
106 <literal>%</literal> character found in the template, the caller
b938cb90 107 must provide a string via varargs, which will be encoded and
dfb815c3
DH
108 embedded at the position of the <literal>%</literal> character.
109 Any other character in the template is copied verbatim into the
110 encoded path.</para>
111
112 <para><function>sd_bus_path_decode_many()</function> does the
113 reverse of <function>sd_bus_path_encode_many()</function>. It
b938cb90
JE
114 decodes the passed object path according to the given
115 path template. For each <literal>%</literal> character in the
dfb815c3 116 template, the caller must provide an output storage
b938cb90 117 (<literal>char **</literal>) via varargs. The decoded label
dfb815c3
DH
118 will be stored there. Each <literal>%</literal> character will
119 only match the current label. It will never match across labels.
a8eaaee7 120 Furthermore, only a single directive is allowed per label.
dfb815c3
DH
121 If <literal>NULL</literal> is passed as output storage, the
122 label is verified but not returned to the caller.</para>
a6278b88
LP
123 </refsect1>
124
125 <refsect1>
126 <title>Return Value</title>
127
128 <para>On success, <function>sd_bus_path_encode()</function>
129 returns positive or 0, and a valid bus path in the return
130 argument. On success, <function>sd_bus_path_decode()</function>
131 returns a positive value if the prefixed matched, or 0 if it
b8bde116
JE
132 did not. If the prefix matched, the external identifier is returned
133 in the return parameter. If it did not match, NULL is returned in
a6278b88
LP
134 the return parameter. On failure, a negative errno-style error
135 number is returned by either function. The returned strings must
136 be
5aded369 137 <citerefentry project='man-pages'><refentrytitle>free</refentrytitle><manvolnum>3</manvolnum></citerefentry>'d
a6278b88
LP
138 by the caller.</para>
139 </refsect1>
140
7647c01d 141 <xi:include href="libsystemd-pkgconfig.xml" />
a6278b88
LP
142
143 <refsect1>
144 <title>See Also</title>
145
146 <para>
147 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
148 <citerefentry><refentrytitle>sd-bus</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
5aded369 149 <citerefentry project='man-pages'><refentrytitle>free</refentrytitle><manvolnum>3</manvolnum></citerefentry>
a6278b88
LP
150 </para>
151 </refsect1>
152
153</refentry>