Retrieve resource returns either an entry or a feed
authorThadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
Sat, 9 Aug 2008 22:55:36 +0000 (19:55 -0300)
committerThadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
Sun, 10 Aug 2008 02:42:05 +0000 (23:42 -0300)
include/atompub/backend.h
src/backend.c

index 3a41899..728c580 100644 (file)
@@ -36,6 +36,7 @@ void atom_backend_enumerate_entries_set (AtomBackend *,
 AtomEntry * atom_retrieve_entry (AtomCtx *, IRI *);
 void atom_enumerate_entries (AtomCtx *, AtomEntry ***, size_t *);
 AtomFeed * atom_retrieve_feed (AtomCtx *);
+AtomResource *atom_retrieve_resource (AtomCtx *, IRI *);
 AtomBackend * atom_backend (AtomCtx *);
 void atom_backend_set (AtomCtx *, AtomBackend *);
 
index d1ffec7..30ba7a7 100644 (file)
 
 
 #include <atompub/atom.h>
+
 #include <glib.h>
 
+#include <string.h>
+
 struct _atom_backend
 {
   AtomEntry * (*retrieve_entry) (AtomCtx *, IRI *);
@@ -91,3 +94,26 @@ atom_retrieve_feed (AtomCtx *ctx)
   atom_feed_entry_append_array (feed, entries, len);
   return feed;
 }
+
+AtomResource *
+atom_retrieve_resource (AtomCtx *ctx, IRI *iri)
+{
+  AtomResource *res;
+  char * path;
+  path = iri_get_path (iri);
+  if (!strcmp (path, "/"))
+    {
+      AtomFeed *feed;
+      feed = atom_retrieve_feed (ctx);
+      res = atom_resource_new_from_feed (feed);
+      atom_feed_delete (feed);
+    }
+  else
+    {
+      AtomEntry *entry;
+      entry = atom_retrieve_entry (ctx, iri);
+      res = atom_resource_new_from_entry (entry);
+      atom_entry_delete (entry);
+    }
+  return res;
+}