[evolution-ews] I#64 - "Listen for server notifications" does not work with OAuth2



commit c3d1d3a89928ef923d523bab203fec701ef11c06
Author: Milan Crha <mcrha redhat com>
Date:   Tue Oct 8 18:22:36 2019 +0200

    I#64 - "Listen for server notifications" does not work with OAuth2
    
    Closes https://gitlab.gnome.org/GNOME/evolution-ews/issues/64

 src/server/e-ews-connection-utils.c | 20 ++++++++++++--------
 src/server/e-ews-connection-utils.h |  1 +
 src/server/e-ews-connection.c       |  4 ++--
 src/server/e-ews-notification.c     | 15 +++++++++++++++
 4 files changed, 30 insertions(+), 10 deletions(-)
---
diff --git a/src/server/e-ews-connection-utils.c b/src/server/e-ews-connection-utils.c
index 360844ed..00fc8415 100644
--- a/src/server/e-ews-connection-utils.c
+++ b/src/server/e-ews-connection-utils.c
@@ -301,6 +301,7 @@ ews_connection_utils_ensure_bearer_auth_usage (SoupSession *session,
 
 static gboolean
 ews_connection_utils_setup_bearer_auth (EEwsConnection *cnc,
+                                       SoupSession *session,
                                        SoupMessage *message,
                                        gboolean is_in_authenticate_handler,
                                        ESoupAuthBearer *bearer,
@@ -324,9 +325,10 @@ ews_connection_utils_setup_bearer_auth (EEwsConnection *cnc,
                e_soup_auth_bearer_set_access_token (bearer, access_token, expires_in_seconds);
 
                if (!is_in_authenticate_handler) {
-                       SoupSession *session;
-
-                       session = e_ews_connection_ref_soup_session (cnc);
+                       if (session)
+                               g_object_ref (session);
+                       else
+                               session = e_ews_connection_ref_soup_session (cnc);
 
                        ews_connection_utils_ensure_bearer_auth_usage (session, message, bearer);
 
@@ -341,6 +343,7 @@ ews_connection_utils_setup_bearer_auth (EEwsConnection *cnc,
 
 static gboolean
 ews_connection_utils_maybe_prepare_bearer_auth (EEwsConnection *cnc,
+                                               SoupSession *session,
                                                SoupMessage *message,
                                                GCancellable *cancellable)
 {
@@ -387,7 +390,7 @@ ews_connection_utils_maybe_prepare_bearer_auth (EEwsConnection *cnc,
 
        using_bearer_auth = e_ews_connection_ref_bearer_auth (cnc);
        if (using_bearer_auth) {
-               success = ews_connection_utils_setup_bearer_auth (cnc, message, FALSE, using_bearer_auth, 
cancellable, &local_error);
+               success = ews_connection_utils_setup_bearer_auth (cnc, session, message, FALSE, 
using_bearer_auth, cancellable, &local_error);
                g_clear_object (&using_bearer_auth);
        } else {
                SoupAuth *soup_auth;
@@ -409,7 +412,7 @@ ews_connection_utils_maybe_prepare_bearer_auth (EEwsConnection *cnc,
 
                soup_auth = g_object_new (E_TYPE_SOUP_AUTH_BEARER, SOUP_AUTH_HOST, soup_uri->host, NULL);
 
-               success = ews_connection_utils_setup_bearer_auth (cnc, message, FALSE, E_SOUP_AUTH_BEARER 
(soup_auth), cancellable, &local_error);
+               success = ews_connection_utils_setup_bearer_auth (cnc, session, message, FALSE, 
E_SOUP_AUTH_BEARER (soup_auth), cancellable, &local_error);
                if (success)
                        e_ews_connection_set_bearer_auth (cnc, E_SOUP_AUTH_BEARER (soup_auth));
 
@@ -465,7 +468,7 @@ e_ews_connection_utils_authenticate (EEwsConnection *cnc,
        if (using_bearer_auth) {
                GError *local_error = NULL;
 
-               ews_connection_utils_setup_bearer_auth (cnc, msg, TRUE, E_SOUP_AUTH_BEARER (auth), NULL, 
&local_error);
+               ews_connection_utils_setup_bearer_auth (cnc, session, msg, TRUE, E_SOUP_AUTH_BEARER (auth), 
NULL, &local_error);
 
                if (local_error)
                        soup_message_set_status_full (msg, SOUP_STATUS_IO_ERROR, local_error->message);
@@ -518,6 +521,7 @@ e_ews_connection_utils_authenticate (EEwsConnection *cnc,
 /* Returns whether succeeded */
 gboolean
 e_ews_connection_utils_prepare_message (EEwsConnection *cnc,
+                                       SoupSession *session,
                                        SoupMessage *message,
                                        GCancellable *cancellable)
 {
@@ -529,14 +533,14 @@ e_ews_connection_utils_prepare_message (EEwsConnection *cnc,
        if (source)
                e_soup_ssl_trust_connect (message, source);
 
-       if (!ews_connection_utils_maybe_prepare_bearer_auth (cnc, message, cancellable))
+       if (!ews_connection_utils_maybe_prepare_bearer_auth (cnc, session, message, cancellable))
                return FALSE;
 
        using_bearer_auth = e_ews_connection_ref_bearer_auth (cnc);
 
        if (using_bearer_auth &&
            e_soup_auth_bearer_is_expired (using_bearer_auth) &&
-           !ews_connection_utils_setup_bearer_auth (cnc, message, FALSE, using_bearer_auth, cancellable, 
&local_error)) {
+           !ews_connection_utils_setup_bearer_auth (cnc, session, message, FALSE, using_bearer_auth, 
cancellable, &local_error)) {
                if (local_error) {
                        soup_message_set_status_full (message, SOUP_STATUS_BAD_REQUEST, local_error->message);
                        g_clear_error (&local_error);
diff --git a/src/server/e-ews-connection-utils.h b/src/server/e-ews-connection-utils.h
index ffdfbf34..669363b9 100644
--- a/src/server/e-ews-connection-utils.h
+++ b/src/server/e-ews-connection-utils.h
@@ -53,6 +53,7 @@ void          e_ews_connection_utils_authenticate     (EEwsConnection *cnc,
                                                         SoupAuth *auth,
                                                         gboolean retrying);
 gboolean       e_ews_connection_utils_prepare_message  (EEwsConnection *cnc,
+                                                        SoupSession *session,
                                                         SoupMessage *message,
                                                         GCancellable *cancellable);
 
diff --git a/src/server/e-ews-connection.c b/src/server/e-ews-connection.c
index 294ee919..81419d54 100644
--- a/src/server/e-ews-connection.c
+++ b/src/server/e-ews-connection.c
@@ -539,7 +539,7 @@ ews_connection_scheduled_cb (gpointer user_data)
 
        switch (sd->op) {
        case EWS_SCHEDULE_OP_QUEUE_MESSAGE:
-               if (!e_ews_connection_utils_prepare_message (sd->cnc, sd->message, NULL)) {
+               if (!e_ews_connection_utils_prepare_message (sd->cnc, NULL, sd->message, NULL)) {
                        e_ews_debug_dump_raw_soup_request (sd->message);
 
                        if (sd->queue_callback) {
@@ -699,7 +699,7 @@ ews_next_request (gpointer _cnc)
        if (cnc->priv->soup_session) {
                SoupMessage *msg = SOUP_MESSAGE (node->msg);
 
-               if (!e_ews_connection_utils_prepare_message (cnc, msg, node->cancellable)) {
+               if (!e_ews_connection_utils_prepare_message (cnc, NULL, msg, node->cancellable)) {
                        e_ews_debug_dump_raw_soup_request (msg);
                        QUEUE_UNLOCK (cnc);
 
diff --git a/src/server/e-ews-notification.c b/src/server/e-ews-notification.c
index 0dde2bae..3bf6cc1e 100644
--- a/src/server/e-ews-notification.c
+++ b/src/server/e-ews-notification.c
@@ -332,6 +332,11 @@ e_ews_notification_subscribe_folder_sync (EEwsNotification *notification,
                e_ews_debug_dump_raw_soup_request (SOUP_MESSAGE (msg));
        }
 
+       if (!e_ews_connection_utils_prepare_message (notification->priv->connection, 
notification->priv->soup_session, SOUP_MESSAGE (msg), cancellable)) {
+               g_object_unref (msg);
+               return FALSE;
+       }
+
        soup_session_send_message (notification->priv->soup_session, SOUP_MESSAGE (msg));
        if (!SOUP_STATUS_IS_SUCCESSFUL (SOUP_MESSAGE (msg)->status_code)) {
                g_object_unref (msg);
@@ -436,6 +441,11 @@ e_ews_notification_unsubscribe_folder_sync (EEwsNotification *notification,
 
        soup_message_body_set_accumulate (SOUP_MESSAGE (msg)->response_body, TRUE);
 
+       if (!e_ews_connection_utils_prepare_message (notification->priv->connection, 
notification->priv->soup_session, SOUP_MESSAGE (msg), notification->priv->cancellable)) {
+               g_object_unref (msg);
+               return FALSE;
+       }
+
        soup_session_send_message (notification->priv->soup_session, SOUP_MESSAGE (msg));
        if (!SOUP_STATUS_IS_SUCCESSFUL (SOUP_MESSAGE (msg)->status_code)) {
                g_object_unref (msg);
@@ -767,6 +777,11 @@ e_ews_notification_get_events_sync (EEwsNotification *notification,
                SOUP_MESSAGE (msg), "got-chunk",
                G_CALLBACK (ews_notification_soup_got_chunk), notification);
 
+       if (!e_ews_connection_utils_prepare_message (notification->priv->connection, 
notification->priv->soup_session, SOUP_MESSAGE (msg), notification->priv->cancellable)) {
+               g_object_unref (msg);
+               return FALSE;
+       }
+
        status_code = soup_session_send_message (notification->priv->soup_session, SOUP_MESSAGE (msg));
 
        ret = SOUP_STATUS_IS_SUCCESSFUL (status_code);


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