[libgrss] Added grss_feed_channel_new_from_xml and grss_feed_channel_new_from_memory



commit 4d9cb66f97fbca9790992679a858086266b154d9
Author: Roberto Guido <rguido src gnome org>
Date:   Mon Apr 21 23:25:04 2014 +0200

    Added grss_feed_channel_new_from_xml and grss_feed_channel_new_from_memory

 doc/reference/libgrss-sections.txt |    2 +
 src/feed-channel.c                 |   63 ++++++++++++++++++++++++++++++++----
 src/feed-channel.h                 |    2 +
 3 files changed, 60 insertions(+), 7 deletions(-)
---
diff --git a/doc/reference/libgrss-sections.txt b/doc/reference/libgrss-sections.txt
index bb2b22b..e8547ec 100644
--- a/doc/reference/libgrss-sections.txt
+++ b/doc/reference/libgrss-sections.txt
@@ -110,6 +110,8 @@ grss_feed_parser_parse
 GrssFeedChannel
 grss_feed_channel_new
 grss_feed_channel_new_with_source
+grss_feed_channel_new_from_xml
+grss_feed_channel_new_from_memory
 grss_feed_channel_new_from_file
 grss_feed_channel_set_format
 grss_feed_channel_get_format
diff --git a/src/feed-channel.c b/src/feed-channel.c
index 7077a89..0ca778f 100644
--- a/src/feed-channel.c
+++ b/src/feed-channel.c
@@ -165,6 +165,61 @@ grss_feed_channel_new_with_source (gchar *source)
 }
 
 /**
+ * grss_feed_channel_new_from_xml:
+ * @doc: an XML document previously parsed with libxml2.
+ * @error: if an error occourred, %NULL is returned and this is filled with the
+ *         message.
+ *
+ * Allocates a new #GrssFeedChannel and init it with contents found in specified
+ * XML document.
+ *
+ * Return value: a #GrssFeedChannel, or %NULL if an error occurs.
+ */
+GrssFeedChannel*
+grss_feed_channel_new_from_xml (xmlDocPtr doc, GError **error)
+{
+       GrssFeedParser *parser;
+       GrssFeedChannel *ret;
+
+       ret = g_object_new (GRSS_FEED_CHANNEL_TYPE, NULL);
+       parser = grss_feed_parser_new ();
+
+       grss_feed_parser_parse_channel (parser, ret, doc, error);
+       if (error != NULL) {
+               g_object_unref (ret);
+               ret = NULL;
+       }
+
+       g_object_unref (parser);
+       return ret;
+}
+
+/**
+ * grss_feed_channel_new_from_memory:
+ * @data: string to parse.
+ * @error: if an error occourred, %NULL is returned and this is filled with the
+ *         message.
+ *
+ * Allocates a new #GrssFeedChannel and init it with contents found in specified
+ * memory block.
+ *
+ * Return value: a #GrssFeedChannel, or %NULL if an error occurs.
+ */
+GrssFeedChannel*
+grss_feed_channel_new_from_memory (const gchar *data, GError **error)
+{
+       xmlDocPtr doc;
+
+       doc = content_to_xml (data, strlen (data));
+       if (doc == NULL) {
+               g_set_error (error, FEED_CHANNEL_ERROR, FEED_CHANNEL_PARSE_ERROR, "Unable to parse data");
+               return NULL;
+       }
+
+       return grss_feed_channel_new_from_xml (doc, error);
+}
+
+/**
  * grss_feed_channel_new_from_file:
  * @path: path of the file to parse.
  * @error: if an error occourred, %NULL is returned and this is filled with the
@@ -180,9 +235,7 @@ GrssFeedChannel*
 grss_feed_channel_new_from_file (const gchar *path, GError **error)
 {
        struct stat sbuf;
-       GList *iter;
        xmlDocPtr doc;
-       GrssFeedParser *parser;
        GrssFeedChannel *ret;
 
        ret = NULL;
@@ -198,13 +251,9 @@ grss_feed_channel_new_from_file (const gchar *path, GError **error)
                return NULL;
        }
 
-       ret = g_object_new (GRSS_FEED_CHANNEL_TYPE, NULL);
-       parser = grss_feed_parser_new ();
-       grss_feed_parser_parse_channel (parser, ret, doc, NULL);
+       ret = grss_feed_channel_new_from_xml (doc, error);
 
-       g_object_unref (parser);
        xmlFreeDoc (doc);
-
        return ret;
 }
 
diff --git a/src/feed-channel.h b/src/feed-channel.h
index 8287c75..d609888 100644
--- a/src/feed-channel.h
+++ b/src/feed-channel.h
@@ -46,6 +46,8 @@ GType                 grss_feed_channel_get_type              (void) G_GNUC_CONST;
 
 GrssFeedChannel*       grss_feed_channel_new                   ();
 GrssFeedChannel*       grss_feed_channel_new_with_source       (gchar *source);
+GrssFeedChannel*       grss_feed_channel_new_from_xml          (xmlDocPtr doc, GError **error);
+GrssFeedChannel*       grss_feed_channel_new_from_memory       (const gchar *data, GError **error);
 GrssFeedChannel*       grss_feed_channel_new_from_file         (const gchar *path, GError **error);
 
 void                   grss_feed_channel_set_format            (GrssFeedChannel *channel, gchar *format);


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