From d668fe7862c834a7af0395d61a7edcefc2732a05 Mon Sep 17 00:00:00 2001 From: Thadeu Lima de Souza Cascardo Date: Sat, 9 Aug 2008 19:00:15 -0300 Subject: [PATCH] Generate feed with many entries --- atom/Makefile.am | 2 +- atom/feed.c | 80 +++++++++++++++++++++++++++++++++++++ include/atompub/Makefile.am | 2 +- include/atompub/atom-xml.h | 1 + include/atompub/feed-xml.h | 29 ++++++++++++++ include/atompub/feed.h | 6 +++ 6 files changed, 118 insertions(+), 2 deletions(-) create mode 100644 atom/feed.c create mode 100644 include/atompub/feed-xml.h diff --git a/atom/Makefile.am b/atom/Makefile.am index 1823945..a49a0ef 100644 --- a/atom/Makefile.am +++ b/atom/Makefile.am @@ -1,5 +1,5 @@ lib_LTLIBRARIES = libatom.la -libatom_la_SOURCES = entry.c person.c +libatom_la_SOURCES = entry.c person.c feed.c libatom_la_CFLAGS = -I$(top_srcdir)/include $(GLIB_CFLAGS) libatom_la_CFLAGS += $(XML_CFLAGS) libatom_la_LIBADD = $(GLIB_LIBS) $(XML_LIBS) diff --git a/atom/feed.c b/atom/feed.c new file mode 100644 index 0000000..af21300 --- /dev/null +++ b/atom/feed.c @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2008 Thadeu Lima de Souza Cascardo + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + + +#include +#include + +#include +#include + +struct _atom_feed +{ + GList *entries; +}; + +AtomFeed * +atom_feed_new (void) +{ + AtomFeed *feed; + feed = g_slice_new (AtomFeed); + feed->entries = NULL; + return feed; +} + +void +atom_feed_delete (AtomFeed *feed) +{ + GList *l; + for (l = g_list_first (feed->entries); l != NULL; l = l->next) + { + atom_entry_delete (l->data); + } + g_slice_free (AtomFeed, feed); +} + +void +atom_feed_entry_append (AtomFeed *feed, AtomEntry *entry) +{ + feed->entries = g_list_prepend (feed->entries, entry); +} + +void +atom_feed_entry_append_array (AtomFeed *feed, AtomEntry **entries, size_t len) +{ + int i; + for (i = 0; i < len; i++) + { + feed->entries = g_list_prepend (feed->entries, entries[i]); + } +} + +xmlNodePtr +atom_feed_to_xmlnode (AtomFeed *feed) +{ + xmlNodePtr node; + xmlNodePtr entry; + GList *l; + node = xmlNewNode (NULL, "feed"); + for (l = g_list_last (feed->entries); l != NULL; l = l->prev) + { + entry = atom_entry_to_xmlnode (l->data); + xmlAddChild (node, entry); + } + return node; +} diff --git a/include/atompub/Makefile.am b/include/atompub/Makefile.am index 32b09d7..dfada39 100644 --- a/include/atompub/Makefile.am +++ b/include/atompub/Makefile.am @@ -1,3 +1,3 @@ pkginclude_HEADERS = atom.h config.h ctx.h entry.h person.h error.h feed.h \ iri.h backend.h atom-glib.h error-glib.h atom-xml.h \ - entry-xml.h person-xml.h + entry-xml.h person-xml.h feed-xml.h diff --git a/include/atompub/atom-xml.h b/include/atompub/atom-xml.h index 5f09100..5ae430d 100644 --- a/include/atompub/atom-xml.h +++ b/include/atompub/atom-xml.h @@ -22,5 +22,6 @@ #include #include +#include #endif diff --git a/include/atompub/feed-xml.h b/include/atompub/feed-xml.h new file mode 100644 index 0000000..81ed0d1 --- /dev/null +++ b/include/atompub/feed-xml.h @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2008 Thadeu Lima de Souza Cascardo + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + + +#ifndef ATOM_FEED_XML_H +#define ATOM_FEED_XML_H + +#include + +#include + +xmlNodePtr atom_feed_to_xmlnode (AtomFeed *); + +#endif diff --git a/include/atompub/feed.h b/include/atompub/feed.h index 1a92f0f..3e18759 100644 --- a/include/atompub/feed.h +++ b/include/atompub/feed.h @@ -21,7 +21,13 @@ #define ATOMPUB_FEED_H #include +#include typedef struct _atom_feed AtomFeed; +AtomFeed * atom_feed_new (void); +void atom_feed_delete (AtomFeed *); +void atom_feed_entry_append (AtomFeed *, AtomEntry *); +void atom_feed_entry_append_array (AtomFeed *, AtomEntry **, size_t); + #endif -- 2.20.1