/pidgin/main: ee6f9faeee6f: sslconn: Clean up tls_connect() func...
Mike Ruprecht
cmaiku at gmail.com
Thu Apr 7 13:36:21 EDT 2016
Changeset: ee6f9faeee6fa6681b11039b35d2deedcb61c79d
Author: Mike Ruprecht <cmaiku at gmail.com>
Date: 2016-04-07 02:45 -0500
Branch: purple-ssl-to-gio
URL: https://hg.pidgin.im/pidgin/main/rev/ee6f9faeee6f
Description:
sslconn: Clean up tls_connect() function error paths
This patch modifies sslconn's tls_connect() function to return a
boolean based on whether or not the function succeeded. This makes
it so that if the GTlsBackend doesn't support TLS or some other
error occurs, purple_ssl_connect_with_fd() can return NULL
preserving previous behavior without relying on the
_ssl_initialized variable.
diffstat:
libpurple/sslconn.c | 32 ++++++++++++++++++++++----------
1 files changed, 22 insertions(+), 10 deletions(-)
diffs (80 lines):
diff --git a/libpurple/sslconn.c b/libpurple/sslconn.c
--- a/libpurple/sslconn.c
+++ b/libpurple/sslconn.c
@@ -70,7 +70,7 @@ tls_handshake_cb(GObject *source, GAsync
gsc->connect_cb(gsc->connect_cb_data, gsc, PURPLE_INPUT_READ);
}
-static void
+static gboolean
tls_connect(PurpleSslConnection *gsc)
{
GSocket *socket;
@@ -79,13 +79,15 @@ tls_connect(PurpleSslConnection *gsc)
GIOStream *tls_conn;
GError *error = NULL;
- g_return_if_fail(gsc->conn == NULL);
+ g_return_val_if_fail(gsc->conn == NULL, FALSE);
socket = g_socket_new_from_fd(gsc->fd, &error);
if (socket == NULL) {
- emit_error(gsc, PURPLE_SSL_CONNECT_FAILED);
- purple_ssl_close(gsc);
- return;
+ purple_debug_warning("sslconn",
+ "Error creating socket from fd (%u): %s",
+ gsc->fd, error->message);
+ g_clear_error(&error);
+ return FALSE;
}
conn = g_socket_connection_factory_create_connection(socket);
@@ -98,9 +100,11 @@ tls_connect(PurpleSslConnection *gsc)
g_object_unref(conn);
if (tls_conn == NULL) {
- emit_error(gsc, PURPLE_SSL_CONNECT_FAILED);
- purple_ssl_close(gsc);
- return;
+ purple_debug_warning("sslconn",
+ "Error creating TLS client connection: %s",
+ error->message);
+ g_clear_error(&error);
+ return FALSE;
}
gsc->conn = G_TLS_CONNECTION(tls_conn);
@@ -110,6 +114,8 @@ tls_connect(PurpleSslConnection *gsc)
g_tls_connection_handshake_async(gsc->conn, G_PRIORITY_DEFAULT,
gsc->cancellable, tls_handshake_cb, gsc);
+
+ return TRUE;
}
static void
@@ -129,7 +135,10 @@ purple_ssl_connect_cb(gpointer data, gin
gsc->fd = source;
- tls_connect(gsc);
+ if (!tls_connect(gsc)) {
+ emit_error(gsc, PURPLE_SSL_CONNECT_FAILED);
+ purple_ssl_close(gsc);
+ }
}
PurpleSslConnection *
@@ -267,7 +276,10 @@ purple_ssl_connect_with_host_fd(PurpleAc
gsc->host = g_strdup(host);
gsc->cancellable = g_cancellable_new();
- tls_connect(gsc);
+ if (!tls_connect(gsc)) {
+ emit_error(gsc, PURPLE_SSL_CONNECT_FAILED);
+ g_clear_pointer(&gsc, purple_ssl_close);
+ }
return (PurpleSslConnection *)gsc;
}
More information about the Commits
mailing list