/soc/2013/ankitkv/gobjectification: c284eef5cd26: Added purple_c...
Ankit Vani
a at nevitus.org
Thu Oct 24 08:51:59 EDT 2013
Changeset: c284eef5cd2639ef96a31b540fc0a59b3ebd84be
Author: Ankit Vani <a at nevitus.org>
Date: 2013-10-24 17:54 +0530
Branch: soc.2013.gobjectification
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/c284eef5cd26
Description:
Added purple_connection_get_error_info()
diffstat:
ChangeLog.API | 1 +
libpurple/connection.c | 52 +++++++++++++++++++++++++++++-------
libpurple/connection.h | 16 +++++++++-
libpurple/protocols/jabber/parser.c | 5 +--
4 files changed, 58 insertions(+), 16 deletions(-)
diffs (185 lines):
diff --git a/ChangeLog.API b/ChangeLog.API
--- a/ChangeLog.API
+++ b/ChangeLog.API
@@ -33,6 +33,7 @@ version 3.0.0 (??/??/????):
* purple_chat_user_set_ui_data
* purple_chat_user_set_chat
* purple_connection_get_active_chats
+ * purple_connection_get_error_info
* purple_connection_get_flags
* purple_connection_set_flags
* purple_connection_update_last_received
diff --git a/libpurple/connection.c b/libpurple/connection.c
--- a/libpurple/connection.c
+++ b/libpurple/connection.c
@@ -79,6 +79,9 @@ struct _PurpleConnectionPrivate
*/
gboolean wants_to_die;
+ /** The connection error and its description if an error occured */
+ PurpleConnectionErrorInfo *error_info;
+
guint disconnect_timeout; /**< Timer used for nasty stack tricks */
time_t last_received; /**< When we last received a packet. Set by the
prpl to avoid sending unneeded keepalives */
@@ -105,6 +108,10 @@ static PurpleConnectionUiOps *connection
static int connections_handle;
+static PurpleConnectionErrorInfo *
+purple_connection_error_info_new(PurpleConnectionError type,
+ const gchar *description);
+
/**************************************************************************
* Connection API
**************************************************************************/
@@ -446,8 +453,8 @@ purple_connection_disconnect_cb(gpointer
void
purple_connection_error (PurpleConnection *gc,
- PurpleConnectionError reason,
- const char *description)
+ PurpleConnectionError reason,
+ const char *description)
{
PurpleConnectionUiOps *ops;
PurpleConnectionPrivate *priv = PURPLE_CONNECTION_GET_PRIVATE(gc);
@@ -471,7 +478,7 @@ purple_connection_error (PurpleConnectio
}
/* If we've already got one error, we don't need any more */
- if (priv->disconnect_timeout > 0)
+ if (purple_connection_get_error_info(gc))
return;
priv->wants_to_die = purple_connection_error_is_fatal (reason);
@@ -484,6 +491,8 @@ purple_connection_error (PurpleConnectio
if (ops && ops->report_disconnect)
ops->report_disconnect(gc, reason, description);
+ priv->error_info = purple_connection_error_info_new(reason, description);
+
purple_signal_emit(purple_connections_get_handle(), "connection-error",
gc, reason, description);
@@ -491,6 +500,16 @@ purple_connection_error (PurpleConnectio
purple_connection_get_account(gc));
}
+PurpleConnectionErrorInfo *
+purple_connection_get_error_info(const PurpleConnection *gc)
+{
+ PurpleConnectionPrivate *priv = PURPLE_CONNECTION_GET_PRIVATE(gc);
+
+ g_return_val_if_fail(priv != NULL, TRUE);
+
+ return priv->error_info;
+}
+
void
purple_connection_ssl_error (PurpleConnection *gc,
PurpleSslErrorType ssl_error)
@@ -555,21 +574,31 @@ void purple_connection_update_last_recei
priv->last_received = time(NULL);
}
+static PurpleConnectionErrorInfo *
+purple_connection_error_info_new(PurpleConnectionError type,
+ const gchar *description)
+{
+ PurpleConnectionErrorInfo *err;
+
+ g_return_val_if_fail(description != NULL, NULL);
+
+ err = g_new(PurpleConnectionErrorInfo, 1);
+
+ err->type = type;
+ err->description = g_strdup(description);
+
+ return err;
+}
+
/**************************************************************************
* GBoxed code
**************************************************************************/
static PurpleConnectionErrorInfo *
purple_connection_error_info_copy(PurpleConnectionErrorInfo *err)
{
- PurpleConnectionErrorInfo *newerr;
-
g_return_val_if_fail(err != NULL, NULL);
- newerr = g_new(PurpleConnectionErrorInfo, 1);
- newerr->type = err->type;
- newerr->description = g_strdup(err->description);
-
- return newerr;
+ return purple_connection_error_info_new(err->type, err->description);
}
static void
@@ -755,6 +784,9 @@ purple_connection_finalize(GObject *obje
purple_account_set_connection(account, NULL);
+ if (priv->error_info)
+ purple_connection_error_info_free(priv->error_info);
+
if (priv->disconnect_timeout > 0)
purple_timeout_remove(priv->disconnect_timeout);
diff --git a/libpurple/connection.h b/libpurple/connection.h
--- a/libpurple/connection.h
+++ b/libpurple/connection.h
@@ -386,7 +386,7 @@ const char *purple_connection_get_displa
*
* @return The protocol data for the connection.
*/
-void *purple_connection_get_protocol_data(const PurpleConnection *connection);
+void *purple_connection_get_protocol_data(const PurpleConnection *gc);
/**
* Updates the connection progress.
@@ -413,7 +413,7 @@ void purple_connection_notice(PurpleConn
*
* @param gc the connection which is closing.
* @param reason why the connection is closing.
- * @param description a non- at c NULL localized description of the error.
+ * @param description a localized description of the error (not @c NULL ).
*/
void
purple_connection_error(PurpleConnection *gc,
@@ -421,6 +421,18 @@ purple_connection_error(PurpleConnection
const char *description);
/**
+ * Returns the #PurpleConnectionErrorInfo instance of a connection if an
+ * error exists.
+ *
+ * @param gc The connection.
+ *
+ * @return The #PurpleConnectionErrorInfo instance of the connection if an
+ * error exists, @c NULL otherwise.
+ */
+PurpleConnectionErrorInfo *
+purple_connection_get_error_info(const PurpleConnection *gc);
+
+/**
* Closes a connection due to an SSL error; this is basically a shortcut to
* turning the #PurpleSslErrorType into a #PurpleConnectionError and a
* human-readable string and then calling purple_connection_error().
diff --git a/libpurple/protocols/jabber/parser.c b/libpurple/protocols/jabber/parser.c
--- a/libpurple/protocols/jabber/parser.c
+++ b/libpurple/protocols/jabber/parser.c
@@ -308,10 +308,7 @@ void jabber_parser_process(JabberStream
}
if (js->protocol_version.major == 0 && js->protocol_version.minor == 9 &&
-#if 0
- /* FIXME Is this required here? */
- !js->gc->disconnect_timeout &&
-#endif
+ !purple_connection_get_error_info(js->gc) &&
(js->state == JABBER_STREAM_INITIALIZING ||
js->state == JABBER_STREAM_INITIALIZING_ENCRYPTION)) {
/*
More information about the Commits
mailing list