chiark / gitweb /
bus: replace sd_bus_label_{escape,unescape}() by new sd_bus_path_{encode,decode}()
authorLennart Poettering <lennart@poettering.net>
Tue, 11 Mar 2014 18:03:50 +0000 (19:03 +0100)
committerLennart Poettering <lennart@poettering.net>
Tue, 11 Mar 2014 18:03:50 +0000 (19:03 +0100)
The new calls work similarly, but enforce a that a common, fixed bus
path prefix is used.

This follows discussions with Simon McVittie on IRC that it should be a
good idea to make sure that people don't use the escaping applied here
too wildly as anything other than the last label of a bus path.

13 files changed:
Makefile-man.am
man/sd_bus_label_escape.xml [deleted file]
man/sd_bus_path_encode.xml [new file with mode: 0644]
src/libsystemd/libsystemd.sym.m4
src/libsystemd/sd-bus/bus-creds.c
src/libsystemd/sd-bus/bus-kernel.c
src/libsystemd/sd-bus/sd-bus.c
src/libsystemd/sd-bus/sd-memfd.c
src/libsystemd/sd-bus/test-bus-marshal.c
src/login/logind-seat-dbus.c
src/login/logind-session-dbus.c
src/machine/machine-dbus.c
src/systemd/sd-bus.h

index 73afdd8c9bb61e1decbcfa29ee7af2cc53758213..346bc6324832784cdff1cf0e49b05da9cdb7bd9f 100644 (file)
@@ -691,7 +691,6 @@ MANPAGES += \
        man/sd_bus_creds_get_pid.3 \
        man/sd_bus_creds_new_from_pid.3 \
        man/sd_bus_error.3 \
-       man/sd_bus_label_escape.3 \
        man/sd_bus_message_append.3 \
        man/sd_bus_message_append_array.3 \
        man/sd_bus_message_append_basic.3 \
@@ -701,6 +700,7 @@ MANPAGES += \
        man/sd_bus_message_get_monotonic_usec.3 \
        man/sd_bus_new.3 \
        man/sd_bus_open_user.3 \
+       man/sd_bus_path_encode.3 \
        man/sd_bus_request_name.3 \
        man/systemd-bus-proxyd.8 \
        man/systemd-bus-proxyd@.service.8
@@ -742,7 +742,6 @@ MANPAGES_ALIAS += \
        man/sd_bus_error_set_const.3 \
        man/sd_bus_error_set_errno.3 \
        man/sd_bus_error_set_errnof.3 \
-       man/sd_bus_label_unescape.3 \
        man/sd_bus_message_append_array_iovec.3 \
        man/sd_bus_message_append_array_memfd.3 \
        man/sd_bus_message_append_array_space.3 \
@@ -754,6 +753,7 @@ MANPAGES_ALIAS += \
        man/sd_bus_open_system.3 \
        man/sd_bus_open_system_container.3 \
        man/sd_bus_open_system_remote.3 \
+       man/sd_bus_path_decode.3 \
        man/sd_bus_ref.3 \
        man/sd_bus_release_name.3 \
        man/sd_bus_unref.3 \
@@ -795,7 +795,6 @@ man/sd_bus_error_set.3: man/sd_bus_error.3
 man/sd_bus_error_set_const.3: man/sd_bus_error.3
 man/sd_bus_error_set_errno.3: man/sd_bus_error.3
 man/sd_bus_error_set_errnof.3: man/sd_bus_error.3
-man/sd_bus_label_unescape.3: man/sd_bus_label_escape.3
 man/sd_bus_message_append_array_iovec.3: man/sd_bus_message_append_array.3
 man/sd_bus_message_append_array_memfd.3: man/sd_bus_message_append_array.3
 man/sd_bus_message_append_array_space.3: man/sd_bus_message_append_array.3
@@ -807,6 +806,7 @@ man/sd_bus_message_get_seqnum.3: man/sd_bus_message_get_monotonic_usec.3
 man/sd_bus_open_system.3: man/sd_bus_open_user.3
 man/sd_bus_open_system_container.3: man/sd_bus_open_user.3
 man/sd_bus_open_system_remote.3: man/sd_bus_open_user.3
