[couchdb-glib] Fixed CouchDBDocument object creation and added missing request body setup in send_message_and_parse
- From: Rodrigo Moya <rodrigo src gnome org>
- To: svn-commits-list gnome org
- Subject: [couchdb-glib] Fixed CouchDBDocument object creation and added missing request body setup in send_message_and_parse
- Date: Tue, 23 Jun 2009 08:21:28 -0400 (EDT)
commit e92c01e7d834b01d156820ec3bc1728f5abac0d6
Author: Rodrigo Moya <rodrigo gnome-db org>
Date: Tue Jun 23 14:21:15 2009 +0200
Fixed CouchDBDocument object creation and added missing request body setup in send_message_and_parse
couchdb-glib/couchdb-document.c | 22 ++++++++++++++--------
couchdb-glib/couchdb-glib.h | 4 +++-
couchdb-glib/utils.c | 4 ++--
3 files changed, 19 insertions(+), 11 deletions(-)
---
diff --git a/couchdb-glib/couchdb-document.c b/couchdb-glib/couchdb-document.c
index bab28d2..38634b7 100644
--- a/couchdb-glib/couchdb-document.c
+++ b/couchdb-glib/couchdb-document.c
@@ -63,7 +63,10 @@ couchdb_document_new (CouchDB *couchdb)
document = g_object_new (COUCHDB_TYPE_DOCUMENT, NULL);
document->couchdb = couchdb;
+ document->dbname = NULL;
+
document->root_node = json_node_new (JSON_NODE_OBJECT);
+ json_node_set_object (document->root_node, json_object_new ());
return document;
}
@@ -99,7 +102,9 @@ couchdb_document_get (CouchDB *couchdb,
}
gboolean
-couchdb_document_put (CouchDBDocument *document, GError **error)
+couchdb_document_put (CouchDBDocument *document,
+ const char *dbname,
+ GError **error)
{
char *url, *body;
const char *id;
@@ -107,19 +112,15 @@ couchdb_document_put (CouchDBDocument *document, GError **error)
gboolean result = FALSE;
g_return_val_if_fail (COUCHDB_IS_DOCUMENT (document), FALSE);
-
- if (!document->dbname) {
- g_warning ("Document does not have a database associated to it");
- return FALSE;
- }
+ g_return_val_if_fail (dbname != NULL, FALSE);
id = couchdb_document_get_string_field (document, "_id");
body = couchdb_document_to_string (document);
if (id) {
- url = g_strdup_printf ("http://%s/%s/%s", document->couchdb->hostname, document->dbname, id);
+ url = g_strdup_printf ("http://%s/%s/%s", document->couchdb->hostname, dbname, id);
parser = send_message_and_parse (document->couchdb, SOUP_METHOD_PUT, url, body, error);
} else {
- url = g_strdup_printf ("http://%s/%s/", document->couchdb->hostname, document->dbname);
+ url = g_strdup_printf ("http://%s/%s/", document->couchdb->hostname, dbname);
parser = send_message_and_parse (document->couchdb, SOUP_METHOD_POST, url, body, error);
}
@@ -131,6 +132,11 @@ couchdb_document_put (CouchDBDocument *document, GError **error)
couchdb_document_set_string_field (document, "_rev", json_object_get_string_member (object, "rev"));
g_object_unref (G_OBJECT (parser));
+
+ if (document->dbname) {
+ g_free (document->dbname);
+ document->dbname = g_strdup (dbname);
+ }
}
/* free memory */
diff --git a/couchdb-glib/couchdb-glib.h b/couchdb-glib/couchdb-glib.h
index ee3795f..20882d0 100644
--- a/couchdb-glib/couchdb-glib.h
+++ b/couchdb-glib/couchdb-glib.h
@@ -78,7 +78,9 @@ CouchDBDocument *couchdb_document_get (CouchDB *couchdb,
const char *dbname,
const char *docid,
GError **error);
-gboolean couchdb_document_put (CouchDBDocument *document, GError **error);
+gboolean couchdb_document_put (CouchDBDocument *document,
+ const char *dbname,
+ GError **error);
const char *couchdb_document_get_id (CouchDBDocument *document);
void couchdb_document_set_id (CouchDBDocument *document, const char *id);
diff --git a/couchdb-glib/utils.c b/couchdb-glib/utils.c
index 23ec721..2a1fab0 100644
--- a/couchdb-glib/utils.c
+++ b/couchdb-glib/utils.c
@@ -71,8 +71,8 @@ send_message_and_parse (CouchDB *couchdb, const char *method, const char *url, c
http_message = soup_message_new (method, url);
if (body != NULL) {
- /* Set the body of the HTTP request */
-
+ soup_message_set_request (http_message, "application/json", SOUP_MEMORY_COPY,
+ body, strlen (body));
}
g_debug ("Sending %s to %s...", method, url);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]