Create purple_connection_ssl_error(), which converts a PurpleSslErrorType cpw.resiak.disconnectreason

Wed, 19 Sep 2007 15:00:48 +0000

author
Will Thompson <resiak@pidgin.im>
date
Wed, 19 Sep 2007 15:00:48 +0000
branch
cpw.resiak.disconnectreason
changeset 20443
7487bb69ae76
parent 20442
97e2d532c2ac
child 20444
cc02f15b7a91

Create purple_connection_ssl_error(), which converts a PurpleSslErrorType
to a PurpleDisconnectReason then calls purple_connection_error_reason().

libpurple/connection.c file | annotate | diff | comparison | revisions
libpurple/connection.h file | annotate | diff | comparison | revisions
libpurple/sslconn.h file | annotate | diff | comparison | revisions
--- a/libpurple/connection.c	Wed Sep 19 11:39:42 2007 +0000
+++ b/libpurple/connection.c	Wed Sep 19 15:00:48 2007 +0000
@@ -525,6 +525,29 @@
 			purple_connection_get_account(gc));
 }
 
+void
+purple_connection_ssl_error (PurpleConnection *gc,
+                             PurpleSslErrorType ssl_error)
+{
+	PurpleDisconnectReason reason;
+
+	switch (ssl_error) {
+		case PURPLE_SSL_HANDSHAKE_FAILED:
+		case PURPLE_SSL_CONNECT_FAILED:
+			reason = PURPLE_REASON_ENCRYPTION_ERROR;
+			break;
+		case PURPLE_SSL_CERTIFICATE_INVALID:
+			/* TODO: maybe PURPLE_SSL_* should be more specific? */
+			reason = PURPLE_REASON_CERT_OTHER_ERROR;
+			break;
+		default:
+			g_assert_not_reached ();
+			reason = PURPLE_REASON_ENCRYPTION_ERROR;
+	}
+
+	purple_connection_error_reason (gc, reason, purple_ssl_strerror(ssl_error));
+}
+
 gboolean
 purple_connection_reason_is_fatal (PurpleDisconnectReason reason)
 {
--- a/libpurple/connection.h	Wed Sep 19 11:39:42 2007 +0000
+++ b/libpurple/connection.h	Wed Sep 19 15:00:48 2007 +0000
@@ -121,6 +121,7 @@
 #include "account.h"
 #include "plugin.h"
 #include "status.h"
+#include "sslconn.h"
 
 /** Connection UI operations.  Used to notify the user of changes to
  *  connections, such as being disconnected, and to respond to the
@@ -389,6 +390,15 @@
                                 const char *description);
 
 /**
+ * Closes a connection due to an SSL error; this is basically a shortcut to
+ * turning the #PurpleSslErrorType into a #PurpleDisconnectReason and a
+ * human-readable string and then calling purple_connection_error_reason().
+ */
+void
+purple_connection_ssl_error (PurpleConnection *gc,
+                             PurpleSslErrorType ssl_error);
+
+/**
  * Reports whether a disconnection reason is fatal (in which case the account
  * should probably not be automatically reconnected) or transient (so
  * auto-reconnection is a good idea.
--- a/libpurple/sslconn.h	Wed Sep 19 11:39:42 2007 +0000
+++ b/libpurple/sslconn.h	Wed Sep 19 15:00:48 2007 +0000
@@ -26,11 +26,6 @@
 #ifndef _PURPLE_SSLCONN_H_
 #define _PURPLE_SSLCONN_H_
 
-#include "certificate.h"
-#include "proxy.h"
-
-#define PURPLE_SSL_DEFAULT_PORT 443
-
 typedef enum
 {
 	PURPLE_SSL_HANDSHAKE_FAILED = 1,
@@ -38,6 +33,11 @@
 	PURPLE_SSL_CERTIFICATE_INVALID = 3
 } PurpleSslErrorType;
 
+#include "certificate.h"
+#include "proxy.h"
+
+#define PURPLE_SSL_DEFAULT_PORT 443
+
 typedef struct _PurpleSslConnection PurpleSslConnection;
 
 typedef void (*PurpleSslInputFunction)(gpointer, PurpleSslConnection *,

mercurial