The frontend tells if a request is a feed or not
authorThadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
Mon, 13 Oct 2008 00:47:00 +0000 (21:47 -0300)
committerThadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
Mon, 13 Oct 2008 01:31:07 +0000 (22:31 -0300)
atom/backend.c
atom/frontend.c
backend/gio/gio.c
include/atompub/backend.h
include/atompub/frontend.h

index d517748..faf031c 100644 (file)
@@ -27,7 +27,6 @@ struct _atom_backend
 {
   AtomEntry * (*retrieve_entry) (AtomCtx *, AtomID *);
   void (*enumerate_entries) (AtomCtx *, char ***, AtomEntry ***, size_t *);
-  int  (*is_feed) (AtomCtx *, AtomID *);
 };
 
 AtomBackend *
@@ -37,7 +36,6 @@ atom_backend_new ()
   backend = g_slice_new (AtomBackend);
   backend->retrieve_entry = NULL;
   backend->enumerate_entries = NULL;
-  backend->is_feed = NULL;
   return backend;
 }
 
@@ -65,13 +63,6 @@ atom_backend_enumerate_entries_set (AtomBackend *backend,
   backend->enumerate_entries = enumerate_entries;
 }
 
-void
-atom_backend_is_feed_set (AtomBackend *backend,
-                         int is_feed (AtomCtx *, AtomID *))
-{
-  backend->is_feed = is_feed;
-}
-
 AtomEntry *
 atom_retrieve_entry (AtomCtx *ctx, AtomID *id)
 {
@@ -122,27 +113,6 @@ atom_backend_enumerate_entries (AtomCtx *ctx, char *** reqs,
     *len = rlen;
 }
 
-int
-atom_is_feed (AtomCtx *ctx, AtomID *id)
-{
-  AtomBackend *backend;
-  AtomError *aerr;
-  backend = atom_backend (ctx);
-  if (backend && backend->is_feed)
-    {
-      return backend->is_feed (ctx, id);
-    }
-  /* Frontend may make the decision of whether the requested resource is
-   * a feed or not. If it is not able to do so and backend isn't either,
-   * it is an error.
-   */
-  aerr = atom_error_new ();
-  atom_error_code_set (aerr, 404);
-  atom_error_message_set (aerr, "Not Found");
-  atom_error_set (ctx, aerr);
-  return 0;
-}
-
 AtomFeed *
 atom_retrieve_feed (AtomCtx *ctx)
 {
index 778ffa1..ed0faad 100644 (file)
@@ -26,6 +26,7 @@
 struct _atom_frontend
 {
   void (*map_entries) (AtomCtx *, char **, AtomEntry **, size_t);
+  int  (*is_feed) (AtomCtx *, char *);
 };
 
 AtomFrontend *
@@ -34,6 +35,7 @@ atom_frontend_new ()
   AtomFrontend *frontend;
   frontend = g_slice_new (AtomFrontend);
   frontend->map_entries = NULL;
+  frontend->is_feed = NULL;
   return frontend;
 }
 
@@ -53,6 +55,13 @@ atom_frontend_map_entries_set (AtomFrontend *frontend,
   frontend->map_entries = map_entries;
 }
 
+void
+atom_frontend_is_feed_set (AtomFrontend *frontend,
+                         int is_feed (AtomCtx *, char *))
+{
+  frontend->is_feed = is_feed;
+}
+
 void
 atom_frontend_map_entries (AtomCtx *ctx, char ** reqs,
                           AtomEntry ** entries, size_t len)
@@ -64,3 +73,20 @@ atom_frontend_map_entries (AtomCtx *ctx, char ** reqs,
       frontend->map_entries (ctx, reqs, entries, len);
     }
 }
+
+int
+atom_is_feed (AtomCtx *ctx, char *req)
+{
+  AtomFrontend *frontend;
+  AtomError *aerr;
+  frontend = atom_frontend (ctx);
+  if (frontend && frontend->is_feed)
+    {
+      return frontend->is_feed (ctx, req);
+    }
+  /* If frontend cannot decide if a request is a feed, let's tell it's
+   * not. If the request mapping cannot be done, it will return a "Not
+   * Found" error anyway.
+   */
+  return 0;
+}
index 2f35a00..33a8ff9 100644 (file)
@@ -127,12 +127,6 @@ gio_enumerate_entries (AtomCtx *ctx, char ***reqs, AtomEntry ***entries,
   g_ptr_array_free (filenames, FALSE);
 }
 
-static int
-gio_atom_is_feed (AtomCtx *ctx, AtomID *id)
-{
-  return (!strcmp (atom_id_string (id), "/"));
-}
-
 AtomBackend *
 gio_backend (void)
 {
@@ -140,6 +134,5 @@ gio_backend (void)
   backend = atom_backend_new ();
   atom_backend_retrieve_entry_set (backend, gio_atom_retrieve_entry);
   atom_backend_enumerate_entries_set (backend, gio_enumerate_entries);
-  atom_backend_is_feed_set (backend, gio_atom_is_feed);
   return backend;
 }
index d423212..d608800 100644 (file)
@@ -34,10 +34,8 @@ void atom_backend_retrieve_entry_set (AtomBackend *,
 void atom_backend_enumerate_entries_set (AtomBackend *,
                                         void (AtomCtx *, char ***,
                                               AtomEntry ***, size_t *));
-void atom_backend_is_feed_set (AtomBackend *, int (AtomCtx *, AtomID *));
 AtomEntry * atom_retrieve_entry (AtomCtx *, AtomID *);
 void atom_enumerate_entries (AtomCtx *, char ***, AtomEntry ***, size_t *);
-int atom_is_feed (AtomCtx *, AtomID *);
 AtomFeed * atom_retrieve_feed (AtomCtx *);
 AtomBackend * atom_backend (AtomCtx *);
 void atom_backend_set (AtomCtx *, AtomBackend *);
index 7e9ecc0..06ff92c 100644 (file)
@@ -29,7 +29,10 @@ void atom_frontend_delete (AtomFrontend *);
 void atom_frontend_map_entries_set (AtomFrontend *,
                                    void (AtomCtx *, char **,
                                          AtomEntry **, size_t));
+void atom_frontend_is_feed_set (AtomFrontend *,
+                               int is_feed (AtomCtx *, char *));
 void atom_map_entries (AtomCtx *, char **, AtomEntry **, size_t);
+int atom_is_feed (AtomCtx *, char *);
 AtomFrontend * atom_frontend (AtomCtx *);
 void atom_frontend_set (AtomCtx *, AtomFrontend *);