changeset 7274:448e39ace278

[gaim-migrate @ 7851] Added a parameter to gaim_ssl_connect() to specify an optional error callback. MSN takes advantage of it, but since I can't reproduce the errors here, I'm not positive it works. It should though! Famous last words. committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Wed, 15 Oct 2003 06:32:13 +0000
parents d152ea377e4a
children 690ff28ae262
files plugins/ssl/ssl-gnutls.c plugins/ssl/ssl-nss.c src/protocols/jabber/jabber.c src/protocols/msn/notification.c src/sslconn.c src/sslconn.h
diffstat 6 files changed, 74 insertions(+), 36 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/ssl/ssl-gnutls.c	Wed Oct 15 06:11:26 2003 +0000
+++ b/plugins/ssl/ssl-gnutls.c	Wed Oct 15 06:32:13 2003 +0000
@@ -94,7 +94,9 @@
 	{
 		gaim_debug_error("gnutls", "Handshake failed\n");
 
-		/* XXX: notify the guy expecting the callback somehow? */
+		if (gsc->error_cb != NULL)
+			gsc->error_cb(gsc, GAIM_SSL_HANDSHAKE_FAILED, data);
+
 		gaim_ssl_close(gsc);
 	}
 	else
--- a/plugins/ssl/ssl-nss.c	Wed Oct 15 06:11:26 2003 +0000
+++ b/plugins/ssl/ssl-nss.c	Wed Oct 15 06:32:13 2003 +0000
@@ -204,6 +204,9 @@
 	{
 		gaim_debug_error("nss", "Handshake failed\n");
 
+		if (gsc->error_cb != NULL)
+			gsc->error_cb(gsc, GAIM_SSL_HANDSHAKE_FAILED, data);
+
 		gaim_ssl_close(gsc);
 
 		return;
--- a/src/protocols/jabber/jabber.c	Wed Oct 15 06:11:26 2003 +0000
+++ b/src/protocols/jabber/jabber.c	Wed Oct 15 06:32:13 2003 +0000
@@ -337,7 +337,7 @@
 	gaim_input_remove(js->gc->inpa);
 	js->gc->inpa = 0;
 	js->gsc = gaim_ssl_connect_fd(js->gc->account, js->fd,
-			jabber_login_callback_ssl, js->gc);
+			jabber_login_callback_ssl, NULL, js->gc);
 }
 
 static void
@@ -382,7 +382,7 @@
 			&& gaim_ssl_is_supported()) {
 		js->gsc = gaim_ssl_connect(account, server,
 				gaim_account_get_int(account, "port", 5222),
-				jabber_login_callback_ssl, gc);
+				jabber_login_callback_ssl, NULL, gc);
 	}
 
 	if(!js->gsc) {
@@ -670,7 +670,7 @@
 			&& gaim_ssl_is_supported()) {
 		js->gsc = gaim_ssl_connect(account, server,
 				gaim_account_get_int(account, "port", 5222),
-				jabber_login_callback_ssl, gc);
+				jabber_login_callback_ssl, NULL, gc);
 	}
 
 	if(!js->gsc) {
--- a/src/protocols/msn/notification.c	Wed Oct 15 06:11:26 2003 +0000
+++ b/src/protocols/msn/notification.c	Wed Oct 15 06:32:13 2003 +0000
@@ -313,6 +313,16 @@
 }
 
 static void
+login_error_cb(GaimSslConnection *gsc, GaimSslErrorType error, void *data)
+{
+	MsnServConn *servconn = (MsnServConn *)data;
+	GaimAccount *account = servconn->session->account;
+	GaimConnection *gc = gaim_account_get_connection(account);
+
+	gaim_connection_error(gc, _("Unable to connect to server"));
+}
+
+static void
 login_connect_cb(gpointer data, GaimSslConnection *gsc,
 				 GaimInputCondition cond)
 {
@@ -420,7 +430,8 @@
 		session->ssl_conn = gaim_ssl_connect(session->account,
 											 session->ssl_login_host,
 											 GAIM_SSL_DEFAULT_PORT,
-											 login_connect_cb, servconn);
+											 login_connect_cb, login_error_cb,
+											 servconn);
 	}
 	else if (strstr(buffer, "HTTP/1.1 401 Unauthorized") != NULL)
 	{
@@ -590,7 +601,8 @@
 	session->ssl_conn = gaim_ssl_connect(session->account,
 										 session->ssl_login_host,
 										 GAIM_SSL_DEFAULT_PORT,
-										 login_connect_cb, servconn);
+										 login_connect_cb, login_error_cb,
+										 servconn);
 }
 
 static gboolean
