[evolution-ews] Clean-up in some EEwsConnection's functions APIs



commit 044b4950ffeb596b3bf9d957a87f715c39a918be
Author: Fabiano Fidêncio <fidencio redhat com>
Date:   Sun May 5 18:12:09 2013 +0200

    Clean-up in some EEwsConnection's functions APIs
    
    https://bugzilla.gnome.org/show_bug.cgi?id=699847

 src/addressbook/e-book-backend-ews.c               |   90 ++++--------
 src/calendar/e-cal-backend-ews.c                   |   62 ++++----
 src/camel/camel-ews-store-summary.c                |    5 +-
 src/collection/e-ews-backend.c                     |   20 +--
 .../e-mail-config-ews-delegates-page.c             |    2 +-
 src/configuration/e-mail-config-ews-ooo-page.c     |    2 +-
 src/server/e-ews-connection.c                      |  158 +++++++++++---------
 src/server/e-ews-connection.h                      |   26 ++--
 src/server/e-ews-folder.c                          |    3 +-
 src/server/e-ews-item.c                            |   69 +++------
 src/server/e-ews-item.h                            |    2 +-
 11 files changed, 189 insertions(+), 250 deletions(-)
---
diff --git a/src/addressbook/e-book-backend-ews.c b/src/addressbook/e-book-backend-ews.c
index c22d6bf..80dbd18 100644
--- a/src/addressbook/e-book-backend-ews.c
+++ b/src/addressbook/e-book-backend-ews.c
@@ -378,7 +378,7 @@ get_photo (EBookBackendEws *ebews,
        EContactPhoto *photo = NULL;
        EEwsAttachmentInfo *info;
        GSList *contact_item_ids = NULL, *new_items = NULL;
-       GSList *attachments = NULL,  *attachments_ids = NULL, *items = NULL;
+       GSList *attachments = NULL,  *attachments_ids = NULL;
        const guchar *content;
        const gchar *contact_photo_id;
        const EwsId *id;
@@ -400,7 +400,7 @@ get_photo (EBookBackendEws *ebews,
                goto exit;
 
        attachments_ids = g_slist_prepend (attachments_ids, g_strdup (contact_photo_id));
-       items = e_ews_connection_get_attachments_sync (
+       if (!e_ews_connection_get_attachments_sync (
                ebews->priv->cnc,
                EWS_PRIORITY_MEDIUM,
                NULL,
@@ -411,9 +411,7 @@ get_photo (EBookBackendEws *ebews,
                NULL,
                NULL,
                cancellable,
-               error);
-
-       if (!items)
+               error))
                goto exit;
 
        info = attachments->data;
@@ -427,7 +425,6 @@ exit:
        g_slist_free_full (contact_item_ids, g_free);
        g_slist_free_full (new_items, g_object_unref);
        g_slist_free_full (attachments_ids, g_free);
-       g_slist_free_full (items, g_free);
        g_slist_free_full (attachments, (GDestroyNotify) e_ews_attachment_info_free);
 
        return photo;
@@ -889,6 +886,7 @@ set_photo (EBookBackendEws *ebews,
                        EWS_PRIORITY_MEDIUM,
                        id,
                        files,
+                       NULL,
                        cancellable,
                        error);
 
@@ -933,7 +931,7 @@ ebews_set_photo_changes (EBookBackendEws *ebews,
                         GError **error)
 {
        EContactPhoto *old_photo, *new_photo;
-       GSList *contact_item_ids = NULL, *new_items = NULL, *attachments_ids = NULL, *deleted_attachments = 
NULL;
+       GSList *contact_item_ids = NULL, *new_items = NULL, *attachments_ids = NULL;
        gchar *id = e_contact_get (old, E_CONTACT_UID);
        const gchar *contact_photo_id;
 
@@ -956,14 +954,13 @@ ebews_set_photo_changes (EBookBackendEws *ebews,
        contact_photo_id = e_ews_item_get_contact_photo_id (new_items->data);
        if (contact_photo_id) {
                attachments_ids = g_slist_prepend (attachments_ids, g_strdup (contact_photo_id));
-               deleted_attachments = e_ews_connection_delete_attachments_sync (
+               if (!e_ews_connection_delete_attachments_sync (
                                        ebews->priv->cnc,
                                        EWS_PRIORITY_MEDIUM,
                                        attachments_ids,
+                                       NULL,
                                        cancellable,
-                                       error);
-
-               if (!deleted_attachments)
+                                       error))
                        goto exit;
        }
 
@@ -976,7 +973,6 @@ exit:
        g_slist_free_full (contact_item_ids, g_free);
        g_slist_free_full (new_items, g_object_unref);
        g_slist_free_full (attachments_ids, g_free);
-       g_slist_free_full (deleted_attachments, g_free);
 }
 
 static void
@@ -1409,8 +1405,7 @@ ews_book_remove_contact_cb (GObject *object,
                g_warning ("\nError removing contact %s \n", error->message);
        }
 
-       g_slist_foreach (remove_contact->sl_ids, (GFunc) g_free, NULL);
-       g_slist_free (remove_contact->sl_ids);
+       g_slist_free_full (remove_contact->sl_ids, g_free);
        g_object_unref (remove_contact->ebews);
        g_object_unref (remove_contact->book);
        g_free (remove_contact);
@@ -1756,8 +1751,7 @@ e_book_backend_ews_get_contact_list (EBookBackend *backend,
                        e_data_book_respond_get_contact_list (book, opid, error, vcard_list);
 
                        g_slist_free (list);
-                       g_slist_foreach (vcard_list, (GFunc) g_free, NULL);
-                       g_slist_free (vcard_list);
+                       g_slist_free_full (vcard_list, g_free);
                        return;
                } else
                        e_data_book_respond_get_contact_list (book, opid, EDB_ERROR (OFFLINE_UNAVAILABLE), 
vcard_list);
@@ -1785,8 +1779,7 @@ e_book_backend_ews_get_contact_list (EBookBackend *backend,
                e_data_book_respond_get_contact_list (book, opid, error, vcard_list);
 
                g_slist_free (list);
-               g_slist_foreach (vcard_list, (GFunc) g_free, NULL);
-               g_slist_free (vcard_list);
+               g_slist_free_full (vcard_list, g_free);
                return;
 
        } else if (!priv->marked_for_offline) {
@@ -1812,8 +1805,7 @@ e_book_backend_ews_get_contact_list (EBookBackend *backend,
                e_data_book_respond_get_contact_list (book, opid, error, vcard_list);
 
                e_ews_folder_id_free (fid);
-               g_slist_foreach (vcard_list, (GFunc) g_free, NULL);
-               g_slist_free (vcard_list);
+               g_slist_free_full (vcard_list, g_free);
                return;
        } else
                e_data_book_respond_get_contact_list (book, opid, EDB_ERROR_EX (OTHER_ERROR, _("Wait till 
syncing is done")), vcard_list);
@@ -2160,7 +2152,7 @@ ews_gal_store_contact (EContact *contact,
                list = e_book_backend_list_views (E_BOOK_BACKEND (data->cbews));
                for (link = list; link != NULL; link = g_list_next (link))
                        e_data_book_view_notify_progress (E_DATA_BOOK_VIEW (link->data), -1, status_message);
-               g_list_free_full (list, (GDestroyNotify) g_object_unref);
+               g_list_free_full (list, g_object_unref);
                g_free (status_message);
 
                data->contact_collector = g_slist_reverse (data->contact_collector);
@@ -2169,8 +2161,7 @@ ews_gal_store_contact (EContact *contact,
                for (l = data->contact_collector; l != NULL; l = g_slist_next (l))
                        e_book_backend_notify_update (E_BOOK_BACKEND (data->cbews), E_CONTACT (l->data));
 
-               g_slist_foreach (data->contact_collector, (GFunc) g_object_unref, NULL);
-               g_slist_free (data->contact_collector);
+               g_slist_free_full (data->contact_collector, g_object_unref);
                data->contact_collector = NULL;
                data->collected_length = 0;
        }
@@ -2366,8 +2357,7 @@ ebews_sync_deleted_items (EBookBackendEws *ebews,
                e_book_backend_notify_remove (E_BOOK_BACKEND (ebews), id);
        }
 
-       g_slist_foreach (deleted_ids, (GFunc) g_free, NULL);
-       g_slist_free (deleted_ids);
+       g_slist_free_full (deleted_ids, g_free);
 }
 
 static void
@@ -2665,20 +2655,9 @@ ebews_fetch_items (EBookBackendEws *ebews,
        }
 
 cleanup:
-       if (new_items) {
-               g_slist_foreach (new_items, (GFunc) g_object_unref, NULL);
-               g_slist_free (new_items);
-       }
-
-       if (dl_ids) {
-               g_slist_foreach (dl_ids, (GFunc) g_free, NULL);
-               g_slist_free (dl_ids);
-       }
-
-       if (contact_item_ids) {
-               g_slist_foreach (contact_item_ids, (GFunc) g_free, NULL);
-               g_slist_free (contact_item_ids);
-       }
+       g_slist_free_full (new_items, g_object_unref);
+       g_slist_free_full (dl_ids, g_free);
+       g_slist_free_full (contact_item_ids, g_free);
 
        return TRUE;
 }
@@ -2730,7 +2709,7 @@ ebews_start_sync (gpointer data)
        list = e_book_backend_list_views (E_BOOK_BACKEND (ebews));
        for (link = list; link != NULL; link = g_list_next (link))
                e_data_book_view_notify_progress (E_DATA_BOOK_VIEW (link->data), -1, status_message);
-       g_list_free_full (list, (GDestroyNotify) g_object_unref);
+       g_list_free_full (list, g_object_unref);
        g_free (status_message);
 
        sync_state = e_book_backend_sqlitedb_get_sync_data (priv->summary, priv->folder_id, NULL);
@@ -2773,10 +2752,7 @@ ebews_start_sync (gpointer data)
                        ebews_fetch_items (ebews, items_created, TRUE, NULL, priv->cancellable, &error);
 
                if (error) {
-                       if (items_updated) {
-                               g_slist_foreach (items_updated, (GFunc) g_object_unref, NULL);
-                               g_slist_free (items_updated);
-                       }
+                       g_slist_free_full (items_updated, g_object_unref);
 
                        break;
                }
@@ -2799,7 +2775,7 @@ ebews_start_sync (gpointer data)
        list = e_book_backend_list_views (E_BOOK_BACKEND (ebews));
        for (link = list; link != NULL; link = g_list_next (link))
                e_data_book_view_notify_progress (E_DATA_BOOK_VIEW (link->data), -1, NULL);
-       g_list_free_full (list, (GDestroyNotify) g_object_unref);
+       g_list_free_full (list, g_object_unref);
 
        if (error) {
                g_warning ("Error Syncing Contacts: Folder %s Error: %s", priv->folder_id, error->message);
@@ -3382,25 +3358,17 @@ e_book_backend_ews_dispose (GObject *object)
                priv->cnc = NULL;
        }
 
-       if (priv->folder_id) {
-               g_free (priv->folder_id);
-               priv->folder_id = NULL;
-       }
+       g_free (priv->folder_id);
+       priv->folder_id = NULL;
 
-       if (priv->oab_url) {
-               g_free (priv->oab_url);
-               priv->oab_url = NULL;
-       }
+       g_free (priv->oab_url);
+       priv->oab_url = NULL;
 
-       if (priv->folder_name) {
-               g_free (priv->folder_name);
-               priv->folder_name = NULL;
-       }
+       g_free (priv->folder_name);
+       priv->folder_name = NULL;
 
-       if (priv->attachment_dir) {
-               g_free (priv->attachment_dir);
-               priv->attachment_dir = NULL;
-       }
+       g_free (priv->attachment_dir);
+       priv->attachment_dir = NULL;
 
        if (priv->dlock) {
                g_mutex_lock (&priv->dlock->mutex);
diff --git a/src/calendar/e-cal-backend-ews.c b/src/calendar/e-cal-backend-ews.c
index e93f3fe..ffaecd2 100644
--- a/src/calendar/e-cal-backend-ews.c
+++ b/src/calendar/e-cal-backend-ews.c
@@ -774,8 +774,7 @@ cal_backend_ews_get_object_list (ECalBackend *backend,
        }
 
        g_object_unref (cbsexp);
-       g_slist_foreach (components, (GFunc) g_object_unref, NULL);
-       g_slist_free (components);
+       g_slist_free_full (components, g_object_unref);
 }
 
 static void
@@ -1386,12 +1385,11 @@ ews_create_attachments_cb (GObject *object,
        icalparameter *icalparam;
        const gchar *comp_uid;
 
-       ids = e_ews_connection_create_attachments_finish (cnc, &change_key, res, &error);
+       if (!e_ews_connection_create_attachments_finish (cnc, &change_key, &ids, res, &error)) {
+               g_warning ("Error while creating attachments: %s\n", error ? error->message : "Unknown 
error");
+               if (error != NULL)
+                       g_clear_error (&error);
 
-       /* make sure there was no error */
-       if (error != NULL) {
-               g_warning ("Error while creating attachments: %s\n", error->message);
-               g_clear_error (&error);
                return;
        }
 
@@ -1497,12 +1495,14 @@ ews_create_object_cb (GObject *object,
        EEwsItem *item;
 
        /* get a list of ids from server (single item) */
-       e_ews_connection_create_items_finish (cnc, res, &ids, &error);
-
-       /* make sure there was no error */
-       if (error != NULL) {
-               convert_error_to_edc_error (&error);
-               e_data_cal_respond_create_objects (create_data->cal, create_data->context, error, NULL, NULL);
+       if (!e_ews_connection_create_items_finish (cnc, res, &ids, &error)) {
+               if (error != NULL) {
+                       convert_error_to_edc_error (&error);
+                       e_data_cal_respond_create_objects (create_data->cal, create_data->context, error, 
NULL, NULL);
+               } else {
+                       e_data_cal_respond_create_objects (
+                                       create_data->cal, create_data->context, EDC_ERROR_EX (OtherError, 
_("Unknown error")), NULL, NULL);
+               }
                return;
        }
 
@@ -1638,8 +1638,7 @@ ews_create_object_cb (GObject *object,
                                comp_uid, i->data, E_CAL_OBJ_MOD_THIS);
                }
 
-               g_slist_foreach (exceptions, (GFunc) g_free, NULL);
-               g_slist_free (exceptions);
+               g_slist_free_full (exceptions, g_free);
        }
 
        /* no need to keep reference to the object */
@@ -2399,9 +2398,9 @@ e_cal_backend_ews_modify_object (ECalBackend *backend,
                        icalprop = icalcomponent_get_next_property (icalcomp, ICAL_ATTACH_PROPERTY);
                }
 
-               items = e_ews_connection_delete_attachments_sync (
+               e_ews_connection_delete_attachments_sync (
                        priv->cnc, EWS_PRIORITY_MEDIUM,
-                       removed_attachments_ids, cancellable, &error);
+                       removed_attachments_ids, &items, cancellable, &error);
 
                changekey = items->data;
 
@@ -3759,9 +3758,9 @@ ews_start_sync_thread (gpointer data)
                                cbews, new_sync_state,
                                items_created, items_updated, items_deleted);
 
-                       g_slist_free_full (items_created, (GDestroyNotify) g_object_unref);
-                       g_slist_free_full (items_updated, (GDestroyNotify) g_object_unref);
-                       g_slist_free_full (items_deleted, (GDestroyNotify) g_free);
+                       g_slist_free_full (items_created, g_object_unref);
+                       g_slist_free_full (items_updated, g_object_unref);
+                       g_slist_free_full (items_deleted, g_free);
                        items_created = NULL;
                        items_updated = NULL;
                        items_deleted = NULL;
@@ -3783,9 +3782,9 @@ ews_start_sync_thread (gpointer data)
 
        ews_refreshing_dec (cbews);
 
-       g_slist_free_full (items_created, (GDestroyNotify) g_object_unref);
-       g_slist_free_full (items_updated, (GDestroyNotify) g_object_unref);
-       g_slist_free_full (items_deleted, (GDestroyNotify) g_free);
+       g_slist_free_full (items_created, g_object_unref);
+       g_slist_free_full (items_updated, g_object_unref);
+       g_slist_free_full (items_deleted, g_free);
 
        g_free (new_sync_state);
        g_free (old_sync_state);
@@ -4006,10 +4005,8 @@ done:
        e_data_cal_respond_get_free_busy (free_busy_data->cal, free_busy_data->context, error);
 
        /* FIXME free free_busy_sl ? */
-       g_slist_foreach (free_busy, (GFunc) g_free, NULL);
-       g_slist_free (free_busy);
-       g_slist_foreach (free_busy_data->users, (GFunc) free, NULL);
-       g_slist_free (free_busy_data->users);
+       g_slist_free_full (free_busy, g_free);
+       g_slist_free_full (free_busy_data->users, g_free);
        g_object_unref (free_busy_data->cal);
        g_object_unref (free_busy_data->cbews);
        g_free (free_busy_data);
@@ -4377,9 +4374,9 @@ cal_backend_ews_try_password_sync (ESourceAuthenticator *authenticator,
                backend->priv->cnc = g_object_ref (connection);
                PRIV_UNLOCK (backend->priv);
 
-               g_slist_free_full (items_created, (GDestroyNotify) g_object_unref);
-               g_slist_free_full (items_updated, (GDestroyNotify) g_object_unref);
-               g_slist_free_full (items_deleted, (GDestroyNotify) g_free);
+               g_slist_free_full (items_created, g_object_unref);
+               g_slist_free_full (items_updated, g_object_unref);
+               g_slist_free_full (items_deleted, g_free);
 
                ews_start_sync (backend);
 
@@ -4470,10 +4467,7 @@ e_cal_backend_ews_init (ECalBackendEws *cbews)
        /* create the mutex for thread safety */
        g_rec_mutex_init (&priv->rec_mutex);
        priv->refreshing_done = e_flag_new ();
-       priv->item_id_hash = g_hash_table_new_full
-               (g_str_hash, g_str_equal,
-               (GDestroyNotify) g_free,
-               (GDestroyNotify) g_object_unref);
+       priv->item_id_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
        priv->default_zone = icaltimezone_get_utc_timezone ();
        priv->cancellable = g_cancellable_new ();
 
diff --git a/src/camel/camel-ews-store-summary.c b/src/camel/camel-ews-store-summary.c
index f0c8edd..430eeeb 100644
--- a/src/camel/camel-ews-store-summary.c
+++ b/src/camel/camel-ews-store-summary.c
@@ -72,10 +72,7 @@ camel_ews_store_summary_init (CamelEwsStoreSummary *ews_summary)
        priv->key_file = g_key_file_new ();
        priv->dirty = FALSE;
        priv->fname_id_hash = g_hash_table_new (g_str_hash, g_str_equal);
-       priv->id_fname_hash = g_hash_table_new_full (
-               g_str_hash, g_str_equal,
-               (GDestroyNotify) g_free,
-               (GDestroyNotify) g_free);
+       priv->id_fname_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
        g_rec_mutex_init (&priv->s_lock);
 }
 
diff --git a/src/collection/e-ews-backend.c b/src/collection/e-ews-backend.c
index c70fc37..26c50b5 100644
--- a/src/collection/e-ews-backend.c
+++ b/src/collection/e-ews-backend.c
@@ -67,19 +67,13 @@ sync_folders_closure_free (SyncFoldersClosure *closure)
        g_object_unref (closure->backend);
 
        /* List of EEwsFolder instances. */
-       g_slist_free_full (
-               closure->folders_created,
-               (GDestroyNotify) g_object_unref);
+       g_slist_free_full (closure->folders_created, g_object_unref);
 
        /* List of folder ID strings. */
-       g_slist_free_full (
-               closure->folders_deleted,
-               (GDestroyNotify) g_free);
+       g_slist_free_full (closure->folders_deleted, g_free);
 
        /* List of EEwsFolder instances. */
-       g_slist_free_full (
-               closure->folders_updated,
-               (GDestroyNotify) g_object_unref);
+       g_slist_free_full (closure->folders_updated, g_object_unref);
 
        g_slice_free (SyncFoldersClosure, closure);
 }
@@ -1009,11 +1003,7 @@ e_ews_backend_init (EEwsBackend *backend)
 {
        backend->priv = E_EWS_BACKEND_GET_PRIVATE (backend);
 
-       backend->priv->folders = g_hash_table_new_full (
-               (GHashFunc) g_str_hash,
-               (GEqualFunc) g_str_equal,
-               (GDestroyNotify) g_free,
-               (GDestroyNotify) g_object_unref);
+       backend->priv->folders = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
 
        g_mutex_init (&backend->priv->folders_lock);
        g_mutex_init (&backend->priv->sync_state_lock);
@@ -1051,7 +1041,7 @@ ews_backend_ref_connection_thread (GSimpleAsyncResult *simple,
 
        if (connection != NULL)
                g_simple_async_result_set_op_res_gpointer (
-                       simple, connection, (GDestroyNotify) g_object_unref);
+                       simple, connection, g_object_unref);
 
        if (error != NULL)
                g_simple_async_result_take_error (simple, error);
diff --git a/src/configuration/e-mail-config-ews-delegates-page.c 
b/src/configuration/e-mail-config-ews-delegates-page.c
index 4842ba8..f6c6adb 100644
--- a/src/configuration/e-mail-config-ews-delegates-page.c
+++ b/src/configuration/e-mail-config-ews-delegates-page.c
@@ -166,7 +166,7 @@ mail_config_ews_delegates_page_get_mailbox (EMailConfigEwsDelegatesPage *page)
                break;
        }
 
-       g_list_free_full (list, (GDestroyNotify) g_object_unref);
+       g_list_free_full (list, g_object_unref);
 
        return mailbox;
 }
diff --git a/src/configuration/e-mail-config-ews-ooo-page.c b/src/configuration/e-mail-config-ews-ooo-page.c
index cb4722a..acc958d 100644
--- a/src/configuration/e-mail-config-ews-ooo-page.c
+++ b/src/configuration/e-mail-config-ews-ooo-page.c
@@ -157,7 +157,7 @@ mail_config_ews_ooo_page_get_mailbox (EMailConfigEwsOooPage *page)
                break;
        }
 
-       g_list_free_full (list, (GDestroyNotify) g_object_unref);
+       g_list_free_full (list, g_object_unref);
 
        return mailbox;
 }
diff --git a/src/server/e-ews-connection.c b/src/server/e-ews-connection.c
index 7a6c10d..749b503 100644
--- a/src/server/e-ews-connection.c
+++ b/src/server/e-ews-connection.c
@@ -1303,15 +1303,11 @@ ews_connection_dispose (GObject *object)
 
        e_ews_connection_set_password (E_EWS_CONNECTION (object), NULL);
 
-       if (priv->jobs) {
-               g_slist_free (priv->jobs);
-               priv->jobs = NULL;
-       }
+       g_slist_free (priv->jobs);
+       priv->jobs = NULL;
 
-       if (priv->active_job_queue) {
-               g_slist_free (priv->active_job_queue);
-               priv->active_job_queue = NULL;
-       }
+       g_slist_free (priv->active_job_queue);
+       priv->active_job_queue = NULL;
 
        /* Chain up to parent's dispose() method. */
        G_OBJECT_CLASS (e_ews_connection_parent_class)->dispose (object);
@@ -1365,7 +1361,7 @@ ews_connection_try_password_sync (ESourceAuthenticator *authenticator,
                connection, EWS_PRIORITY_MEDIUM, "Default",
                NULL, ids, &folders, cancellable, &local_error);
 
-       g_slist_free_full (folders, (GDestroyNotify) g_object_unref);
+       g_slist_free_full (folders, g_object_unref);
        g_slist_free_full (ids, (GDestroyNotify) e_ews_folder_id_free);
 
        if (local_error == NULL) {
@@ -2317,7 +2313,7 @@ e_ews_autodiscover_ws_url (CamelEwsSettings *settings,
                        ad->cancellable,
                        G_CALLBACK (autodiscover_cancelled_cb),
                        g_object_ref (cnc),
-                       (GDestroyNotify) g_object_unref);
+                       g_object_unref);
        }
 
        g_simple_async_result_set_op_res_gpointer (
@@ -5884,48 +5880,56 @@ e_ews_connection_create_attachments (EEwsConnection *cnc,
        g_object_unref (simple);
 }
 
-GSList *
+gboolean
 e_ews_connection_create_attachments_finish (EEwsConnection *cnc,
                                             gchar **change_key,
+                                           GSList **attachments_ids,
                                             GAsyncResult *result,
                                             GError **error)
 {
        GSimpleAsyncResult *simple;
        EwsAsyncData *async_data;
-       GSList *ids = NULL;
 
-       g_return_val_if_fail (cnc != NULL, NULL);
+       g_return_val_if_fail (cnc != NULL, FALSE);
        g_return_val_if_fail (
                g_simple_async_result_is_valid (
                result, G_OBJECT (cnc), e_ews_connection_create_attachments),
-               NULL);
+               FALSE);
 
        simple = G_SIMPLE_ASYNC_RESULT (result);
        async_data = g_simple_async_result_get_op_res_gpointer (simple);
 
        if (g_simple_async_result_propagate_error (simple, error))
-               return NULL;
+               return FALSE;
+
+       if (attachments_ids)
+               *attachments_ids = async_data->items;
+       else
+               g_slist_free_full (async_data->items, g_free);
 
-       ids = async_data->items;
-       *change_key = async_data->sync_state;
+       if (change_key)
+               *change_key = async_data->sync_state;
+       else
+               g_free (async_data->sync_state);
 
-       return ids;
+       return TRUE;
 }
 
-GSList *
+gboolean
 e_ews_connection_create_attachments_sync (EEwsConnection *cnc,
                                           gint pri,
                                           const EwsId *parent,
                                           const GSList *files,
                                           gchar **change_key,
+                                         GSList **attachments_ids,
                                           GCancellable *cancellable,
                                           GError **error)
 {
        EAsyncClosure *closure;
        GAsyncResult *result;
-       GSList *ids;
+       gboolean ret;
 
-       g_return_val_if_fail (cnc != NULL, NULL);
+       g_return_val_if_fail (cnc != NULL, FALSE);
 
        closure = e_async_closure_new ();
 
@@ -5935,12 +5939,12 @@ e_ews_connection_create_attachments_sync (EEwsConnection *cnc,
 
        result = e_async_closure_wait (closure);
 
-       ids = e_ews_connection_create_attachments_finish (
-               cnc, change_key, result, error);
+       ret = e_ews_connection_create_attachments_finish (
+               cnc, change_key, attachments_ids, result, error);
 
        e_async_closure_free (closure);
 
-       return ids;
+       return ret;
 }
 
 /* Delete attachemnts */
@@ -6006,7 +6010,7 @@ delete_attachments_response_cb (ESoapResponse *response,
 void
 e_ews_connection_delete_attachments (EEwsConnection *cnc,
                                      gint pri,
-                                     const GSList *ids,
+                                     const GSList *attachments_ids,
                                      GCancellable *cancellable,
                                      GAsyncReadyCallback callback,
                                      gpointer user_data)
@@ -6023,7 +6027,7 @@ e_ews_connection_delete_attachments (EEwsConnection *cnc,
        /* start interation over all items to get the attachemnts */
        e_soap_message_start_element (msg, "AttachmentIds", "messages", NULL);
 
-       for (l = ids; l != NULL; l = g_slist_next (l)) {
+       for (l = attachments_ids; l != NULL; l = l->next) {
                e_ews_message_write_string_parameter_with_attribute (msg, "AttachmentId", NULL, NULL, "Id", 
l->data);
        }
 
@@ -6046,59 +6050,63 @@ e_ews_connection_delete_attachments (EEwsConnection *cnc,
        g_object_unref (simple);
 }
 
-GSList *
+gboolean
 e_ews_connection_delete_attachments_finish (EEwsConnection *cnc,
                                             GAsyncResult *result,
+                                           GSList **parents_ids,
                                             GError **error)
 {
        GSimpleAsyncResult *simple;
        EwsAsyncData *async_data;
-       GSList *ids = NULL;
 
-       g_return_val_if_fail (cnc != NULL, NULL);
+       g_return_val_if_fail (cnc != NULL, FALSE);
        g_return_val_if_fail (
                g_simple_async_result_is_valid (
                result, G_OBJECT (cnc), e_ews_connection_delete_attachments),
-               NULL);
+               FALSE);
 
        simple = G_SIMPLE_ASYNC_RESULT (result);
        async_data = g_simple_async_result_get_op_res_gpointer (simple);
 
        if (g_simple_async_result_propagate_error (simple, error))
-               return NULL;
+               return FALSE;
 
-       ids = async_data->items;
+       if (parents_ids)
+               *parents_ids = async_data->items;
+       else
+               g_slist_free_full (async_data->items, g_free);
 
-       return ids;
+       return TRUE;
 }
 
-GSList *
+gboolean
 e_ews_connection_delete_attachments_sync (EEwsConnection *cnc,
                                           gint pri,
-                                          const GSList *ids,
+                                          const GSList *attachments_ids,
+                                         GSList **parents_ids,
                                           GCancellable *cancellable,
                                           GError **error)
 {
        EAsyncClosure *closure;
        GAsyncResult *result;
-       GSList *parents;
+       gboolean ret;
 
-       g_return_val_if_fail (cnc != NULL, NULL);
+       g_return_val_if_fail (cnc != NULL, FALSE);
 
        closure = e_async_closure_new ();
 
        e_ews_connection_delete_attachments (
-               cnc, pri, ids, cancellable,
+               cnc, pri, attachments_ids, cancellable,
                e_async_closure_callback, closure);
 
        result = e_async_closure_wait (closure);
 
-       parents = e_ews_connection_delete_attachments_finish (
-               cnc, result, error);
+       ret = e_ews_connection_delete_attachments_finish (
+               cnc, result, parents_ids, error);
 
        e_async_closure_free (closure);
 
-       return parents;
+       return ret;
 }
 
 static void
@@ -6107,7 +6115,6 @@ ews_handle_attachments_param (ESoapParameter *param,
 {
        ESoapParameter *subparam, *attspara;
        EEwsAttachmentInfo *info = NULL;
-       gchar *attach_id = NULL;
        EEwsItem *item;
        const gchar *name;
 
@@ -6118,26 +6125,21 @@ ews_handle_attachments_param (ESoapParameter *param,
 
                if (!g_ascii_strcasecmp (name, "ItemAttachment")) {
                        item = e_ews_item_new_from_soap_parameter (subparam);
-                       attach_id = g_strdup (e_ews_item_get_attachment_id (item)->id);
                        info = e_ews_item_dump_mime_content (item, async_data->directory);
 
                } else if (!g_ascii_strcasecmp (name, "FileAttachment")) {
                        info = e_ews_dump_file_attachment_from_soap_parameter (
                                        subparam,
                                        async_data->directory,
-                                       async_data->sync_state,
-                                       &attach_id);
+                                       async_data->sync_state);
                }
 
-               if (info && attach_id) {
+               if (info)
                        async_data->items = g_slist_append (async_data->items, info);
-                       async_data->items_created = g_slist_append (async_data->items_created, attach_id);
-               } else {
+               else
                        e_ews_attachment_info_free (info);
-                       g_free (attach_id);
-               }
+
                info = NULL;
-               attach_id = NULL;
        }
 }
 
@@ -6243,7 +6245,7 @@ e_ews_connection_get_attachments (EEwsConnection *cnc,
        g_object_unref (simple);
 }
 
-GSList *
+gboolean
 e_ews_connection_get_attachments_finish (EEwsConnection *cnc,
                                          GAsyncResult *result,
                                          GSList **items,
@@ -6252,24 +6254,27 @@ e_ews_connection_get_attachments_finish (EEwsConnection *cnc,
        GSimpleAsyncResult *simple;
        EwsAsyncData *async_data;
 
-       g_return_val_if_fail (cnc != NULL, NULL);
+       g_return_val_if_fail (cnc != NULL, FALSE);
        g_return_val_if_fail (
                g_simple_async_result_is_valid (
                result, G_OBJECT (cnc), e_ews_connection_get_attachments),
-               NULL);
+               FALSE);
 
        simple = G_SIMPLE_ASYNC_RESULT (result);
        async_data = g_simple_async_result_get_op_res_gpointer (simple);
 
        if (g_simple_async_result_propagate_error (simple, error))
-               return NULL;
+               return FALSE;
 
-       *items = async_data->items;
+       if (items)
+               *items = async_data->items;
+       else
+               g_slist_free_full (async_data->items, (GDestroyNotify) e_ews_attachment_info_free);
 
-       return async_data->items_created;
+       return TRUE;
 }
 
-GSList *
+gboolean
 e_ews_connection_get_attachments_sync (EEwsConnection *cnc,
                                        gint pri,
                                        const gchar *uid,
@@ -6284,9 +6289,9 @@ e_ews_connection_get_attachments_sync (EEwsConnection *cnc,
 {
        EAsyncClosure *closure;
        GAsyncResult *result;
-       GSList *attachments_ids;
+       gboolean ret;
 
-       g_return_val_if_fail (cnc != NULL, NULL);
+       g_return_val_if_fail (cnc != NULL, FALSE);
 
        closure = e_async_closure_new ();
 
@@ -6297,12 +6302,12 @@ e_ews_connection_get_attachments_sync (EEwsConnection *cnc,
 
        result = e_async_closure_wait (closure);
 
-       attachments_ids = e_ews_connection_get_attachments_finish (
+       ret = e_ews_connection_get_attachments_finish (
                cnc, result, items, error);
 
        e_async_closure_free (closure);
 
-       return attachments_ids;
+       return ret;
 }
 
 void
@@ -6472,44 +6477,49 @@ e_ews_connection_create_photo_attachment (EEwsConnection *cnc,
        g_object_unref (simple);
 }
 
-GSList *
+gboolean
 e_ews_connection_create_photo_attachment_finish (EEwsConnection *cnc,
                                                 GAsyncResult *result,
+                                                GSList **parents_ids,
                                                 GError **error)
 {
        GSimpleAsyncResult *simple;
        EwsAsyncData *async_data;
-       GSList *ids;
 
-       g_return_val_if_fail (cnc != NULL, NULL);
+       g_return_val_if_fail (cnc != NULL, FALSE);
        g_return_val_if_fail (
                g_simple_async_result_is_valid (
                result, G_OBJECT (cnc), e_ews_connection_create_photo_attachment),
-               NULL);
+               FALSE);
 
        simple = G_SIMPLE_ASYNC_RESULT (result);
        async_data = g_simple_async_result_get_op_res_gpointer (simple);
 
        if (g_simple_async_result_propagate_error (simple, error))
-               return NULL;
+               return FALSE;
+
+       if (parents_ids)
+               *parents_ids = async_data->items;
+       else
+               g_slist_free_full (async_data->items, g_free);
 
-       ids = async_data->items;
-       return ids;
+       return TRUE;
 }
 
-GSList *
+gboolean
 e_ews_connection_create_photo_attachment_sync (EEwsConnection *cnc,
                                               gint pri,
                                               const EwsId *parent,
                                               const GSList *files,
+                                              GSList **parents_ids,
                                               GCancellable *cancellable,
                                               GError **error)
 {
        EAsyncClosure *closure;
        GAsyncResult *result;
-       GSList *ids;
+       gboolean ret;
 
-       g_return_val_if_fail (cnc != NULL, NULL);
+       g_return_val_if_fail (cnc != NULL, FALSE);
 
        closure = e_async_closure_new ();
 
@@ -6519,11 +6529,11 @@ e_ews_connection_create_photo_attachment_sync (EEwsConnection *cnc,
 
        result = e_async_closure_wait (closure);
 
-       ids = e_ews_connection_create_photo_attachment_finish (cnc, result, error);
+       ret = e_ews_connection_create_photo_attachment_finish (cnc, result, parents_ids, error);
 
        e_async_closure_free (closure);
 
-       return ids;
+       return ret;
 }
 
 static void
diff --git a/src/server/e-ews-connection.h b/src/server/e-ews-connection.h
index 6a6fd16..5598e50 100644
--- a/src/server/e-ews-connection.h
+++ b/src/server/e-ews-connection.h
@@ -354,15 +354,17 @@ void              e_ews_connection_create_photo_attachment
                                                 GCancellable *cancellable,
                                                 GAsyncReadyCallback callback,
                                                 gpointer user_data);
-GSList *       e_ews_connection_create_photo_attachment_finish
+gboolean       e_ews_connection_create_photo_attachment_finish
                                                (EEwsConnection *cnc,
                                                 GAsyncResult *result,
+                                                GSList **parents_ids,
                                                 GError **error);
-GSList *       e_ews_connection_create_photo_attachment_sync
+gboolean       e_ews_connection_create_photo_attachment_sync
                                                (EEwsConnection *cnc,
                                                 gint pri,
                                                 const EwsId *parent,
                                                 const GSList *files,
+                                                GSList **parents_ids,
                                                 GCancellable *cancellable,
                                                 GError **error);
 
@@ -722,35 +724,39 @@ void              e_ews_connection_create_attachments
                                                 GCancellable *cancellable,
                                                 GAsyncReadyCallback callback,
                                                 gpointer user_data);
-GSList *       e_ews_connection_create_attachments_finish
+gboolean       e_ews_connection_create_attachments_finish
                                                (EEwsConnection *cnc,
                                                 gchar **change_key,
+                                                GSList **attachments_ids,
                                                 GAsyncResult *result,
                                                 GError **error);
-GSList *       e_ews_connection_create_attachments_sync
+gboolean       e_ews_connection_create_attachments_sync
                                                (EEwsConnection *cnc,
                                                 gint pri,
                                                 const EwsId *parent,
                                                 const GSList *files,
                                                 gchar **change_key,
+                                                GSList **attachments_ids,
                                                 GCancellable *cancellable,
                                                 GError **error);
 
 void           e_ews_connection_delete_attachments
                                                (EEwsConnection *cnc,
                                                 gint pri,
-                                                const GSList *ids,
+                                                const GSList *attachments_ids,
                                                 GCancellable *cancellable,
                                                 GAsyncReadyCallback callback,
                                                 gpointer user_data);
-GSList *       e_ews_connection_delete_attachments_finish
+gboolean       e_ews_connection_delete_attachments_finish
                                                (EEwsConnection *cnc,
                                                 GAsyncResult *result,
+                                                GSList **parents_ids,
                                                 GError **error);
-GSList *       e_ews_connection_delete_attachments_sync
+gboolean       e_ews_connection_delete_attachments_sync
                                                (EEwsConnection *cnc,
                                                 gint pri,
-                                                const GSList *ids,
+                                                const GSList *attachments_ids,
+                                                GSList **parents_ids,
                                                 GCancellable *cancellable,
                                                 GError **error);
 
@@ -766,12 +772,12 @@ void              e_ews_connection_get_attachments
                                                 GCancellable *cancellable,
                                                 GAsyncReadyCallback callback,
                                                 gpointer user_data);
-GSList *       e_ews_connection_get_attachments_finish
+gboolean       e_ews_connection_get_attachments_finish
                                                (EEwsConnection *cnc,
                                                 GAsyncResult *result,
                                                 GSList **items,
                                                 GError **error);
-GSList *       e_ews_connection_get_attachments_sync
+gboolean       e_ews_connection_get_attachments_sync
                                                (EEwsConnection *cnc,
                                                 gint pri,
                                                 const gchar *comp_uid,
diff --git a/src/server/e-ews-folder.c b/src/server/e-ews-folder.c
index 17d2e8a..98ee323 100644
--- a/src/server/e-ews-folder.c
+++ b/src/server/e-ews-folder.c
@@ -350,8 +350,7 @@ e_ews_folder_set_name (EEwsFolder *folder,
 
        priv = folder->priv;
 
-       if (priv->name)
-               g_free (priv->name);
+       g_free (priv->name);
        priv->name = g_strdup (new_name);
 }
 
diff --git a/src/server/e-ews-item.c b/src/server/e-ews-item.c
index fe9a798..365e73d 100644
--- a/src/server/e-ews-item.c
+++ b/src/server/e-ews-item.c
@@ -188,7 +188,7 @@ struct _EEwsItemPrivate {
        EwsMailbox *sender;
 
        GSList *modified_occurrences;
-       GSList *attachments_list;
+       GSList *attachments_ids;
        GSList *attendees;
 
        EwsId *calendar_item_accept_id;
@@ -258,41 +258,23 @@ e_ews_item_dispose (GObject *object)
        g_free (priv->contact_photo_id);
        priv->contact_photo_id = NULL;
 
-       if (priv->to_recipients) {
-               g_slist_foreach (priv->to_recipients, (GFunc) e_ews_mailbox_free, NULL);
-               g_slist_free (priv->to_recipients);
-               priv->to_recipients = NULL;
-       }
+       g_slist_free_full (priv->to_recipients, (GDestroyNotify) e_ews_mailbox_free);
+       priv->to_recipients = NULL;
 
-       if (priv->cc_recipients) {
-               g_slist_foreach (priv->cc_recipients, (GFunc) e_ews_mailbox_free, NULL);
-               g_slist_free (priv->cc_recipients);
-               priv->cc_recipients = NULL;
-       }
+       g_slist_free_full (priv->cc_recipients, (GDestroyNotify) e_ews_mailbox_free);
+       priv->cc_recipients = NULL;
 
-       if (priv->bcc_recipients) {
-               g_slist_foreach (priv->bcc_recipients, (GFunc) e_ews_mailbox_free, NULL);
-               g_slist_free (priv->bcc_recipients);
-               priv->bcc_recipients = NULL;
-       }
+       g_slist_free_full (priv->bcc_recipients, (GDestroyNotify) e_ews_mailbox_free);
+       priv->bcc_recipients = NULL;
 
-       if (priv->modified_occurrences) {
-               g_slist_foreach (priv->modified_occurrences, (GFunc) g_free, NULL);
-               g_slist_free (priv->modified_occurrences);
-               priv->modified_occurrences = NULL;
-       }
+       g_slist_free_full (priv->modified_occurrences, g_free);
+       priv->modified_occurrences = NULL;
 
-       if (priv->attachments_list) {
-               g_slist_foreach (priv->attachments_list, (GFunc) g_free, NULL);
-               g_slist_free (priv->attachments_list);
-               priv->attachments_list = NULL;
-       }
+       g_slist_free_full (priv->attachments_ids, g_free);
+       priv->attachments_ids = NULL;
 
-       if (priv->attendees) {
-               g_slist_foreach (priv->attendees, (GFunc) ews_item_free_attendee, NULL);
-               g_slist_free (priv->attendees);
-               priv->attendees = NULL;
-       }
+       g_slist_free_full (priv->attendees, (GDestroyNotify) ews_item_free_attendee);
+       priv->attendees = NULL;
 
        if (priv->calendar_item_accept_id) {
                g_free (priv->calendar_item_accept_id->id);
@@ -537,11 +519,8 @@ parse_categories (EEwsItemPrivate *priv,
        ESoapParameter *subparam;
 
        /* release all the old data (if any) */
-       if (priv->categories) {
-               g_slist_foreach (priv->categories, (GFunc) g_free, NULL);
-               g_slist_free (priv->categories);
-               priv->categories = NULL;
-       }
+       g_slist_free_full (priv->categories, g_free);
+       priv->categories = NULL;
 
        /* categories are an array of <string> */
        for (subparam = e_soap_parameter_get_first_child (param);
@@ -594,7 +573,7 @@ process_attachments_list (EEwsItemPrivate *priv,
 {
        ESoapParameter *subparam, *subparam1;
 
-       GSList *list = NULL;
+       GSList *ids = NULL;
 
        for (subparam = e_soap_parameter_get_first_child (param); subparam != NULL; subparam = 
e_soap_parameter_get_next_child (subparam)) {
                gchar *id;
@@ -613,10 +592,10 @@ process_attachments_list (EEwsItemPrivate *priv,
                        g_free (value);
                }
 
-               list = g_slist_append (list, id);
+               ids = g_slist_append (ids, id);
        }
 
-       priv->attachments_list = list;
+       priv->attachments_ids = ids;
        return;
 }
 
@@ -1508,7 +1487,7 @@ e_ews_item_get_attachments_ids (EEwsItem *item)
 {
        g_return_val_if_fail (E_IS_EWS_ITEM (item), NULL);
 
-       return item->priv->attachments_list;
+       return item->priv->attachments_ids;
 }
 
 gchar *
@@ -1532,6 +1511,7 @@ e_ews_embed_attachment_id_in_uri (const gchar *olduri,
                g_warning ("Failed to move attachment cache file [%s -> %s]: %s\n", tmpfilename, filename, 
strerror (errno));
        }
 
+       g_free (tmpfilename);
        g_free (tmpdir);
 
        return g_filename_to_uri (filename, NULL, NULL);
@@ -1540,8 +1520,7 @@ e_ews_embed_attachment_id_in_uri (const gchar *olduri,
 EEwsAttachmentInfo *
 e_ews_dump_file_attachment_from_soap_parameter (ESoapParameter *param,
                                                 const gchar *cache,
-                                                const gchar *comp_uid,
-                                                gchar **attach_id)
+                                                const gchar *comp_uid)
 {
        ESoapParameter *subparam;
        const gchar *param_name, *tmpfilename;
@@ -1554,7 +1533,6 @@ e_ews_dump_file_attachment_from_soap_parameter (ESoapParameter *param,
        g_return_val_if_fail (param != NULL, NULL);
 
        /* Parse element, look for filename and content */
-       *attach_id = NULL;
        for (subparam = e_soap_parameter_get_first_child (param); subparam != NULL; subparam = 
e_soap_parameter_get_next_child (subparam)) {
                param_name = e_soap_parameter_get_name (subparam);
 
@@ -1566,16 +1544,13 @@ e_ews_dump_file_attachment_from_soap_parameter (ESoapParameter *param,
                        value = e_soap_parameter_get_string_value (subparam);
                        content = g_base64_decode (value, &data_len);
                        g_free (value);
-               } else if (g_ascii_strcasecmp (param_name, "AttachmentId") == 0) {
-                       *attach_id = e_soap_parameter_get_property (subparam, "Id");
                }
        }
 
        /* Make sure we have needed data */
-       if (!content || !name || !*attach_id) {
+       if (!content || !name) {
                g_free (name);
                g_free (content);
-               g_free (*attach_id);
                return NULL;
        }
 
diff --git a/src/server/e-ews-item.h b/src/server/e-ews-item.h
index 2f3d26a..5cff519 100644
--- a/src/server/e-ews-item.h
+++ b/src/server/e-ews-item.h
@@ -225,7 +225,7 @@ GSList *    e_ews_item_get_attachments_ids
                                                (EEwsItem *item);
 
 EEwsAttachmentInfo *
-e_ews_dump_file_attachment_from_soap_parameter (ESoapParameter *param, const gchar *cache, const gchar 
*comp_uid, gchar **attach_id);
+e_ews_dump_file_attachment_from_soap_parameter (ESoapParameter *param, const gchar *cache, const gchar 
*comp_uid);
 
 gchar *
 e_ews_item_ical_dump (EEwsItem *item);



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