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