diff options
author | Elliott Sales de Andrade <quantum.analyst@gmail.com> | 2020-12-18 01:39:20 -0600 |
---|---|---|
committer | Elliott Sales de Andrade <quantum.analyst@gmail.com> | 2020-12-18 01:39:20 -0600 |
commit | 2d153efa6743949ba3b6f96f8ee69290fcac4663 (patch) | |
tree | fd8205d53df41bf37289d223599751e17ca6cdc9 | |
parent | 90a34014acfa307148f51bb32339223e882a289a (diff) | |
download | pidgin-2d153efa6743949ba3b6f96f8ee69290fcac4663.tar.gz |
Remove proxy connection code.
Testing Done:
Compile only; everything that uses it's been removed already.
Reviewed at https://reviews.imfreedom.org/r/283/
-rw-r--r-- | ChangeLog.API | 5 | ||||
-rw-r--r-- | libpurple/connection.c | 2 | ||||
-rw-r--r-- | libpurple/proxy.c | 251 | ||||
-rw-r--r-- | libpurple/proxy.h | 56 |
4 files changed, 5 insertions, 309 deletions
diff --git a/ChangeLog.API b/ChangeLog.API index e4710bab51..0b51850ed3 100644 --- a/ChangeLog.API +++ b/ChangeLog.API @@ -434,6 +434,11 @@ version 3.0.0 (??/??/????): * purple_plugins_unload * purple_plugins_unload_all * purple_pounces_load + * PurpleProxyConnectData + * PurpleProxyConnectFunction + * purple_proxy_connect + * purple_proxy_connect_cancel + * purple_proxy_connect_cancel_with_handle * purple_prefs_set_generic * purple_prefs_update_old * purple_presence_add_status diff --git a/libpurple/connection.c b/libpurple/connection.c index 243a768b92..9f206254ff 100644 --- a/libpurple/connection.c +++ b/libpurple/connection.c @@ -894,8 +894,6 @@ purple_connection_finalize(GObject *object) buddies = g_slist_delete_link(buddies, buddies); } - purple_proxy_connect_cancel_with_handle(gc); - connections = g_list_remove(connections, gc); purple_connection_set_state(gc, PURPLE_CONNECTION_DISCONNECTED); diff --git a/libpurple/proxy.c b/libpurple/proxy.c index 5c396cf6c9..e89d87463b 100644 --- a/libpurple/proxy.c +++ b/libpurple/proxy.c @@ -20,11 +20,6 @@ * */ -/* this is a little piece of code to handle proxy connection */ -/* it is intended to : 1st handle http proxy, using the CONNECT command - , 2nd provide an easy way to add socks support - , 3rd draw women to it like flies to honey */ - #include <glib/gi18n-lib.h> #include "internal.h" @@ -48,28 +43,8 @@ struct _PurpleProxyInfo char *password; /* The password. */ }; -struct _PurpleProxyConnectData { - void *handle; - PurpleProxyConnectFunction connect_cb; - gpointer data; - gchar *host; - int port; - int fd; - PurpleProxyInfo *gpi; - - GCancellable *cancellable; -}; - static PurpleProxyInfo *global_proxy_info = NULL; -static GSList *handles = NULL; - -/* - * TODO: Eventually (GObjectification) this bad boy will be removed, because it is - * a gross fix for a crashy problem. - */ -#define PURPLE_PROXY_CONNECT_DATA_IS_VALID(connect_data) g_slist_find(handles, connect_data) - /************************************************************************** * Proxy structure API **************************************************************************/ @@ -547,84 +522,6 @@ purple_win32_proxy_get_info(void) * Proxy API **************************************************************************/ -/* - * Whoever calls this needs to have called - * purple_proxy_connect_data_disconnect() beforehand. - */ -static void -purple_proxy_connect_data_destroy(PurpleProxyConnectData *connect_data) -{ - if (!PURPLE_PROXY_CONNECT_DATA_IS_VALID(connect_data)) - return; - - handles = g_slist_remove(handles, connect_data); - - if(G_IS_CANCELLABLE(connect_data->cancellable)) { - g_cancellable_cancel(connect_data->cancellable); - - g_object_unref(G_OBJECT(connect_data->cancellable)); - - connect_data->cancellable = NULL; - } - - g_free(connect_data->host); - g_free(connect_data); -} - -/* - * purple_proxy_connect_data_disconnect: - * @error_message: An error message explaining why the connection - * failed. This will be passed to the callback function - * specified in the call to purple_proxy_connect(). If the - * connection was successful then pass in null. - * - * Free all information dealing with a connection attempt and - * reset the connect_data to prepare for it to try to connect - * to another IP address. - * - * If an error message is passed in, then we know the connection - * attempt failed. If so, we call the callback with the given - * error message, then destroy the connect_data. - */ -static void -purple_proxy_connect_data_disconnect(PurpleProxyConnectData *connect_data, const gchar *error_message) -{ - if (connect_data->fd >= 0) - { - close(connect_data->fd); - connect_data->fd = -1; - } - - if (error_message != NULL) - { - purple_debug_error("proxy", "Connection attempt failed: %s\n", - error_message); - - /* Everything failed! Tell the originator of the request. */ - connect_data->connect_cb(connect_data->data, -1, error_message); - purple_proxy_connect_data_destroy(connect_data); - } -} - -static void -purple_proxy_connect_data_connected(PurpleProxyConnectData *connect_data) -{ - purple_debug_info("proxy", "Connected to %s:%d.\n", - connect_data->host, connect_data->port); - - connect_data->connect_cb(connect_data->data, connect_data->fd, NULL); - - /* - * We've passed the file descriptor to the protocol, so it's no longer - * our responsibility, and we should be careful not to free it when - * we destroy the connect_data. - */ - connect_data->fd = -1; - - purple_proxy_connect_data_disconnect(connect_data, NULL); - purple_proxy_connect_data_destroy(connect_data); -} - PurpleProxyInfo * purple_proxy_get_setup(PurpleAccount *account) { @@ -704,148 +601,6 @@ purple_proxy_get_setup(PurpleAccount *account) return gpi; } -/* Grabbed duplicate_fd() from GLib's testcases (gio/tests/socket.c). - * Can be dropped once this API has been converted to Gio. - */ -static int -duplicate_fd (int fd) -{ -#ifdef G_OS_WIN32 - HANDLE newfd; - - if (!DuplicateHandle (GetCurrentProcess (), - (HANDLE)fd, - GetCurrentProcess (), - &newfd, - 0, - FALSE, - DUPLICATE_SAME_ACCESS)) - { - return -1; - } - - return (int)newfd; -#else - return dup (fd); -#endif -} -/* End function grabbed from GLib */ - -static void -connect_to_host_cb(GObject *source, GAsyncResult *res, gpointer user_data) -{ - PurpleProxyConnectData *connect_data = user_data; - GSocketConnection *conn; - GError *error = NULL; - GSocket *socket; - - conn = g_socket_client_connect_to_host_finish(G_SOCKET_CLIENT(source), - res, &error); - if (conn == NULL) { - /* Ignore cancelled error as that signifies connect_data has - * been freed - */ - if (!g_error_matches(error, G_IO_ERROR, - G_IO_ERROR_CANCELLED)) { - purple_debug_error("proxy", "Unable to connect to " - "destination host: %s\n", - error->message); - purple_proxy_connect_data_disconnect(connect_data, - "Unable to connect to destination " - "host.\n"); - } - - g_clear_error(&error); - return; - } - - socket = g_socket_connection_get_socket(conn); - g_assert(socket != NULL); - - /* Duplicate the file descriptor, and then free the connection. - * libpurple's proxy code doesn't keep an object around for the - * lifetime of the connection. Therefore, in order to not leak - * memory, the GSocketConnection must be freed here. In order - * to avoid the double close/free of the file descriptor, the - * file descriptor is duplicated. - */ - connect_data->fd = duplicate_fd(g_socket_get_fd(socket)); - g_object_unref(conn); - - purple_proxy_connect_data_connected(connect_data); -} - -PurpleProxyConnectData * -purple_proxy_connect(void *handle, PurpleAccount *account, - const char *host, int port, - PurpleProxyConnectFunction connect_cb, gpointer data) -{ - PurpleProxyConnectData *connect_data; - GSocketClient *client; - GError *error = NULL; - - g_return_val_if_fail(host != NULL, NULL); - g_return_val_if_fail(port > 0, NULL); - g_return_val_if_fail(connect_cb != NULL, NULL); - - client = purple_gio_socket_client_new(account, &error); - - if (client == NULL) { - /* Assume it's a proxy error */ - purple_notify_error(NULL, NULL, _("Invalid proxy settings"), - error->message, - purple_request_cpar_from_account(account)); - g_clear_error(&error); - return NULL; - } - - connect_data = g_new0(PurpleProxyConnectData, 1); - connect_data->fd = -1; - connect_data->handle = handle; - connect_data->connect_cb = connect_cb; - connect_data->data = data; - connect_data->host = g_strdup(host); - connect_data->port = port; - connect_data->gpi = purple_proxy_get_setup(account); - connect_data->cancellable = g_cancellable_new(); - - purple_debug_info("proxy", "Attempting connection to %s:%u\n", - host, port); - - g_socket_client_connect_to_host_async(client, host, port, - connect_data->cancellable, connect_to_host_cb, - connect_data); - g_object_unref(client); - - handles = g_slist_prepend(handles, connect_data); - - return connect_data; -} - -void -purple_proxy_connect_cancel(PurpleProxyConnectData *connect_data) -{ - g_return_if_fail(connect_data != NULL); - - purple_proxy_connect_data_disconnect(connect_data, NULL); - purple_proxy_connect_data_destroy(connect_data); -} - -void -purple_proxy_connect_cancel_with_handle(void *handle) -{ - GSList *l, *l_next; - - for (l = handles; l != NULL; l = l_next) { - PurpleProxyConnectData *connect_data = l->data; - - l_next = l->next; - - if (connect_data->handle == handle) - purple_proxy_connect_cancel(connect_data); - } -} - GProxyResolver * purple_proxy_get_proxy_resolver(PurpleAccount *account, GError **error) { @@ -1011,12 +766,6 @@ purple_proxy_init(void) void purple_proxy_uninit(void) { - while (handles != NULL) - { - purple_proxy_connect_data_disconnect(handles->data, NULL); - purple_proxy_connect_data_destroy(handles->data); - } - purple_prefs_disconnect_by_handle(purple_proxy_get_handle()); purple_proxy_info_destroy(global_proxy_info); diff --git a/libpurple/proxy.h b/libpurple/proxy.h index b98276d993..022696c0a1 100644 --- a/libpurple/proxy.h +++ b/libpurple/proxy.h @@ -67,10 +67,6 @@ typedef enum */ typedef struct _PurpleProxyInfo PurpleProxyInfo; -typedef struct _PurpleProxyConnectData PurpleProxyConnectData; - -typedef void (*PurpleProxyConnectFunction)(gpointer data, gint source, const gchar *error_message); - #include "account.h" @@ -258,58 +254,6 @@ void purple_proxy_uninit(void); PurpleProxyInfo *purple_proxy_get_setup(PurpleAccount *account); /** - * purple_proxy_connect: (skip) - * @handle: A handle that should be associated with this - * connection attempt. The handle can be used - * to cancel the connection attempt using the - * purple_proxy_connect_cancel_with_handle() - * function. - * @account: The account making the connection. - * @host: The destination host. - * @port: The destination port. - * @connect_cb: (scope call): The function to call when the connection is - * established. If the connection failed then - * fd will be -1 and error message will be set - * to something descriptive (hopefully). - * @data: User-defined data. - * - * Makes a connection to the specified host and port. Note that this - * function name can be misleading--although it is called "proxy - * connect," it is used for establishing any outgoing TCP connection, - * whether through a proxy or not. - * - * Returns: NULL if there was an error, or a reference to an - * opaque data structure that can be used to cancel - * the pending connection, if needed. - */ -PurpleProxyConnectData *purple_proxy_connect(void *handle, - PurpleAccount *account, - const char *host, int port, - PurpleProxyConnectFunction connect_cb, gpointer data); - -/** - * purple_proxy_connect_cancel: (skip) - * @connect_data: The #PurpleProxyConnectData to cancel. - * - * Cancel an in-progress connection attempt. This should be called - * by the protocol if the user disables an account while it is still - * performing the initial sign on. Or when establishing a file - * transfer, if we attempt to connect to a remote user but they - * are behind a firewall then the protocol can cancel the connection - * attempt early rather than just letting the OS's TCP/IP stack - * time-out the connection. - */ -void purple_proxy_connect_cancel(PurpleProxyConnectData *connect_data); - -/** - * purple_proxy_connect_cancel_with_handle: (skip) - * @handle: The handle. - * - * Closes all proxy connections registered with the specified handle. - */ -void purple_proxy_connect_cancel_with_handle(void *handle); - -/** * purple_proxy_get_proxy_resolver: * @account: The account for which to get the proxy resolver. * @error: Return location for a GError, or NULL. |