projects
/
cascardo
/
atompub.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
The frontend tells if a request is a feed or not
[cascardo/atompub.git]
/
backend
/
gio
/
gio.c
diff --git
a/backend/gio/gio.c
b/backend/gio/gio.c
index
8b1dad6
..
33a8ff9
100644
(file)
--- a/
backend/gio/gio.c
+++ b/
backend/gio/gio.c
@@
-21,12
+21,13
@@
#include <gio/gio.h>
#include <atompub/atom.h>
#include <atompub/atom-glib.h>
#include <gio/gio.h>
#include <atompub/atom.h>
#include <atompub/atom-glib.h>
+#include <string.h>
static GFile *
static GFile *
-gio_i
ri_to_file (AtomCtx *ctx, IRI *iri
)
+gio_i
d_to_file (AtomCtx *ctx, AtomID *id
)
{
gchar *root = atom_config_get_str (ctx, "gio", "root");
{
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);
gchar *filename = g_build_filename (root, path, NULL);
GFile *file = g_file_new_for_path (filename);
g_free (root);
@@
-34,13
+35,13
@@
gio_iri_to_file (AtomCtx *ctx, IRI *iri)
return file;
}
return file;
}
-static Atom *
+static Atom
Entry
*
gio_file_to_atom (AtomCtx *ctx, GFile *file)
{
GError *error = NULL;
gchar *data;
gsize len;
gio_file_to_atom (AtomCtx *ctx, GFile *file)
{
GError *error = NULL;
gchar *data;
gsize len;
- Atom *atom;
+ Atom
Entry
*atom;
error = NULL;
if (!g_file_load_contents (file, NULL, &data, &len, NULL, &error))
{
error = NULL;
if (!g_file_load_contents (file, NULL, &data, &len, NULL, &error))
{
@@
-54,51
+55,76
@@
gio_file_to_atom (AtomCtx *ctx, GFile *file)
return atom;
}
return atom;
}
-static Atom *
-gio_atom_retrieve_
resource (AtomCtx *ctx, IRI *iri
)
+static Atom
Entry
*
+gio_atom_retrieve_
entry (AtomCtx *ctx, AtomID *id
)
{
GFile *file;
{
GFile *file;
- Atom *atom;
- file = gio_i
ri_to_file (ctx, iri
);
+ Atom
Entry
*atom;
+ file = gio_i
d_to_file (ctx, id
);
atom = gio_file_to_atom (ctx, file);
g_object_unref (file);
return atom;
}
static void
atom = gio_file_to_atom (ctx, file);
g_object_unref (file);
return atom;
}
static void
-gio_enumerate_entries (AtomCtx *ctx, Atom ***entries, size_t *len)
+gio_enumerate_entries (AtomCtx *ctx, char ***reqs, AtomEntry ***entries,
+ size_t *len)
{
GFile *dir;
GFileEnumerator *enumerator;
GFileInfo *info;
GFile *file;
{
GFile *dir;
GFileEnumerator *enumerator;
GFileInfo *info;
GFile *file;
+ AtomEntry *entry;
+ GError *error;
gchar *root;
gchar *name;
gchar *filename;
GPtrArray *array;
gchar *root;
gchar *name;
gchar *filename;
GPtrArray *array;
+ GPtrArray *filenames;
root = atom_config_get_str (ctx, "gio", "root");
dir = g_file_new_for_path (root);
root = atom_config_get_str (ctx, "gio", "root");
dir = g_file_new_for_path (root);
+ error = NULL;
enumerator = g_file_enumerate_children (dir, G_FILE_ATTRIBUTE_STANDARD_NAME,
enumerator = g_file_enumerate_children (dir, G_FILE_ATTRIBUTE_STANDARD_NAME,
- G_FILE_QUERY_INFO_NONE, NULL, NULL);
+ G_FILE_QUERY_INFO_NONE, NULL, &error);
+ if (enumerator == NULL)
+ {
+ AtomError *aerr = atom_error_new_from_gerror (error);
+ atom_error_set (ctx, aerr);
+ g_error_free (error);
+ return;
+ }
array = g_ptr_array_new ();
array = g_ptr_array_new ();
+ filenames = g_ptr_array_new ();
while ((info = g_file_enumerator_next_file (enumerator, NULL, NULL)) != NULL)
{
name = g_file_info_get_name (info);
filename = g_build_filename (root, name, NULL);
while ((info = g_file_enumerator_next_file (enumerator, NULL, NULL)) != NULL)
{
name = g_file_info_get_name (info);
filename = g_build_filename (root, name, NULL);
- g_object_unref (info);
file = g_file_new_for_path (filename);
file = g_file_new_for_path (filename);
- g_ptr_array_add (array, gio_file_to_atom (ctx, file));
+ entry = gio_file_to_atom (ctx, file);
+ if (entry)
+ {
+ g_ptr_array_add (array, entry);
+ g_ptr_array_add (filenames, g_strdup (name));
+ }
+ else
+ {
+ atom_error_set (ctx, NULL);
+ }
g_object_unref (file);
g_free (filename);
g_object_unref (file);
g_free (filename);
+ g_object_unref (info);
}
g_object_unref (enumerator);
g_object_unref (dir);
g_free (root);
}
g_object_unref (enumerator);
g_object_unref (dir);
g_free (root);
+ if (reqs)
+ *reqs = filenames->pdata;
if (entries)
*entries = array->pdata;
if (len)
*len = array->len;
g_ptr_array_free (array, FALSE);
if (entries)
*entries = array->pdata;
if (len)
*len = array->len;
g_ptr_array_free (array, FALSE);
+ g_ptr_array_free (filenames, FALSE);
}
AtomBackend *
}
AtomBackend *
@@
-106,7
+132,7
@@
gio_backend (void)
{
AtomBackend *backend;
backend = atom_backend_new ();
{
AtomBackend *backend;
backend = atom_backend_new ();
- atom_backend_retrieve_
resource_set (backend, gio_atom_retrieve_resource
);
+ atom_backend_retrieve_
entry_set (backend, gio_atom_retrieve_entry
);
atom_backend_enumerate_entries_set (backend, gio_enumerate_entries);
return backend;
}
atom_backend_enumerate_entries_set (backend, gio_enumerate_entries);
return backend;
}