static gchar* feeds_xbel_group_handler_dump (GrssFeedsGroupHandler *self, GList *channels, GError **error) { int size; xmlChar *ret; xmlDocPtr doc; xmlNodePtr xbelNode; xmlNodePtr childNode; GList *iter; GrssFeedChannel *channel; doc = xmlNewDoc (BAD_CAST"1.0"); xbelNode = xmlNewDocNode (doc, NULL, BAD_CAST"xbel", NULL); xmlNewProp (xbelNode, BAD_CAST"version", BAD_CAST"1.0"); for (iter = channels; iter; iter = g_list_next (iter)) { channel = (GrssFeedChannel*) iter->data; childNode = xmlNewChild (xbelNode, NULL, BAD_CAST"bookmark", NULL); xmlNewProp (childNode, BAD_CAST"href", BAD_CAST grss_feed_channel_get_source (channel)); xmlNewTextChild (childNode, NULL, BAD_CAST"title", BAD_CAST grss_feed_channel_get_title (channel)); } xmlDocSetRootElement (doc, xbelNode); xmlDocDumpFormatMemoryEnc (doc, &ret, &size, "utf-8", 1); xmlFreeDoc (doc); return (gchar*) ret; }
static void feed_fetched (GrssFeedsPool *pool, GrssFeedChannel *feed, GList *items) { GList *iter; GrssFeedItem *item; if (items == NULL) { printf ("Error while fetching %s\n", grss_feed_channel_get_title (feed)); return; } printf ("Fetched from %s\n", grss_feed_channel_get_title (feed)); for (iter = items; iter; iter = g_list_next (iter)) { item = (GrssFeedItem*) iter->data; printf ("\t\t%s\n", grss_feed_item_get_title (item)); } printf ("\n\n"); }
static gchar* feed_atom_formatter_format (GrssFeedFormatter *formatter) { const gchar *str; gchar *formatted; time_t date; GList *iter; GList *items; const GList *list; GString *text; GrssFeedChannel *channel; GrssFeedItem *item; text = g_string_new ("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<feed xmlns=\"http://www.w3.org/2005/Atom\">\n"); channel = grss_feed_formatter_get_channel (formatter); items = grss_feed_formatter_get_items (formatter); if (channel != NULL) { str = grss_feed_channel_get_title (channel); if (str != NULL) g_string_append_printf (text, "\t<title>%s</title>\n", str); str = grss_feed_channel_get_description (channel); if (str != NULL) g_string_append_printf (text, "\t<subtitle>%s</subtitle>\n", str); str = grss_feed_channel_get_homepage (channel); if (str != NULL) g_string_append_printf (text, "\t<link href=\"%s\" />\n", str); str = grss_feed_channel_get_copyright (channel); if (str != NULL) g_string_append_printf (text, "\t<rights>%s</rights>\n", str); str = grss_feed_channel_get_editor (channel); if (str != NULL) g_string_append_printf (text, "\t<author>%s</author>\n", str); str = grss_feed_channel_get_generator (channel); if (str != NULL) g_string_append_printf (text, "\t<generator>%s</generator>\n", str); list = grss_feed_channel_get_contributors (channel); while (list != NULL) { g_string_append_printf (text, "\t<contributor>%s</contributor>\n", (gchar*) list->data); list = list->next; } date = grss_feed_channel_get_update_time (channel); if (date == 0) date = grss_feed_channel_get_publish_time (channel); formatted = date_to_ISO8601 (date); g_string_append_printf (text, "\t<updated>%s</updated>\n", formatted); g_free (formatted); str = grss_feed_channel_get_icon (channel); if (str != NULL) g_string_append_printf (text, "\t<icon>%s</icon>\n", str); str = grss_feed_channel_get_image (channel); if (str != NULL) g_string_append_printf (text, "\t<logo>%s</logo>\n", str); for (iter = items; iter; iter = iter->next) { item = iter->data; g_string_append (text, "\t<entry>\n"); str = grss_feed_item_get_title (item); if (str != NULL) g_string_append_printf (text, "\t\t<title>%s</title>\n", str); str = grss_feed_item_get_id (item); if (str != NULL) g_string_append_printf (text, "\t\t<id>%s</id>\n", str); str = grss_feed_item_get_source (item); if (str != NULL) g_string_append_printf (text, "\t\t<link href=\"%s\" />\n", str); str = grss_feed_item_get_description (item); if (str != NULL) g_string_append_printf (text, "\t\t<summary>%s</summary>\n", str); str = grss_feed_item_get_author (item); if (str != NULL) g_string_append_printf (text, "\t\t<author>%s</author>\n", str); str = grss_feed_item_get_copyright (item); if (str != NULL) g_string_append_printf (text, "\t\t<rights>%s</rights>\n", str); list = grss_feed_item_get_contributors (item); while (list != NULL) { g_string_append_printf (text, "\t\t<contributor>%s</contributor>\n", (gchar*) list->data); list = list->next; } date = grss_feed_item_get_publish_time (item); formatted = date_to_ISO8601 (date); g_string_append_printf (text, "\t\t<published>%s</published>\n", formatted); g_free (formatted); g_string_append (text, "\t</entry>\n"); } } g_string_append (text, "</feed>"); return g_string_free (text, FALSE); }
static gchar* feed_rss_formatter_format (GrssFeedFormatter *formatter) { const gchar *str; const gchar *title; const gchar *link; gchar *formatted; time_t date; GList *iter; GList *items; GrssPerson *person; const GList *list; GString *text; GrssFeedChannel *channel; GrssFeedItem *item; /* Based on http://cyber.law.harvard.edu/rss/examples/rss2sample.xml */ text = g_string_new ("<?xml version=\"1.0\"?>\n<rss version=\"2.0\">\n"); channel = grss_feed_formatter_get_channel (formatter); items = grss_feed_formatter_get_items (formatter); if (channel != NULL) { g_string_append_printf (text, "<channel>\n"); title = grss_feed_channel_get_title (channel); if (title != NULL) g_string_append_printf (text, "\t<title>%s</title>\n", title); else title = ""; str = grss_feed_channel_get_description (channel); if (str != NULL) g_string_append_printf (text, "\t<description>%s</description>\n", str); link = grss_feed_channel_get_homepage (channel); if (link != NULL) g_string_append_printf (text, "\t<link>%s</link>\n", link); else link = ""; str = grss_feed_channel_get_copyright (channel); if (str != NULL) g_string_append_printf (text, "\t<copyright>%s</copyright>\n", str); person = grss_feed_channel_get_editor (channel); if (person != NULL) // TODO: implement handling additional attrs g_string_append_printf (text, "\t<managingEditor>%s</managingEditor>\n", grss_person_get_name (person)); str = grss_feed_channel_get_generator (channel); if (str != NULL) g_string_append_printf (text, "\t<generator>%s</generator>\n", str); date = grss_feed_channel_get_update_time (channel); formatted = date_to_ISO8601 (date); g_string_append_printf (text, "\t<pubDate>%s</pubDate>\n", formatted); g_free (formatted); str = grss_feed_channel_get_image (channel); if (str != NULL) { g_string_append_printf (text, "\t<image>\n"); g_string_append_printf (text, "\t\t<title>%s</title>\n", title); g_string_append_printf (text, "\t\t<url>%s</url>\n", str); g_string_append_printf (text, "\t\t<link>%s</link>\n", link); g_string_append_printf (text, "\t</image>\n"); } for (iter = items; iter; iter = iter->next) { item = iter->data; g_string_append (text, "\t<item>\n"); str = grss_feed_item_get_title (item); if (str != NULL) g_string_append_printf (text, "\t\t<title>%s</title>\n", str); str = grss_feed_item_get_id (item); if (str != NULL) g_string_append_printf (text, "\t\t<guid>%s</guid>\n", str); str = grss_feed_item_get_source (item); if (str != NULL) g_string_append_printf (text, "\t\t<link>%s</link>\n", str); str = grss_feed_item_get_description (item); if (str != NULL) g_string_append_printf (text, "\t\t<description>%s</description>\n", str); person = grss_feed_item_get_author (item); if (person != NULL) // FIXME: implement adding email and uri g_string_append_printf (text, "\t\t<author>%s</author>\n", grss_person_get_name (person)); date = grss_feed_item_get_publish_time (item); formatted = date_to_ISO8601 (date); g_string_append_printf (text, "\t\t<pubDate>%s</pubDate>\n", formatted); g_free (formatted); g_string_append (text, "\t</item>\n"); } } g_string_append (text, "</channel>\n</rss>"); return g_string_free (text, FALSE); }