chiark / gitweb /
bus: make GetManagedObjects() work
[elogind.git] / src / libsystemd-bus / sd-bus.c
index b1dcd8dc624fc2e65846429f58cd12fc7d83adbc..342af4d1d5c4c7a385364121a5176ac17e6eb35f 100644 (file)
@@ -1887,7 +1887,6 @@ static int node_vtable_get_userdata(
         assert(bus);
         assert(path);
         assert(c);
-        assert(userdata);
 
         u = c->userdata;
         if (c->find) {
@@ -1896,7 +1895,9 @@ static int node_vtable_get_userdata(
                         return r;
         }
 
-        *userdata = u;
+        if (userdata)
+                *userdata = u;
+
         return 1;
 }
 
@@ -2344,8 +2345,8 @@ static bool bus_node_exists(sd_bus *bus, struct node *n, const char *path, bool
         assert(bus);
         assert(n);
 
-        if (n->child)
-                return true;
+        /* Tests if there's anything attached directly to this node
+         * for the specified path */
 
         LIST_FOREACH(callbacks, k, n->callbacks) {
                 if (require_fallback && !k->is_fallback)
@@ -2359,11 +2360,11 @@ static bool bus_node_exists(sd_bus *bus, struct node *n, const char *path, bool
                 if (require_fallback && !c->is_fallback)
                         continue;
 
-                return true;
+                if (node_vtable_get_userdata(bus, path, c, NULL) > 0)
+                        return true;
         }
 
         return !require_fallback && (n->enumerators || n->object_manager);
-
 }
 
 static int process_introspect(
@@ -2400,12 +2401,10 @@ static int process_introspect(
         empty = set_isempty(s);
 
         LIST_FOREACH(vtables, c, n->vtables) {
-                void *u;
-
                 if (require_fallback && !c->is_fallback)
                         continue;
 
-                r = node_vtable_get_userdata(bus, m->path, c, &u);
+                r = node_vtable_get_userdata(bus, m->path, c, NULL);
                 if (r < 0)
                         return r;
                 if (r == 0)
@@ -2500,6 +2499,7 @@ static int object_manager_serialize_vtable(
 static int object_manager_serialize_path(
                 sd_bus *bus,
                 sd_bus_message *reply,
+                const char *prefix,
                 const char *path,
                 bool require_fallback,
                 sd_bus_error *error) {
@@ -2510,10 +2510,11 @@ static int object_manager_serialize_path(
 
         assert(bus);
         assert(reply);
+        assert(prefix);
         assert(path);
         assert(error);
 
-        n = hashmap_get(bus->nodes, path);
+        n = hashmap_get(bus->nodes, prefix);
         if (!n)
                 return 0;
 
@@ -2567,7 +2568,7 @@ static int object_manager_serialize_path_and_fallbacks(
         assert(error);
 
         /* First, add all vtables registered for this path */
-        r = object_manager_serialize_path(bus, reply, path, false, error);
+        r = object_manager_serialize_path(bus, reply, path, path, false, error);
         if (r < 0)
                 return r;
         if (sd_bus_error_is_set(error))
@@ -2588,7 +2589,7 @@ static int object_manager_serialize_path_and_fallbacks(
 
                         *e = 0;
 
-                        r = object_manager_serialize_path(bus, reply, p, true, error);
+                        r = object_manager_serialize_path(bus, reply, p, path, true, error);
                         if (r < 0)
                                 return r;
 
@@ -2688,7 +2689,13 @@ static int process_get_managed_objects(
         return 1;
 }
 
-static int object_find_and_run(sd_bus *bus, sd_bus_message *m, const char *p, bool require_fallback, bool *found_object) {
+static int object_find_and_run(
+                sd_bus *bus,
+                sd_bus_message *m,
+                const char *p,
+                bool require_fallback,
+                bool *found_object) {
+
         struct node *n;
         struct vtable_member vtable_key, *v;
         int r;
@@ -3640,7 +3647,7 @@ static int add_object_vtable_internal(
                 sd_bus_object_find_t find,
                 void *userdata) {
 
-        struct node_vtable *c, *i;
+        struct node_vtable *c = NULL, *i;
         const sd_bus_vtable *v;
         struct node *n;
         int r;
@@ -3961,7 +3968,7 @@ static int emit_properties_changed_on_interface(
         struct node_vtable *c;
         struct node *n;
         char **property;
-        void *u;
+        void *u = NULL;
         int r;
 
         assert(bus);
@@ -4034,7 +4041,7 @@ static int emit_properties_changed_on_interface(
                 if (r < 0)
                         return r;
 
-                r = v->vtable->property.get(bus, m->path, interface, *property, m, &error, u);
+                r = v->vtable->property.get(bus, m->path, interface, *property, m, &error, vtable_property_convert_userdata(v->vtable, u));
                 if (r < 0)
                         return r;