[couchdb-glib] Added replication API
- From: Rodrigo Moya <rodrigo src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [couchdb-glib] Added replication API
- Date: Tue, 9 Feb 2010 16:38:30 +0000 (UTC)
commit f4f273f3eddeca6fde6f48cd4cab83828986d40d
Author: Rodrigo Moya <rodrigo gnome-db org>
Date: Tue Feb 9 14:38:32 2010 +0100
Added replication API
couchdb-glib/couchdb-session.c | 64 ++++++++++++++++++++++++++++++++++++++--
couchdb-glib/couchdb-session.h | 6 ++++
2 files changed, 67 insertions(+), 3 deletions(-)
---
diff --git a/couchdb-glib/couchdb-session.c b/couchdb-glib/couchdb-session.c
index c073b27..9dfcd85 100644
--- a/couchdb-glib/couchdb-session.c
+++ b/couchdb-glib/couchdb-session.c
@@ -433,6 +433,7 @@ couchdb_session_list_documents (CouchdbSession *couchdb, const char *dbname, GEr
}
}
}
+
g_object_unref (G_OBJECT (parser));
g_free (url);
@@ -684,15 +685,15 @@ couchdb_session_send_message (CouchdbSession *couchdb, const char *method, const
{
SoupMessage *http_message;
guint status;
- GError *real_error;
+ GError **real_error;
g_return_val_if_fail (COUCHDB_IS_SESSION (couchdb), FALSE);
g_return_val_if_fail (method != NULL, FALSE);
if (error != NULL)
- real_error = *error;
+ real_error = error;
else
- real_error = NULL;
+ *real_error = NULL;
http_message = soup_message_new (method, url);
if (body != NULL) {
@@ -748,3 +749,60 @@ debug_message (const gchar *log_domain, GLogLevelFlags log_level,
}
#endif
+/**
+ * couchdb_session_replicate:
+ * @couchdb: A #CouchdbSession object
+ * @source: Source database
+ * @target: Target database
+ * @continous: Whether to replicate once or keep replicating
+ * @error: Placeholder for error information
+ *
+ * Replicates a source database to another database, on the same CouchDB instance
+ * or on a remote instance.
+ *
+ * If @continous is FALSE, the replication will happen once, but if set to TRUE,
+ * CouchDB will listen to all changes made to the source database, and automatically
+ * replicate over any new docs as the come into the source to the target.
+ *
+ * Return value: TRUE if successful, FALSE otherwise, in which case the @error
+ * parameter will be set to contain information about the error.
+ */
+gboolean
+couchdb_session_replicate (CouchdbSession *couchdb,
+ const gchar *source,
+ const gchar *target,
+ gboolean continous,
+ GError **error)
+{
+ char *url, *body;
+ CouchdbDocument *input;
+ JsonParser *output;
+ gboolean send_ok;
+
+ g_return_val_if_fail (COUCHDB_IS_SESSION (couchdb), FALSE);
+ g_return_val_if_fail (source != NULL, FALSE);
+ g_return_val_if_fail (target != NULL, FALSE);
+
+ /* Build the input document */
+ input = couchdb_document_new (couchdb);
+ couchdb_document_set_string_field (input, "source", source);
+ couchdb_document_set_string_field (input, "target", target);
+ if (continous)
+ couchdb_document_set_boolean_field (input, "continous", TRUE);
+
+ /* Send message */
+ url = g_strdup_printf ("%s/_replicate", couchdb_session_get_uri (couchdb));
+ body = couchdb_document_to_string (input);
+ output = json_parser_new ();
+
+ send_ok = couchdb_session_send_message (couchdb, SOUP_METHOD_POST, url, body, output, error);
+ /* FIXME: what to do with the information returned? -> http://books.couchdb.org/relax/reference/replication */
+
+ /* Free memory */
+ g_object_unref (G_OBJECT (output));
+ g_object_unref (G_OBJECT (input));
+ g_free (body);
+ g_free (url);
+
+ return send_ok;
+}
diff --git a/couchdb-glib/couchdb-session.h b/couchdb-glib/couchdb-session.h
index 9035357..5cc4b42 100644
--- a/couchdb-glib/couchdb-session.h
+++ b/couchdb-glib/couchdb-session.h
@@ -85,6 +85,12 @@ gboolean couchdb_session_send_message (CouchdbSession *couchdb, cons
GSList *couchdb_session_list_documents (CouchdbSession *couchdb, const char *dbname, GError **error);
void couchdb_session_free_document_list (GSList *doclist);
+gboolean couchdb_session_replicate (CouchdbSession *couchdb,
+ const gchar *source,
+ const gchar *target,
+ gboolean continous,
+ GError **error);
+
G_END_DECLS
#endif /* __COUCHDB_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]