[evolution-data-server/wip/mcrha/soup3] Simplify ESoupSSLTrust and connect it always in the ESoupSession
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server/wip/mcrha/soup3] Simplify ESoupSSLTrust and connect it always in the ESoupSession
- Date: Tue, 31 May 2022 08:38:12 +0000 (UTC)
commit 504b277af1650ed7b8e1916f3863c2b955b00f33
Author: Milan Crha <mcrha redhat com>
Date: Tue May 31 10:16:18 2022 +0200
Simplify ESoupSSLTrust and connect it always in the ESoupSession
src/libedataserver/e-soup-session.c | 6 +--
src/libedataserver/e-soup-ssl-trust.c | 74 +++++------------------------------
2 files changed, 13 insertions(+), 67 deletions(-)
---
diff --git a/src/libedataserver/e-soup-session.c b/src/libedataserver/e-soup-session.c
index f473ea86e..e6edf7cb0 100644
--- a/src/libedataserver/e-soup-session.c
+++ b/src/libedataserver/e-soup-session.c
@@ -1067,10 +1067,10 @@ e_soup_session_prepare_message_send_phase1_sync (ESoupSession *session,
*out_restarted_id = g_signal_connect_data (message, "restarted",
G_CALLBACK (e_soup_session_restore_method_on_restarted_cb), g_strdup (soup_message_get_method
(message)), (GClosureNotify) g_free, 0);
- if (session->priv->source &&
- e_source_has_extension (session->priv->source, E_SOURCE_EXTENSION_WEBDAV_BACKEND)) {
+ /* Always connect the SSL trust, even when the WebDAV extension is not present on the source,
+ otherwise any SSL trust is not properly handled. */
+ if (session->priv->source)
e_soup_ssl_trust_connect (message, session->priv->source);
- }
return TRUE;
}
diff --git a/src/libedataserver/e-soup-ssl-trust.c b/src/libedataserver/e-soup-ssl-trust.c
index c812fae88..5e6c8a73a 100644
--- a/src/libedataserver/e-soup-ssl-trust.c
+++ b/src/libedataserver/e-soup-ssl-trust.c
@@ -30,35 +30,28 @@
#include "e-soup-ssl-trust.h"
-typedef struct _ESoupSslTrustData {
- SoupMessage *soup_message; /* weak */
- ESource *source;
-
- GClosure *accept_certificate_closure;
-} ESoupSslTrustData;
-
static gboolean
-e_soup_ssl_trust_accept_certificate_cb (GTlsConnection *conn,
+e_soup_ssl_trust_accept_certificate_cb (SoupMessage *message,
GTlsCertificate *peer_cert,
GTlsCertificateFlags errors,
gpointer user_data)
{
- ESoupSslTrustData *handler = user_data;
+ ESource *source = user_data;
ETrustPromptResponse response;
GUri *g_uri;
const gchar *host;
gchar *auth_host = NULL;
- g_uri = soup_message_get_uri (handler->soup_message);
+ g_uri = soup_message_get_uri (message);
if (!g_uri || !g_uri_get_host (g_uri))
return FALSE;
host = g_uri_get_host (g_uri);
- if (e_source_has_extension (handler->source, E_SOURCE_EXTENSION_AUTHENTICATION)) {
+ if (e_source_has_extension (source, E_SOURCE_EXTENSION_AUTHENTICATION)) {
ESourceAuthentication *extension_authentication;
- extension_authentication = e_source_get_extension (handler->source,
E_SOURCE_EXTENSION_AUTHENTICATION);
+ extension_authentication = e_source_get_extension (source, E_SOURCE_EXTENSION_AUTHENTICATION);
auth_host = e_source_authentication_dup_host (extension_authentication);
if (auth_host && *auth_host) {
@@ -73,7 +66,7 @@ e_soup_ssl_trust_accept_certificate_cb (GTlsConnection *conn,
}
response = e_source_webdav_verify_ssl_trust (
- e_source_get_extension (handler->source, E_SOURCE_EXTENSION_WEBDAV_BACKEND),
+ e_source_get_extension (source, E_SOURCE_EXTENSION_WEBDAV_BACKEND),
host, peer_cert, errors);
g_free (auth_host);
@@ -82,43 +75,6 @@ e_soup_ssl_trust_accept_certificate_cb (GTlsConnection *conn,
response == E_TRUST_PROMPT_RESPONSE_ACCEPT_TEMPORARILY);
}
-static void
-e_soup_ssl_trust_network_event_cb (SoupMessage *msg,
- GSocketClientEvent event,
- GIOStream *connection,
- gpointer user_data)
-{
- ESoupSslTrustData *handler = user_data;
-
- /* It's either a GTlsConnection or a GTcpConnection */
- if (event == G_SOCKET_CLIENT_TLS_HANDSHAKING &&
- G_IS_TLS_CONNECTION (connection)) {
- g_signal_connect_closure (
- G_TLS_CONNECTION (connection), "accept-certificate",
- handler->accept_certificate_closure, FALSE);
- }
-}
-
-static void
-e_soup_ssl_trust_message_finalized_cb (gpointer data,
- GObject *unused_message)
-{
- ESoupSslTrustData *handler;
-
- /* The network event handler will be disconnected from the message just
- * before this is called. */
- handler = data;
-
- g_clear_object (&handler->source);
-
- /* Synchronously disconnects the accept certificate handler from all
- * GTlsConnections. */
- g_closure_invalidate (handler->accept_certificate_closure);
- g_closure_unref (handler->accept_certificate_closure);
-
- g_free (handler);
-}
-
/**
* e_soup_ssl_trust_connect:
* @soup_message: a #SoupMessage about to be sent to the source
@@ -144,21 +100,11 @@ void
e_soup_ssl_trust_connect (SoupMessage *soup_message,
ESource *source)
{
- ESoupSslTrustData *handler;
-
g_return_if_fail (SOUP_IS_MESSAGE (soup_message));
g_return_if_fail (E_IS_SOURCE (source));
- handler = g_malloc (sizeof (ESoupSslTrustData));
- handler->soup_message = soup_message;
- g_object_weak_ref (G_OBJECT (soup_message), e_soup_ssl_trust_message_finalized_cb, handler);
- handler->source = g_object_ref (source);
- handler->accept_certificate_closure = g_cclosure_new (G_CALLBACK
(e_soup_ssl_trust_accept_certificate_cb), handler, NULL);
-
- g_closure_ref (handler->accept_certificate_closure);
- g_closure_sink (handler->accept_certificate_closure);
-
- g_signal_connect (
- soup_message, "network-event",
- G_CALLBACK (e_soup_ssl_trust_network_event_cb), handler);
+ g_signal_connect_data (
+ soup_message, "accept-certificate",
+ G_CALLBACK (e_soup_ssl_trust_accept_certificate_cb), g_object_ref (source),
+ (GClosureNotify) g_object_unref, 0);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]