From: Thadeu Lima de Souza Cascardo Date: Thu, 31 Jul 2008 20:54:41 +0000 (-0300) Subject: Added very basic GIO support for local files. X-Git-Url: http://git.cascardo.eti.br/?p=cascardo%2Fatompub.git;a=commitdiff_plain;h=76db3f66324dd66faae215944f1296db7cb9de59 Added very basic GIO support for local files. --- diff --git a/backend/Makefile.am b/backend/Makefile.am index 21c53b6..0f36893 100644 --- a/backend/Makefile.am +++ b/backend/Makefile.am @@ -1 +1 @@ -SUBDIRS = files +SUBDIRS = files gio diff --git a/backend/gio/Makefile.am b/backend/gio/Makefile.am new file mode 100644 index 0000000..fa5d3e8 --- /dev/null +++ b/backend/gio/Makefile.am @@ -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 index 0000000..5ac4550 --- /dev/null +++ b/backend/gio/gio.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 + +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; +} diff --git a/configure.ac b/configure.ac index a4dc0f9..04154c2 100644 --- a/configure.ac +++ b/configure.ac @@ -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 diff --git a/src/Makefile.am b/src/Makefile.am index dc6f32a..bdd5d12 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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)