From: Thadeu Lima de Souza Cascardo Date: Mon, 13 Oct 2008 03:29:54 +0000 (-0300) Subject: Added function to serve requests from any frontend X-Git-Url: http://git.cascardo.eti.br/?p=cascardo%2Fatompub.git;a=commitdiff_plain;h=a31ac2babb967583a167889fab9b6cfdb25905de Added function to serve requests from any frontend 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. --- diff --git a/atom/Makefile.am b/atom/Makefile.am index 439d11a..5bb2ff2 100644 --- a/atom/Makefile.am +++ b/atom/Makefile.am @@ -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 index 0000000..e9199b2 --- /dev/null +++ b/atom/core.c @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2008 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 + +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); + } +} diff --git a/include/atompub/Makefile.am b/include/atompub/Makefile.am index 0a4af0a..1ac753d 100644 --- a/include/atompub/Makefile.am +++ b/include/atompub/Makefile.am @@ -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 diff --git a/include/atompub/atom.h b/include/atompub/atom.h index ee56898..15e18e9 100644 --- a/include/atompub/atom.h +++ b/include/atompub/atom.h @@ -33,5 +33,6 @@ #include #include #include +#include #endif diff --git a/include/atompub/core.h b/include/atompub/core.h new file mode 100644 index 0000000..0ca7c2a --- /dev/null +++ b/include/atompub/core.h @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2008 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. + */ + + +#ifndef ATOMPUB_CORE_H +#define ATOMPUB_CORE_H + +#include + +void atom_serve_request (AtomCtx *); + +#endif diff --git a/src/main.c b/src/main.c index 4368fb4..6491ee8 100644 --- a/src/main.c +++ b/src/main.c @@ -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; }