[PATCH 1/2] Add functionality to set/get upnp:searchClass



---
 libgupnp-av/gupnp-didl-lite-container.c |   78 +++++++++++++++++++++++++++++++
 libgupnp-av/gupnp-didl-lite-container.h |   10 ++++
 2 files changed, 88 insertions(+), 0 deletions(-)

diff --git a/libgupnp-av/gupnp-didl-lite-container.c b/libgupnp-av/gupnp-didl-lite-container.c
index b2f190d..cafd0b4 100644
--- a/libgupnp-av/gupnp-didl-lite-container.c
+++ b/libgupnp-av/gupnp-didl-lite-container.c
@@ -234,6 +234,44 @@ gupnp_didl_lite_container_get_create_classes (GUPnPDIDLLiteContainer *container)
 }
 
 /**
+ * gupnp_didl_lite_container_get_search_classes:
+ * @container: #GUPnPDIDLLiteContainer
+ *
+ * Gets the list of search classes of the @object.
+ *
+ * Return value: The list of search classes belonging to @object, or %NULL.
+ * #g_list_free the returned list after usage and #g_free each string in it.
+ **/
+GList *
+gupnp_didl_lite_container_get_search_classes (GUPnPDIDLLiteContainer *container)
+{
+        GList *classes = NULL;
+        GList *ret = NULL;
+        GList *l;
+
+        g_return_val_if_fail (container != NULL, NULL);
+        g_return_val_if_fail (GUPNP_IS_DIDL_LITE_CONTAINER (container), NULL);
+
+        classes = gupnp_didl_lite_object_get_properties (
+                        GUPNP_DIDL_LITE_OBJECT (container),
+                        "searchClass");
+
+        for (l = classes; l; l = l->next) {
+                char *search_class;
+                xmlNode *node;
+
+                node = (xmlNode *) l->data;
+                search_class = g_strdup ((const char *) node->content);
+
+                ret = g_list_append (ret, search_class);
+        }
+
+        g_list_free (classes);
+
+        return ret;
+}
+
+/**
  * gupnp_didl_lite_container_set_searchable:
  * @container: #GUPnPDIDLLiteContainer
  * @searchable: The searchibility
@@ -323,3 +361,43 @@ gupnp_didl_lite_container_add_create_class (
                      (unsigned char *) "createClass",
                      (unsigned char *) create_class);
 }
+
+/**
+ * gupnp_didl_lite_container_add_search_class:
+ * @container: #GUPnPDIDLLiteContainer
+ * @search_class: The searchClass to add.
+ *
+ * Add a new search class to the @object.
+ *
+ * Return value: None.
+ **/
+void
+gupnp_didl_lite_container_add_search_class (
+                GUPnPDIDLLiteContainer *container,
+                const char             *search_class,
+                gboolean                include_derived)
+{
+        xmlNode *xml_node;
+        xmlNode *new_xml_node;
+        xmlNs *namespace;
+        char *str;
+
+        g_return_if_fail (container != NULL);
+        g_return_if_fail (GUPNP_IS_DIDL_LITE_CONTAINER (container));
+
+        xml_node = gupnp_didl_lite_object_get_xml_node
+                                (GUPNP_DIDL_LITE_OBJECT (container));
+        namespace = gupnp_didl_lite_object_get_upnp_namespace
+                                (GUPNP_DIDL_LITE_OBJECT (container));
+
+        new_xml_node = xmlNewChild (xml_node,
+                                    namespace,
+                                    (unsigned char *) "searchClass",
+                                    (unsigned char *) search_class);
+
+        str = g_strdup_printf ("%d", include_derived);
+        xmlSetProp (new_xml_node,
+                    (unsigned char*) "includeDerived",
+                    (unsigned char*) str);
+        g_free (str);
+}
diff --git a/libgupnp-av/gupnp-didl-lite-container.h b/libgupnp-av/gupnp-didl-lite-container.h
index 082915e..49448e6 100644
--- a/libgupnp-av/gupnp-didl-lite-container.h
+++ b/libgupnp-av/gupnp-didl-lite-container.h
@@ -78,6 +78,10 @@ GList *
 gupnp_didl_lite_container_get_create_classes
                                         (GUPnPDIDLLiteContainer *container);
 
+GList *
+gupnp_didl_lite_container_get_search_classes
+                                        (GUPnPDIDLLiteContainer *container);
+
 void
 gupnp_didl_lite_container_set_searchable
                                         (GUPnPDIDLLiteContainer *container,
@@ -93,6 +97,12 @@ gupnp_didl_lite_container_add_create_class
                                         (GUPnPDIDLLiteContainer *container,
                                          const char             *create_class);
 
+void
+gupnp_didl_lite_container_add_search_class
+                                        (GUPnPDIDLLiteContainer *container,
+                                         const char             *search_class,
+                                         gboolean                include_derived);
+
 G_END_DECLS
 
 #endif /* __GUPNP_DIDL_LITE_CONTAINER_H__ */
-- 
1.7.1


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