+man/sd_bus_path_decode.3: man/sd_bus_path_encode.3
 man/sd_bus_ref.3: man/sd_bus_new.3
 man/sd_bus_release_name.3: man/sd_bus_request_name.3
 man/sd_bus_unref.3: man/sd_bus_new.3
@@ -922,9 +922,6 @@ man/sd_bus_error_set_errno.html: man/sd_bus_error.html
 man/sd_bus_error_set_errnof.html: man/sd_bus_error.html
        $(html-alias)
 
-man/sd_bus_label_unescape.html: man/sd_bus_label_escape.html
-       $(html-alias)
-
 man/sd_bus_message_append_array_iovec.html: man/sd_bus_message_append_array.html
        $(html-alias)
 
@@ -958,6 +955,9 @@ man/sd_bus_open_system_container.html: man/sd_bus_open_user.html
 man/sd_bus_open_system_remote.html: man/sd_bus_open_user.html
        $(html-alias)
 
+man/sd_bus_path_decode.html: man/sd_bus_path_encode.html
+       $(html-alias)
+
 man/sd_bus_ref.html: man/sd_bus_new.html
        $(html-alias)
 
@@ -1392,7 +1392,6 @@ EXTRA_DIST += \
        man/sd_bus_creds_get_pid.xml \
        man/sd_bus_creds_new_from_pid.xml \
        man/sd_bus_error.xml \
-       man/sd_bus_label_escape.xml \
        man/sd_bus_message_append.xml \
        man/sd_bus_message_append_array.xml \
        man/sd_bus_message_append_basic.xml \
@@ -1402,6 +1401,7 @@ EXTRA_DIST += \
        man/sd_bus_message_get_monotonic_usec.xml \
        man/sd_bus_new.xml \
        man/sd_bus_open_user.xml \
+       man/sd_bus_path_encode.xml \
        man/sd_bus_request_name.xml \
        man/sd_get_seats.xml \
        man/sd_id128_get_machine.xml \
