Merge branch 'master' into entry
authorThadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
Sat, 9 Aug 2008 07:59:01 +0000 (04:59 -0300)
committerThadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
Sat, 9 Aug 2008 07:59:01 +0000 (04:59 -0300)
Conflicts:

Makefile.am
atom/Makefile.am
atom/entry.c
configure.ac

Get atom entry implementation from libatom. Some changes needed in
headers and usage of it.

35 files changed:
AUTHORS
Makefile.am
atom/Makefile.am
atompub.conf [new file with mode: 0644]
backend/Makefile.am [new file with mode: 0644]
backend/files/Makefile.am [new file with mode: 0644]
backend/files/giochannel.c [new file with mode: 0644]
backend/gio/Makefile.am [new file with mode: 0644]
backend/gio/gio.c [new file with mode: 0644]
config/Makefile.am [new file with mode: 0644]
config/gkeyfile.c [new file with mode: 0644]
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]
include/Makefile.am [new file with mode: 0644]
include/atompub/Makefile.am [new file with mode: 0644]
include/atompub/atom-glib.h [new file with mode: 0644]
include/atompub/atom.h [new file with mode: 0644]
include/atompub/backend.h [new file with mode: 0644]
include/atompub/config.h [new file with mode: 0644]
include/atompub/ctx.h [new file with mode: 0644]
include/atompub/entry.h [new file with mode: 0644]
include/atompub/error-glib.h [new file with mode: 0644]
include/atompub/error.h [new file with mode: 0644]
include/atompub/feed.h [new file with mode: 0644]
include/atompub/iri.h [new file with mode: 0644]
iri/Makefile.am [new file with mode: 0644]
iri/iri.c [new file with mode: 0644]
src/Makefile.am [new file with mode: 0644]
src/backend.c [new file with mode: 0644]
src/config.c [new file with mode: 0644]
src/ctx.c [new file with mode: 0644]
src/error.c [new file with mode: 0644]
src/main.c [new file with mode: 0644]

diff --git a/AUTHORS b/AUTHORS
index e69de29..66739c0 100644 (file)
--- a/AUTHORS
+++ b/AUTHORS
@@ -0,0 +1 @@
+Thadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
index af437a6..c613e3d 100644 (file)
@@ -1 +1 @@
-SUBDIRS = src
+SUBDIRS = include config backend frontend atom iri src
index 6822b1e..8b2f66b 100644 (file)
@@ -1,4 +1,5 @@
 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)
