]>
Commit | Line | Data |
---|---|---|
3802a3d3 | 1 | <?xml version='1.0'?> <!--*- Mode: nxml; nxml-child-indent: 2; indent-tabs-mode: nil -*--> |
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 ZJS |
6 | SPDX-License-Identifier: LGPL-2.1+ |
7 | ||
b975b0d5 | 8 | This file is part of systemd. |
a6278b88 | 9 | |
b975b0d5 | 10 | Copyright 2014 Zbigniew Jędrzejewski-Szmek |
a6278b88 | 11 | |
b975b0d5 ZJS |
12 | systemd is free software; you can redistribute it and/or modify it |
13 | under the terms of the GNU Lesser General Public License as published by | |
14 | the Free Software Foundation; either version 2.1 of the License, or | |
15 | (at your option) any later version. | |
a6278b88 | 16 | |
b975b0d5 ZJS |
17 | systemd is distributed in the hope that it will be useful, but |
18 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
20 | Lesser General Public License for more details. | |
a6278b88 | 21 | |
b975b0d5 ZJS |
22 | You should have received a copy of the GNU Lesser General Public License |
23 | along with systemd; If not, see <http://www.gnu.org/licenses/>. | |
a6278b88 LP |
24 | --> |
25 | ||
48f69d8f | 26 | <refentry id="sd_bus_path_encode"> |
a6278b88 LP |
27 | |
28 | <refentryinfo> | |
29 | <title>sd_bus_path_encode</title> | |
30 | <productname>systemd</productname> | |
31 | ||
32 | <authorgroup> | |
33 | <author> | |
34 | <contrib>A monkey with a typewriter</contrib> | |
35 | <firstname>Zbigniew</firstname> | |
36 | <surname>Jędrzejewski-Szmek</surname> | |
37 | <email>zbyszek@in.waw.pl</email> | |
38 | </author> | |
39 | </authorgroup> | |
40 | </refentryinfo> | |
41 | ||
42 | <refmeta> | |
43 | <refentrytitle>sd_bus_path_encode</refentrytitle> | |
44 | <manvolnum>3</manvolnum> | |
45 | </refmeta> | |
46 | ||
47 | <refnamediv> | |
48 | <refname>sd_bus_path_encode</refname> | |
dfb815c3 | 49 | <refname>sd_bus_path_encode_many</refname> |
a6278b88 | 50 | <refname>sd_bus_path_decode</refname> |
dfb815c3 | 51 | <refname>sd_bus_path_decode_many</refname> |
a6278b88 LP |
52 | |
53 | <refpurpose>Convert an external identifier into an object path and back</refpurpose> | |
54 | </refnamediv> | |
55 | ||
56 | <refsynopsisdiv> | |
57 | <funcsynopsis> | |
58 | <funcsynopsisinfo>#include <systemd/sd-bus.h></funcsynopsisinfo> | |
59 | ||
60 | <funcprototype> | |
61 | <funcdef>int <function>sd_bus_path_encode</function></funcdef> | |
62 | <paramdef>const char *<parameter>prefix</parameter></paramdef> | |
63 | <paramdef>const char *<parameter>external_id</parameter></paramdef> | |
64 | <paramdef>char **<parameter>ret_path</parameter></paramdef> | |
65 | </funcprototype> | |
66 | ||
dfb815c3 DH |
67 | <funcprototype> |
68 | <funcdef>int <function>sd_bus_path_encode_many</function></funcdef> | |
69 | <paramdef>char **<parameter>out</parameter></paramdef> | |
70 | <paramdef>const char *<parameter>path_template</parameter></paramdef> | |
1eecafb8 | 71 | <paramdef>…</paramdef> |
dfb815c3 DH |
72 | </funcprototype> |
73 | ||
a6278b88 LP |
74 | <funcprototype> |
75 | <funcdef>int <function>sd_bus_path_decode</function></funcdef> | |
a6278b88 | 76 | <paramdef>const char *<parameter>path</parameter></paramdef> |
53d68375 | 77 | <paramdef>const char *<parameter>prefix</parameter></paramdef> |
a6278b88 LP |
78 | <paramdef>char **<parameter>ret_external_id</parameter></paramdef> |
79 | </funcprototype> | |
dfb815c3 DH |
80 | |
81 | <funcprototype> | |
82 | <funcdef>int <function>sd_bus_path_decode_many</function></funcdef> | |
83 | <paramdef>const char *<parameter>path</parameter></paramdef> | |
84 | <paramdef>const char *<parameter>path_template</parameter></paramdef> | |
1eecafb8 | 85 | <paramdef>…</paramdef> |
dfb815c3 | 86 | </funcprototype> |
a6278b88 LP |
87 | </funcsynopsis> |
88 | </refsynopsisdiv> | |
89 | ||
90 | <refsect1> | |
91 | <title>Description</title> | |
92 | ||
93 | <para><function>sd_bus_path_encode()</function> and | |
94 | <function>sd_bus_path_decode()</function> convert external | |
95 | identifier strings into object paths and back. These functions are | |
96 | useful to map application-specific string identifiers of any kind | |
97 | into bus object paths in a simple, reversible and safe way.</para> | |
98 | ||
99 | <para><function>sd_bus_path_encode()</function> takes a bus path | |
100 | prefix and an external identifier string as arguments, plus a | |
101 | place to store the returned bus path string. The bus path prefix | |
102 | must be a valid bus path, starting with a slash | |
b8bde116 JE |
103 | <literal>/</literal>, and not ending in one. The external |
104 | identifier string may be in any format, may be the empty string, | |
105 | and has no restrictions on the charset — however, it must | |
a6278b88 LP |
106 | always be <constant>NUL</constant>-terminated. The returned string |
107 | will be the concatenation of the bus path prefix plus an escaped | |
108 | version of the external identifier string. This operation may be | |
109 | reversed with <function>sd_bus_decode()</function>. It is | |
b8bde116 | 110 | recommended to only use external identifiers that generally |
a6278b88 | 111 | require little escaping to be turned into valid bus path |
b8bde116 | 112 | identifiers (for example, by sticking to a 7-bit ASCII character |
a6278b88 LP |
113 | set), in order to ensure the resulting bus path is still short and |
114 | easily processed.</para> | |
115 | ||
116 | <para><function>sd_bus_path_decode()</function> reverses the | |
117 | operation of <function>sd_bus_path_encode()</function> and thus | |
118 | regenerates an external identifier string from a bus path. It | |
119 | takes a bus path and a prefix string, plus a place to store the | |
120 | returned external identifier string. If the bus path does not | |
121 | start with the specified prefix, 0 is returned and the returned | |
b8bde116 | 122 | string is set to <constant>NULL</constant>. Otherwise, the |
a6278b88 LP |
123 | string following the prefix is unescaped and returned in the |
124 | external identifier string.</para> | |
125 | ||
dca348bc | 126 | <para>The escaping used will replace all characters which are |
b8bde116 | 127 | invalid in a bus object path by <literal>_</literal>, followed by a |
a6278b88 LP |
128 | hexadecimal value. As a special case, the empty string will be |
129 | replaced by a lone <literal>_</literal>.</para> | |
dfb815c3 DH |
130 | |
131 | <para><function>sd_bus_path_encode_many()</function> works like | |
132 | its counterpart <function>sd_bus_path_encode()</function>, but | |
b938cb90 | 133 | takes a path template as argument and encodes multiple labels |
dfb815c3 DH |
134 | according to its embedded directives. For each |
135 | <literal>%</literal> character found in the template, the caller | |
b938cb90 | 136 | must provide a string via varargs, which will be encoded and |
dfb815c3 DH |
137 | embedded at the position of the <literal>%</literal> character. |
138 | Any other character in the template is copied verbatim into the | |
139 | encoded path.</para> | |
140 | ||
141 | <para><function>sd_bus_path_decode_many()</function> does the | |
142 | reverse of <function>sd_bus_path_encode_many()</function>. It | |
b938cb90 JE |
143 | decodes the passed object path according to the given |
144 | path template. For each <literal>%</literal> character in the | |
dfb815c3 | 145 | template, the caller must provide an output storage |
b938cb90 | 146 | (<literal>char **</literal>) via varargs. The decoded label |
dfb815c3 DH |
147 | will be stored there. Each <literal>%</literal> character will |
148 | only match the current label. It will never match across labels. | |
a8eaaee7 | 149 | Furthermore, only a single directive is allowed per label. |
dfb815c3 DH |
150 | If <literal>NULL</literal> is passed as output storage, the |
151 | label is verified but not returned to the caller.</para> | |
a6278b88 LP |
152 | </refsect1> |
153 | ||
154 | <refsect1> | |
155 | <title>Return Value</title> | |
156 | ||
157 | <para>On success, <function>sd_bus_path_encode()</function> | |
158 | returns positive or 0, and a valid bus path in the return | |
159 | argument. On success, <function>sd_bus_path_decode()</function> | |
160 | returns a positive value if the prefixed matched, or 0 if it | |
b8bde116 JE |
161 | did not. If the prefix matched, the external identifier is returned |
162 | in the return parameter. If it did not match, NULL is returned in | |
a6278b88 LP |
163 | the return parameter. On failure, a negative errno-style error |
164 | number is returned by either function. The returned strings must | |
165 | be | |
5aded369 | 166 | <citerefentry project='man-pages'><refentrytitle>free</refentrytitle><manvolnum>3</manvolnum></citerefentry>'d |
a6278b88 LP |
167 | by the caller.</para> |
168 | </refsect1> | |
169 | ||
170 | <refsect1> | |
171 | <title>Notes</title> | |
172 | ||
173 | <para><function>sd_bus_path_encode()</function> and | |
174 | <function>sd_bus_path_decode()</function> are available as a | |
175 | shared library, which can be compiled and linked to with the | |
5aded369 | 176 | <constant>libsystemd</constant> <citerefentry project='die-net'><refentrytitle>pkg-config</refentrytitle><manvolnum>1</manvolnum></citerefentry> |
a6278b88 LP |
177 | file.</para> |
178 | </refsect1> | |
179 | ||
180 | <refsect1> | |
181 | <title>See Also</title> | |
182 | ||
183 | <para> | |
184 | <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>, | |
185 | <citerefentry><refentrytitle>sd-bus</refentrytitle><manvolnum>3</manvolnum></citerefentry>, | |
5aded369 | 186 | <citerefentry project='man-pages'><refentrytitle>free</refentrytitle><manvolnum>3</manvolnum></citerefentry> |
a6278b88 LP |
187 | </para> |
188 | </refsect1> | |
189 | ||
190 | </refentry> |