Added function to serve requests from any frontend
authorThadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
Mon, 13 Oct 2008 03:29:54 +0000 (00:29 -0300)
committerThadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
Mon, 13 Oct 2008 03:44:51 +0000 (00:44 -0300)
This function serves requests from any frontend. This would be common
code among all frontends. That's why implementing in the core makes more
sense.

atom/Makefile.am
atom/core.c [new file with mode: 0644]
include/atompub/Makefile.am
include/atompub/atom.h
include/atompub/core.h [new file with mode: 0644]
src/main.c

index 439d11a..5bb2ff2 100644 (file)
@@ -1,6 +1,7 @@
 lib_LTLIBRARIES = libatom.la
 libatom_la_SOURCES = id.c entry.c person.c feed.c \
-               config.c ctx.c backend.c error.c frontend.c request.c
+               config.c ctx.c backend.c error.c frontend.c request.c \
+               core.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/core.c b/atom/core.c
new file mode 100644 (file)
index 0000000..e9199b2
--- /dev/null
@@ -0,0 +1,76 @@
+/*
+ *  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>
+
+#include <string.h>
+
+static
+void atom_get (AtomCtx *ctx, AtomRequest *request)
+{
+  if (atom_is_feed (ctx, atom_request_request (request)))
+    {
+      AtomFeed *feed;
+      feed = atom_retrieve_feed (ctx);
+      if (feed != NULL)
+        {
+          atom_handle_feed (ctx, feed);
+          atom_feed_delete (feed);
+        }
+    }
+  else
+     {
+       AtomEntry *entry;
+       entry = atom_retrieve_entry (ctx, atom_request_request (request));
+       if (entry != NULL)
+         {
+           atom_handle_entry (ctx, entry);
+           atom_entry_delete (entry);
+         }
+     }
+}
+
+void
+atom_serve_request (AtomCtx *ctx)
+{
+  AtomRequest *request;
+  AtomError *error;
+  request = atom_get_request (ctx);
+  if (request != NULL)
+    {
+      if (atom_request_type (request) == ATOM_REQUEST_GET)
+        {
+          atom_get (ctx, request);
+        }
+      else
+        {
+          error = atom_error_new ();
+          atom_error_code_set (error, 501);
+          atom_error_message_set (error, "Not Implemented");
+          atom_error_set (ctx, error);
+        }
+    }
+  if (atom_error_get (ctx))
+    {
+      atom_handle_error (ctx);
+      atom_error_set (ctx, NULL);
+    }
+}
index 0a4af0a..1ac753d 100644 (file)
@@ -1,4 +1,4 @@
 pkginclude_HEADERS = atom.h config.h ctx.h entry.h person.h error.h feed.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 \
-               map.h frontend.h request.h
+               map.h frontend.h request.h core.h
index ee56898..15e18e9 100644 (file)
@@ -33,5 +33,6 @@
 #include <atompub/map.h>
 #include <atompub/frontend.h>
 #include <atompub/request.h>
+#include <atompub/core.h>
 
 #endif
diff --git a/include/atompub/core.h b/include/atompub/core.h
new file mode 100644 (file)
index 0000000..0ca7c2a
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ *  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_CORE_H
+#define ATOMPUB_CORE_H
+
+#include <atompub/ctx.h>
+
+void atom_serve_request (AtomCtx *);
+
+#endif
index 4368fb4..6491ee8 100644 (file)
@@ -44,7 +44,7 @@ main (int argc, char **argv)
       exit (1);
     }
   atom_backend_enumerate_entries (ctx, NULL, NULL, NULL);
-  cgi_serve_request (ctx);
+  atom_serve_request (ctx);
   atom_ctx_delete (ctx);
   return 0;
 }