[couchdb-glib] Check existence of fields before trying to get them from json_object_* to avoid warnings



commit f8765589465b16610e73fb37906716bade83efe6
Author: Rodrigo Moya <rodrigo gnome-db org>
Date:   Wed Apr 6 13:48:38 2011 +0200

    Check existence of fields before trying to get them from json_object_* to avoid warnings

 couchdb-glib/couchdb-document-contact.c |   75 ++++++++++++++++++------------
 1 files changed, 45 insertions(+), 30 deletions(-)
---
diff --git a/couchdb-glib/couchdb-document-contact.c b/couchdb-glib/couchdb-document-contact.c
index b62a93d..a23c28f 100644
--- a/couchdb-glib/couchdb-document-contact.c
+++ b/couchdb-glib/couchdb-document-contact.c
@@ -371,12 +371,15 @@ couchdb_document_contact_get_email_addresses (CouchdbDocumentContact *document)
 	g_return_val_if_fail (COUCHDB_IS_DOCUMENT_CONTACT (document), NULL);
 	g_return_val_if_fail (couchdb_document_is_contact (COUCHDB_DOCUMENT (document)), NULL);
 
-	addresses_json = json_object_get_object_member (
-		couchdb_document_get_json_object (COUCHDB_DOCUMENT (document)), "email_addresses");;
-	if (addresses_json) {
-		json_object_foreach_member (addresses_json,
-					    (JsonObjectForeach) foreach_object_cb,
-					    &list);
+	if (json_object_has_member (couchdb_document_get_json_object (COUCHDB_DOCUMENT (document)),
+				    "email_addresses")) {
+		addresses_json = json_object_get_object_member (
+			couchdb_document_get_json_object (COUCHDB_DOCUMENT (document)), "email_addresses");;
+		if (addresses_json) {
+			json_object_foreach_member (addresses_json,
+						    (JsonObjectForeach) foreach_object_cb,
+						    &list);
+		}
 	}
 
 	return list;
@@ -424,12 +427,15 @@ couchdb_document_contact_get_phone_numbers (CouchdbDocumentContact *document)
 	g_return_val_if_fail (COUCHDB_IS_DOCUMENT_CONTACT (document), NULL);
 	g_return_val_if_fail (couchdb_document_is_contact (COUCHDB_DOCUMENT (document)), NULL);
 
-	phone_numbers = json_object_get_object_member (
-		couchdb_document_get_json_object (COUCHDB_DOCUMENT (document)), "phone_numbers");
-	if (phone_numbers) {
-		json_object_foreach_member (phone_numbers,
-					    (JsonObjectForeach) foreach_object_cb,
-					    &list);
+	if (json_object_has_member (couchdb_document_get_json_object (COUCHDB_DOCUMENT (document)),
+				    "phone_numbers")) {
+		phone_numbers = json_object_get_object_member (
+			couchdb_document_get_json_object (COUCHDB_DOCUMENT (document)), "phone_numbers");
+		if (phone_numbers) {
+			json_object_foreach_member (phone_numbers,
+						    (JsonObjectForeach) foreach_object_cb,
+						    &list);
+		}
 	}
 
 	return list;
@@ -478,12 +484,15 @@ couchdb_document_contact_get_addresses (CouchdbDocumentContact *document)
 	g_return_val_if_fail (COUCHDB_IS_DOCUMENT_CONTACT (document), NULL);
 	g_return_val_if_fail (couchdb_document_is_contact (COUCHDB_DOCUMENT (document)), NULL);
 
-	addresses = json_object_get_object_member (
-		couchdb_document_get_json_object (COUCHDB_DOCUMENT (document)), "addresses");
-	if (addresses) {
-		json_object_foreach_member (addresses,
-					    (JsonObjectForeach) foreach_object_cb,
-					    &list);
+	if (json_object_has_member (couchdb_document_get_json_object (COUCHDB_DOCUMENT (document)),
+				    "addresses")) {
+		addresses = json_object_get_object_member (
+			couchdb_document_get_json_object (COUCHDB_DOCUMENT (document)), "addresses");
+		if (addresses) {
+			json_object_foreach_member (addresses,
+						    (JsonObjectForeach) foreach_object_cb,
+						    &list);
+		}
 	}
 
 	return list;
@@ -543,12 +552,15 @@ couchdb_document_contact_get_im_addresses (CouchdbDocumentContact *document)
 	g_return_val_if_fail (COUCHDB_IS_DOCUMENT_CONTACT (document), NULL);
 	g_return_val_if_fail (couchdb_document_is_contact (COUCHDB_DOCUMENT (document)), NULL);
 
-	im_addresses = json_object_get_object_member (
-		couchdb_document_get_json_object (COUCHDB_DOCUMENT (document)), "im_addresses");
-	if (im_addresses != NULL) {
-		json_object_foreach_member (im_addresses,
-					    (JsonObjectForeach) foreach_object_cb,
-					    &list);
+	if (json_object_has_member (couchdb_document_get_json_object (COUCHDB_DOCUMENT (document)),
+				    "im_addresses")) {
+		im_addresses = json_object_get_object_member (
+			couchdb_document_get_json_object (COUCHDB_DOCUMENT (document)), "im_addresses");
+		if (im_addresses != NULL) {
+			json_object_foreach_member (im_addresses,
+						    (JsonObjectForeach) foreach_object_cb,
+						    &list);
+		}
 	}
 
 	return list;
@@ -597,12 +609,15 @@ couchdb_document_contact_get_urls (CouchdbDocumentContact *document)
 	g_return_val_if_fail (COUCHDB_IS_DOCUMENT_CONTACT (document), NULL);
 	g_return_val_if_fail (couchdb_document_is_contact (COUCHDB_DOCUMENT (document)), NULL);
 
-	urls = json_object_get_object_member (
-		couchdb_document_get_json_object (COUCHDB_DOCUMENT (document)), "urls");
-	if (urls) {
-		json_object_foreach_member (urls,
-					    (JsonObjectForeach) foreach_object_cb,
-					    &list);
+	if (json_object_has_member (couchdb_document_get_json_object (COUCHDB_DOCUMENT (document)),
+				    "urls")) {
+		urls = json_object_get_object_member (
+			couchdb_document_get_json_object (COUCHDB_DOCUMENT (document)), "urls");
+		if (urls) {
+			json_object_foreach_member (urls,
+						    (JsonObjectForeach) foreach_object_cb,
+						    &list);
+		}
 	}
 
 	return list;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]