libpurple/connection.c

changeset 42998
9fae31173eb3
parent 42997
368deff13c21
child 42999
5a506dee26d2
--- a/libpurple/connection.c	Fri Oct 04 00:48:33 2024 -0500
+++ b/libpurple/connection.c	Fri Oct 04 01:08:05 2024 -0500
@@ -23,7 +23,6 @@
 #include <glib/gi18n-lib.h>
 
 #include "connection.h"
-#include "purpleconnectionprivate.h"
 
 #include "debug.h"
 #include "prefs.h"
@@ -47,20 +46,6 @@
 
 	PurpleAccount *account;       /* The account being connected to.   */
 	char *password;               /* The password used.                */
-
-	/* Wants to Die state.  This is set when the user chooses to log out, or
-	 * when the protocol is disconnected and should not be automatically
-	 * reconnected (incorrect password, etc.).  Protocols should rely on
-	 * purple_connection_error() to set this for them rather than
-	 * setting it themselves.
-	 * See purple_connection_error_is_fatal()
-	 */
-	gboolean wants_to_die;
-
-	/* The connection error and its description if an error occurred. */
-	PurpleConnectionErrorInfo *error_info;
-
-	guint disconnect_timeout;  /* Timer used for nasty stack tricks. */
 } PurpleConnectionPrivate;
 
 enum {
@@ -76,8 +61,6 @@
 
 static GParamSpec *properties[N_PROPERTIES] = {NULL, };
 
-static int connections_handle;
-
 G_DEFINE_TYPE_WITH_PRIVATE(PurpleConnection, purple_connection, G_TYPE_OBJECT)
 
 /**************************************************************************
@@ -198,165 +181,6 @@
 }
 
 gboolean
-_purple_connection_wants_to_die(PurpleConnection *connection) {
-	PurpleConnectionPrivate *priv = NULL;
-
-	g_return_val_if_fail(PURPLE_IS_CONNECTION(connection), FALSE);
-
-	priv = purple_connection_get_instance_private(connection);
-
-	return priv->wants_to_die;
-}
-
-static gboolean
-purple_connection_disconnect_cb(gpointer data) {
-	PurpleAccount *account = data;
-	PurpleConnection *connection;
-
-	connection = purple_account_get_connection(account);
-
-	if(PURPLE_IS_CONNECTION(connection)) {
-		PurpleConnectionPrivate *priv = NULL;
-
-		priv = purple_connection_get_instance_private(connection);
-
-		priv->disconnect_timeout = 0;
-
-		if(priv->state != PURPLE_CONNECTION_STATE_DISCONNECTED) {
-			/* If the connection is not disconnected, disconnect it. */
-			purple_account_disconnect(account);
-		} else {
-			/* Otherwise assume the connection was already disconnected or in
-			 * the process of being disconnected and we just need to finish our
-			 * cleanup.
-			 */
-			GError *error = NULL;
-
-			if(!purple_connection_disconnect(connection, &error)) {
-				const char *message = "unknown error";
-
-				if(error != NULL) {
-					message = error->message;
-				}
-
-				purple_debug_warning("connections",
-				                     "failed to disconnect %p : %s",
-				                     connection, message);
-			}
-
-			g_clear_error(&error);
-
-			purple_account_set_connection(account, NULL);
-		}
-	}
-
-	return G_SOURCE_REMOVE;
-}
-
-void
-purple_connection_error(PurpleConnection *connection,
-                        PurpleConnectionError reason,
-                        const char *description)
-{
-	PurpleConnectionPrivate *priv = NULL;
-
-	g_return_if_fail(PURPLE_IS_CONNECTION(connection));
-
-	priv = purple_connection_get_instance_private(connection);
-
-	/* This sanity check relies on PURPLE_CONNECTION_ERROR_OTHER_ERROR
-	 * being the last member of the PurpleConnectionError enum in
-	 * connection.h; if other reasons are added after it, this check should
-	 * be updated.
-	 */
-	if(reason > PURPLE_CONNECTION_ERROR_OTHER_ERROR) {
-		purple_debug_error("connection",
-			"purple_connection_error: reason %u isn't a "
-			"valid reason\n", reason);
-		reason = PURPLE_CONNECTION_ERROR_OTHER_ERROR;
-	}
-
-	if(description == NULL) {
-		purple_debug_error("connection", "purple_connection_error called with NULL description\n");
-		description = _("Unknown error");
-	}
-
-	/* If we've already got one error, we don't need any more */
-	if(priv->error_info != NULL) {
-		return;
-	}
-
-	priv->wants_to_die = purple_connection_error_is_fatal(reason);
-
-	purple_debug_info("connection",
-	                  "Connection error on %p (reason: %u description: %s)\n",
-	                  connection, reason, description);
-
-	priv->error_info = purple_connection_error_info_new(reason, description);
-
-	purple_signal_emit(purple_connections_get_handle(), "connection-error",
-	                   connection, reason, description);
-
-	priv->disconnect_timeout = g_timeout_add(0, purple_connection_disconnect_cb,
-	                                         priv->account);
-}
-
-PurpleConnectionErrorInfo *
-purple_connection_get_error_info(PurpleConnection *connection) {
-	PurpleConnectionPrivate *priv = NULL;
-
-	g_return_val_if_fail(PURPLE_IS_CONNECTION(connection), NULL);
-
-	priv = purple_connection_get_instance_private(connection);
-
-	return priv->error_info;
-}
-
-void
-purple_connection_g_error(PurpleConnection *connection, const GError *error) {
-	PurpleConnectionError reason;
-
-	if(g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
-		/* Not a connection error. Ignore. */
-		return;
-	}
-
-	if(error->domain == G_TLS_ERROR) {
-		switch (error->code) {
-		case G_TLS_ERROR_UNAVAILABLE:
-			reason = PURPLE_CONNECTION_ERROR_NO_SSL_SUPPORT;
-			break;
-		case G_TLS_ERROR_NOT_TLS:
-		case G_TLS_ERROR_HANDSHAKE:
-			reason = PURPLE_CONNECTION_ERROR_ENCRYPTION_ERROR;
-			break;
-		case G_TLS_ERROR_BAD_CERTIFICATE:
-		case G_TLS_ERROR_CERTIFICATE_REQUIRED:
-			reason = PURPLE_CONNECTION_ERROR_CERT_OTHER_ERROR;
-			break;
-		case G_TLS_ERROR_EOF:
-		case G_TLS_ERROR_MISC:
-		default:
-			reason = PURPLE_CONNECTION_ERROR_NETWORK_ERROR;
-		}
-	} else if (error->domain == G_IO_ERROR) {
-		reason = PURPLE_CONNECTION_ERROR_NETWORK_ERROR;
-	} else if (error->domain == PURPLE_CONNECTION_ERROR) {
-		reason = error->code;
-	} else {
-		reason = PURPLE_CONNECTION_ERROR_OTHER_ERROR;
-	}
-
-	purple_connection_error(connection, reason, error->message);
-}
-
-void
-purple_connection_take_error(PurpleConnection *connection, GError *error) {
-	purple_connection_g_error(connection, error);
-	g_error_free(error);
-}
-
-gboolean
 purple_connection_error_is_fatal(PurpleConnectionError reason) {
 	switch (reason) {
 	case PURPLE_CONNECTION_ERROR_NETWORK_ERROR:
@@ -517,8 +341,6 @@
 
 	g_clear_object(&priv->account);
 
-	g_clear_handle_id(&priv->disconnect_timeout, g_source_remove);
-
 	G_OBJECT_CLASS(purple_connection_parent_class)->dispose(obj);
 }
 
@@ -529,8 +351,6 @@
 
 	priv = purple_connection_get_instance_private(connection);
 
-	g_clear_pointer(&priv->error_info, purple_connection_error_info_free);
-
 	purple_str_wipe(priv->password);
 	g_free(priv->id);
 
@@ -717,26 +537,3 @@
 
 	return priv->cancellable;
 }
-
-/**************************************************************************
- * Connections API
- **************************************************************************/
-void
-purple_connections_init(void) {
-	void *handle = purple_connections_get_handle();
-
-	purple_signal_register(handle, "connection-error",
-	                       purple_marshal_VOID__POINTER_INT_POINTER,
-	                       G_TYPE_NONE, 3, PURPLE_TYPE_CONNECTION,
-	                       PURPLE_TYPE_CONNECTION_ERROR, G_TYPE_STRING);
-}
-
-void
-purple_connections_uninit(void) {
-	purple_signals_unregister_by_instance(purple_connections_get_handle());
-}
-
-void *
-purple_connections_get_handle(void) {
-	return &connections_handle;
-}

mercurial