Added very basic GIO support for local files.
authorThadeu Lima de Souza Cascardo <cascardo@minaslivre.org>
Thu, 31 Jul 2008 20:54:41 +0000 (17:54 -0300)
committerThadeu Lima de Souza Cascardo <cascardo@minaslivre.org>
Thu, 31 Jul 2008 20:54:41 +0000 (17:54 -0300)
backend/Makefile.am
backend/gio/Makefile.am [new file with mode: 0644]
backend/gio/gio.c [new file with mode: 0644]
configure.ac
src/Makefile.am

index 21c53b6..0f36893 100644 (file)
@@ -1 +1 @@
-SUBDIRS = files
+SUBDIRS = files gio
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..5ac4550
--- /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 <glib.h>
+#include <gio/gio.h>
+#include <atompub/atom.h>
+
+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;
+}
+
+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))
+    {
+      g_object_unref (file);
+      atom_error_set (ctx, error);
+      return NULL;
+    }
+  g_object_unref (channel);
+  atom = atom_new_data_len (data, len);
+  g_free (data);
+  return atom;
+}
index a4dc0f9..04154c2 100644 (file)
@@ -5,6 +5,7 @@ AC_PROG_CC
 AM_PROG_CC_C_O
 AC_PROG_LIBTOOL
 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
        include/Makefile
index dc6f32a..bdd5d12 100644 (file)
@@ -7,4 +7,4 @@ 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)
+atompub_LDADD += $(GLIB_LIBS) $(GIO_LIBS)