/pidgin/main: 5230b8073a37: Merged in CMaiku/pidgin (pull reques...
Gary Kramlich <[email protected]> Sun, 28 Aug 2016 23:58:01 -0400
| Newsgroups | gmane.comp.gnome.gaim.cvs |
|---|---|
| Message-ID | <[email protected]> |
Changeset: 5230b8073a37f2355da6981bb8b87a5775fcb9aa Author: Gary Kramlich <[email protected]> Date: 2016-08-28 22:57 -0500 Branch: default URL: https://hg.pidgin.im/pidgin/main/rev/5230b8073a37 Description: Merged in CMaiku/pidgin (pull request #109) Gio fixes w/ GError for Purple connection error improvements diffstat: libpurple/Makefile.am | 2 + libpurple/connection.c | 19 +++- libpurple/connection.h | 32 ++++++++- libpurple/protocols/irc/irc.c | 67 ++++++++------------ libpurple/protocols/irc/msgs.c | 88 ++++++++++++++------------ libpurple/protocols/irc/parse.c | 13 ++- libpurple/proxy.c | 52 +++++++------- libpurple/proxy.h | 4 +- libpurple/purple-gio.c | 131 ++++++++++++++++++++++++++++++++++++++++ libpurple/purple-gio.h | 76 +++++++++++++++++++++++ 10 files changed, 361 insertions(+), 123 deletions(-) diffs (truncated from 833 to 300 lines): diff --git a/libpurple/Makefile.am b/libpurple/Makefile.am --- a/libpurple/Makefile.am +++ b/libpurple/Makefile.am @@ -97,6 +97,7 @@ purple_coresources = \ proxy.c \ protocol.c \ protocols.c \ + purple-gio.c \ purple-socket.c \ queuedoutputstream.c \ request.c \ @@ -181,6 +182,7 @@ purple_coreheaders = \ proxy.h \ protocol.h \ protocols.h \ + purple-gio.h \ purple-socket.h \ queuedoutputstream.h \ request.h \ diff --git a/libpurple/connection.c b/libpurple/connection.c --- a/libpurple/connection.c +++ b/libpurple/connection.c @@ -39,6 +39,8 @@ #include "signals.h" #include "util.h" +G_DEFINE_QUARK(purple-connection-error-quark, purple_connection_error); + #define KEEPALIVE_INTERVAL 30 #define PURPLE_CONNECTION_GET_PRIVATE(obj) \ @@ -543,11 +545,9 @@ purple_connection_ssl_error (PurpleConne } void -purple_connection_g_error(PurpleConnection *pc, const GError *error, - const gchar *description) +purple_connection_g_error(PurpleConnection *pc, const GError *error) { PurpleConnectionError reason; - gchar *tmp; if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) { /* Not a connection error. Ignore. */ @@ -574,13 +574,20 @@ purple_connection_g_error(PurpleConnecti } } 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; } - tmp = g_strdup_printf(description, error->message); - purple_connection_error(pc, reason, tmp); - g_free(tmp); + purple_connection_error(pc, reason, error->message); +} + +void +purple_connection_take_error(PurpleConnection *pc, GError *error) +{ + purple_connection_g_error(pc, error); + g_error_free(error); } gboolean diff --git a/libpurple/connection.h b/libpurple/connection.h --- a/libpurple/connection.h +++ b/libpurple/connection.h @@ -29,6 +29,8 @@ * @see_also: <link linkend="chapter-signals-connection">Connection signals</link> */ +#include <glib.h> + #define PURPLE_TYPE_CONNECTION (purple_connection_get_type()) #define PURPLE_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), PURPLE_TYPE_CONNECTION, PurpleConnection)) #define PURPLE_CONNECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), PURPLE_TYPE_CONNECTION, PurpleConnectionClass)) @@ -99,6 +101,16 @@ typedef enum PURPLE_CONNECTION_CONNECTING } PurpleConnectionState; +#define PURPLE_CONNECTION_ERROR purple_connection_error_quark() + +/** + * purple_connection_error_quark: + * + * Error domain for Purple connection errors. Errors in this domain will be + * from the #PurpleConnectionError enum. + */ +GQuark purple_connection_error_quark(void); + /** * PurpleConnectionError: * @PURPLE_CONNECTION_ERROR_NETWORK_ERROR: There was an error sending or @@ -510,8 +522,6 @@ purple_connection_ssl_error (PurpleConne * purple_connection_g_error * @gc: Connection the error is associated with * @error: Error information - * @description: Extra string which further explains the error. - * Substitutes a "%s" with the GError message. * * Closes a connection similar to purple_connection_error(), but * takes a GError which is then converted to purple error codes. @@ -524,8 +534,22 @@ purple_connection_ssl_error (PurpleConne */ void purple_connection_g_error(PurpleConnection *pc, - const GError *error, - const gchar *description); + const GError *error); + +/* + * purple_connection_take_error + * @gc: Connection the error is associated with + * @error: (transfer full): Error information + * + * Closes a connection similar to purple_connection_error(), but + * takes a GError which is then converted to purple error codes. + * + * This function is equivalent to purple_connection_g_error(), + * except that it takes ownership of the GError. + */ +void +purple_connection_take_error(PurpleConnection *pc, + GError *error); /** * purple_connection_error_is_fatal: diff --git a/libpurple/protocols/irc/irc.c b/libpurple/protocols/irc/irc.c --- a/libpurple/protocols/irc/irc.c +++ b/libpurple/protocols/irc/irc.c @@ -32,7 +32,7 @@ #include "notify.h" #include "protocol.h" #include "plugins.h" -#include "tls-certificate.h" +#include "purple-gio.h" #include "util.h" #include "version.h" @@ -106,9 +106,8 @@ irc_flush_cb(GObject *source, GAsyncResu res, &error); if (!result) { - purple_connection_g_error(gc, error, - _("Lost connection with server: %s")); - g_clear_error(&error); + g_prefix_error(&error, _("Lost connection with server: ")); + purple_connection_take_error(gc, error); return; } } @@ -286,16 +285,17 @@ static void irc_login(PurpleAccount *acc char **userparts; const char *username = purple_account_get_username(account); GSocketClient *client; - GProxyResolver *resolver; + GError *error = NULL; gc = purple_account_get_connection(account); purple_connection_set_flags(gc, PURPLE_CONNECTION_FLAG_NO_NEWLINES | PURPLE_CONNECTION_FLAG_NO_IMAGES); if (strpbrk(username, " \t\v\r\n") != NULL) { - purple_connection_error (gc, + purple_connection_take_error(gc, g_error_new_literal( + PURPLE_CONNECTION_ERROR, PURPLE_CONNECTION_ERROR_INVALID_SETTINGS, - _("IRC nick and server may not contain whitespace")); + _("IRC nick and server may not contain whitespace"))); return; } @@ -318,23 +318,16 @@ static void irc_login(PurpleAccount *acc purple_connection_update_progress(gc, _("Connecting"), 1, 2); - if ((resolver = purple_proxy_get_proxy_resolver(account)) == NULL) { - /* Invalid proxy settings */ - purple_connection_error (gc, - PURPLE_CONNECTION_ERROR_NETWORK_ERROR, - _("Unable to connect")); + client = purple_gio_socket_client_new(account, &error); + + if (client == NULL) { + purple_connection_take_error(gc, error); return; } - client = g_socket_client_new(); - g_socket_client_set_proxy_resolver(client, resolver); - g_object_unref(resolver); - /* Optionally use TLS if it's set in the account settings */ - if (purple_account_get_bool(account, "ssl", FALSE)) { - g_socket_client_set_tls(client, TRUE); - purple_tls_certificate_attach_to_socket_client(client); - } + g_socket_client_set_tls(client, + purple_account_get_bool(account, "ssl", FALSE)); g_socket_client_connect_to_host_async(client, irc->server, purple_account_get_int(account, "port", @@ -426,9 +419,8 @@ irc_login_cb(GObject *source, GAsyncResu res, &error); if (conn == NULL) { - purple_connection_g_error(gc, error, - _("Unable to connect: %s")); - g_clear_error(&error); + g_prefix_error(&error, _("Unable to connect: ")); + purple_connection_take_error(gc, error); return; } @@ -460,21 +452,16 @@ static void irc_close(PurpleConnection * g_clear_object(&irc->cancellable); } + if (irc->conn != NULL) { + purple_gio_graceful_close(G_IO_STREAM(irc->conn), + G_INPUT_STREAM(irc->input), + G_OUTPUT_STREAM(irc->output)); + } + g_clear_object(&irc->input); g_clear_object(&irc->output); + g_clear_object(&irc->conn); - if (irc->conn != NULL) { - GError *error = NULL; - - if (!g_io_stream_close(G_IO_STREAM(irc->conn), NULL, &error)) { - purple_debug_warning("irc", - "Error closing connection: %s", - error->message); - g_clear_error(&error); - } - - g_clear_object(&irc->conn); - } if (irc->timer) purple_timeout_remove(irc->timer); g_hash_table_destroy(irc->cmds); @@ -602,14 +589,14 @@ irc_read_input_cb(GObject *source, GAsyn G_DATA_INPUT_STREAM(source), res, &len, &error); if (line == NULL && error != NULL) { - purple_connection_g_error(gc, error, - _("Lost connection with server: %s")); - g_clear_error(&error); + g_prefix_error(&error, _("Lost connection with server: ")); + purple_connection_take_error(gc, error); return; } else if (line == NULL) { - purple_connection_error (gc, + purple_connection_take_error(gc, g_error_new_literal( + PURPLE_CONNECTION_ERROR, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, - _("Server closed the connection")); + _("Server closed the connection"))); return; } diff --git a/libpurple/protocols/irc/msgs.c b/libpurple/protocols/irc/msgs.c --- a/libpurple/protocols/irc/msgs.c +++ b/libpurple/protocols/irc/msgs.c @@ -1132,9 +1132,10 @@ void irc_msg_badnick(struct irc_conn *ir purple_request_cpar_from_connection(gc)); } else { - purple_connection_error (gc, - PURPLE_CONNECTION_ERROR_INVALID_SETTINGS, - _("Your selected account name was rejected by the server. It probably contains invalid characters.")); + purple_connection_take_error(gc, g_error_new_literal( + PURPLE_CONNECTION_ERROR, + PURPLE_CONNECTION_ERROR_INVALID_SETTINGS, + _("Your selected account name was rejected by the server. It probably contains invalid characters."))); } } @@ -1484,18 +1485,17 @@ irc_auth_start_cyrus(struct irc_conn *ir secprops.property_values = 0; do { - gchar *tmp = NULL; again = FALSE; ret = sasl_client_new("irc", irc->server, NULL, NULL, irc->sasl_cb, 0, &irc->sasl_conn); if (ret != SASL_OK) { purple_debug_error("irc", "sasl_client_new failed: %d\n", ret); - tmp = g_strdup_printf(_("Failed to initialize SASL authentication: %s"), - sasl_errdetail(irc->sasl_conn)); - purple_connection_error (gc, - PURPLE_CONNECTION_ERROR_OTHER_ERROR, tmp); - g_free(tmp); _______________________________________________ Commits mailing list [email protected] https://pidgin.im/cgi-bin/mailman/listinfo/commits