changeset 20115:a68d51d60177

Create purple_connection_ssl_error(), which converts a PurpleSslErrorType to a PurpleDisconnectReason then calls purple_connection_error_reason().
author Will Thompson <will.thompson@collabora.co.uk>
date Wed, 19 Sep 2007 15:00:48 +0000
parents a465779350aa
children a61aa7cc757d
files libpurple/connection.c libpurple/connection.h libpurple/sslconn.h
diffstat 3 files changed, 38 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- 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 *,