Simplify and fix SSL/StartTLS handling in LmSocket
authorSenko Rasic <senko.rasic@collabora.co.uk>
Mon, 29 Oct 2007 16:59:36 +0100
changeset 291 cebf76f7f0e9
parent 290 4ab72c1064e9
child 292 bb7269466be2
Simplify and fix SSL/StartTLS handling in LmSocket
loudmouth/lm-connection.c
loudmouth/lm-socket.c
loudmouth/lm-socket.h
--- a/loudmouth/lm-connection.c	Mon Oct 29 14:49:34 2007 +0100
+++ b/loudmouth/lm-connection.c	Mon Oct 29 16:59:36 2007 +0100
@@ -932,7 +932,7 @@
 			    LmMessage *message,
 			    gpointer user_data)
 {
-	if (lm_socket_starttls (connection->socket, connection->ssl)) {
+	if (lm_socket_starttls (connection->socket)) {
 		connection_send_stream_header (connection);
 	} else {
 		connection_do_close (connection);
--- a/loudmouth/lm-socket.c	Mon Oct 29 14:49:34 2007 +0100
+++ b/loudmouth/lm-socket.c	Mon Oct 29 16:59:36 2007 +0100
@@ -340,13 +340,10 @@
 }
 
 gboolean
-lm_socket_starttls (LmSocket *socket, LmSSL *ssl)
+lm_socket_starttls (LmSocket *socket)
 {
-	/* no-op if we're using old-style ssl (so ssl is set up already) */
-	if (socket->ssl)
-		return TRUE;
+	g_return_val_if_fail (lm_ssl_get_use_starttls (socket->ssl) == FALSE, FALSE);
 
-	socket->ssl = ssl;
 	return _lm_socket_ssl_init (socket, TRUE);
 }
 
@@ -996,7 +993,7 @@
 	socket->server = g_strdup (server);
 	socket->port = port;
 	socket->cancel_open = FALSE;
-	socket->ssl = NULL;
+	socket->ssl = ssl;
 	socket->proxy = NULL;
 	socket->blocking = blocking;
 	socket->data_func = data_func;
@@ -1012,8 +1009,7 @@
 		socket->proxy = lm_proxy_ref (proxy);
 	}
 
-	if (ssl) {
-		socket->ssl = lm_ssl_ref (ssl);
+	if (socket->ssl && !lm_ssl_get_use_starttls (socket->ssl)) {
 		_lm_ssl_initialize (socket->ssl);
 	}
 
--- a/loudmouth/lm-socket.h	Mon Oct 29 14:49:34 2007 +0100
+++ b/loudmouth/lm-socket.h	Mon Oct 29 16:59:36 2007 +0100
@@ -69,7 +69,7 @@
 #ifdef HAVE_ASYNCNS
 void	    _asyncns_cancel               (LmSocket *socket);
 #endif
-gboolean    lm_socket_starttls            (LmSocket *socket, LmSSL *ssl);
+gboolean    lm_socket_starttls            (LmSocket *socket);
 
 #endif /* __LM_SOCKET_H__ */