[PATCH 3/6] [grl-plugin-registry] Get plugins' info from XML file
- From: Joaquim Rocha <jrocha igalia com>
- To: grilo-list gnome org
- Subject: [PATCH 3/6] [grl-plugin-registry] Get plugins' info from XML file
- Date: Wed, 9 Jun 2010 10:14:44 +0200
Builds the XML from the library name and parses it to retrieve the
plugin's info.
---
src/grl-plugin-registry.c | 66 +++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 66 insertions(+), 0 deletions(-)
diff --git a/src/grl-plugin-registry.c b/src/grl-plugin-registry.c
index a1d86f9..0572a7e 100644
--- a/src/grl-plugin-registry.c
+++ b/src/grl-plugin-registry.c
@@ -44,6 +44,7 @@
#include <string.h>
#include <gmodule.h>
+#include <libxml/parser.h>
#define SYSTEM_KEYS_MAX 256
@@ -52,6 +53,8 @@
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "grl-plugin-registry"
+#define XML_ROOT_ELEMENT_NAME "pluginInfo"
+
#define GRL_PLUGIN_REGISTRY_GET_PRIVATE(object) \
(G_TYPE_INSTANCE_GET_PRIVATE((object), \
GRL_TYPE_PLUGIN_REGISTRY, \
@@ -267,6 +270,64 @@ sort_by_rank (GrlMediaPlugin **source_list)
}
}
+static gchar *
+get_xml_path_from_plugin_path (const gchar *path)
+{
+ gchar *path_prefix, *xml_path, *extension;
+ gint extension_index;
+
+ extension = g_strrstr (path, G_MODULE_SUFFIX);
+ if (!extension) {
+ return g_strdup (path);
+ }
+
+ extension_index = g_utf8_pointer_to_offset (path, extension);
+ path_prefix = (gchar *) g_malloc(extension - path);
+ g_utf8_strncpy (path_prefix,
+ path,
+ extension_index);
+ xml_path = g_strconcat (path_prefix, "xml", NULL);
+ g_free (path_prefix);
+
+ return xml_path;
+}
+
+static GHashTable *
+get_info_from_plugin_xml (const gchar *xml_path)
+{
+ GHashTable *hash_table;
+ xmlNodePtr node, child;
+ xmlDocPtr doc_ptr = xmlReadFile (xml_path,
+ NULL,
+ XML_PARSE_RECOVER | XML_PARSE_NOBLANKS |
+ XML_PARSE_NOWARNING | XML_PARSE_NOERROR);
+ if (!doc_ptr) {
+ g_warning ("Could not read XML file under the location: %s", xml_path);
+ return NULL;
+ }
+
+ node = xmlDocGetRootElement (doc_ptr);
+ if (!node || g_strcmp0 ((gchar *) node->name, XML_ROOT_ELEMENT_NAME)) {
+ g_warning ("%s did not have a %s root element.",
+ xml_path,
+ XML_ROOT_ELEMENT_NAME);
+ xmlFreeDoc (doc_ptr);
+ return NULL;
+ }
+
+ hash_table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
+ child = node->children;
+ while (child) {
+ g_hash_table_insert (hash_table,
+ g_strdup ((gchar *) child->name),
+ (gchar *) xmlNodeGetContent (child));
+ child = child->next;
+ }
+ xmlFreeDoc (doc_ptr);
+
+ return hash_table;
+}
+
/* ================ API ================ */
/**
@@ -370,6 +431,7 @@ grl_plugin_registry_load (GrlPluginRegistry *registry, const gchar *path)
GModule *module;
GrlPluginDescriptor *plugin;
GList *plugin_configs;
+ gchar *xml_path;
module = g_module_open (path, G_MODULE_BIND_LAZY);
if (!module) {
@@ -388,6 +450,10 @@ grl_plugin_registry_load (GrlPluginRegistry *registry, const gchar *path)
return FALSE;
}
+ xml_path = get_xml_path_from_plugin_path (path);
+ plugin->info.optional_info = get_info_from_plugin_xml (xml_path);
+ g_free (xml_path);
+
set_plugin_rank (registry, plugin);
g_hash_table_insert (registry->priv->plugins,
--
1.7.0.4
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]