Added initial CGI frontend.
authorThadeu Lima de Souza Cascardo <cascardo@minaslivre.org>
Sun, 27 Jan 2008 03:39:19 +0000 (01:39 -0200)
committerThadeu Lima de Souza Cascardo <cascardo@minaslivre.org>
Sun, 27 Jan 2008 03:39:19 +0000 (01:39 -0200)
Makefile.am
configure.ac
frontend/Makefile.am [new file with mode: 0644]
frontend/cgi/Makefile.am [new file with mode: 0644]
frontend/cgi/cgi.c [new file with mode: 0644]
src/Makefile.am

index 9f33783..c613e3d 100644 (file)
@@ -1 +1 @@
-SUBDIRS = include config backend atom iri src
+SUBDIRS = include config backend frontend atom iri src
index 607525c..a4dc0f9 100644 (file)
@@ -12,5 +12,7 @@ AC_OUTPUT(Makefile
        config/Makefile
        backend/Makefile
        backend/files/Makefile
+       frontend/Makefile
+       frontend/cgi/Makefile
        atom/Makefile
        iri/Makefile)
diff --git a/frontend/Makefile.am b/frontend/Makefile.am
new file mode 100644 (file)
index 0000000..334c496
--- /dev/null
@@ -0,0 +1 @@
+SUBDIRS = cgi
diff --git a/frontend/cgi/Makefile.am b/frontend/cgi/Makefile.am
new file mode 100644 (file)
index 0000000..4e8f5a3
--- /dev/null
@@ -0,0 +1,3 @@
+noinst_LTLIBRARIES = libcgi.la
+libcgi_la_SOURCES = cgi.c
+libcgi_la_CFLAGS = -I$(top_srcdir)/include $(GLIB_CFLAGS)
diff --git a/frontend/cgi/cgi.c b/frontend/cgi/cgi.c
new file mode 100644 (file)
index 0000000..84481b9
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ *  Copyright (C) 2007  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 <stdlib.h>
+#include <string.h>
+
+void
+cgi_serve_request (AtomCtx *ctx)
+{
+  char *method = getenv ("REQUEST_METHOD");
+  char *path = getenv ("PATH_INFO");
+  if (method == NULL)
+    return;
+  if (path == NULL)
+    {
+      path = atom_config_get_str (ctx, "cgi", "index");
+    }
+  if (!strcmp (method, "GET"))
+    {
+      IRI *iri = iri_new ();
+      Atom *atom;
+      iri_set_path (iri, path);
+      atom = atom_retrieve_resource (ctx, iri);
+      iri_delete (iri);
+      if (atom)
+       {
+         fprintf (stdout, "Content-Type: application/atom+xml\n\n");
+         write (stdout, atom_string (atom), atom_len (atom));
+         atom_delete (atom);
+       }
+    }
+  else
+    {
+      fprintf (stdout, "Status: 501 Not Implemented\n\n");
+    }
+}
index 781a530..c57620b 100644 (file)
@@ -3,6 +3,7 @@ atompub_SOURCES = main.c config.c ctx.c backend.c
 atompub_CFLAGS = -I$(top_srcdir)/include
 atompub_CFLAGS += $(GLIB_CFLAGS)
 atompub_LDADD = -L$(top_builddir)/backend/files -lgiochannel
+atompub_LDADD = -L$(top_builddir)/frontend/cgi -lcgi
 atompub_LDADD += -L$(top_builddir)/config -lgkeyfile
 atompub_LDADD += -L$(top_builddir)/atom -latom
 atompub_LDADD += -L$(top_builddir)/iri -liri