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 = bus_label_escape(a)); assert_se(streq(t, b)); assert_se(x = bus_label_unescape(t)); assert_se(streq(a, x)); assert_se(y = bus_label_unescape(b)); assert_se(streq(a, y)); }
int image_object_find(sd_bus *bus, const char *path, const char *interface, void *userdata, void **found, sd_bus_error *error) { _cleanup_free_ char *e = NULL; Manager *m = userdata; Image *image = NULL; const char *p; int r; assert(bus); assert(path); assert(interface); assert(found); p = startswith(path, "/org/freedesktop/machine1/image/"); if (!p) return 0; e = bus_label_unescape(p); if (!e) return -ENOMEM; image = hashmap_get(m->image_cache, e); if (image) { *found = image; return 1; } r = hashmap_ensure_allocated(&m->image_cache, &string_hash_ops); if (r < 0) return r; if (!m->image_cache_defer_event) { r = sd_event_add_defer(m->event, &m->image_cache_defer_event, image_flush_cache, m); if (r < 0) return r; r = sd_event_source_set_priority(m->image_cache_defer_event, SD_EVENT_PRIORITY_IDLE); if (r < 0) return r; } r = sd_event_source_set_enabled(m->image_cache_defer_event, SD_EVENT_ONESHOT); if (r < 0) return r; r = image_find(e, &image); if (r <= 0) return r; image->userdata = m; r = hashmap_put(m->image_cache, image->name, image); if (r < 0) { image_unref(image); return r; } *found = image; return 1; }
int unit_name_from_dbus_path(const char *path, char **name) { const char *e; char *n; e = startswith(path, "/org/freedesktop/systemd1/unit/"); if (!e) return -EINVAL; n = bus_label_unescape(e); if (!n) return -ENOMEM; *name = n; return 0; }
_public_ int sd_bus_creds_get_description(sd_bus_creds *c, const char **ret) { assert_return(c, -EINVAL); assert_return(ret, -EINVAL); if (!(c->mask & SD_BUS_CREDS_DESCRIPTION)) return -ENODATA; assert(c->description); if (!c->unescaped_description) { c->unescaped_description = bus_label_unescape(c->description); if (!c->unescaped_description) return -ENOMEM; } *ret = c->unescaped_description; return 0; }