@@ -682,7 +694,8 @@
 		session->ssl_conn = gaim_ssl_connect(session->account,
 											 "nexus.passport.com",
 											 GAIM_SSL_DEFAULT_PORT,
-											 nexus_connect_cb, servconn);
+											 nexus_connect_cb, login_error_cb,
+											 servconn);
 
 		if (session->ssl_conn == NULL)
 		{
--- a/src/sslconn.c	Wed Oct 15 06:11:26 2003 +0000
+++ b/src/sslconn.c	Wed Oct 15 06:32:13 2003 +0000
@@ -63,7 +63,8 @@
 
 GaimSslConnection *
 gaim_ssl_connect(GaimAccount *account, const char *host, int port,
-				 GaimSslInputFunction func, void *data)
+				 GaimSslInputFunction func, GaimSslErrorFunction error_func,
+				 void *data)
 {
 	GaimSslConnection *gsc;
 	GaimSslOps *ops;
@@ -87,10 +88,11 @@
 
 	gsc = g_new0(GaimSslConnection, 1);
 
-	gsc->host       = g_strdup(host);
-	gsc->port       = port;
-	gsc->connect_cb_data  = data;
-	gsc->connect_cb = func;
+	gsc->host            = g_strdup(host);
+	gsc->port            = port;
+	gsc->connect_cb_data = data;
+	gsc->connect_cb      = func;
+	gsc->error_cb        = error_func;
 
 	i = gaim_proxy_connect(account, host, port, ops->connect_cb, gsc);
 
@@ -114,7 +116,8 @@
 }
 
 void
-gaim_ssl_input_add(GaimSslConnection *gsc, GaimSslInputFunction func, void *data)
+gaim_ssl_input_add(GaimSslConnection *gsc, GaimSslInputFunction func,
+				   void *data)
 {
 	GaimSslOps *ops;
 
@@ -124,13 +127,15 @@
 	ops = gaim_ssl_get_ops();
 
 	gsc->recv_cb_data = data;
-	gsc->recv_cb = func;
+	gsc->recv_cb      = func;
+
 	gsc->inpa = gaim_input_add(gsc->fd, GAIM_INPUT_READ, recv_cb, gsc);
 }
 
 GaimSslConnection *
 gaim_ssl_connect_fd(GaimAccount *account, int fd,
-					GaimSslInputFunction func, void *data)
+					GaimSslInputFunction func,
+					GaimSslErrorFunction error_func, void *data)
 {
 	GaimSslConnection *gsc;
 	GaimSslOps *ops;
@@ -152,8 +157,9 @@
 
 	gsc = g_new0(GaimSslConnection, 1);
 
-	gsc->connect_cb_data  = data;
-	gsc->connect_cb = func;
+	gsc->connect_cb_data = data;
+	gsc->connect_cb      = func;
+	gsc->error_cb        = error_func;
 
 	ops->connect_cb(gsc, fd, GAIM_INPUT_READ);
 
--- a/src/sslconn.h	Wed Oct 15 06:11:26 2003 +0000
+++ b/src/sslconn.h	Wed Oct 15 06:32:13 2003 +0000
@@ -27,10 +27,18 @@
 
 #define GAIM_SSL_DEFAULT_PORT 443
 
+typedef enum
+{
+	GAIM_SSL_HANDSHAKE_FAILED = 1
+
+} GaimSslErrorType;
+
 typedef struct _GaimSslConnection GaimSslConnection;
 
 typedef void (*GaimSslInputFunction)(gpointer, GaimSslConnection *,
 									 GaimInputCondition);
+typedef void (*GaimSslErrorFunction)(GaimSslConnection *, GaimSslErrorType,
+									 gpointer);
 
 struct _GaimSslConnection
 {
@@ -38,6 +46,7 @@
 	int port;
 	void *connect_cb_data;
 	GaimSslInputFunction connect_cb;
+	GaimSslErrorFunction error_cb;
 	void *recv_cb_data;
 	GaimSslInputFunction recv_cb;
 
@@ -82,19 +91,37 @@
 /**
  * Makes a SSL connection to the specified host and port.
  *
- * @param account The account making the connection.
- * @param host    The destination host.
- * @param port    The destination port.
- * @param func    The SSL input handler function.
- * @param data    User-defined data.
+ * @param account    The account making the connection.
+ * @param host       The destination host.
+ * @param port       The destination port.
+ * @param func       The SSL input handler function.
+ * @param error_func The SSL error handler function.
+ * @param data       User-defined data.
  *
  * @return The SSL connection handle.
  */
 GaimSslConnection *gaim_ssl_connect(GaimAccount *account, const char *host,
 									int port, GaimSslInputFunction func,
+									GaimSslErrorFunction error_func,
 									void *data);
 
 /**
+ * Makes a SSL connection using an already open file descriptor.
+ *
+ * @param account    The account making the connection.
+ * @param fd         The file descriptor.
+ * @param func       The SSL input handler function.
+ * @param error_func The SSL error handler function.
+ * @param data       User-defined data.
+ *
+ * @return The SSL connection handle.
+ */
+GaimSslConnection *gaim_ssl_connect_fd(GaimAccount *account, int fd,
+									   GaimSslInputFunction func,
+									   GaimSslErrorFunction error_func,
+									   void *data);
+
+/**
  * Adds an input watcher for the specified SSL connection.
  *
  * @param gsc   The SSL connection handle.
@@ -102,20 +129,7 @@
  * @param data  User-defined data.
  */
 void gaim_ssl_input_add(GaimSslConnection *gsc, GaimSslInputFunction func,
-									void *data);
-
-/**
- * Makes a SSL connection using an already open file descriptor.
- *
- * @param account The account making the connection.
- * @param fd      The file descriptor.
- * @param func    The SSL input handler function.
- * @param data    User-defined data.
- *
- * @return The SSL connection handle.
- */
-GaimSslConnection *gaim_ssl_connect_fd(GaimAccount *account, int fd,
-									   GaimSslInputFunction func, void *data);
+						void *data);
 
 /**
  * Closes a SSL connection.