diff --git a/man/sd_bus_label_escape.xml b/man/sd_bus_label_escape.xml
deleted file mode 100644 (file)
index 0b5564f..0000000
+++ /dev/null
@@ -1,111 +0,0 @@
-<?xml version='1.0'?> <!--*-nxml-*-->
-<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
-"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
-
-<!--
-This file is part of systemd.
-
-Copyright 2014 Zbigniew Jędrzejewski-Szmek
-
-systemd is free software; you can redistribute it and/or modify it
-under the terms of the GNU Lesser General Public License as published by
-the Free Software Foundation; either version 2.1 of the License, or
-(at your option) any later version.
-
-systemd is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-Lesser General Public License for more details.
-
-You should have received a copy of the GNU Lesser General Public License
-along with systemd; If not, see <http://www.gnu.org/licenses/>.
--->
-
-<refentry id="sd_bus_label_escape" conditional="ENABLE_KDBUS">
-
-  <refentryinfo>
-    <title>sd_bus_label_escape</title>
-    <productname>systemd</productname>
-
-    <authorgroup>
-      <author>
-        <contrib>A monkey with a typewriter</contrib>
-        <firstname>Zbigniew</firstname>
-        <surname>Jędrzejewski-Szmek</surname>
-        <email>zbyszek@in.waw.pl</email>
-      </author>
-    </authorgroup>
-  </refentryinfo>
-
-  <refmeta>
-    <refentrytitle>sd_bus_label_escape</refentrytitle>
-    <manvolnum>3</manvolnum>
-  </refmeta>
-
-  <refnamediv>
-    <refname>sd_bus_label_escape</refname>
-    <refname>sd_bus_label_unescape</refname>
-
-    <refpurpose>Escape D-Bus object path special characters</refpurpose>
-  </refnamediv>
-
-  <refsynopsisdiv>
-    <funcsynopsis>
-      <funcsynopsisinfo>#include &lt;systemd/sd-bus.h&gt;</funcsynopsisinfo>
-
-      <funcprototype>
-        <funcdef>char *<function>sd_bus_label_escape</function></funcdef>
-        <paramdef>const char *<parameter>s</parameter></paramdef>
-      </funcprototype>
-
-      <funcprototype>
-        <funcdef>char *<function>sd_bus_label_unescape</function></funcdef>
-        <paramdef>const char *<parameter>f</parameter></paramdef>
-      </funcprototype>
-    </funcsynopsis>
-  </refsynopsisdiv>
-
-  <refsect1>
-    <title>Description</title>
-
-    <para><function>sd_bus_label_escape()</function> takes a
-    <constant>NUL</constant>-terminated string as a argument. It will
-    replace all characters which are invalid in a D-Bus object path by
-    <literal>_</literal> and a hexadecimal number. As a special case,
-    the empty string will be replaced by a lone <literal>_</literal>.
-    <function>sd_bus_label_unescape()</function> can be used to
-    reverse this process.</para>
-  </refsect1>
-
-  <refsect1>
-    <title>Return Value</title>
-
-    <para>On success, a new <constant>NUL</constant>-terminated string
-    will be returned. It must be
-    <citerefentry><refentrytitle>free</refentrytitle><manvolnum>3</manvolnum></citerefentry>d
-    by the caller. If a memory allocation failure occurs,
-    <constant>NULL</constant> will be returned.
-    </para>
-  </refsect1>
-
-  <refsect1>
-    <title>Notes</title>
-
-    <para><function>sd_bus_label_escape()</function> and
-    <function>sd_bus_label_unescape()</function> are available as a
-    shared library, which can be compiled and linked to with the
-    <constant>libsystemd</constant> <citerefentry><refentrytitle>pkg-config</refentrytitle><manvolnum>1</manvolnum></citerefentry>
-    file.</para>
-  </refsect1>
-
-  <refsect1>
-    <title>See Also</title>
-
-    <para>
-      <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
-      <citerefentry><refentrytitle>sd-bus</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
-      <citerefentry><refentrytitle>free</refentrytitle><manvolnum>3</manvolnum></citerefentry>
-    </para>
-  </refsect1>
-
-</refentry>
diff --git a/man/sd_bus_path_encode.xml b/man/sd_bus_path_encode.xml
new file mode 100644 (file)
index 0000000..5c166d0
--- /dev/null
@@ -0,0 +1,150 @@
+<?xml version='1.0'?> <!--*-nxml-*-->
+<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
+"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
+
+<!--
+This file is part of systemd.
+
+Copyright 2014 Zbigniew Jędrzejewski-Szmek
+
+systemd is free software; you can redistribute it and/or modify it
+under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 2.1 of the License, or
+(at your option) any later version.
+
+systemd is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License
+along with systemd; If not, see <http://www.gnu.org/licenses/>.
+-->
+
+<refentry id="sd_bus_path_encode" conditional="ENABLE_KDBUS">
+
+  <refentryinfo>
+    <title>sd_bus_path_encode</title>
+    <productname>systemd</productname>
+
+    <authorgroup>
+      <author>
+        <contrib>A monkey with a typewriter</contrib>
+        <firstname>Zbigniew</firstname>
+        <surname>Jędrzejewski-Szmek</surname>
+        <email>zbyszek@in.waw.pl</email>
+      </author>
+    </authorgroup>
+  </refentryinfo>
+
+  <refmeta>
+    <refentrytitle>sd_bus_path_encode</refentrytitle>
+    <manvolnum>3</manvolnum>
+  </refmeta>
+
+  <refnamediv>
+    <refname>sd_bus_path_encode</refname>
+    <refname>sd_bus_path_decode</refname>
+
+    <refpurpose>Convert an external identifier into an object path and back</refpurpose>
+  </refnamediv>
+
+  <refsynopsisdiv>
+    <funcsynopsis>
+      <funcsynopsisinfo>#include &lt;systemd/sd-bus.h&gt;</funcsynopsisinfo>
+
+      <funcprototype>
+        <funcdef>int <function>sd_bus_path_encode</function></funcdef>
+        <paramdef>const char *<parameter>prefix</parameter></paramdef>
+        <paramdef>const char *<parameter>external_id</parameter></paramdef>
+        <paramdef>char **<parameter>ret_path</parameter></paramdef>
+      </funcprototype>
+
+      <funcprototype>
+        <funcdef>int <function>sd_bus_path_decode</function></funcdef>
+        <paramdef>const char *<parameter>prefix</parameter></paramdef>
+        <paramdef>const char *<parameter>path</parameter></paramdef>
+        <paramdef>char **<parameter>ret_external_id</parameter></paramdef>
+      </funcprototype>
+    </funcsynopsis>
+  </refsynopsisdiv>
+
+  <refsect1>
+    <title>Description</title>
+
+    <para><function>sd_bus_path_encode()</function> and
+    <function>sd_bus_path_decode()</function> convert external
+    identifier strings into object paths and back. These functions are
+    useful to map application-specific string identifiers of any kind
+    into bus object paths in a simple, reversible and safe way.</para>
+
+    <para><function>sd_bus_path_encode()</function> takes a bus path
+    prefix and an external identifier string as arguments, plus a
+    place to store the returned bus path string. The bus path prefix
+    must be a valid bus path, starting with a slash
+    <literal>/</literal>, but not ending in one. The external
+    identifier string may be in any format, may be the empty string
+    and no restrictions on the charset are made - however it must
+    always be <constant>NUL</constant>-terminated. The returned string
+    will be the concatenation of the bus path prefix plus an escaped
+    version of the external identifier string. This operation may be
+    reversed with <function>sd_bus_decode()</function>. It is
+    recommended to only use external identifiers here that generally
+    require little escaping to be turned into valid bus path
+    identifiers (for example by sticking to a 7bit ASCII character
+    set), in order to ensure the resulting bus path is still short and
+    easily processed.</para>
+
+    <para><function>sd_bus_path_decode()</function> reverses the
+    operation of <function>sd_bus_path_encode()</function> and thus
+    regenerates an external identifier string from a bus path. It
+    takes a bus path and a prefix string, plus a place to store the
+    returned external identifier string. If the bus path does not
+    start with the specified prefix, 0 is returned and the returned
+    string is set to <constant>NULL</constant>. Otherwise the the
+    string following the prefix is unescaped and returned in the
+    external identifier string.</para>
+
+    <para>The escaping used will will replace all characters which are
+    invalid in a bus object path by <literal>_</literal> followed by a
+    hexadecimal value. As a special case, the empty string will be
+    replaced by a lone <literal>_</literal>.</para>
+  </refsect1>
+
+  <refsect1>
+    <title>Return Value</title>
+
+    <para>On success, <function>sd_bus_path_encode()</function>
+    returns positive or 0, and a valid bus path in the return
+    argument. On success, <function>sd_bus_path_decode()</function>
+    returns a positive value if the prefixed matched, or 0 if it
+    didn't. If the prefix matched the external identifier is returned
+    in the return parameter. If it did not match NULL is returned in
+    the return parameter. On failure, a negative errno-style error
+    number is returned by either function. The returned strings must
+    be
+    <citerefentry><refentrytitle>free</refentrytitle><manvolnum>3</manvolnum></citerefentry>'d
+    by the caller.</para>
+  </refsect1>
+
+  <refsect1>
+    <title>Notes</title>
+
+    <para><function>sd_bus_path_encode()</function> and
+    <function>sd_bus_path_decode()</function> are available as a
+    shared library, which can be compiled and linked to with the
+    <constant>libsystemd</constant> <citerefentry><refentrytitle>pkg-config</refentrytitle><manvolnum>1</manvolnum></citerefentry>
+    file.</para>
+  </refsect1>
+
+  <refsect1>
+    <title>See Also</title>
+
+    <para>
+      <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
+      <citerefentry><refentrytitle>sd-bus</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
+      <citerefentry><refentrytitle>free</refentrytitle><manvolnum>3</manvolnum></citerefentry>
+    </para>
+  </refsect1>
+
+</refentry>
index c708c7f38fbe2e28e96868a0397b0973b1061b0f..9c29169e7cb7e9c890ddf49f6d5383c3e3246183 100644 (file)
@@ -311,8 +311,8 @@ m4_ifdef(`ENABLE_KDBUS',
         sd_bus_error_copy;
         sd_bus_error_is_set;
         sd_bus_error_has_name;
-        sd_bus_label_escape;
-        sd_bus_label_unescape;
+        sd_bus_path_encode;
+        sd_bus_path_decode;
         sd_bus_track_new;
         sd_bus_track_ref;
         sd_bus_track_unref;
index 2d56f3c461d9c470665255acdcb6832fca475b2a..3da77cf1d708bbcdf75623c1bd6d906f65aa5e23 100644 (file)
@@ -30,6 +30,7 @@
 #include "time-util.h"
 #include "strv.h"
 #include "bus-creds.h"
+#include "bus-label.h"
 
 enum {
         CAP_OFFSET_INHERITABLE = 0,
@@ -474,7 +475,7 @@ _public_ int sd_bus_creds_get_connection_name(sd_bus_creds *c, const char **ret)
         assert(c->conn_name);
 
         if (!c->unescaped_conn_name) {
-                c->unescaped_conn_name = sd_bus_label_unescape(c->conn_name);
+                c->unescaped_conn_name = bus_label_unescape(c->conn_name);
                 if (!c->unescaped_conn_name)
                         return -ENOMEM;
         }
index 2a1b0b424a9dba2a7fd96ca2f13083984473b16c..8a2ca0299677284ea431db18d12fc3b961415e90 100644 (file)
@@ -36,6 +36,7 @@
 #include "bus-kernel.h"
 #include "bus-bloom.h"
 #include "bus-util.h"
+#include "bus-label.h"
 #include "cgroup-util.h"
 
 #define UNIQUE_NAME_MAX (3+DECIMAL_STR_MAX(uint64_t))
@@ -658,7 +659,7 @@ int bus_kernel_take_fd(sd_bus *b) {
         b->use_memfd = 1;
 
         if (b->connection_name) {
-                g = sd_bus_label_escape(b->connection_name);
+                g = bus_label_escape(b->connection_name);
                 if (!g)
                         return -ENOMEM;
 
@@ -678,7 +679,7 @@ int bus_kernel_take_fd(sd_bus *b) {
                 } else {
                         _cleanup_free_ char *e = NULL;
 
-                        e = sd_bus_label_escape(pr);
+                        e = bus_label_escape(pr);
                         if (!e)
                                 return -ENOMEM;
 
@@ -691,7 +692,7 @@ int bus_kernel_take_fd(sd_bus *b) {
                         name = g;
                 }
 
-                b->connection_name = sd_bus_label_unescape(name);
+                b->connection_name = bus_label_unescape(name);
                 if (!b->connection_name)
                         return -ENOMEM;
         }
@@ -1119,7 +1120,7 @@ int bus_kernel_pop_memfd(sd_bus *bus, void **address, size_t *mapped, size_t *al
 
                 assert(bus->connection_name);
 
-                g = sd_bus_label_escape(bus->connection_name);
+                g = bus_label_escape(bus->connection_name);
                 if (!g)
                         return -ENOMEM;
 
index fbf1a5919f19d9bb6d3c00f751646777e2f5e887..ffa3369feb377c077a7e00eda73b008af8fe93b9 100644 (file)
@@ -3063,12 +3063,46 @@ _public_ int sd_bus_get_tid(sd_bus *b, pid_t *tid) {
         return -ENXIO;
 }
 
-_public_ char *sd_bus_label_escape(const char *s) {
-        return bus_label_escape(s);
+_public_ int sd_bus_path_encode(const char *prefix, const char *external_id, char **ret_path) {
+        _cleanup_free_ char *e = NULL;
+        char *ret;
+
+        assert_return(object_path_is_valid(prefix), -EINVAL);
+        assert_return(external_id, -EINVAL);
+        assert_return(ret_path, -EINVAL);
+
+        e = bus_label_escape(external_id);
+        if (!e)
+                return -ENOMEM;
+
+        ret = strjoin(prefix, "/", e, NULL);
+        if (!ret)
+                return -ENOMEM;
+
+        *ret_path = ret;
+        return 0;
 }
 
-_public_ char *sd_bus_label_unescape(const char *f) {
-        return bus_label_unescape(f);
+_public_ int sd_bus_path_decode(const char *path, const char *prefix, char **external_id) {
+        const char *e;
+        char *ret;
+
+        assert_return(object_path_is_valid(path), -EINVAL);
+        assert_return(object_path_is_valid(prefix), -EINVAL);
+        assert_return(external_id, -EINVAL);
+
+        e = object_path_startswith(path, prefix);
+        if (!e) {
+                *external_id = NULL;
+                return 0;
+        }
+
+        ret = bus_label_unescape(e);
+        if (!ret)
+                return -ENOMEM;
+
+        *external_id = ret;
+        return 1;
 }
 
 _public_ int sd_bus_get_peer_creds(sd_bus *bus, uint64_t mask, sd_bus_creds **ret) {
index 7c71476eeef5043d0b096a6ca35c4b4cc6c99656..8f9e236392511220a62f15db89822d5bb1eedcb9 100644 (file)
@@ -27,6 +27,7 @@
 
 #include "util.h"
 #include "kdbus.h"
+#include "bus-label.h"
 
 #include "sd-memfd.h"
 #include "sd-bus.h"
@@ -56,7 +57,7 @@ _public_ int sd_memfd_new(sd_memfd **m, const char *name) {
                  * set here, let's do the usual bus escaping to deal
                  * with that. */
 
-                g = sd_bus_label_escape(name);
+                g = bus_label_escape(name);
                 if (!g)
                         return -ENOMEM;
 
@@ -76,7 +77,7 @@ _public_ int sd_memfd_new(sd_memfd **m, const char *name) {
                 else {
                         _cleanup_free_ char *e = NULL;
 
-                        e = sd_bus_label_escape(pr);
+                        e = bus_label_escape(pr);
                         if (!e)
                                 return -ENOMEM;
 
@@ -311,7 +312,7 @@ _public_ int sd_memfd_get_name(sd_memfd *m, char **name) {
         if (!n)
                 return -ENOMEM;
 
-        e = sd_bus_label_unescape(n);
+        e = bus_label_unescape(n);
         if (!e)
                 return -ENOMEM;
 
index d438a231a635426cfffaf812fd0ae76d5169cc38..2321873da53d65536ab4c2ae0ec710acf0047816 100644 (file)
 #include "bus-message.h"
 #include "bus-util.h"
 #include "bus-dump.h"
+#include "bus-label.h"
+
+static void test_bus_path_encode(void) {
+        _cleanup_free_ char *a = NULL, *b = NULL, *c = NULL, *d = NULL, *e = NULL, *f = NULL;
+
+        assert_se(sd_bus_path_encode("/foo/bar", "waldo", &a) >= 0 && streq(a, "/foo/bar/waldo"));
+        assert_se(sd_bus_path_decode(a, "/waldo", &b) == 0 && b == NULL);
+        assert_se(sd_bus_path_decode(a, "/foo/bar", &b) > 0 && streq(b, "waldo"));
+
+        assert_se(sd_bus_path_encode("xxxx", "waldo", &c) < 0);
+        assert_se(sd_bus_path_encode("/foo/", "waldo", &c) < 0);
+
+        assert_se(sd_bus_path_encode("/foo/bar", "", &c) >= 0 && streq(c, "/foo/bar/_"));
+        assert_se(sd_bus_path_decode(c, "/foo/bar", &d) > 0 && streq(d, ""));
+
+        assert_se(sd_bus_path_encode("/foo/bar", "foo.bar", &e) >= 0 && streq(e, "/foo/bar/foo_2ebar"));
+        assert_se(sd_bus_path_decode(e, "/foo/bar", &f) > 0 && streq(f, "foo.bar"));
+}
 
 static void test_bus_label_escape_one(const char *a, const char *b) {
         _cleanup_free_ char *t = NULL, *x = NULL, *y = NULL;
 
-        assert_se(t = sd_bus_label_escape(a));
+        assert_se(t = bus_label_escape(a));
         assert_se(streq(t, b));
 
-        assert_se(x = sd_bus_label_unescape(t));
+        assert_se(x = bus_label_unescape(t));
         assert_se(streq(a, x));
 
-        assert_se(y = sd_bus_label_unescape(b));
+        assert_se(y = bus_label_unescape(b));
         assert_se(streq(a, y));
 }
 
@@ -322,6 +340,7 @@ int main(int argc, char *argv[]) {
         assert_se(streq(d, "3"));
 
         test_bus_label_escape();
+        test_bus_path_encode();
 
         return 0;
 }
index 315e6baf6bec12b5fd9a1be2005bd08494ffd16f..82323d6b8770e796f796e8ec4c384f388dac2c6e 100644 (file)
@@ -27,6 +27,7 @@
 #include "bus-util.h"
 #include "strv.h"
 #include "bus-errors.h"
+#include "bus-label.h"
 #include "logind.h"
 #include "logind-seat.h"
 
@@ -356,7 +357,7 @@ int seat_object_find(sd_bus *bus, const char *path, const char *interface, void
                 if (!p)
                         return 0;
 
-                e = sd_bus_label_unescape(p);
+                e = bus_label_unescape(p);
                 if (!e)
                         return -ENOMEM;
 
@@ -374,7 +375,7 @@ char *seat_bus_path(Seat *s) {
 
         assert(s);
 
-        t = sd_bus_label_escape(s->id);
+        t = bus_label_escape(s->id);
         if (!t)
                 return NULL;
 
index c3d4d60158f274c3b221086a917989fdc0f9d80b..ffdc5582dca356f84f7ba1664af1b2f42d5201a2 100644 (file)
@@ -27,6 +27,7 @@
 #include "strv.h"
 #include "bus-util.h"
 #include "bus-errors.h"
+#include "bus-label.h"
 
 #include "logind.h"
 #include "logind-session.h"
@@ -515,7 +516,7 @@ int session_object_find(sd_bus *bus, const char *path, const char *interface, vo
                 if (!p)
                         return 0;
 
-                e = sd_bus_label_unescape(p);
+                e = bus_label_unescape(p);
                 if (!e)
                         return -ENOMEM;
 
@@ -533,7 +534,7 @@ char *session_bus_path(Session *s) {
 
         assert(s);
 
-        t = sd_bus_label_escape(s->id);
+        t = bus_label_escape(s->id);
         if (!t)
                 return NULL;
 
index c9e3bb7c758d0793dafe7338cb4f7afbeba55c3a..920c9956aeeb953948c12be2cc7f5a350369620f 100644 (file)
@@ -24,6 +24,7 @@
 #include <sys/capability.h>
 
 #include "bus-util.h"
+#include "bus-label.h"
 #include "strv.h"
 #include "machine.h"
 
@@ -182,7 +183,7 @@ int machine_object_find(sd_bus *bus, const char *path, const char *interface, vo
                 if (!p)
                         return 0;
 
-                e = sd_bus_label_unescape(p);
+                e = bus_label_unescape(p);
                 if (!e)
                         return -ENOMEM;
 
@@ -200,7 +201,7 @@ char *machine_bus_path(Machine *m) {
 
         assert(m);
 
-        e = sd_bus_label_escape(m->name);
+        e = bus_label_escape(m->name);
         if (!e)
                 return NULL;
 
index e26ca6b704269591672ce161e495fc677d79c77e..8817380f1a06de3a3b83b5ff48a6ef6219df3718 100644 (file)
@@ -349,8 +349,8 @@ int sd_bus_error_has_name(const sd_bus_error *e, const char *name);
 
 /* Label escaping */
 
-char *sd_bus_label_escape(const char *s);
-char *sd_bus_label_unescape(const char *f);
+int sd_bus_path_encode(const char *prefix, const char *external_id, char **ret_path);
+int sd_bus_path_decode(const char *path, const char *prefix, char **ret_external_id);
 
 /* Tracking peers */