Generate feed with many entries
authorThadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
Sat, 9 Aug 2008 22:00:15 +0000 (19:00 -0300)
committerThadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
Sat, 9 Aug 2008 22:00:15 +0000 (19:00 -0300)
atom/Makefile.am
atom/feed.c [new file with mode: 0644]
include/atompub/Makefile.am
include/atompub/atom-xml.h
include/atompub/feed-xml.h [new file with mode: 0644]
include/atompub/feed.h

index 1823945..a49a0ef 100644 (file)
@@ -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 (file)
index 0000000..af21300
--- /dev/null
@@ -0,0 +1,80 @@
+/*
+ *  Copyright (C) 2008  Thadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
+ *
+ *  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 <atompub/atom.h>
+#include <atompub/atom-xml.h>
+
+#include <glib.h>
+#include <libxml/tree.h>
+
+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;
+}
index 32b09d7..dfada39 100644 (file)
@@ -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
index 5f09100..5ae430d 100644 (file)
@@ -22,5 +22,6 @@
 
 #include <atompub/person-xml.h>
 #include <atompub/entry-xml.h>
+#include <atompub/feed-xml.h>
 
 #endif
diff --git a/include/atompub/feed-xml.h b/include/atompub/feed-xml.h
new file mode 100644 (file)
index 0000000..81ed0d1
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ *  Copyright (C) 2008  Thadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
+ *
+ *  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 <atompub/feed.h>
+
+#include <libxml/tree.h>
+
+xmlNodePtr atom_feed_to_xmlnode (AtomFeed *);
+
+#endif
index 1a92f0f..3e18759 100644 (file)
 #define ATOMPUB_FEED_H
 
 #include <atompub/ctx.h>
+#include <atompub/entry.h>
 
 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