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")); }
int sysview_session_new(sysview_session **out, sysview_seat *seat, const char *name) { _cleanup_(sysview_session_freep) sysview_session *session = NULL; int r; assert_return(seat, -EINVAL); session = new0(sysview_session, 1); if (!session) return -ENOMEM; session->seat = seat; if (name) { /* * If a name is given, we require it to be a logind session * name. The session will be put in managed mode and we use * logind to request controller access. */ session->name = strdup(name); if (!session->name) return -ENOMEM; r = sd_bus_path_encode("/org/freedesktop/login1/session", session->name, &session->path); if (r < 0) return r; session->custom = false;; } else { /* * No session name was given. We assume this is an unmanaged * session controlled by the application. We don't use logind * at all and leave session management to the application. The * name of the session-object is set to a unique random string * that does not clash with the logind namespace. */ r = asprintf(&session->name, "@custom%" PRIu64, ++seat->context->custom_sid); if (r < 0) return -ENOMEM; session->custom = true; } r = hashmap_put(seat->context->session_map, session->name, session); if (r < 0) return r; r = hashmap_put(seat->session_map, session->name, session); if (r < 0) return r; if (out) *out = session; session = NULL; return 0; }
int bus_image_path(Image *image, char **ret) { assert(image); assert(ret); if (!image->discoverable) return -EINVAL; return sd_bus_path_encode("/org/freedesktop/portable1/image", image->name, ret); }
static inline int dispd_dbus_get_sink_path(struct dispd_sink *s, char **out) { int r = sd_bus_path_encode("/org/freedesktop/miracle/wfd/sink", dispd_sink_get_label(s), out); if(0 > r) { return log_ERRNO(); } return 0; }
static inline int dispd_dbus_get_session_path(struct dispd_session *s, char **out) { char buf[64]; int r = snprintf(buf, sizeof(buf), "%u", dispd_session_get_id(s)); if(0 > r) { return log_ERRNO(); } r = sd_bus_path_encode("/org/freedesktop/miracle/wfd/session", buf, out); if(0 > r) { return log_ERRNO(); } return 0; }
int sysview_seat_new(sysview_seat **out, sysview_context *c, const char *name) { _cleanup_(sysview_seat_freep) sysview_seat *seat = NULL; int r; assert_return(c, -EINVAL); assert_return(name, -EINVAL); seat = new0(sysview_seat, 1); if (!seat) return -ENOMEM; seat->context = c; seat->name = strdup(name); if (!seat->name) return -ENOMEM; r = sd_bus_path_encode("/org/freedesktop/login1/seat", seat->name, &seat->path); if (r < 0) return r; seat->session_map = hashmap_new(&string_hash_ops); if (!seat->session_map) return -ENOMEM; seat->device_map = hashmap_new(&string_hash_ops); if (!seat->device_map) return -ENOMEM; r = hashmap_put(c->seat_map, seat->name, seat); if (r < 0) return r; if (out) *out = seat; seat = NULL; return 0; }