diff options
author | Christophe Guiraud <christophe.guiraud@intel.com> | 2013-05-13 11:56:17 +0200 |
---|---|---|
committer | Mark Ryan <mark.d.ryan@intel.com> | 2013-05-16 12:37:59 +0200 |
commit | 24027a95f8c356888c933af9b0fecc0419043a0b (patch) | |
tree | b3545f9b2e2766e1d692697120154dc7a518be0a | |
parent | 6a89c9b2547b8c5590240de71919c181924f8c2d (diff) | |
download | dleyna-server-24027a95f8c356888c933af9b0fecc0419043a0b.tar.gz |
[Bug Fix] Use object and parent id values for detecting root object
Change the way to identify root object.
We now use both object and parent ids values.
Object with a "0" object id value or a "-1" parent id value will
be considered as root object.
Reasons for accepting both:
a) there's code out there where root parent_id != -1 and
b) there's also code out there where root-like (parentless)
objects id != 0.
Object with a "0" id value or a "-1" parent id value
This fixes the case of issue #32 where root have an empty string as
parent id value.
According to the specification root parent id must have a "-1" value.
Fix issue: https://github.com/01org/dleyna-server/issues/32
Signed-off-by: Christophe Guiraud <christophe.guiraud@intel.com>
-rw-r--r-- | libdleyna/server/device.c | 46 | ||||
-rw-r--r-- | libdleyna/server/props.c | 22 |
2 files changed, 50 insertions, 18 deletions
diff --git a/libdleyna/server/device.c b/libdleyna/server/device.c index 977479a..a6268d0 100644 --- a/libdleyna/server/device.c +++ b/libdleyna/server/device.c @@ -1419,25 +1419,41 @@ static void prv_get_object(GUPnPDIDLLiteParser *parser, { dls_async_task_t *cb_data = user_data; dls_async_get_all_t *cb_task_data = &cb_data->ut.get_all; - const char *id; + const char *object_id; + const char *parent_id; const char *parent_path; gchar *path = NULL; - id = gupnp_didl_lite_object_get_parent_id(object); + object_id = gupnp_didl_lite_object_get_id(object); + if (!object_id) + goto on_error; + + parent_id = gupnp_didl_lite_object_get_parent_id(object); + if (!parent_id) + goto on_error; - if (!id || !strcmp(id, "-1") || !strcmp(id, "")) { + if (!strcmp(object_id, "0") || !strcmp(parent_id, "-1")) { parent_path = cb_data->task.target.root_path; } else { - path = dls_path_from_id(cb_data->task.target.root_path, id); + path = dls_path_from_id(cb_data->task.target.root_path, + parent_id); parent_path = path; } if (!dls_props_add_object(cb_task_data->vb, object, cb_data->task.target.root_path, parent_path, DLS_UPNP_MASK_ALL_PROPS)) - cb_data->error = g_error_new(DLEYNA_SERVER_ERROR, - DLEYNA_ERROR_BAD_RESULT, - "Unable to retrieve mandatory object properties"); + goto on_error; + + g_free(path); + + return; + +on_error: + + cb_data->error = g_error_new(DLEYNA_SERVER_ERROR, + DLEYNA_ERROR_BAD_RESULT, + "Unable to retrieve mandatory object properties"); g_free(path); } @@ -2571,7 +2587,8 @@ static void prv_found_target(GUPnPDIDLLiteParser *parser, { dls_async_task_t *cb_data = user_data; dls_async_bas_t *cb_task_data = &cb_data->ut.bas; - const char *id; + const char *object_id; + const char *parent_id; const char *parent_path; gchar *path = NULL; gboolean have_child_count; @@ -2581,12 +2598,19 @@ static void prv_found_target(GUPnPDIDLLiteParser *parser, builder = g_new0(dls_device_object_builder_t, 1); - id = gupnp_didl_lite_object_get_parent_id(object); + object_id = gupnp_didl_lite_object_get_id(object); + if (!object_id) + goto on_error; + + parent_id = gupnp_didl_lite_object_get_parent_id(object); + if (!parent_id) + goto on_error; - if (!id || !strcmp(id, "-1") || !strcmp(id, "")) { + if (!strcmp(object_id, "0") || !strcmp(parent_id, "-1")) { parent_path = cb_data->task.target.root_path; } else { - path = dls_path_from_id(cb_data->task.target.root_path, id); + path = dls_path_from_id(cb_data->task.target.root_path, + parent_id); parent_path = path; } diff --git a/libdleyna/server/props.c b/libdleyna/server/props.c index f88c800..ad36174 100644 --- a/libdleyna/server/props.c +++ b/libdleyna/server/props.c @@ -1729,7 +1729,8 @@ on_exit: GVariant *dls_props_get_object_prop(const gchar *prop, const gchar *root_path, GUPnPDIDLLiteObject *object) { - const char *id; + const char *object_id; + const char *parent_id; gchar *path; const char *upnp_class; const char *media_spec_type; @@ -1740,14 +1741,21 @@ GVariant *dls_props_get_object_prop(const gchar *prop, const gchar *root_path, guint uint_val; if (!strcmp(prop, DLS_INTERFACE_PROP_PARENT)) { - id = gupnp_didl_lite_object_get_parent_id(object); - if (!id || !strcmp(id, "-1")) { + object_id = gupnp_didl_lite_object_get_id(object); + if (!object_id) + goto on_error; + + parent_id = gupnp_didl_lite_object_get_parent_id(object); + if (!parent_id) + goto on_error; + + if (!strcmp(object_id, "0") || !strcmp(parent_id, "-1")) { DLEYNA_LOG_DEBUG("Prop %s = %s", prop, root_path); retval = g_variant_ref_sink(g_variant_new_string( root_path)); } else { - path = dls_path_from_id(root_path, id); + path = dls_path_from_id(root_path, parent_id); DLEYNA_LOG_DEBUG("Prop %s = %s", prop, path); @@ -1756,11 +1764,11 @@ GVariant *dls_props_get_object_prop(const gchar *prop, const gchar *root_path, g_free(path); } } else if (!strcmp(prop, DLS_INTERFACE_PROP_PATH)) { - id = gupnp_didl_lite_object_get_id(object); - if (!id) + object_id = gupnp_didl_lite_object_get_id(object); + if (!object_id) goto on_error; - path = dls_path_from_id(root_path, id); + path = dls_path_from_id(root_path, object_id); DLEYNA_LOG_DEBUG("Prop %s = %s", prop, path); |