edbus: fix checking if root objects are our son
strncmp'ing is not sufficient because it whould fail in case an object like "/org/bla" is registered (and in conn->root_objs) and we were registering "/org/blatest/". We would incorrectly put "/org/bla" as son of "/org/blatest". Fix this by looking up the next char, checking if it's a slash. Also re-format the code a little bit. SVN revision: 79179
This commit is contained in:
parent
312bb0d887
commit
8fe3146fe8
|
@ -514,8 +514,9 @@ _edbus_service_object_parent_find(EDBus_Service_Object *obj)
|
|||
static EDBus_Service_Object *
|
||||
_edbus_service_object_add(EDBus_Connection *conn, const char *path)
|
||||
{
|
||||
EDBus_Service_Object *obj, *aux;
|
||||
EDBus_Service_Object *obj, *rootobj;
|
||||
Eina_Inlist *safe;
|
||||
size_t pathlen;
|
||||
|
||||
obj = calloc(1, sizeof(EDBus_Service_Object));
|
||||
EINA_SAFETY_ON_NULL_RETURN_VAL(obj, NULL);
|
||||
|
@ -543,16 +544,24 @@ _edbus_service_object_add(EDBus_Connection *conn, const char *path)
|
|||
return obj;
|
||||
}
|
||||
|
||||
EINA_INLIST_FOREACH_SAFE(conn->root_objs, safe, aux)
|
||||
/*
|
||||
* If there wasn't any object above us, check if anyone in conn->root_obj
|
||||
* should become our child and append ourselves there.
|
||||
*/
|
||||
pathlen = strlen(obj->path);
|
||||
EINA_INLIST_FOREACH_SAFE(conn->root_objs, safe, rootobj)
|
||||
{
|
||||
if (!strncmp(obj->path, aux->path, strlen(obj->path)))
|
||||
{
|
||||
conn->root_objs = eina_inlist_remove(conn->root_objs,
|
||||
EINA_INLIST_GET(aux));
|
||||
obj->children = eina_inlist_append(obj->children,
|
||||
EINA_INLIST_GET(aux));
|
||||
aux->parent = obj;
|
||||
}
|
||||
if (strncmp(obj->path, rootobj->path, pathlen) != 0)
|
||||
continue;
|
||||
|
||||
if (rootobj->path[pathlen] != '/')
|
||||
continue;
|
||||
|
||||
conn->root_objs = eina_inlist_remove(conn->root_objs,
|
||||
EINA_INLIST_GET(rootobj));
|
||||
obj->children = eina_inlist_append(obj->children,
|
||||
EINA_INLIST_GET(rootobj));
|
||||
rootobj->parent = obj;
|
||||
}
|
||||
conn->root_objs = eina_inlist_append(conn->root_objs, EINA_INLIST_GET(obj));
|
||||
|
||||
|
|
Loading…
Reference in New Issue