+Thadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
-SUBDIRS = src
+SUBDIRS = include config backend frontend atom iri src
lib_LTLIBRARIES = libatom.la
-libatom_la_SOURCES = atom.c
-libatom_la_CFLAGS = $(XML_CFLAGS)
-libatom_la_LIBADD = $(XML_LIBS)
+libatom_la_SOURCES = entry.c
+libatom_la_CFLAGS = -I$(top_srcdir)/include $(GLIB_CFLAGS)
+libatom_la_CFLAGS += $(XML_CFLAGS)
+libatom_la_LIBADD = $(GLIB_LIBS) $(XML_LIBS)
--- /dev/null
+[giochannel]
+root=/var/www/atom/
+[gio]
+root=/var/www/atom/
--- /dev/null
+SUBDIRS = files gio
--- /dev/null
+noinst_LTLIBRARIES = libgiochannel.la
+libgiochannel_la_SOURCES = giochannel.c
+libgiochannel_la_CFLAGS = -I$(top_srcdir)/include $(GLIB_CFLAGS)
--- /dev/null
+/*
+ * 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 <glib.h>
+#include <atompub/atom.h>
+#include <atompub/atom-glib.h>
+
+static gchar *
+giochannel_iri_to_filename (AtomCtx *ctx, IRI *iri)
+{
+ gchar *root = atom_config_get_str (ctx, "giochannel", "root");
+ gchar *path = iri_get_path (iri);
+ gchar *filename = g_build_filename (root, path, NULL);
+ g_free (root);
+ return filename;
+}
+
+static Atom *
+giochannel_atom_retrieve_resource (AtomCtx *ctx, IRI *iri)
+{
+ gchar *filename;
+ GIOChannel *channel;
+ GError *error = NULL;
+ gchar *data;
+ gsize len;
+ Atom *atom;
+ filename = giochannel_iri_to_filename (ctx, iri);
+ channel = g_io_channel_new_file ((const gchar *) filename, "r", &error);
+ g_free (filename);
+ if (channel == NULL)
+ {
+ AtomError *aerr = atom_error_new_from_gerror (error);
+ atom_error_set (ctx, aerr);
+ g_error_free (error);
+ return NULL;
+ }
+ error = NULL;
+ if (g_io_channel_read_to_end (channel, &data, &len, &error) !=
+ G_IO_STATUS_NORMAL)
+ {
+ AtomError *aerr = atom_error_new_from_gerror (error);
+ g_io_channel_unref (channel);
+ atom_error_set (ctx, aerr);
+ g_error_free (error);
+ return NULL;
+ }
+ g_io_channel_unref (channel);
+ atom = atom_new_data_len (data, len);
+ g_free (data);
+ return atom;
+}
+
+AtomBackend *
+giochannel_backend (void)
+{
+ AtomBackend *backend;
+ backend = atom_backend_new ();
+ atom_backend_retrieve_resource_set (backend,
+ giochannel_atom_retrieve_resource);
+ return backend;
+}
--- /dev/null
+noinst_LTLIBRARIES = libgio.la
+libgio_la_SOURCES = gio.c
+libgio_la_CFLAGS = -I$(top_srcdir)/include $(GLIB_CFLAGS) $(GIO_CFLAGS)
--- /dev/null
+/*
+ * 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 <glib.h>
+#include <gio/gio.h>
+#include <atompub/atom.h>
+#include <atompub/atom-glib.h>
+
+static GFile *
+gio_iri_to_file (AtomCtx *ctx, IRI *iri)
+{
+ gchar *root = atom_config_get_str (ctx, "gio", "root");
+ gchar *path = iri_get_path (iri);
+ gchar *filename = g_build_filename (root, path, NULL);
+ GFile *file = g_file_new_for_path (filename);
+ g_free (root);
+ g_free (filename);
+ return file;
+}
+
+static Atom *
+gio_atom_retrieve_resource (AtomCtx *ctx, IRI *iri)
+{
+ GFile *file;
+ GError *error = NULL;
+ gchar *data;
+ gsize len;
+ Atom *atom;
+ file = gio_iri_to_file (ctx, iri);
+ error = NULL;
+ if (!g_file_load_contents (file, NULL, &data, &len, NULL, &error))
+ {
+ AtomError *aerr = atom_error_new_from_gerror (error);
+ g_object_unref (file);
+ atom_error_set (ctx, aerr);
+ g_error_free (error);
+ return NULL;
+ }
+ g_object_unref (file);
+ atom = atom_new_data_len (data, len);
+ g_free (data);
+ return atom;
+}
+
+AtomBackend *
+gio_backend (void)
+{
+ AtomBackend *backend;
+ backend = atom_backend_new ();
+ atom_backend_retrieve_resource_set (backend, gio_atom_retrieve_resource);
+ return backend;
+}
--- /dev/null
+noinst_LTLIBRARIES = libgkeyfile.la
+libgkeyfile_la_SOURCES = gkeyfile.c
+libgkeyfile_la_CFLAGS = -I$(top_srcdir)/include $(GLIB_CFLAGS)
--- /dev/null
+/*
+ * 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 <glib.h>
+
+gchar *
+gkeyfile_atom_config_get_str (AtomCtx *ctx, gchar *group, gchar * key)
+{
+ GKeyFile *keyfile;
+ gchar *value;
+ GError *error = NULL;
+ keyfile = atom_config_data (ctx);
+ value = g_key_file_get_string (keyfile, group, key, &error);
+ if (value == NULL)
+ {
+ AtomError *aerr = atom_error_new ();
+ atom_error_code_set (aerr, 500);
+ atom_error_message_set (aerr, error->message);
+ atom_error_set (ctx, aerr);
+ g_error_free (error);
+ }
+ return value;
+}
+
+void
+gkeyfile_atom_config_init (AtomCtx *ctx)
+{
+ GKeyFile *keyfile;
+ GError *error = NULL;
+ keyfile = g_key_file_new ();
+ if (!g_key_file_load_from_file (keyfile, "atompub.conf",
+ G_KEY_FILE_NONE, &error))
+ {
+ AtomError *aerr = atom_error_new ();
+ atom_error_code_set (aerr, 500);
+ atom_error_message_set (aerr, error->message);
+ atom_error_set (ctx, aerr);
+ g_error_free (error);
+ return;
+ }
+ atom_config_data_set (ctx, keyfile);
+}
-AC_INIT(libatom, 0.1, cascardo@holoscopio.com)
+AC_INIT(atompub, 0.1, cascardo@holoscopio.com)
AM_INIT_AUTOMAKE
AC_PROG_INSTALL
AC_PROG_CC
AM_PROG_CC_C_O
AC_PROG_LIBTOOL
PKG_CHECK_MODULES(XML, libxml-2.0, , AC_MSG_ERROR(Could not find libxml2))
+AM_PATH_GLIB_2_0(2.14.0, , AC_MSG_ERROR(Could not find GLib))
+PKG_CHECK_MODULES(GIO, gio-2.0, , AC_MSG_ERROR(Could not find GIO))
AC_OUTPUT(Makefile
- src/Makefile)
+ src/Makefile
+ include/Makefile
+ include/atompub/Makefile
+ config/Makefile
+ backend/Makefile
+ backend/files/Makefile
+ backend/gio/Makefile
+ frontend/Makefile
+ frontend/cgi/Makefile
+ atom/Makefile
+ iri/Makefile)
--- /dev/null
+SUBDIRS = cgi
--- /dev/null
+noinst_LTLIBRARIES = libcgi.la
+libcgi_la_SOURCES = cgi.c
+libcgi_la_CFLAGS = -I$(top_srcdir)/include $(GLIB_CFLAGS)
--- /dev/null
+/*
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.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;
+ AtomError *error;
+ iri_set_path (iri, path);
+ atom = atom_retrieve_resource (ctx, iri);
+ iri_delete (iri);
+ if (atom)
+ {
+ char *header = "Content-type: application/atom+xml\n\n";
+ write (1, header, strlen (header));
+ write (1, atom_string (atom), atom_len (atom));
+ atom_delete (atom);
+ }
+ else if ((error = atom_error_get (ctx)) != NULL)
+ {
+ int code = atom_error_code (error);
+ char *message = atom_error_message (error);
+ fprintf (stdout, "Status: %d %s\n\n%s\n", code, message, message);
+ }
+ else
+ {
+ fprintf (stdout, "Status: 500 Server error\n\nServer error\n");
+ }
+ }
+ else
+ {
+ fprintf (stdout, "Status: 501 Not Implemented\n\n");
+ }
+}
--- /dev/null
+SUBDIRS = atompub
--- /dev/null
+include_HEADERS = atom.h config.h ctx.h entry.h error.h feed.h \
+ iri.h backend.h atom-glib.h error-glib.h
--- /dev/null
+/*
+ * 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_ATOM_GLIB_H
+#define ATOMPUB_ATOM_GLIB_H
+
+#include <atompub/error-glib.h>
+
+#endif
--- /dev/null
+/*
+ * 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.
+ */
+
+
+#ifndef ATOMPUB_ATOM_H
+#define ATOMPUB_ATOM_H
+
+#include <atompub/ctx.h>
+#include <atompub/config.h>
+#include <atompub/error.h>
+#include <atompub/iri.h>
+#include <atompub/entry.h>
+#include <atompub/feed.h>
+#include <atompub/backend.h>
+
+#endif
--- /dev/null
+/*
+ * 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.
+ */
+
+
+#ifndef ATOMPUB_BACKEND_H
+#define ATOMPUB_BACKEND_H
+
+#include <atompub/ctx.h>
+#include <atompub/entry.h>
+#include <atompub/iri.h>
+
+typedef struct _atom_backend AtomBackend;
+
+AtomBackend *atom_backend_new (void);
+void atom_backend_delete (AtomBackend *);
+void atom_backend_retrieve_resource_set (AtomBackend *,
+ Atom * (AtomCtx *, IRI *));
+Atom * atom_retrieve_resource (AtomCtx *, IRI *);
+AtomBackend * atom_backend (AtomCtx *);
+void atom_backend_set (AtomCtx *, AtomBackend *);
+
+#endif
--- /dev/null
+/*
+ * 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.
+ */
+
+
+#ifndef ATOMPUB_CONFIG_H
+#define ATOMPUB_CONFIG_H
+
+#include <atompub/ctx.h>
+
+void atom_config_init (AtomCtx *);
+char *atom_config_get_str (AtomCtx *, char *, char *);
+
+#endif
--- /dev/null
+/*
+ * 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.
+ */
+
+
+#ifndef ATOMPUB_CTX_H
+#define ATOMPUB_CTX_H
+
+typedef struct _atom_ctx AtomCtx;
+
+AtomCtx * atom_ctx_new (void);
+void atom_ctx_delete (AtomCtx *);
+void * atom_config_data (AtomCtx *);
+void atom_config_data_set (AtomCtx *, void *);
+
+#endif
--- /dev/null
+/*
+ * 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.
+ */
+
+
+#ifndef ATOMPUB_ENTRY_H
+#define ATOMPUB_ENTRY_H
+
+#include <sys/types.h>
+
+typedef struct _atom_entry Atom;
+
+Atom * atom_new_data_len (char *, size_t);
+void atom_delete (Atom *);
+char * atom_string (Atom *);
+size_t atom_len (Atom *);
+
+#endif
--- /dev/null
+/*
+ * 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_ERROR_GLIB_H
+#define ATOMPUB_ERROR_GLIB_H
+
+#include <atompub/error.h>
+#include <glib.h>
+
+AtomError * atom_error_new_from_gerror (GError *);
+
+#endif
--- /dev/null
+/*
+ * 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.
+ */
+
+
+#ifndef ATOMPUB_ERROR_H
+#define ATOMPUB_ERROR_H
+
+#include <atompub/ctx.h>
+
+typedef struct _atom_error AtomError;
+
+AtomError * atom_error_get (AtomCtx *);
+void atom_error_set (AtomCtx *, AtomError *);
+AtomError * atom_error_new (void);
+void atom_error_delete (AtomError *);
+int atom_error_code (AtomError *);
+void atom_error_code_set (AtomError *, int);
+char * atom_error_message (AtomError *);
+void atom_error_message_set (AtomError *, char *);
+
+#endif
--- /dev/null
+/*
+ * 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.
+ */
+
+
+#ifndef ATOMPUB_FEED_H
+#define ATOMPUB_FEED_H
+
+#include <atompub/ctx.h>
+
+typedef struct _atom_feed AtomFeed;
+
+#endif
--- /dev/null
+/*
+ * 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.
+ */
+
+
+#ifndef ATOMPUB_IRI_H
+#define ATOMPUB_IRI_H
+
+#include <atompub/ctx.h>
+
+typedef struct _iri IRI;
+
+IRI * iri_new (void);
+void iri_delete (IRI *);
+char * iri_get_path (IRI *);
+void iri_set_path (IRI *, char *);
+
+#endif
--- /dev/null
+noinst_LTLIBRARIES = libiri.la
+libiri_la_SOURCES = iri.c
+libiri_la_CFLAGS = -I$(top_srcdir)/include $(GLIB_CFLAGS)
--- /dev/null
+/*
+ * 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 <glib.h>
+
+struct _iri
+{
+ char *scheme;
+ char *host;
+ char *path;
+};
+
+IRI *
+iri_new ()
+{
+ IRI *iri;
+ iri = g_slice_new (IRI);
+ iri->scheme = NULL;
+ iri->host = NULL;
+ iri->path = NULL;
+ return iri;
+}
+
+void
+iri_delete (IRI *iri)
+{
+ if (iri->scheme)
+ g_free (iri->scheme);
+ if (iri->host)
+ g_free (iri->host);
+ if (iri->path)
+ g_free (iri->path);
+ g_slice_free (IRI, iri);
+}
+
+char *
+iri_get_path (IRI *iri)
+{
+ return iri->path;
+}
+
+void
+iri_set_path (IRI *iri, char *path)
+{
+ if (iri->path)
+ g_free (iri->path);
+ iri->path = g_strdup (path);
+}
--- /dev/null
+bin_PROGRAMS = atompub
+atompub_SOURCES = main.c config.c ctx.c backend.c error.c
+atompub_CFLAGS = -I$(top_srcdir)/include
+atompub_CFLAGS += $(GLIB_CFLAGS)
+atompub_LDADD = -L$(top_builddir)/backend/files -lgiochannel
+atompub_LDADD += -L$(top_builddir)/backend/gio -lgio
+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
+atompub_LDADD += $(GLIB_LIBS) $(GIO_LIBS)
--- /dev/null
+/*
+ * 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 <glib.h>
+
+struct _atom_backend
+{
+ Atom * (*retrieve_resource) (AtomCtx *, IRI *);
+};
+
+AtomBackend *
+atom_backend_new ()
+{
+ AtomBackend *backend;
+ backend = g_slice_new (AtomBackend);
+ backend->retrieve_resource = NULL;
+ return backend;
+}
+
+void
+atom_backend_delete (AtomBackend *backend)
+{
+ g_slice_free (AtomBackend, backend);
+}
+
+void
+atom_backend_retrieve_resource_set (AtomBackend *backend,
+ Atom *retrieve_resource (AtomCtx *,
+ IRI *))
+{
+ backend->retrieve_resource = retrieve_resource;
+}
+
+Atom *
+atom_retrieve_resource (AtomCtx *ctx, IRI *iri)
+{
+ AtomBackend *backend;
+ backend = atom_backend (ctx);
+ if (backend && backend->retrieve_resource)
+ return backend->retrieve_resource (ctx, iri);
+ return NULL;
+}
--- /dev/null
+/*
+ * 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>
+
+extern void gkeyfile_atom_config_init (AtomCtx *);
+extern char *gkeyfile_atom_config_get_str (AtomCtx *, char *, char *);
+
+void
+atom_config_init (AtomCtx *ctx)
+{
+ gkeyfile_atom_config_init (ctx);
+}
+
+char *
+atom_config_get_str (AtomCtx *ctx, char *namespace, char *key)
+{
+ return gkeyfile_atom_config_get_str (ctx, namespace, key);
+}
--- /dev/null
+/*
+ * 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 <glib.h>
+
+struct _atom_ctx
+{
+ AtomError *error;
+ gpointer config_data;
+ AtomBackend *backend;
+};
+
+AtomCtx *
+atom_ctx_new ()
+{
+ AtomCtx *ctx;
+ ctx = g_slice_new (AtomCtx);
+ ctx->error = NULL;
+ ctx->config_data = NULL;
+ ctx->backend = NULL;
+ return ctx;
+}
+
+void
+atom_ctx_delete (AtomCtx *ctx)
+{
+ if (ctx->error)
+ atom_error_delete (ctx->error);
+ if (ctx->backend)
+ atom_backend_delete (ctx->backend);
+ g_slice_free (AtomCtx, ctx);
+}
+
+void
+atom_error_set (AtomCtx *ctx, AtomError *error)
+{
+ if (ctx->error)
+ atom_error_delete (ctx->error);
+ ctx->error = error;
+}
+
+AtomError *
+atom_error_get (AtomCtx *ctx)
+{
+ return ctx->error;
+}
+
+void *
+atom_config_data (AtomCtx *ctx)
+{
+ return ctx->config_data;
+}
+
+void
+atom_config_data_set (AtomCtx *ctx, void *data)
+{
+ ctx->config_data = data;
+}
+
+AtomBackend *
+atom_backend (AtomCtx *ctx)
+{
+ return ctx->backend;
+}
+
+void
+atom_backend_set (AtomCtx *ctx, AtomBackend *backend)
+{
+ ctx->backend = backend;
+}
--- /dev/null
+/*
+ * 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_error
+{
+ int code;
+ char * message;
+};
+
+AtomError *
+atom_error_new ()
+{
+ AtomError *error;
+ error = g_slice_new (AtomError);
+ error->code = 0;
+ error->message = NULL;
+ return error;
+}
+
+void
+atom_error_delete (AtomError *error)
+{
+ if (error->message)
+ g_free (error->message);
+ g_slice_free (AtomError, error);
+}
+
+int
+atom_error_code (AtomError *error)
+{
+ return error->code;
+}
+
+void
+atom_error_code_set (AtomError *error, int code)
+{
+ error->code = code;
+}
+
+char *
+atom_error_message (AtomError *error)
+{
+ return error->message;
+}
+
+void
+atom_error_message_set (AtomError *error, char *message)
+{
+ error->message = g_strdup (message);
+}
+
+AtomError *
+atom_error_new_from_gerror (GError *error)
+{
+ AtomError *aerr;
+ aerr = atom_error_new ();
+ if (error->domain == G_FILE_ERROR)
+ {
+ switch (error->code)
+ {
+ case G_FILE_ERROR_EXIST:
+ case G_FILE_ERROR_ACCES:
+ case G_FILE_ERROR_PERM:
+ aerr->code = 403;
+ break;
+ case G_FILE_ERROR_NOENT:
+ aerr->code = 404;
+ break;
+ default:
+ aerr->code = 500;
+ break;
+ }
+ }
+ else
+ {
+ aerr->code = 500;
+ }
+ aerr->message = error->message;
+ return aerr;
+}
--- /dev/null
+/*
+ * 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 <glib-object.h>
+
+#include <atompub/atom.h>
+
+#include <stdlib.h>
+
+extern void cgi_serve_request (AtomCtx *ctx);
+extern AtomBackend * giochannel_backend (void);
+
+int
+main (int argc, char **argv)
+{
+ AtomCtx *ctx;
+ IRI *iri;
+ Atom *atom;
+ AtomError *error;
+ g_type_init ();
+ ctx = atom_ctx_new ();
+ atom_config_init (ctx);
+ atom_backend_set (ctx, giochannel_backend ());
+ if ((error = atom_error_get (ctx)) != NULL)
+ {
+ g_message ("%s\n", atom_error_message (error));
+ exit (1);
+ }
+ cgi_serve_request (ctx);
+ atom_ctx_delete (ctx);
+ return 0;
+}