diff options
author | Rick Bell <richard.s.bell@intel.com> | 2015-04-21 12:04:38 -0700 |
---|---|---|
committer | Rick Bell <richard.s.bell@intel.com> | 2015-04-21 12:04:38 -0700 |
commit | 54a0f4fa30f73b23d890b4fdc3d4cb67ae9e13e9 (patch) | |
tree | 52633a88daf65007bedad99d8dc1a6eef3eecb96 | |
parent | faa9d36afcd65ea46784794ac5a0fa092aa5d731 (diff) | |
parent | 6c93a242449a79d7fd89d7377e5618bc17e1f237 (diff) | |
download | dleyna-renderer-54a0f4fa30f73b23d890b4fdc3d4cb67ae9e13e9.tar.gz |
Merge pull request #132 from lferrandis/uid
Uid
-rw-r--r-- | libdleyna/renderer/device.c | 54 | ||||
-rw-r--r-- | libdleyna/renderer/device.h | 2 | ||||
-rw-r--r-- | libdleyna/renderer/upnp.c | 7 |
3 files changed, 54 insertions, 9 deletions
diff --git a/libdleyna/renderer/device.c b/libdleyna/renderer/device.c index 55a245f..64b5770 100644 --- a/libdleyna/renderer/device.c +++ b/libdleyna/renderer/device.c @@ -827,21 +827,71 @@ void dlr_device_construct( DLEYNA_LOG_DEBUG("Exit"); } +static char *prv_convert_udn_to_path(const char *udn) +{ + char *uuid; + size_t len; + size_t dest_len; + size_t i; + + /* This function will generate a valid dbus path from the udn + * We are not going to check the UDN validity. We will try to + * convert it anyway. To avoid any security problem, we will + * check some limits and possibily return only a partial + * UDN. For a better understanding, a valid UDN should be: + * UDN = "uuid:4Hex-2Hex-2Hex-Hex-Hex-6Hex" + * + * The convertion rules are: + * 1 - An invalid char will be escaped using its hexa representation + * prefixed with '_': Ex ':' -> '_3A' + * 2 - The max size of the converted UDN can be 3 times the original + * size (if all char are not dbus compliant). + * The max size of a dbus path is an UINT32: G_MAXUINT32 + * We will limit the of the converted string size to G_MAXUINT32 / 2 + * otherwise we will never have space to generate object path. + */ + + len = strlen(udn); + dest_len = MIN(len * 3, G_MAXUINT32 / 2); + + uuid = g_malloc(dest_len + 1); + i = 0; + + while (*udn && (i < dest_len)) + { + if (g_ascii_isalnum(*udn) || (*udn == '_')) + uuid[i++] = *udn; + else + i += g_snprintf(uuid + i, dest_len + 1,"_%02x", *udn); + + udn++; + } + + + uuid[i]=0; + + return uuid; +} + dlr_device_t *dlr_device_new( dleyna_connector_id_t connection, GUPnPDeviceProxy *proxy, const gchar *ip_address, - guint counter, + const char *udn, const dleyna_connector_dispatch_cb_t *dispatch_table, const dleyna_task_queue_key_t *queue_id) { dlr_device_t *dev; gchar *new_path; + gchar *uuid; dlr_device_context_t *context; DLEYNA_LOG_DEBUG("New Device on %s", ip_address); - new_path = g_strdup_printf("%s/%u", DLEYNA_SERVER_PATH, counter); + uuid = prv_convert_udn_to_path(udn); + new_path = g_strdup_printf("%s/%s", DLEYNA_SERVER_PATH, uuid); + g_free(uuid); + DLEYNA_LOG_DEBUG("Server Path %s", new_path); dev = g_new0(dlr_device_t, 1); diff --git a/libdleyna/renderer/device.h b/libdleyna/renderer/device.h index 899b6b2..b0374ad 100644 --- a/libdleyna/renderer/device.h +++ b/libdleyna/renderer/device.h @@ -102,7 +102,7 @@ dlr_device_t *dlr_device_new( dleyna_connector_id_t connection, GUPnPDeviceProxy *proxy, const gchar *ip_address, - guint counter, + const char *udn, const dleyna_connector_dispatch_cb_t *dispatch_table, const dleyna_task_queue_key_t *queue_id); diff --git a/libdleyna/renderer/upnp.c b/libdleyna/renderer/upnp.c index 1b2b845..ac1b08a 100644 --- a/libdleyna/renderer/upnp.c +++ b/libdleyna/renderer/upnp.c @@ -45,7 +45,6 @@ struct dlr_upnp_t_ { void *user_data; GHashTable *server_udn_map; GHashTable *server_uc_map; - guint counter; dlr_host_service_t *host_service; }; @@ -186,14 +185,10 @@ static void prv_server_available_cb(GUPnPControlPoint *cp, queue_id = prv_create_device_queue(&priv_t); device = dlr_device_new(upnp->connection, proxy, ip_address, - upnp->counter, - upnp->interface_info, - queue_id); + udn, upnp->interface_info, queue_id); prv_update_device_context(priv_t, upnp, udn, device, ip_address, queue_id); - - upnp->counter++; } else { DLEYNA_LOG_DEBUG("Device Found"); |