Archives for: May 2005, 12
05/12/05
JAY!!!! :-D
As I blogged before I've been working on a PlanetPlanet implementation in C. I got a basic RSS2 parser working before, but that code was plain ugly.
Now I refactored all code using GObjects (learnt a lot whilst doing this), and it works :-D
Currently it can parse RSS2 feeds (as many as your memory allows you to ;-)) and combine them into one RSS2 feed. Adding more feed types should be fairly easy.
This is a sample result, and here you can see a FeedValidator validation result. Never mind the encoding issue, that's related to the server settings of the machine I'm hosted on (and I'm no administrator :-().
This is the code I used to generate the feed:
#include <glib.h>
#include <libxml/tree.h>
#include "src/feedmerge-feed.h"
#include "src/feedmerge-merge.h"
gint main(gint argc, gchar *argv[]) {
FeedMergeFeed *feed1 = NULL, *feed2 = NULL;
GSList *feeds = NULL;
xmlDoc *doc = NULL;
g_type_init();
feed1 = (FeedMergeFeed *) feedmerge_feed_new();
feed2 = (FeedMergeFeed *) feedmerge_feed_new();
feedmerge_feed_fetch_feed(feed1, "http://blog.eikke.com/xmlsrv/rss2.php?blog=1");
feedmerge_feed_fetch_feed(feed2, "http://blog.eikke.com/xmlsrv/rss2.php?blog=7");
feedmerge_feed_parse_document(feed1);
feedmerge_feed_parse_document(feed2);
/* feedmerge_feed_dump(feed2); */
feeds = g_slist_append(feeds, feed1);
feeds = g_slist_append(feeds, feed2);
/* output type, GSList containing the feeds, feed title, URI and description */
doc = feedmerge_merge_merge(FEEDMERGE_FEED_TYPE_RSS_200, feeds,
"Test feed", "http://blog.eikke.com/ikke", "This is a test merged feed");
g_assert(doc != NULL);
/* output to stdout */
xmlSaveFormatFileEnc("-", doc, "UTF-8", 1);
xmlFreeDoc(doc);
g_object_unref(feed1);
g_object_unref(feed2);
g_slist_free(feeds);
}
Using gob2 again to write my objects, it's just a pleasure to play with :-) Strong type checking is automagically added etc, just great. I'm eager to see some GObject introspection samples.
Of course what I got now can be further abstracted to something like this:
xmlDoc *doc = feedmerge_vamerge("http://a.b/feed1.xml", "file:///tmp/feed2.xml",
"scp://somehost:/test.xml", "Title", "http://www.eikke.com", "This is a nifty combined feed");
i.e. using varargs.
Thanks to GnomeVFS I don't have to care where the feed comes from, which is just great.
I had to handle some nasty and stupid bugs while coding this (in my own code, of course) and propably I leak memory at several places too, but well... ;-) We got valgrind :-) And thanks to the GCC people for blessing us with the "-Werror" flag, I love that feature.
I won't publish the code yet, but maybe it'll get into Soylent (who knows?) so then it'll be in some CVS/SVN/whatever repository.
Regarding Soylent: we're looking for a new name. Please help us out, I can't wait to start doing some real work.
That's it for now.