--- a/libpurple/protocols/silc/silc.c Mon Nov 04 01:18:24 2019 +0000
+++ b/libpurple/protocols/silc/silc.c Mon Nov 04 02:24:02 2019 +0000
@@ -42,6 +42,25 @@
+silcpurple_free(SilcPurple sg) + g_return_if_fail(sg != NULL); + g_cancellable_cancel(sg->cancellable); + g_clear_object(&sg->cancellable); + g_clear_object(&sg->sockconn); + g_clear_pointer(&sg->client, silc_client_free); + g_clear_pointer(&sg->sha1hash, silc_hash_free); + g_clear_pointer(&sg->mimeass, silc_mime_assembler_free); + g_clear_pointer(&sg->public_key, silc_pkcs_public_key_free); + g_clear_pointer(&sg->private_key, silc_pkcs_private_key_free); silcpurple_list_icon(PurpleAccount *a, PurpleBuddy *b)
@@ -135,15 +154,6 @@
-#if __SILC_TOOLKIT_VERSION < SILC_VERSION(1,1,1)
-silcpurple_scheduler(gpointer *context)
- SilcClient client = (SilcClient)context;
- silc_client_run_one(client);
@@ -241,7 +251,6 @@
-#endif /* __SILC_TOOLKIT_VERSION */
silcpurple_connect_cb(SilcClient client, SilcClientConnection conn,
@@ -378,9 +387,7 @@
purple_connection_error(gc,
PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
- silc_pkcs_public_key_free(sg->public_key);
- silc_pkcs_private_key_free(sg->private_key);
purple_connection_set_protocol_data(gc, NULL);
@@ -413,29 +420,43 @@
-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")); + 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);
@@ -444,20 +465,27 @@
PurpleConnection *gc = sg->gc;
PurpleAccount *account = purple_connection_get_account(gc);
+ 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 */
- if (purple_proxy_connect(gc, account,
+ g_socket_client_connect_to_host_async(client, 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"));
- purple_connection_set_protocol_data(gc, NULL);
+ sg->cancellable, silcpurple_login_connected, gc); + g_object_unref(client); static void silcpurple_got_password_cb(PurpleConnection *gc, PurpleRequestFields *fields)
@@ -480,7 +508,7 @@
_("Password is required to sign on."), NULL,
purple_request_cpar_from_connection(gc));
purple_connection_set_protocol_data(gc, NULL);
@@ -499,7 +527,7 @@
purple_connection_error(gc, PURPLE_CONNECTION_ERROR_OTHER_ERROR,
_("Unable to load SILC key pair"));
purple_connection_set_protocol_data(gc, NULL);
silcpurple_continue_running(sg);
@@ -516,7 +544,7 @@
purple_connection_error(gc, PURPLE_CONNECTION_ERROR_OTHER_ERROR,
_("Unable to load SILC key pair"));
purple_connection_set_protocol_data(gc, NULL);
static void silcpurple_running(SilcClient client, void *context)
@@ -545,7 +573,7 @@
purple_connection_error(gc, PURPLE_CONNECTION_ERROR_OTHER_ERROR,
_("Unable to load SILC key pair"));
purple_connection_set_protocol_data(gc, NULL);
silcpurple_continue_running(sg);
@@ -616,6 +644,7 @@
sg = silc_calloc(1, sizeof(*sg));
+ sg->cancellable = g_cancellable_new(); @@ -627,7 +656,7 @@
purple_connection_error(gc, PURPLE_CONNECTION_ERROR_OTHER_ERROR,
_("Unable to initialize SILC protocol"));
purple_connection_set_protocol_data(gc, NULL);
@@ -640,20 +669,15 @@
purple_connection_error(gc, PURPLE_CONNECTION_ERROR_OTHER_ERROR,
_("Error loading SILC key pair"));
purple_connection_set_protocol_data(gc, NULL);
-#if __SILC_TOOLKIT_VERSION < SILC_VERSION(1,1,1)
- /* Schedule SILC using Glib's event loop */
- sg->scheduler = g_timeout_add(300, (GSourceFunc)silcpurple_scheduler, client);
sg->tasks = silc_dlist_init();
silc_schedule_set_notify(client->schedule, silcpurple_scheduler,
silc_client_run_one(client);
-#endif /* __SILC_TOOLKIT_VERSION */
@@ -664,12 +688,8 @@
purple_debug_info("silc", "Finalizing SilcPurple %p\n", sg);
silc_client_stop(sg->client, NULL, NULL);
- silc_client_free(sg->client);
- silc_hash_free(sg->sha1hash);
- silc_mime_assembler_free(sg->mimeass);
@@ -677,9 +697,7 @@
silcpurple_close(PurpleConnection *gc)
SilcPurple sg = purple_connection_get_protocol_data(gc);
-#if __SILC_TOOLKIT_VERSION >= SILC_VERSION(1,1,1)
-#endif /* __SILC_TOOLKIT_VERSION */
const char *ui_name = NULL, *ui_website = NULL;
@@ -709,7 +727,6 @@
silc_client_close_connection(sg->client, sg->conn);
-#if __SILC_TOOLKIT_VERSION >= SILC_VERSION(1,1,1)
silc_client_run_one(sg->client);
silc_schedule_set_notify(sg->client->schedule, NULL, NULL);
@@ -720,7 +737,6 @@
silc_dlist_uninit(sg->tasks);
-#endif /* __SILC_TOOLKIT_VERSION */
g_source_remove(sg->scheduler);
--- a/libpurple/protocols/silc/silcpurple.h Mon Nov 04 01:18:24 2019 +0000
+++ b/libpurple/protocols/silc/silcpurple.h Mon Nov 04 02:24:02 2019 +0000
@@ -37,9 +37,6 @@
-#define SILC_VERSION(a, b, c) (((a) << 24) + ((b) << 16) + ((c) << 8))
#define SILCPURPLE_TYPE_PROTOCOL (silcpurple_protocol_get_type())
#define SILCPURPLE_PROTOCOL(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), SILCPURPLE_TYPE_PROTOCOL, SilcProtocol))
#define SILCPURPLE_PROTOCOL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), SILCPURPLE_TYPE_PROTOCOL, SilcProtocolClass))
@@ -86,6 +83,9 @@
/* The SILC Purple plugin context */
typedef struct SilcPurpleStruct {
+ GCancellable *cancellable; + GSocketConnection *sockconn; SilcClientConnection conn;
SilcPublicKey public_key;