diff options
author | Milan Crha <mcrha@redhat.com> | 2012-06-15 15:25:08 +0200 |
---|---|---|
committer | Milan Crha <mcrha@redhat.com> | 2012-06-15 15:25:08 +0200 |
commit | d3eeb57252c130d9a4909d02d522eb83a94d8688 (patch) | |
tree | 936ec1c2690a8443ab11db3d340e2cf19408fdba | |
parent | 37b906729e635174d0c8ba6ef369cb5d5534bea0 (diff) | |
download | evolution-data-server-d3eeb57252c130d9a4909d02d522eb83a94d8688.tar.gz |
Bug #678069 - Crash in _gdata_entry_update_from_e_contact()
-rw-r--r-- | addressbook/backends/google/e-book-backend-google.c | 63 |
1 files changed, 50 insertions, 13 deletions
diff --git a/addressbook/backends/google/e-book-backend-google.c b/addressbook/backends/google/e-book-backend-google.c index cae047f03..34da808f6 100644 --- a/addressbook/backends/google/e-book-backend-google.c +++ b/addressbook/backends/google/e-book-backend-google.c @@ -116,8 +116,8 @@ gboolean __e_book_backend_google_debug__; static void data_book_error_from_gdata_error (GError **dest_err, const GError *error); -static GDataEntry *_gdata_entry_new_from_e_contact (EBookBackend *backend, EContact *contact); -static gboolean _gdata_entry_update_from_e_contact (EBookBackend *backend, GDataEntry *entry, EContact *contact, gboolean ensure_personal_group); +static GDataEntry *_gdata_entry_new_from_e_contact (EBookBackend *backend, EContact *contact, GCancellable *cancellable); +static gboolean _gdata_entry_update_from_e_contact (EBookBackend *backend, GDataEntry *entry, EContact *contact, gboolean ensure_personal_group, GCancellable *cancellable); static EContact *_e_contact_new_from_gdata_entry (EBookBackend *backend, GDataEntry *entry); static void _e_contact_add_gdata_entry_xml (EContact *contact, GDataEntry *entry); @@ -639,7 +639,7 @@ check_get_new_contacts_finished (GetContactsData *data) __debug__ ("Proceeding with check_get_new_contacts_finished() for data: %p.", data); - finish_operation (data->backend, 0, data->gdata_error); + finish_operation (data->backend, -1, data->gdata_error); /* Tidy up */ g_object_unref (data->cancellable); @@ -873,7 +873,7 @@ get_new_contacts (EBookBackend *backend) } /* Query for new contacts asynchronously */ - cancellable = start_operation (backend, 0, NULL, _("Querying for updated contacts…")); + cancellable = start_operation (backend, -1, NULL, _("Querying for updated contacts…")); data = g_slice_new (GetContactsData); data->backend = g_object_ref (backend); @@ -1040,7 +1040,7 @@ get_groups_cb (GDataService *service, g_get_current_time (&(priv->last_groups_update)); } - finish_operation (backend, 1, gdata_error); + finish_operation (backend, -2, gdata_error); g_clear_error (&gdata_error); } @@ -1065,7 +1065,7 @@ get_groups (EBookBackend *backend) } /* Run the query asynchronously */ - cancellable = start_operation (backend, 1, NULL, _("Querying for updated groups…")); + cancellable = start_operation (backend, -2, NULL, _("Querying for updated groups…")); gdata_contacts_service_query_groups_async ( GDATA_CONTACTS_SERVICE (priv->service), query, @@ -1080,6 +1080,37 @@ get_groups (EBookBackend *backend) g_object_unref (query); } +static void +get_groups_sync (EBookBackend *backend, + GCancellable *cancellable) +{ + EBookBackendGooglePrivate *priv; + GDataQuery *query; + GDataFeed *feed; + + priv = E_BOOK_BACKEND_GOOGLE_GET_PRIVATE (backend); + + __debug__ (G_STRFUNC); + g_return_if_fail (backend_is_authorized (backend)); + + /* Build our query, always fetch all of them */ + query = GDATA_QUERY (gdata_contacts_query_new_with_limits (NULL, 0, G_MAXINT)); + + /* Run the query synchronously */ + feed = gdata_contacts_service_query_groups ( + GDATA_CONTACTS_SERVICE (priv->service), + query, + cancellable, + (GDataQueryProgressCallback) process_group, + backend, + NULL); + + if (feed) + g_object_unref (feed); + + g_object_unref (query); +} + static gchar * create_group (EBookBackend *backend, const gchar *category_name, @@ -1499,7 +1530,7 @@ e_book_backend_google_create_contacts (EBookBackend *backend, /* Build the GDataEntry from the vCard */ contact = e_contact_new_from_vcard (vcard_str); - entry = _gdata_entry_new_from_e_contact (backend, contact); + entry = _gdata_entry_new_from_e_contact (backend, contact, cancellable); g_object_unref (contact); /* Debug XML output */ @@ -1898,7 +1929,7 @@ e_book_backend_google_modify_contacts (EBookBackend *backend, } /* Update the old GDataEntry from the new contact */ - _gdata_entry_update_from_e_contact (backend, entry, contact, FALSE); + _gdata_entry_update_from_e_contact (backend, entry, contact, FALSE, cancellable); /* Output debug XML */ if (__e_book_backend_google_debug__) { @@ -2761,11 +2792,12 @@ static gboolean is_known_google_im_protocol (const gchar *protocol); static GDataEntry * _gdata_entry_new_from_e_contact (EBookBackend *backend, - EContact *contact) + EContact *contact, + GCancellable *cancellable) { GDataEntry *entry = GDATA_ENTRY (gdata_contacts_contact_new (NULL)); - if (_gdata_entry_update_from_e_contact (backend, entry, contact, TRUE)) + if (_gdata_entry_update_from_e_contact (backend, entry, contact, TRUE, cancellable)) return entry; g_object_unref (entry); @@ -2801,7 +2833,8 @@ static gboolean _gdata_entry_update_from_e_contact (EBookBackend *backend, GDataEntry *entry, EContact *contact, - gboolean ensure_personal_group) + gboolean ensure_personal_group, + GCancellable *cancellable) { EBookBackendGooglePrivate *priv; GList *attributes, *iter, *category_names; @@ -2825,6 +2858,10 @@ _gdata_entry_update_from_e_contact (EBookBackend *backend, priv = E_BOOK_BACKEND_GOOGLE_GET_PRIVATE (backend); + /* for cases when system groups were not fetched yet */ + if (g_hash_table_size (priv->system_groups_by_id) == 0) + get_groups_sync (backend, cancellable); + attributes = e_vcard_get_attributes (E_VCARD (contact)); /* N and FN */ @@ -3082,8 +3119,8 @@ _gdata_entry_update_from_e_contact (EBookBackend *backend, category_id = create_group (backend, category_name, &error); if (category_id == NULL) { - g_warning ("Error creating group '%s': %s", category_name, error->message); - g_error_free (error); + g_warning ("Error creating group '%s': %s", category_name, error ? error->message : "Unknown error"); + g_clear_error (&error); continue; } } |