#include <glib.h>
#include <atompub/atom.h>
+#include <atompub/atom-glib.h>
-gchar *giochannel_iri_to_filename (AtomCtx *ctx, IRI *iri)
+static gchar *
+giochannel_req_to_filename (AtomCtx *ctx, char *req)
{
gchar *root = atom_config_get_str (ctx, "giochannel", "root");
- gchar *path = iri_get_path (iri);
- gchar *filename = g_build_filename (root, path, NULL);
+ gchar *filename = g_build_filename (root, req, NULL);
g_free (root);
- g_free (path);
return filename;
}
-Atom * giochannel_atom_retrieve_resource (AtomCtx *ctx, IRI *iri)
+static AtomEntry *
+giochannel_atom_retrieve_entry (AtomCtx *ctx, char *req)
{
gchar *filename;
GIOChannel *channel;
GError *error = NULL;
gchar *data;
gsize len;
- Atom *atom;
- filename = giochannel_iri_to_filename (ctx, iri);
+ AtomEntry *atom;
+ filename = giochannel_req_to_filename (ctx, req);
channel = g_io_channel_new_file ((const gchar *) filename, "r", &error);
g_free (filename);
if (channel == NULL)
{
- atom_error_set (ctx, error);
+ 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, error);
+ atom_error_set (ctx, aerr);
+ g_error_free (error);
return NULL;
}
g_io_channel_unref (channel);
- atom = atom_new_data_len (data, len);
+ atom = atom_entry_new_data_len (data, len);
g_free (data);
return atom;
}
+
+AtomBackend *
+giochannel_backend (void)
+{
+ AtomBackend *backend;
+ backend = atom_backend_new ();
+ atom_backend_retrieve_entry_set (backend,
+ giochannel_atom_retrieve_entry);
+ return backend;
+}