[grilo-plugins] upnp: Verify server SearchCapabilities



commit 52fcb40e016faf7c77a60cf8aff6cbe5d434f17b
Author: Juan A. Suarez Romero <jasuarez igalia com>
Date:   Wed Dec 12 18:54:39 2012 +0000

    upnp: Verify server SearchCapabilities
    
    Performing a search() and/or a filtered browse() requires that UPnP server
    supports some specific keys in its SearchCapabilities.
    
    This commit verifies that actually the server supports them, and deactivate
    these features if searching through those keys is not supported in the server.

 src/upnp/grl-upnp.c |   51 +++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 41 insertions(+), 10 deletions(-)
---
diff --git a/src/upnp/grl-upnp.c b/src/upnp/grl-upnp.c
index dbab8d2..3b22df6 100644
--- a/src/upnp/grl-upnp.c
+++ b/src/upnp/grl-upnp.c
@@ -85,6 +85,7 @@ struct _GrlUpnpPrivate {
   GUPnPServiceProxy* service;
   GUPnPControlPoint *cp;
   gboolean search_enabled;
+  gboolean browse_filtered_enabled;
   gchar *upnp_name;
 };
 
@@ -350,12 +351,31 @@ gupnp_search_caps_cb (GUPnPServiceProxy *service,
 
   source = GRL_SOURCE (source_info->source);
 
-  if (caps && caps[0] != '\0') {
+  if (caps) {
+    if (g_strcmp0 (caps, "*") == 0) {
+      source_info->source->priv->search_enabled = TRUE;
+      source_info->source->priv->browse_filtered_enabled = TRUE;
+    } else {
+      if (g_strstr_len (caps, -1, "upnp:class")) {
+        if (g_strstr_len (caps, -1, "dc:title") ||
+            g_strstr_len (caps, -1, "upnp:album") ||
+            g_strstr_len (caps, -1, "upnp_artist")) {
+          source_info->source->priv->search_enabled = TRUE;
+        }
+        if (g_strstr_len (caps, -1, "@parentID")) {
+          source_info->source->priv->browse_filtered_enabled = TRUE;
+        }
+      }
+    }
+  }
+
+  if (source_info->source->priv->search_enabled) {
     GRL_DEBUG ("Setting search enabled for source '%s'",
                grl_source_get_name (source));
-    source_info->source->priv->search_enabled = TRUE;
-  } else {
-    GRL_DEBUG ("Setting search disabled for source '%s'",
+  }
+
+  if (source_info->source->priv->browse_filtered_enabled) {
+    GRL_DEBUG ("Setting filtered browse enabled for source '%s'",
                grl_source_get_name (source));
   }
 
@@ -1426,17 +1446,28 @@ static GrlCaps *
 grl_upnp_source_get_caps (GrlSource *source,
                           GrlSupportedOps operation)
 {
-  static GrlCaps *caps = NULL;
-
-  if (!caps) {
-    caps = grl_caps_new ();
+  static GrlCaps *search_caps = NULL;
+  static GrlCaps *browse_caps = NULL;
 
+  if (!search_caps) {
+    search_caps = grl_caps_new ();
     if (GRL_UPNP_SOURCE (source)->priv->search_enabled) {
-      grl_caps_set_type_filter (caps, GRL_TYPE_FILTER_ALL);
+      grl_caps_set_type_filter (search_caps, GRL_TYPE_FILTER_ALL);
     }
   }
 
-  return caps;
+  if (!browse_caps) {
+    browse_caps = grl_caps_new ();
+    if (GRL_UPNP_SOURCE (source)->priv->browse_filtered_enabled) {
+      grl_caps_set_type_filter (browse_caps, GRL_TYPE_FILTER_ALL);
+    }
+  }
+
+  if (operation == GRL_OP_BROWSE) {
+    return browse_caps;
+  } else {
+    return search_caps;
+  }
 }
 
 



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