Send notify for all lower versions as well
authorZeeshan Ali (Khattak) <zeeshanak@gnome.org>
Tue, 8 Mar 2011 15:20:55 +0000 (17:20 +0200)
committerZeeshan Ali (Khattak) <zeeshanak@gnome.org>
Wed, 9 Mar 2011 14:06:03 +0000 (16:06 +0200)
libgssdp/gssdp-protocol.h
libgssdp/gssdp-resource-group.c

index 050b122..2589e23 100644 (file)
@@ -59,6 +59,17 @@ G_BEGIN_DECLS
         "NT: %s\r\n"                                \
         "USN: %s\r\n\r\n"
 
+#define SSDP_ALIVE_MESSAGE_WITH_VERSION             \
+        "NOTIFY * HTTP/1.1\r\n"                     \
+        "Host: " SSDP_ADDR ":" SSDP_PORT_STR "\r\n" \
+        "Cache-Control: max-age=%d\r\n"             \
+        "Location: %s\r\n"                          \
+        "%s"                                        \
+        "Server: %s\r\n"                            \
+        "NTS: ssdp:alive\r\n"                       \
+        "NT: %s%d\r\n"                              \
+        "USN: %s\r\n\r\n"
+
 #define SSDP_BYEBYE_MESSAGE                         \
         "NOTIFY * HTTP/1.1\r\n"                     \
         "Host: " SSDP_ADDR ":" SSDP_PORT_STR "\r\n" \
@@ -66,6 +77,13 @@ G_BEGIN_DECLS
         "NT: %s\r\n"                                \
         "USN: %s\r\n\r\n"
 
+#define SSDP_BYEBYE_MESSAGE_WITH_VERSION            \
+        "NOTIFY * HTTP/1.1\r\n"                     \
+        "Host: " SSDP_ADDR ":" SSDP_PORT_STR "\r\n" \
+        "NTS: ssdp:byebye\r\n"                      \
+        "NT: %s%d\r\n"                              \
+        "USN: %s\r\n\r\n"
+
 #define SSDP_SEARCH_METHOD "M-SEARCH"
 #define GENA_NOTIFY_METHOD "NOTIFY"
 
index af5c8f5..a873ea1 100644 (file)
@@ -982,14 +982,67 @@ queue_message (GSSDPResourceGroup *resource_group,
 }
 
 /**
- * Send ssdp:alive message for @resource
+ * Add ssdp:alive messages for the given resource to sending queue
+ **/
+static void
+queue_alive_messages (GSSDPResourceGroup *resource_group,
+                      guint               max_age,
+                      const char         *location,
+                      const char         *al,
+                      const char         *server_id,
+                      const char         *target,
+                      const char         *usn)
+{
+        char *version_str;
+        char *message;
+
+        version_str = get_version_for_target ((char *) target);
+        if (version_str != NULL) {
+                char *_target;
+                int version;
+
+                version = atoi (version_str);
+                _target = g_strndup (target, version_str - target);
+
+                while (version > 0) {
+                        message = g_strdup_printf
+                                              (SSDP_ALIVE_MESSAGE_WITH_VERSION,
+                                               max_age,
+                                               location,
+                                               al,
+                                               server_id,
+                                               _target,
+                                               version,
+                                               usn);
+
+                        queue_message (resource_group, message);
+
+                        version--;
+                }
+
+                g_free (_target);
+        } else {
+                message = g_strdup_printf (SSDP_ALIVE_MESSAGE,
+                                           max_age,
+                                           location,
+                                           al,
+                                           server_id,
+                                           target,
+                                           usn);
+
+                queue_message (resource_group, message);
+        }
+}
+
+/**
+ * Send ssdp:alive messages for @resource
  **/
 static void
 resource_alive (Resource *resource)
 {
         GSSDPClient *client;
         guint max_age;
-        char *al, *message;
+        char *al;
 
         if (!resource->initial_alive_sent) {
                 /* Unannounce before first announce. This is done to
@@ -1007,15 +1060,13 @@ resource_alive (Resource *resource)
 
         al = construct_al (resource);
 
-        message = g_strdup_printf (SSDP_ALIVE_MESSAGE,
-                                   max_age,
-                                   (char *) resource->locations->data,
-                                   al ? al : "",
-                                   gssdp_client_get_server_id (client),
-                                   resource->target,
-                                   resource->usn);
-
-        queue_message (resource->resource_group, message);
+        queue_alive_messages (resource->resource_group,
+                              max_age,
+                              (const char *) resource->locations->data,
+                              al ? al : "",
+                              gssdp_client_get_server_id (client),
+                              resource->target,
+                              resource->usn);
 
         g_free (al);
 }
@@ -1026,14 +1077,38 @@ resource_alive (Resource *resource)
 static void
 resource_byebye (Resource *resource)
 {
+        char *version_str;
         char *message;
 
-        /* Queue message */
-        message = g_strdup_printf (SSDP_BYEBYE_MESSAGE,
-                                   resource->target,
-                                   resource->usn);
-        
-        queue_message (resource->resource_group, message);
+        version_str = get_version_for_target (resource->target);
+        if (version_str != NULL) {
+                char *_target;
+                int version;
+
+                version = atoi (version_str);
+                _target = g_strndup (resource->target,
+                                     version_str - resource->target);
+
+                while (version > 0) {
+                        message = g_strdup_printf
+                                              (SSDP_BYEBYE_MESSAGE_WITH_VERSION,
+                                               _target,
+                                               version,
+                                               resource->usn);
+
+                        queue_message (resource->resource_group, message);
+
+                        version--;
+                }
+
+                g_free (_target);
+        } else {
+                message = g_strdup_printf (SSDP_BYEBYE_MESSAGE,
+                                           resource->target,
+                                           resource->usn);
+
+                queue_message (resource->resource_group, message);
+        }
 }
 
 /**