--- a/libpurple/protocols/silc/silc.c Sun Nov 03 04:07:39 2019 -0500
+++ b/libpurple/protocols/silc/silc.c Sun Nov 03 17:16:20 2019 -0500
@@ -45,6 +45,9 @@
silcpurple_free(SilcPurple sg)
+ g_cancellable_cancel(sg->cancellable); + g_clear_object(&sg->cancellable); + g_clear_object(&sg->sockconn); @@ -409,29 +412,45 @@
-silcpurple_login_connected(gpointer data, gint source, const gchar *error_message)
+silcpurple_login_connected(GObject *source, GAsyncResult *res, gpointer data) PurpleConnection *gc = data;
+ GSocketConnection *conn; g_return_if_fail(gc != NULL);
sg = purple_connection_get_protocol_data(gc);
- purple_connection_error(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
- _("Connection failed"));
- silc_pkcs_public_key_free(sg->public_key);
- silc_pkcs_private_key_free(sg->private_key);
- purple_connection_set_protocol_data(gc, NULL);
+ conn = g_socket_client_connect_to_host_finish(G_SOCKET_CLIENT(source), + if (!g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) { + purple_connection_error(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, + _("Connection failed")); + silc_pkcs_public_key_free(sg->public_key); + silc_pkcs_private_key_free(sg->private_key); + purple_connection_set_protocol_data(gc, NULL); + socket = g_socket_connection_get_socket(conn); + g_assert(socket != NULL); + fd = g_socket_get_fd(socket); silc_hash_alloc((unsigned char *)"sha1", &sg->sha1hash);
/* Wrap socket to TCP stream */
- silc_socket_tcp_stream_create(source, TRUE, FALSE,
+ silc_socket_tcp_stream_create(fd, TRUE, FALSE, silcpurple_stream_created, gc);
@@ -440,20 +459,27 @@
PurpleConnection *gc = sg->gc;
PurpleAccount *account = purple_connection_get_account(gc);
- /* Connect to the SILC server */
- if (purple_proxy_connect(gc, account,
- purple_account_get_string(account, "server",
- purple_account_get_int(account, "port", 706),
- silcpurple_login_connected, gc) == NULL)
- purple_connection_error(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
- _("Unable to connect"));
+ client = purple_gio_socket_client_new(account, &error); + /* Assume it's a proxy error */ + purple_notify_error(NULL, NULL, _("Invalid proxy settings"), + purple_request_cpar_from_account(account)); + purple_connection_take_error(gc, error); purple_connection_set_protocol_data(gc, NULL);
+ /* Connect to the SILC server */ + g_socket_client_connect_to_host_async(client, + purple_account_get_string(account, "server", + purple_account_get_int(account, "port", 706), + sg->cancellable, silcpurple_login_connected, gc); + g_object_unref(client); static void silcpurple_got_password_cb(PurpleConnection *gc, PurpleRequestFields *fields)
@@ -612,6 +638,7 @@
sg = silc_calloc(1, sizeof(*sg));
+ sg->cancellable = g_cancellable_new(); --- a/libpurple/protocols/silc/silcpurple.h Sun Nov 03 04:07:39 2019 -0500
+++ b/libpurple/protocols/silc/silcpurple.h Sun Nov 03 17:16:20 2019 -0500
@@ -83,6 +83,9 @@
/* The SILC Purple plugin context */
typedef struct SilcPurpleStruct {
+ GCancellable *cancellable; + GSocketConnection *sockconn; SilcClientConnection conn;
SilcPublicKey public_key;