Make all backends return NULL when calling get_contact() and the contact is not found.
authorChristophe Dumez <christophe.dumez@intel.com>
Wed, 5 Oct 2011 07:03:42 +0000 (10:03 +0300)
committerChristophe Dumez <christophe.dumez@intel.com>
Fri, 7 Oct 2011 10:22:07 +0000 (13:22 +0300)
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
addressbook/backends/ldap/e-book-backend-ldap.c
addressbook/backends/vcf/e-book-backend-vcf.c
addressbook/libedata-book/e-book-backend-sync.c

index 0e889f8..4ac347b 100644 (file)
@@ -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
index ac3c2fc..1412cfd 100644 (file)
@@ -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);
        }
 }
index 48b8aac..fb84ec6 100644 (file)
@@ -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));
        }
 }
index 8c39269..ecb386d 100644 (file)
@@ -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