/pidgin/main: 13e2a9fcbddd: purple-gio: Add purple_gio_socket_cl...
Mike Ruprecht <[email protected]> Sun, 28 Aug 2016 23:58:01 -0400
| Newsgroups | gmane.comp.gnome.gaim.cvs |
|---|---|
| Message-ID | <[email protected]> |
Changeset: 13e2a9fcbddd8ed1a3acac80ad7f03434491a02b Author: Mike Ruprecht <[email protected]> Date: 2016-08-26 18:06 -0500 Branch: default URL: https://hg.pidgin.im/pidgin/main/rev/13e2a9fcbddd Description: purple-gio: Add purple_gio_socket_client_new() helper function This patch adds purple_gio_socket_client_new() as a new helper function to simplify GSocketClient creation for protocol plugins. It gets the appropriate proxy settings from the account and sets up TLS certificate handling. diffstat: libpurple/purple-gio.c | 27 +++++++++++++++++++++++++++ libpurple/purple-gio.h | 17 +++++++++++++++++ 2 files changed, 44 insertions(+), 0 deletions(-) diffs (76 lines): diff --git a/libpurple/purple-gio.c b/libpurple/purple-gio.c --- a/libpurple/purple-gio.c +++ b/libpurple/purple-gio.c @@ -22,7 +22,9 @@ */ #include "internal.h" +#include "proxy.h" #include "purple-gio.h" +#include "tls-certificate.h" typedef struct { GIOStream *stream; @@ -105,3 +107,28 @@ purple_gio_graceful_close(GIOStream *str } } +GSocketClient * +purple_gio_socket_client_new(PurpleAccount *account, GError **error) +{ + GProxyResolver *resolver; + GSocketClient *client; + + resolver = purple_proxy_get_proxy_resolver(account); + + if (resolver == NULL) { + g_set_error_literal(error, PURPLE_CONNECTION_ERROR, + PURPLE_CONNECTION_ERROR_INVALID_SETTINGS, + _("Invalid proxy settings")); + return NULL; + } + + client = g_socket_client_new(); + g_socket_client_set_proxy_resolver(client, resolver); + g_object_unref(resolver); + + /* Attach purple's tls certificate handler in case tls is used */ + purple_tls_certificate_attach_to_socket_client(client); + + return client; +} + diff --git a/libpurple/purple-gio.h b/libpurple/purple-gio.h --- a/libpurple/purple-gio.h +++ b/libpurple/purple-gio.h @@ -35,6 +35,8 @@ * gracefully. */ +#include "account.h" + #include <gio/gio.h> G_BEGIN_DECLS @@ -54,6 +56,21 @@ void purple_gio_graceful_close(GIOStream *stream, GInputStream *input, GOutputStream *output); +/** + * purple_gio_socket_client_new: + * @account: The #PurpleAccount to use for this connection + * @error: Return location for a GError, or NULL + * + * A helper function to simplify creating a #GSocketClient. It's intended + * to be used in protocol plugins. + * + * Returns: A new #GSocketClient with the appropriate + * GProxyResolver, based on the #PurpleAccount settings and + * TLS Certificate handling, or NULL if an error occurred. + */ +GSocketClient * +purple_gio_socket_client_new(PurpleAccount *account, GError **error); + G_END_DECLS #endif /* _PURPLE_GIO_H */ _______________________________________________ Commits mailing list [email protected] https://pidgin.im/cgi-bin/mailman/listinfo/commits