lib_LTLIBRARIES = libatom.la
-libatom_la_SOURCES = entry.c person.c feed.c resource.c
+libatom_la_SOURCES = id.c entry.c person.c feed.c resource.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)
--- /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_id
+{
+ char *iri;
+};
+
+AtomID *
+atom_id_new (char *iri)
+{
+ AtomID *id;
+ id = g_slice_new (AtomID);
+ id->iri = g_strdup (iri);
+ return id;
+}
+
+void
+atom_id_delete (AtomID *id)
+{
+ if (id->iri)
+ g_free (id->iri);
+ g_slice_free (AtomID, id);
+}
+
+char *
+atom_id_string (AtomID *id)
+{
+ return id->iri;
+}
#include <atompub/atom-glib.h>
static gchar *
-giochannel_iri_to_filename (AtomCtx *ctx, IRI *iri)
+giochannel_id_to_filename (AtomCtx *ctx, AtomID *id)
{
gchar *root = atom_config_get_str (ctx, "giochannel", "root");
- gchar *path = iri_get_path (iri);
+ gchar *path = atom_id_string (id);
gchar *filename = g_build_filename (root, path, NULL);
g_free (root);
return filename;
}
static AtomEntry *
-giochannel_atom_retrieve_entry (AtomCtx *ctx, IRI *iri)
+giochannel_atom_retrieve_entry (AtomCtx *ctx, AtomID *id)
{
gchar *filename;
GIOChannel *channel;
gchar *data;
gsize len;
AtomEntry *atom;
- filename = giochannel_iri_to_filename (ctx, iri);
+ filename = giochannel_id_to_filename (ctx, id);
channel = g_io_channel_new_file ((const gchar *) filename, "r", &error);
g_free (filename);
if (channel == NULL)
#include <gio/gio.h>
#include <atompub/atom.h>
#include <atompub/atom-glib.h>
+#include <string.h>
static GFile *
-gio_iri_to_file (AtomCtx *ctx, IRI *iri)
+gio_id_to_file (AtomCtx *ctx, AtomID *id)
{
gchar *root = atom_config_get_str (ctx, "gio", "root");
- gchar *path = iri_get_path (iri);
+ gchar *path = atom_id_string (id);
gchar *filename = g_build_filename (root, path, NULL);
GFile *file = g_file_new_for_path (filename);
g_free (root);
}
static AtomEntry *
-gio_atom_retrieve_entry (AtomCtx *ctx, IRI *iri)
+gio_atom_retrieve_entry (AtomCtx *ctx, AtomID *id)
{
GFile *file;
AtomEntry *atom;
- file = gio_iri_to_file (ctx, iri);
+ file = gio_id_to_file (ctx, id);
atom = gio_file_to_atom (ctx, file);
g_object_unref (file);
return atom;
g_ptr_array_free (array, FALSE);
}
+static int
+gio_atom_is_feed (AtomCtx *ctx, AtomID *id)
+{
+ return (!strcmp (atom_id_string (id), "/"));
+}
+
AtomBackend *
gio_backend (void)
{
backend = atom_backend_new ();
atom_backend_retrieve_entry_set (backend, gio_atom_retrieve_entry);
atom_backend_enumerate_entries_set (backend, gio_enumerate_entries);
+ atom_backend_is_feed_set (backend, gio_atom_is_feed);
return backend;
}
}
if (!strcmp (method, "GET"))
{
- IRI *iri;
+ AtomID *id;
AtomResource *atom;
AtomError *error;
- iri = iri_new ();
- iri_set_path (iri, path);
- atom = atom_retrieve_resource (ctx, iri);
- iri_delete (iri);
+ id = atom_id_new (path);
+ atom = atom_retrieve_resource (ctx, id);
+ atom_id_delete (id);
if (atom)
{
char * str;
pkginclude_HEADERS = atom.h config.h ctx.h entry.h person.h error.h feed.h \
- iri.h backend.h atom-glib.h error-glib.h atom-xml.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 resource.h
AtomBackend *atom_backend_new (void);
void atom_backend_delete (AtomBackend *);
void atom_backend_retrieve_entry_set (AtomBackend *,
- AtomEntry * (AtomCtx *, IRI *));
+ AtomEntry * (AtomCtx *, AtomID *));
void atom_backend_enumerate_entries_set (AtomBackend *,
void (AtomCtx *, AtomEntry ***, size_t *));
-AtomEntry * atom_retrieve_entry (AtomCtx *, IRI *);
+void atom_backend_is_feed_set (AtomBackend *, int (AtomCtx *, AtomID *));
+AtomEntry * atom_retrieve_entry (AtomCtx *, AtomID *);
void atom_enumerate_entries (AtomCtx *, AtomEntry ***, size_t *);
+int atom_is_feed (AtomCtx *, AtomID *);
AtomFeed * atom_retrieve_feed (AtomCtx *);
-AtomResource *atom_retrieve_resource (AtomCtx *, IRI *);
+AtomResource *atom_retrieve_resource (AtomCtx *, AtomID *);
AtomBackend * atom_backend (AtomCtx *);
void atom_backend_set (AtomCtx *, AtomBackend *);
--- /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_ID_H
+#define ATOMPUB_ID_H
+
+#include <atompub/ctx.h>
+
+typedef struct _atom_id AtomID;
+
+AtomID * atom_id_new (char *);
+void atom_id_delete (AtomID *);
+char * atom_id_string (AtomID *);
+
+#endif
struct _atom_backend
{
- AtomEntry * (*retrieve_entry) (AtomCtx *, IRI *);
+ AtomEntry * (*retrieve_entry) (AtomCtx *, AtomID *);
void (*enumerate_entries) (AtomCtx *, AtomEntry ***, size_t *);
+ int (*is_feed) (AtomCtx *, AtomID *);
};
AtomBackend *
void
atom_backend_retrieve_entry_set (AtomBackend *backend,
AtomEntry *retrieve_entry (AtomCtx *,
- IRI *))
+ AtomID *))
{
backend->retrieve_entry = retrieve_entry;
}
backend->enumerate_entries = enumerate_entries;
}
+void
+atom_backend_is_feed_set (AtomBackend *backend,
+ int is_feed (AtomCTx *, AtomID *))
+{
+ backend->is_feed = is_feed;
+}
+
AtomEntry *
-atom_retrieve_entry (AtomCtx *ctx, IRI *iri)
+atom_retrieve_entry (AtomCtx *ctx, AtomID *id)
{
AtomBackend *backend;
backend = atom_backend (ctx);
if (backend && backend->retrieve_entry)
- return backend->retrieve_entry (ctx, iri);
+ return backend->retrieve_entry (ctx, id);
return NULL;
}
*len = 0;
}
+int
+atom_is_feed (AtomCtx *ctx, AtomID *id)
+{
+ AtomBackend *backend;
+ backend = atom_backend (ctx);
+ if (backend && backend->is_feed)
+ {
+ return backend->is_feed (ctx, id);
+ }
+ return 0;
+}
+
AtomFeed *
atom_retrieve_feed (AtomCtx *ctx)
{
}
AtomResource *
-atom_retrieve_resource (AtomCtx *ctx, IRI *iri)
+atom_retrieve_resource (AtomCtx *ctx, AtomID *id)
{
AtomResource *res;
- char * path;
- path = iri_get_path (iri);
- if (!strcmp (path, "/"))
+ if (atom_is_feed (ctx, id))
{
AtomFeed *feed;
feed = atom_retrieve_feed (ctx);
else
{
AtomEntry *entry;
- entry = atom_retrieve_entry (ctx, iri);
+ entry = atom_retrieve_entry (ctx, id);
if (entry == NULL)
return NULL;
res = atom_resource_new_from_entry (entry);