[evolution-data-server] Make all backends return NULL when calling get_contact() and the contact is not found.



commit bd6eb6896f663bc95521b07cab48fce760b91ae6
Author: Christophe Dumez <christophe dumez intel com>
Date:   Wed Oct 5 10:03:42 2011 +0300

    Make all backends return NULL when calling get_contact() and the contact is not found.
    
    Some backends returned NULL (google, webdav) while other returned
    an empty string (ldap, file, vcf). The behavior should be
    consistent and I believe the best is to return NULL since it is
    an error case (NOT_FOUND error is returned), this avoids useless
    string allocation and possible leaks.

 addressbook/backends/file/e-book-backend-file.c |    3 ---
 addressbook/backends/ldap/e-book-backend-ldap.c |   16 ++++++++--------
 addressbook/backends/vcf/e-book-backend-vcf.c   |    2 +-
 addressbook/libedata-book/e-book-backend-sync.c |    3 +--
 4 files changed, 10 insertions(+), 14 deletions(-)
---
diff --git a/addressbook/backends/file/e-book-backend-file.c b/addressbook/backends/file/e-book-backend-file.c
index 0e889f8..4ac347b 100644
--- a/addressbook/backends/file/e-book-backend-file.c
+++ b/addressbook/backends/file/e-book-backend-file.c
@@ -513,9 +513,6 @@ e_book_backend_file_get_contact (EBookBackendSync *backend,
 	}
 
 	*vcard = load_vcard (bf, id, perror);
-
-	if (!*vcard)
-		*vcard = g_strdup ("");
 }
 
 static void
diff --git a/addressbook/backends/ldap/e-book-backend-ldap.c b/addressbook/backends/ldap/e-book-backend-ldap.c
index ac3c2fc..1412cfd 100644
--- a/addressbook/backends/ldap/e-book-backend-ldap.c
+++ b/addressbook/backends/ldap/e-book-backend-ldap.c
@@ -2331,7 +2331,7 @@ get_contact_handler (LDAPOp *op,
 	g_static_rec_mutex_lock (&eds_ldap_handler_lock);
 	if (!bl->priv->ldap) {
 		g_static_rec_mutex_unlock (&eds_ldap_handler_lock);
-		e_data_book_respond_get_contact (op->book, op->opid, EDB_ERROR_NOT_CONNECTED (), "");
+		e_data_book_respond_get_contact (op->book, op->opid, EDB_ERROR_NOT_CONNECTED (), NULL);
 		ldap_op_finished (op);
 		if (enable_debug)
 			printf ("get_contact_handler... ldap handler is NULL \n");
@@ -2356,7 +2356,7 @@ get_contact_handler (LDAPOp *op,
 			e_data_book_respond_get_contact (op->book,
 							 op->opid,
 							 e_data_book_create_error_fmt (E_DATA_BOOK_STATUS_OTHER_ERROR, "%s: NULL returned from ldap_first_entry", G_STRFUNC),
-							 "");
+							 NULL);
 			ldap_op_finished (op);
 			return;
 		}
@@ -2398,7 +2398,7 @@ get_contact_handler (LDAPOp *op,
 		e_data_book_respond_get_contact (op->book,
 						 op->opid,
 						 ldap_error_to_response (ldap_error),
-						 "");
+						 NULL);
 		ldap_op_finished (op);
 	}
 	else {
@@ -2406,7 +2406,7 @@ get_contact_handler (LDAPOp *op,
 						 op->opid,
 						 e_data_book_create_error_fmt (E_DATA_BOOK_STATUS_OTHER_ERROR,
 							"%s: Unhandled result type %d returned", G_STRFUNC, msg_type),
-						 "");
+						 NULL);
 		ldap_op_finished (op);
 	}
 
@@ -2441,7 +2441,7 @@ e_book_backend_ldap_get_contact (EBookBackend *backend,
 			gchar *vcard_str;
 
 			if (!contact) {
-				e_data_book_respond_get_contact (book, opid, EDB_ERROR (CONTACT_NOT_FOUND), "");
+				e_data_book_respond_get_contact (book, opid, EDB_ERROR (CONTACT_NOT_FOUND), NULL);
 				return;
 			}
 
@@ -2456,7 +2456,7 @@ e_book_backend_ldap_get_contact (EBookBackend *backend,
 			return;
 		}
 
-		e_data_book_respond_get_contact(book, opid, EDB_ERROR (REPOSITORY_OFFLINE), "");
+		e_data_book_respond_get_contact(book, opid, EDB_ERROR (REPOSITORY_OFFLINE), NULL);
 		return;
 	}
 
@@ -2468,7 +2468,7 @@ e_book_backend_ldap_get_contact (EBookBackend *backend,
 	g_static_rec_mutex_lock (&eds_ldap_handler_lock);
 	if (!bl->priv->ldap) {
 		g_static_rec_mutex_unlock (&eds_ldap_handler_lock);
-		e_data_book_respond_get_contact (book, opid, EDB_ERROR_NOT_CONNECTED (), "");
+		e_data_book_respond_get_contact (book, opid, EDB_ERROR_NOT_CONNECTED (), NULL);
 		if (enable_debug)
 			printf("e_book_backend_ldap_get_contact ... ldap handler is NULL\n");
 		return;
@@ -2506,7 +2506,7 @@ e_book_backend_ldap_get_contact (EBookBackend *backend,
 		e_data_book_respond_get_contact (book,
 						 opid,
 						 ldap_error_to_response (ldap_error),
-						 "");
+						 NULL);
 		get_contact_dtor ((LDAPOp *) get_contact_op);
 	}
 }
diff --git a/addressbook/backends/vcf/e-book-backend-vcf.c b/addressbook/backends/vcf/e-book-backend-vcf.c
index 48b8aac..fb84ec6 100644
--- a/addressbook/backends/vcf/e-book-backend-vcf.c
+++ b/addressbook/backends/vcf/e-book-backend-vcf.c
@@ -376,7 +376,7 @@ e_book_backend_vcf_get_contact (EBookBackendSync *backend,
 	if (elem) {
 		*vcard = g_strdup (elem->data);
 	} else {
-		*vcard = g_strdup ("");
+		*vcard = NULL;
 		g_propagate_error (perror, EDB_ERROR (CONTACT_NOT_FOUND));
 	}
 }
diff --git a/addressbook/libedata-book/e-book-backend-sync.c b/addressbook/libedata-book/e-book-backend-sync.c
index 8c39269..ecb386d 100644
--- a/addressbook/libedata-book/e-book-backend-sync.c
+++ b/addressbook/libedata-book/e-book-backend-sync.c
@@ -550,8 +550,7 @@ book_backend_get_contact (EBookBackend *backend,
 
 	e_data_book_respond_get_contact (book, opid, error, vcard);
 
-	if (vcard)
-		g_free (vcard);
+	g_free (vcard);
 }
 
 static void



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