From: Thadeu Lima de Souza Cascardo Date: Sun, 26 Oct 2008 17:46:55 +0000 (-0200) Subject: Implement publish_entry function in GIO backend X-Git-Url: http://git.cascardo.info/?p=cascardo%2Fatompub.git;a=commitdiff_plain;h=5f00c5043e2c2805cd5bf18ef665a7fa4bc0ce60 Implement publish_entry function in GIO backend --- diff --git a/backend/gio/gio.c b/backend/gio/gio.c index 02a8640..140628d 100644 --- a/backend/gio/gio.c +++ b/backend/gio/gio.c @@ -54,6 +54,24 @@ gio_file_to_atom (AtomCtx *ctx, GFile *file) return atom; } +static void +gio_atom_to_file (AtomCtx *ctx, AtomEntry *entry, GFile *file) +{ + GError *error = NULL; + gchar *data = NULL; + gsize len = 0; + atom_entry_string (entry, &data, &len); + if (!g_file_replace_contents (file, data, len, NULL, FALSE, 0, NULL, + NULL, &error)) + { + AtomError *aerr = atom_error_new_from_gerror (error); + atom_error_set (ctx, aerr); + g_error_free (error); + return NULL; + } + g_free (data); +} + static AtomEntry * gio_atom_retrieve_entry (AtomCtx *ctx, char *req) { @@ -65,6 +83,18 @@ gio_atom_retrieve_entry (AtomCtx *ctx, char *req) return atom; } +static void +gio_atom_publish_entry (AtomCtx *ctx, char *req, AtomEntry *entry) +{ + GFile *file; + /* TODO: Create a function to map from an Entry ID to a new filename */ + if (req == NULL) + req = atom_entry_id (entry); + file = gio_req_to_file (ctx, req); + gio_atom_to_file (ctx, entry, file); + g_object_unref (file); +} + static void gio_enumerate_entries (AtomCtx *ctx, char ***reqs, AtomEntry ***entries, size_t *len) @@ -133,5 +163,6 @@ 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_publish_entry_set (backend, gio_atom_publish_entry); return backend; }