diff --git a/atompub.conf b/atompub.conf
new file mode 100644 (file)
index 0000000..d6b3af5
--- /dev/null
@@ -0,0 +1,4 @@
+[giochannel]
+root=/var/www/atom/
+[gio]
+root=/var/www/atom/
diff --git a/backend/Makefile.am b/backend/Makefile.am
new file mode 100644 (file)
index 0000000..0f36893
--- /dev/null
@@ -0,0 +1 @@
+SUBDIRS = files gio
diff --git a/backend/files/Makefile.am b/backend/files/Makefile.am
new file mode 100644 (file)
index 0000000..f890b09
--- /dev/null
@@ -0,0 +1,3 @@
+noinst_LTLIBRARIES = libgiochannel.la
+libgiochannel_la_SOURCES = giochannel.c
+libgiochannel_la_CFLAGS = -I$(top_srcdir)/include $(GLIB_CFLAGS)
diff --git a/backend/files/giochannel.c b/backend/files/giochannel.c
new file mode 100644 (file)
index 0000000..dde0c56
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+ *  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;
+}
diff --git a/backend/gio/Makefile.am b/backend/gio/Makefile.am
new file mode 100644 (file)
index 0000000..fa5d3e8
--- /dev/null
@@ -0,0 +1,3 @@
+noinst_LTLIBRARIES = libgio.la
+libgio_la_SOURCES = gio.c
+libgio_la_CFLAGS = -I$(top_srcdir)/include $(GLIB_CFLAGS) $(GIO_CFLAGS)
diff --git a/backend/gio/gio.c b/backend/gio/gio.c
new file mode 100644 (file)
index 0000000..b930e10
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+ *  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;
+}
diff --git a/config/Makefile.am b/config/Makefile.am
new file mode 100644 (file)
index 0000000..f778d19
--- /dev/null
@@ -0,0 +1,3 @@
+noinst_LTLIBRARIES = libgkeyfile.la
+libgkeyfile_la_SOURCES = gkeyfile.c
+libgkeyfile_la_CFLAGS = -I$(top_srcdir)/include $(GLIB_CFLAGS)
diff --git a/config/gkeyfile.c b/config/gkeyfile.c
new file mode 100644 (file)
index 0000000..891f4b5
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ *  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);
+}
index 988b9a9..d2ad06d 100644 (file)
@@ -1,9 +1,21 @@
-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)
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..f61ea67
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+ *  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");
+    }
+}
diff --git a/include/Makefile.am b/include/Makefile.am
new file mode 100644 (file)
index 0000000..cf7748e
--- /dev/null
@@ -0,0 +1 @@
+SUBDIRS = atompub
diff --git a/include/atompub/Makefile.am b/include/atompub/Makefile.am
new file mode 100644 (file)
index 0000000..6926c5d
--- /dev/null
@@ -0,0 +1,2 @@
+include_HEADERS = atom.h config.h ctx.h entry.h error.h feed.h \
+               iri.h backend.h atom-glib.h error-glib.h
diff --git a/include/atompub/atom-glib.h b/include/atompub/atom-glib.h
new file mode 100644 (file)
index 0000000..107aeaa
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ *  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
diff --git a/include/atompub/atom.h b/include/atompub/atom.h
new file mode 100644 (file)
index 0000000..9f524dd
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ *  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
diff --git a/include/atompub/backend.h b/include/atompub/backend.h
new file mode 100644 (file)
index 0000000..5099ccd
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ *  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
diff --git a/include/atompub/config.h b/include/atompub/config.h
new file mode 100644 (file)
index 0000000..d5f3fad
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ *  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
diff --git a/include/atompub/ctx.h b/include/atompub/ctx.h
new file mode 100644 (file)
index 0000000..35ecca6
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ *  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
diff --git a/include/atompub/entry.h b/include/atompub/entry.h
new file mode 100644 (file)
index 0000000..dd2cf05
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ *  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
diff --git a/include/atompub/error-glib.h b/include/atompub/error-glib.h
new file mode 100644 (file)
index 0000000..68d748a
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ *  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
diff --git a/include/atompub/error.h b/include/atompub/error.h
new file mode 100644 (file)
index 0000000..9d7cae5
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ *  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
diff --git a/include/atompub/feed.h b/include/atompub/feed.h
new file mode 100644 (file)
index 0000000..1a92f0f
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ *  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
diff --git a/include/atompub/iri.h b/include/atompub/iri.h
new file mode 100644 (file)
index 0000000..0135916
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ *  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
diff --git a/iri/Makefile.am b/iri/Makefile.am
new file mode 100644 (file)
index 0000000..bedcb44
--- /dev/null
@@ -0,0 +1,3 @@
+noinst_LTLIBRARIES = libiri.la
+libiri_la_SOURCES = iri.c
+libiri_la_CFLAGS = -I$(top_srcdir)/include $(GLIB_CFLAGS)
diff --git a/iri/iri.c b/iri/iri.c
new file mode 100644 (file)
index 0000000..47b79ac
--- /dev/null
+++ b/iri/iri.c
@@ -0,0 +1,66 @@
+/*
+ *  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);
+}
diff --git a/src/Makefile.am b/src/Makefile.am
new file mode 100644 (file)
index 0000000..069bffa
--- /dev/null
@@ -0,0 +1,11 @@
+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)
diff --git a/src/backend.c b/src/backend.c
new file mode 100644 (file)
index 0000000..f8bcf35
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ *  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;
+}
diff --git a/src/config.c b/src/config.c
new file mode 100644 (file)
index 0000000..833ae18
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ *  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);
+}
diff --git a/src/ctx.c b/src/ctx.c
new file mode 100644 (file)
index 0000000..e9d940b
--- /dev/null
+++ b/src/ctx.c
@@ -0,0 +1,88 @@
+/*
+ *  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;
+}
diff --git a/src/error.c b/src/error.c
new file mode 100644 (file)
index 0000000..d272cb2
--- /dev/null
@@ -0,0 +1,100 @@
+/*
+ *  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;
+}
diff --git a/src/main.c b/src/main.c
new file mode 100644 (file)
index 0000000..4c10bd1
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ *  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;
+}