[gupnp] [PATCH] Respond to M-SEARCH requests for urns specifying an eligible version



<Patch attached as well as inline in case my mailer mangles word wrapping>


From bd8a30b61dcd5ad29259a575ce1095f3f9b15462 Mon Sep 17 00:00:00 2001
From: Stephen Depooter <stephend xandros com>
Date: Wed, 9 Jun 2010 15:51:11 -0400
Subject: [PATCH] Respond to M-SEARCH requests for urns specifying an eligible 
version

UPNP requires that we only respond to M-SEARCH requests for urn:
interfaces where we implement a compatible version of the specified
interface.
---
 libgssdp/gssdp-resource-group.c |   34 ++++++++++++++++++++++++++++------
 1 files changed, 28 insertions(+), 6 deletions(-)

diff --git a/libgssdp/gssdp-resource-group.c b/libgssdp/gssdp-resource-group.c
index 9a98409..6c552bb 100644
--- a/libgssdp/gssdp-resource-group.c
+++ b/libgssdp/gssdp-resource-group.c
@@ -737,9 +737,11 @@ message_received_cb (GSSDPClient        *client,
                      gpointer            user_data)
 {
         GSSDPResourceGroup *resource_group;
-        const char *target, *mx_str;
+        const char *target, *mx_str, *target_version_str;
         gboolean want_all;
+        gboolean do_version_match;
         int mx;
+        int target_version;
         GList *l;
 
         resource_group = GSSDP_RESOURCE_GROUP (user_data);
@@ -760,6 +762,16 @@ message_received_cb (GSSDPClient        *client,
                 return;
         }
 
+	target_version = 0;
+        do_version_match = (strncmp (target, "urn:", 4) == 0);
+        if (do_version_match) {
+                /* target is a URN, need to deal with version. */
+                target_version_str = g_strrstr (target, ":") + 1;
+                target_version = atoi(target_version_str);
+        }
+
+
+
         /* Is this the "ssdp:all" target? */
         want_all = (strcmp (target, GSSDP_ALL_RESOURCES) == 0);
 
@@ -781,6 +793,16 @@ message_received_cb (GSSDPClient        *client,
                                    target,
                                    0,
                                    NULL)) {
+                        if (do_version_match) {
+                                char* resource_version_str = 
g_strrstr(resource->target, ":") + 1;
+                                int resource_version = 
atoi(resource_version_str);
+                                if (target_version > resource_version)
+                                        continue;
+			}
+
+
+
+
                         /* Match. */
                         guint timeout;
                         DiscoveryResponse *response;
@@ -791,7 +813,7 @@ message_received_cb (GSSDPClient        *client,
 
                         /* Prepare response */
                         response = g_slice_new (DiscoveryResponse);
-                        
+
                         response->dest_ip   = g_strdup (from_ip);
                         response->dest_port = from_port;
                         response->resource  = resource;
@@ -803,12 +825,12 @@ message_received_cb (GSSDPClient        *client,
 
                         /* Add timeout */
                         response->timeout_src = g_timeout_source_new 
(timeout);
-			g_source_set_callback (response->timeout_src,
-					       discovery_response_timeout,
-					       response, NULL);
+                        g_source_set_callback (response->timeout_src,
+                                               discovery_response_timeout,
+                                               response, NULL);
 
                         context = gssdp_client_get_main_context (client);
-			g_source_attach (response->timeout_src, context);
+                        g_source_attach (response->timeout_src, context);
 
                         g_source_unref (response->timeout_src);
                         
-- 
1.5.6.5



-- 
Stephen Depooter
<stephend xandros com>
From bd8a30b61dcd5ad29259a575ce1095f3f9b15462 Mon Sep 17 00:00:00 2001
From: Stephen Depooter <stephend xandros com>
Date: Wed, 9 Jun 2010 15:51:11 -0400
Subject: [PATCH] Respond to M-SEARCH requests for urns specifying an eligable version

UPNP requires that we only respond to M-SEARCH requests for urn:
interfaces where we implement a compatible version of the specified
interface.
---
 libgssdp/gssdp-resource-group.c |   34 ++++++++++++++++++++++++++++------
 1 files changed, 28 insertions(+), 6 deletions(-)

diff --git a/libgssdp/gssdp-resource-group.c b/libgssdp/gssdp-resource-group.c
index 9a98409..6c552bb 100644
--- a/libgssdp/gssdp-resource-group.c
+++ b/libgssdp/gssdp-resource-group.c
@@ -737,9 +737,11 @@ message_received_cb (GSSDPClient        *client,
                      gpointer            user_data)
 {
         GSSDPResourceGroup *resource_group;
-        const char *target, *mx_str;
+        const char *target, *mx_str, *target_version_str;
         gboolean want_all;
+        gboolean do_version_match;
         int mx;
+        int target_version;
         GList *l;
 
         resource_group = GSSDP_RESOURCE_GROUP (user_data);
@@ -760,6 +762,16 @@ message_received_cb (GSSDPClient        *client,
                 return;
         }
 
+	target_version = 0;
+        do_version_match = (strncmp (target, "urn:", 4) == 0);
+        if (do_version_match) {
+                /* target is a URN, need to deal with version. */
+                target_version_str = g_strrstr (target, ":") + 1;
+                target_version = atoi(target_version_str);
+        }
+
+
+
         /* Is this the "ssdp:all" target? */
         want_all = (strcmp (target, GSSDP_ALL_RESOURCES) == 0);
 
@@ -781,6 +793,16 @@ message_received_cb (GSSDPClient        *client,
                                    target,
                                    0,
                                    NULL)) {
+                        if (do_version_match) {
+                                char* resource_version_str = g_strrstr(resource->target, ":") + 1;
+                                int resource_version = atoi(resource_version_str);
+                                if (target_version > resource_version)
+                                        continue;
+			}
+
+
+
+
                         /* Match. */
                         guint timeout;
                         DiscoveryResponse *response;
@@ -791,7 +813,7 @@ message_received_cb (GSSDPClient        *client,
 
                         /* Prepare response */
                         response = g_slice_new (DiscoveryResponse);
-                        
+
                         response->dest_ip   = g_strdup (from_ip);
                         response->dest_port = from_port;
                         response->resource  = resource;
@@ -803,12 +825,12 @@ message_received_cb (GSSDPClient        *client,
 
                         /* Add timeout */
                         response->timeout_src = g_timeout_source_new (timeout);
-			g_source_set_callback (response->timeout_src,
-					       discovery_response_timeout,
-					       response, NULL);
+                        g_source_set_callback (response->timeout_src,
+                                               discovery_response_timeout,
+                                               response, NULL);
 
                         context = gssdp_client_get_main_context (client);
-			g_source_attach (response->timeout_src, context);
+                        g_source_attach (response->timeout_src, context);
 
                         g_source_unref (response->timeout_src);
                         
-- 
1.5.6.5



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]