Introducing AtomID, which is used in core, instead of IRI
authorThadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
Sun, 31 Aug 2008 04:16:24 +0000 (01:16 -0300)
committerThadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
Sun, 31 Aug 2008 04:16:24 +0000 (01:16 -0300)
atom/Makefile.am
atom/id.c [new file with mode: 0644]
backend/files/giochannel.c
backend/gio/gio.c
frontend/cgi/cgi.c
include/atompub/Makefile.am
include/atompub/backend.h
include/atompub/id.h [new file with mode: 0644]
src/backend.c

index 471de39..2261251 100644 (file)
@@ -1,5 +1,5 @@
 lib_LTLIBRARIES = libatom.la
-libatom_la_SOURCES = entry.c person.c feed.c resource.c
+libatom_la_SOURCES = id.c entry.c person.c feed.c resource.c
 libatom_la_CFLAGS = -I$(top_srcdir)/include $(GLIB_CFLAGS)
 libatom_la_CFLAGS += $(XML_CFLAGS) $(GIO_CFLAGS)
 libatom_la_LIBADD = $(GIO_LIBS) $(GLIB_LIBS) $(XML_LIBS)
diff --git a/atom/id.c b/atom/id.c
new file mode 100644 (file)
index 0000000..8389cc7
--- /dev/null
+++ b/atom/id.c
@@ -0,0 +1,50 @@
+/*
+ *  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 <glib.h>
+
+struct _atom_id
+{
+  char *iri;
+};
+
+AtomID *
+atom_id_new (char *iri)
+{
+  AtomID *id;
+  id = g_slice_new (AtomID);
+  id->iri = g_strdup (iri);
+  return id;
+}
+
+void
+atom_id_delete (AtomID *id)
+{
+  if (id->iri)
+    g_free (id->iri);
+  g_slice_free (AtomID, id);
+}
+
+char *
+atom_id_string (AtomID *id)
+{
+  return id->iri;
+}
index 707b822..7661ae1 100644 (file)
 #include <atompub/atom-glib.h>
 
 static gchar *
-giochannel_iri_to_filename (AtomCtx *ctx, IRI *iri)
+giochannel_id_to_filename (AtomCtx *ctx, AtomID *id)
 {
   gchar *root = atom_config_get_str (ctx, "giochannel", "root");
-  gchar *path = iri_get_path (iri);
+  gchar *path = atom_id_string (id);
   gchar *filename = g_build_filename (root, path, NULL);
   g_free (root);
   return filename;
 }
 
 static AtomEntry *
-giochannel_atom_retrieve_entry (AtomCtx *ctx, IRI *iri)
+giochannel_atom_retrieve_entry (AtomCtx *ctx, AtomID *id)
 {
   gchar *filename;
   GIOChannel *channel;
@@ -40,7 +40,7 @@ giochannel_atom_retrieve_entry (AtomCtx *ctx, IRI *iri)
   gchar *data;
   gsize len;
   AtomEntry *atom;
-  filename = giochannel_iri_to_filename (ctx, iri);
+  filename = giochannel_id_to_filename (ctx, id);
   channel = g_io_channel_new_file ((const gchar *) filename, "r", &error);
   g_free (filename);
   if (channel == NULL)
index a7366bf..f430f84 100644 (file)
 #include <gio/gio.h>
 #include <atompub/atom.h>
 #include <atompub/atom-glib.h>
+#include <string.h>
 
 static GFile *
-gio_iri_to_file (AtomCtx *ctx, IRI *iri)
+gio_id_to_file (AtomCtx *ctx, AtomID *id)
 {
   gchar *root = atom_config_get_str (ctx, "gio", "root");
-  gchar *path = iri_get_path (iri);
+  gchar *path = atom_id_string (id);
   gchar *filename = g_build_filename (root, path, NULL);
   GFile *file = g_file_new_for_path (filename);
   g_free (root);
@@ -55,11 +56,11 @@ gio_file_to_atom (AtomCtx *ctx, GFile *file)
 }
 
 static AtomEntry *
-gio_atom_retrieve_entry (AtomCtx *ctx, IRI *iri)
+gio_atom_retrieve_entry (AtomCtx *ctx, AtomID *id)
 {
   GFile *file;
   AtomEntry *atom;
-  file = gio_iri_to_file (ctx, iri);
+  file = gio_id_to_file (ctx, id);
   atom = gio_file_to_atom (ctx, file);
   g_object_unref (file);
   return atom;
@@ -101,6 +102,12 @@ gio_enumerate_entries (AtomCtx *ctx, AtomEntry ***entries, size_t *len)
   g_ptr_array_free (array, FALSE);
 }
 
+static int
+gio_atom_is_feed (AtomCtx *ctx, AtomID *id)
+{
+  return (!strcmp (atom_id_string (id), "/"));
+}
+
 AtomBackend *
 gio_backend (void)
 {
@@ -108,5 +115,6 @@ 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 73adcda..f77fe06 100644 (file)
@@ -37,13 +37,12 @@ cgi_serve_request (AtomCtx *ctx)
     }
   if (!strcmp (method, "GET"))
     {
-      IRI *iri;
+      AtomID *id;
       AtomResource *atom;
       AtomError *error;
-      iri = iri_new ();
-      iri_set_path (iri, path);
-      atom = atom_retrieve_resource (ctx, iri);
-      iri_delete (iri);
+      id = atom_id_new (path);
+      atom = atom_retrieve_resource (ctx, id);
+      atom_id_delete (id);
       if (atom)
        {
          char * str;
index 3b2816b..fb38d4d 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 \
+               id.h iri.h backend.h atom-glib.h error-glib.h atom-xml.h \
                entry-xml.h person-xml.h feed-xml.h globals.h resource.h
index 728c580..087cb25 100644 (file)
@@ -30,13 +30,15 @@ typedef struct _atom_backend AtomBackend;
 AtomBackend *atom_backend_new (void);
 void atom_backend_delete (AtomBackend *);
 void atom_backend_retrieve_entry_set (AtomBackend *,
-                                     AtomEntry * (AtomCtx *, IRI *));
+                                     AtomEntry * (AtomCtx *, AtomID *));
 void atom_backend_enumerate_entries_set (AtomBackend *,
                                         void (AtomCtx *, AtomEntry ***, size_t *));
-AtomEntry * atom_retrieve_entry (AtomCtx *, IRI *);
+void atom_backend_is_feed_set (AtomBackend *, int (AtomCtx *, AtomID *));
+AtomEntry * atom_retrieve_entry (AtomCtx *, AtomID *);
 void atom_enumerate_entries (AtomCtx *, AtomEntry ***, size_t *);
+int atom_is_feed (AtomCtx *, AtomID *);
 AtomFeed * atom_retrieve_feed (AtomCtx *);
-AtomResource *atom_retrieve_resource (AtomCtx *, IRI *);
+AtomResource *atom_retrieve_resource (AtomCtx *, AtomID *);
 AtomBackend * atom_backend (AtomCtx *);
 void atom_backend_set (AtomCtx *, AtomBackend *);
 
diff --git a/include/atompub/id.h b/include/atompub/id.h
new file mode 100644 (file)
index 0000000..e1c9a62
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ *  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 ATOMPUB_ID_H
+#define ATOMPUB_ID_H
+
+#include <atompub/ctx.h>
+
+typedef struct _atom_id AtomID;
+
+AtomID * atom_id_new (char *);
+void atom_id_delete (AtomID *);
+char * atom_id_string (AtomID *);
+
+#endif
index 31c8ecd..2c96af3 100644 (file)
@@ -25,8 +25,9 @@
 
 struct _atom_backend
 {
-  AtomEntry * (*retrieve_entry) (AtomCtx *, IRI *);
+  AtomEntry * (*retrieve_entry) (AtomCtx *, AtomID *);
   void (*enumerate_entries) (AtomCtx *, AtomEntry ***, size_t *);
+  int  (*is_feed) (AtomCtx *, AtomID *);
 };
 
 AtomBackend *
@@ -48,7 +49,7 @@ atom_backend_delete (AtomBackend *backend)
 void
 atom_backend_retrieve_entry_set (AtomBackend *backend,
                                 AtomEntry *retrieve_entry (AtomCtx *,
-                                                           IRI *))
+                                                           AtomID *))
 {
   backend->retrieve_entry = retrieve_entry;
 }
@@ -61,13 +62,20 @@ 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, IRI *iri)
+atom_retrieve_entry (AtomCtx *ctx, AtomID *id)
 {
   AtomBackend *backend;
   backend = atom_backend (ctx);
   if (backend && backend->retrieve_entry)
-    return backend->retrieve_entry (ctx, iri);
+    return backend->retrieve_entry (ctx, id);
   return NULL;
 }
 
@@ -87,6 +95,18 @@ atom_backend_enumerate_entries (AtomCtx *ctx, AtomEntry *** entries, size_t *len
     *len = 0;
 }
 
+int
+atom_is_feed (AtomCtx *ctx, AtomID *id)
+{
+  AtomBackend *backend;
+  backend = atom_backend (ctx);
+  if (backend && backend->is_feed)
+    {
+      return backend->is_feed (ctx, id);
+    }
+  return 0;
+}
+
 AtomFeed *
 atom_retrieve_feed (AtomCtx *ctx)
 {
@@ -100,12 +120,10 @@ atom_retrieve_feed (AtomCtx *ctx)
 }
 
 AtomResource *
-atom_retrieve_resource (AtomCtx *ctx, IRI *iri)
+atom_retrieve_resource (AtomCtx *ctx, AtomID *id)
 {
   AtomResource *res;
-  char * path;
-  path = iri_get_path (iri);
-  if (!strcmp (path, "/"))
+  if (atom_is_feed (ctx, id))
     {
       AtomFeed *feed;
       feed = atom_retrieve_feed (ctx);
@@ -117,7 +135,7 @@ atom_retrieve_resource (AtomCtx *ctx, IRI *iri)
   else
     {
       AtomEntry *entry;
-      entry = atom_retrieve_entry (ctx, iri);
+      entry = atom_retrieve_entry (ctx, id);
       if (entry == NULL)
         return NULL;
       res = atom_resource_new_from_entry (entry);