[evolution-ews] Bug #711148 - Ensure that ews_discover_server_version() will be called on the first connection for C



commit 9cb22cded530aeb4de453bbefb894bf3b2c02b26
Author: Fabiano Fidêncio <fidencio redhat com>
Date:   Wed Oct 30 14:45:42 2013 +0100

    Bug #711148 - Ensure that ews_discover_server_version() will be called on the first connection for 
Calendar/Camel

 src/addressbook/e-book-backend-ews.c |    2 -
 src/calendar/e-cal-backend-ews.c     |   76 +++------------------------------
 src/server/e-ews-connection.c        |   19 +++++++-
 3 files changed, 23 insertions(+), 74 deletions(-)
---
diff --git a/src/addressbook/e-book-backend-ews.c b/src/addressbook/e-book-backend-ews.c
index b5c34c0..a3c5a53 100644
--- a/src/addressbook/e-book-backend-ews.c
+++ b/src/addressbook/e-book-backend-ews.c
@@ -3781,8 +3781,6 @@ book_backend_ews_try_password_sync (ESourceAuthenticator *authenticator,
        CamelEwsSettings *ews_settings;
        gchar *hosturl;
 
-       /* This tests the password by fetching the contacts folder. */
-
        backend = E_BOOK_BACKEND_EWS (authenticator);
        ews_settings = book_backend_ews_get_collection_settings (backend);
        hosturl = camel_ews_settings_dup_hosturl (ews_settings);
diff --git a/src/calendar/e-cal-backend-ews.c b/src/calendar/e-cal-backend-ews.c
index b180cec..e30d9e6 100644
--- a/src/calendar/e-cal-backend-ews.c
+++ b/src/calendar/e-cal-backend-ews.c
@@ -4487,105 +4487,43 @@ cal_backend_ews_try_password_sync (ESourceAuthenticator *authenticator,
                                    GError **error)
 {
        ECalBackendEws *backend;
-       ECalBackendStore *store;
        EEwsConnection *connection;
        ESourceAuthenticationResult result;
        CamelEwsSettings *ews_settings;
-       GSList *items_created = NULL;
-       GSList *items_updated = NULL;
-       GSList *items_deleted = NULL;
-       gboolean includes_last_item = FALSE;
-       const gchar *old_sync_state;
-       gchar *new_sync_state = NULL;
        gchar *hosturl;
-       GError *local_error = NULL;
-
-       /* This tests the password by synchronizing the folder. */
 
        backend = E_CAL_BACKEND_EWS (authenticator);
        ews_settings = cal_backend_ews_get_collection_settings (backend);
        hosturl = camel_ews_settings_dup_hosturl (ews_settings);
 
        connection = e_ews_connection_new (hosturl, ews_settings);
-       e_ews_connection_set_password (connection, password->str);
-
-       g_free (hosturl);
 
        g_object_bind_property (
                backend, "proxy-resolver",
                connection, "proxy-resolver",
                G_BINDING_SYNC_CREATE);
 
-       store = backend->priv->store;
-       old_sync_state = e_cal_backend_store_get_key_value (store, SYNC_KEY);
+       result = e_source_authenticator_try_password_sync (
+               E_SOURCE_AUTHENTICATOR (connection),
+               password, cancellable, error);
 
-       /* fetch only up to one item, it's to check whether connection works */
-       e_ews_connection_sync_folder_items_sync (
-               connection,
-               EWS_PRIORITY_MEDIUM,
-               old_sync_state,
-               backend->priv->folder_id,
-               "IdOnly", NULL, 1,
-               &new_sync_state,
-               &includes_last_item,
-               &items_created,
-               &items_updated,
-               &items_deleted,
-               cancellable, &local_error);
-
-       if (g_error_matches (local_error, EWS_CONNECTION_ERROR, EWS_CONNECTION_ERROR_INVALIDSYNCSTATEDATA)) {
-               g_clear_error (&local_error);
-               e_cal_backend_store_put_key_value (store, SYNC_KEY, NULL);
-               cbews_forget_all_components (backend);
-
-               e_ews_connection_sync_folder_items_sync (connection, EWS_PRIORITY_MEDIUM, NULL, 
backend->priv->folder_id, "IdOnly", NULL, 1,
-                       &new_sync_state, &includes_last_item, &items_created, &items_updated, &items_deleted,
-                       cancellable, &local_error);
-       }
+       if (result == E_SOURCE_AUTHENTICATION_ACCEPTED) {
 
-       if (local_error == NULL) {
                PRIV_LOCK (backend->priv);
-               if (backend->priv->user_email)
-                       g_free (backend->priv->user_email);
-               backend->priv->user_email = camel_ews_settings_dup_email (ews_settings);
 
                if (backend->priv->cnc != NULL)
                        g_object_unref (backend->priv->cnc);
                backend->priv->cnc = g_object_ref (connection);
-               PRIV_UNLOCK (backend->priv);
 
-               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);
+               PRIV_UNLOCK (backend->priv);
 
                ews_start_sync (backend);
-
-               result = E_SOURCE_AUTHENTICATION_ACCEPTED;
-
-       } else {
-               gboolean auth_failed;
-
-               /* Make sure we're not leaking anything. */
-               g_warn_if_fail (items_created == NULL);
-               g_warn_if_fail (items_updated == NULL);
-               g_warn_if_fail (items_deleted == NULL);
-
-               auth_failed = g_error_matches (
-                       local_error, EWS_CONNECTION_ERROR,
-                       EWS_CONNECTION_ERROR_AUTHENTICATION_FAILED);
-
-               if (auth_failed) {
-                       g_clear_error (&local_error);
-                       result = E_SOURCE_AUTHENTICATION_REJECTED;
-               } else {
-                       g_propagate_error (error, local_error);
-                       result = E_SOURCE_AUTHENTICATION_ERROR;
-               }
        }
 
-       g_free (new_sync_state);
        g_object_unref (connection);
 
+       g_free (hosturl);
+
        return result;
 }
 
diff --git a/src/server/e-ews-connection.c b/src/server/e-ews-connection.c
index 8c7bb66..fee3d5c 100644
--- a/src/server/e-ews-connection.c
+++ b/src/server/e-ews-connection.c
@@ -887,6 +887,16 @@ sync_hierarchy_response_cb (ESoapResponse *response,
 
        async_data = g_simple_async_result_get_op_res_gpointer (simple);
 
+       /*
+        * During the first connection, we are able to get the current version of the Exchange server.
+        * For Addressbook/Calendar backends, we are ensuring it happens during the
+        * ews_connection_try_password_sync(), that calls e_e_ews_connection_get_folder_sync() and then
+        * we are able to get the current version of the server from this first response.
+        *
+        * For Camel, the first connection is done calling e_ews_connection_sync_folder_hierarchy_sync().
+        */
+       ews_discover_server_version (async_data->cnc, response);
+
        param = e_soap_response_get_first_parameter_by_name (
                response, "ResponseMessages", &error);
 
@@ -992,9 +1002,11 @@ get_folder_response_cb (ESoapResponse *response,
 
        /*
         * During the first connection, we are able to get the current version of the Exchange server.
-        * We are ensuring it happens during the ews_connection_try_password_sync(), that calls
-        * ews_connection_get_folder_sync() and then we are able to get the current version of the
-        * server from this first response.
+        * For Addressbook/Calendar backends, we are ensuring it happens during the
+        * ews_connection_try_password_sync(), that calls e_e_ews_connection_get_folder_sync() and then
+        * we are able to get the current version of the server from this first response.
+        *
+        * For Camel, the first connection is done calling e_ews_connection_sync_folder_hierarchy_sync().
         */
        ews_discover_server_version (async_data->cnc, response);
 
@@ -3996,6 +4008,7 @@ e_ews_connection_sync_folder_hierarchy (EEwsConnection *cnc,
                e_ews_connection_sync_folder_hierarchy);
 
        async_data = g_new0 (EwsAsyncData, 1);
+       async_data->cnc = cnc;
        g_simple_async_result_set_op_res_gpointer (
                simple, async_data, (GDestroyNotify) async_data_free);
 


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