1SD_BUS_PATH_ENCODE(3)         sd_bus_path_encode         SD_BUS_PATH_ENCODE(3)
2
3
4

NAME

6       sd_bus_path_encode, sd_bus_path_encode_many, sd_bus_path_decode,
7       sd_bus_path_decode_many - Convert an external identifier into an object
8       path and back
9

SYNOPSIS

11       #include <systemd/sd-bus.h>
12
13       int sd_bus_path_encode(const char *prefix, const char *external_id,
14                              char **ret_path);
15
16       int sd_bus_path_encode_many(char **out, const char *path_template,
17                                   ...);
18
19       int sd_bus_path_decode(const char *path, const char *prefix,
20                              char **ret_external_id);
21
22       int sd_bus_path_decode_many(const char *path,
23                                   const char *path_template, ...);
24

DESCRIPTION

26       sd_bus_path_encode() and sd_bus_path_decode() convert external
27       identifier strings into object paths and back. These functions are
28       useful to map application-specific string identifiers of any kind into
29       bus object paths in a simple, reversible and safe way.
30
31       sd_bus_path_encode() takes a bus path prefix and an external identifier
32       string as arguments, plus a place to store the returned bus path
33       string. The bus path prefix must be a valid bus path, starting with a
34       slash "/", and not ending in one. The external identifier string may be
35       in any format, may be the empty string, and has no restrictions on the
36       charset — however, it must always be NUL-terminated. The returned
37       string will be the concatenation of the bus path prefix plus an escaped
38       version of the external identifier string. This operation may be
39       reversed with sd_bus_path_decode(). It is recommended to only use
40       external identifiers that generally require little escaping to be
41       turned into valid bus path identifiers (for example, by sticking to a
42       7-bit ASCII character set), in order to ensure the resulting bus path
43       is still short and easily processed.
44
45       sd_bus_path_decode() reverses the operation of sd_bus_path_encode() and
46       thus regenerates an external identifier string from a bus path. It
47       takes a bus path and a prefix string, plus a place to store the
48       returned external identifier string. If the bus path does not start
49       with the specified prefix, 0 is returned and the returned string is set
50       to NULL. Otherwise, the string following the prefix is unescaped and
51       returned in the external identifier string.
52
53       The escaping used will replace all characters which are invalid in a
54       bus object path by "_", followed by a hexadecimal value. As a special
55       case, the empty string will be replaced by a lone "_".
56
57       sd_bus_path_encode_many() works like its counterpart
58       sd_bus_path_encode(), but takes a path template as argument and encodes
59       multiple labels according to its embedded directives. For each "%"
60       character found in the template, the caller must provide a string via
61       varargs, which will be encoded and embedded at the position of the "%"
62       character. Any other character in the template is copied verbatim into
63       the encoded path.
64
65       sd_bus_path_decode_many() does the reverse of
66       sd_bus_path_encode_many(). It decodes the passed object path according
67       to the given path template. For each "%" character in the template, the
68       caller must provide an output storage ("char **") via varargs. The
69       decoded label will be stored there. Each "%" character will only match
70       the current label. It will never match across labels. Furthermore, only
71       a single directive is allowed per label. If NULL is passed as output
72       storage, the label is verified but not returned to the caller.
73

RETURN VALUE

75       On success, sd_bus_path_encode() returns positive or 0, and a valid bus
76       path in the return argument. On success, sd_bus_path_decode() returns a
77       positive value if the prefixed matched, or 0 if it did not. If the
78       prefix matched, the external identifier is returned in the return
79       parameter. If it did not match, NULL is returned in the return
80       parameter. On failure, a negative errno-style error number is returned
81       by either function. The returned strings must be free(3)'d by the
82       caller.
83

NOTES

85       Functions described here are available as a shared library, which can
86       be compiled against and linked to with the libsystemd pkg-config(1)
87       file.
88
89       The code described here uses getenv(3), which is declared to be not
90       multi-thread-safe. This means that the code calling the functions
91       described here must not call setenv(3) from a parallel thread. It is
92       recommended to only do calls to setenv() from an early phase of the
93       program when no other threads have been started.
94

SEE ALSO

96       systemd(1), sd-bus(3), free(3)
97
98
99
100systemd 254                                              SD_BUS_PATH_ENCODE(3)
Impressum