diff options
author | Lennart Poettering <lennart@poettering.net> | 2013-11-21 01:03:26 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2013-11-21 01:03:26 +0100 |
commit | 28383ba18963cdedd98ced271b3425f7321119b7 (patch) | |
tree | 5d6254dbdd2dd07476cfaf7b4fd9a72c9048e9c2 /src/shared | |
parent | 850516e012f0e2c96cecb63c1e8997e13912fcd6 (diff) |
bus: add API calls to escape string components of objects paths
Diffstat (limited to 'src/shared')
-rw-r--r-- | src/shared/unit-name.c | 5 | ||||
-rw-r--r-- | src/shared/util.c | 72 | ||||
-rw-r--r-- | src/shared/util.h | 3 |
3 files changed, 3 insertions, 77 deletions
diff --git a/src/shared/unit-name.c b/src/shared/unit-name.c index bc8094d112..2335463777 100644 --- a/src/shared/unit-name.c +++ b/src/shared/unit-name.c @@ -23,6 +23,7 @@ #include <string.h> #include <assert.h> +#include "sd-bus.h" #include "path-util.h" #include "util.h" #include "unit-name.h" @@ -459,7 +460,7 @@ char *unit_dbus_path_from_name(const char *name) { assert(name); - e = bus_path_escape(name); + e = sd_bus_label_escape(name); if (!e) return NULL; @@ -474,7 +475,7 @@ int unit_name_from_dbus_path(const char *path, char **name) { if (!e) return -EINVAL; - n = bus_path_unescape(e); + n = sd_bus_label_unescape(e); if (!n) return -ENOMEM; diff --git a/src/shared/util.c b/src/shared/util.c index deb74c4655..97c9497df6 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -1356,78 +1356,6 @@ char *xescape(const char *s, const char *bad) { return r; } -char *bus_path_escape(const char *s) { - char *r, *t; - const char *f; - - assert(s); - - /* Escapes all chars that D-Bus' object path cannot deal - * with. Can be reversed with bus_path_unescape(). We special - * case the empty string. */ - - if (*s == 0) - return strdup("_"); - - r = new(char, strlen(s)*3 + 1); - if (!r) - return NULL; - - for (f = s, t = r; *f; f++) { - - /* Escape everything that is not a-zA-Z0-9. We also - * escape 0-9 if it's the first character */ - - if (!(*f >= 'A' && *f <= 'Z') && - !(*f >= 'a' && *f <= 'z') && - !(f > s && *f >= '0' && *f <= '9')) { - *(t++) = '_'; - *(t++) = hexchar(*f >> 4); - *(t++) = hexchar(*f); - } else - *(t++) = *f; - } - - *t = 0; - - return r; -} - -char *bus_path_unescape(const char *f) { - char *r, *t; - - assert(f); - - /* Special case for the empty string */ - if (streq(f, "_")) - return strdup(""); - - r = new(char, strlen(f) + 1); - if (!r) - return NULL; - - for (t = r; *f; f++) { - - if (*f == '_') { - int a, b; - - if ((a = unhexchar(f[1])) < 0 || - (b = unhexchar(f[2])) < 0) { - /* Invalid escape code, let's take it literal then */ - *(t++) = '_'; - } else { - *(t++) = (char) ((a << 4) | b); - f += 2; - } - } else - *(t++) = *f; - } - - *t = 0; - - return r; -} - char *ascii_strlower(char *t) { char *p; diff --git a/src/shared/util.h b/src/shared/util.h index d46ff27f1c..00d2364c61 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -237,9 +237,6 @@ char *cunescape_length_with_prefix(const char *s, size_t length, const char *pre char *xescape(const char *s, const char *bad); -char *bus_path_escape(const char *s); -char *bus_path_unescape(const char *s); - char *ascii_strlower(char *path); bool dirent_is_file(const struct dirent *de) _pure_; |