From: Thadeu Lima de Souza Cascardo Date: Sun, 27 Jan 2008 03:39:19 +0000 (-0200) Subject: Added initial CGI frontend. X-Git-Url: http://git.cascardo.eti.br/?p=cascardo%2Fatompub.git;a=commitdiff_plain;h=f5f94660160dbd2046b9d1f48a8fc2808aa5bd22 Added initial CGI frontend. --- diff --git a/Makefile.am b/Makefile.am index 9f33783..c613e3d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1 +1 @@ -SUBDIRS = include config backend atom iri src +SUBDIRS = include config backend frontend atom iri src diff --git a/configure.ac b/configure.ac index 607525c..a4dc0f9 100644 --- a/configure.ac +++ b/configure.ac @@ -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 index 0000000..334c496 --- /dev/null +++ b/frontend/Makefile.am @@ -0,0 +1 @@ +SUBDIRS = cgi diff --git a/frontend/cgi/Makefile.am b/frontend/cgi/Makefile.am new file mode 100644 index 0000000..4e8f5a3 --- /dev/null +++ b/frontend/cgi/Makefile.am @@ -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 index 0000000..84481b9 --- /dev/null +++ b/frontend/cgi/cgi.c @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2007 Thadeu Lima de Souza Cascardo + * + * 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 + +#include +#include + +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"); + } +} diff --git a/src/Makefile.am b/src/Makefile.am index 781a530..c57620b 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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