Properly detect if SSL has been started in case of StartTLS usage.
authorSenko Rasic <senko.rasic@collabora.co.uk>
Mon, 29 Oct 2007 23:35:01 +0100
changeset 298 71aaed5a9c34
parent 297 f65eee8ec802
child 299 f38f614ce2ea
Properly detect if SSL has been started in case of StartTLS usage.
loudmouth/lm-socket.c
--- a/loudmouth/lm-socket.c	Mon Oct 29 22:34:34 2007 +0100
+++ b/loudmouth/lm-socket.c	Mon Oct 29 23:35:01 2007 +0100
@@ -58,6 +58,7 @@
 	gboolean      blocking;
 
 	LmSSL        *ssl;
+	gboolean      ssl_started;
 	LmProxy      *proxy;
 
 	GIOChannel   *io_channel;
@@ -139,7 +140,7 @@
 {
 	gint b_written;
 
-	if (socket->ssl) {
+	if (socket->ssl_started) {
 		b_written = _lm_ssl_send (socket->ssl, buf, len);
 	} else {
 		GIOStatus io_status = G_IO_STATUS_AGAIN;
@@ -174,7 +175,7 @@
 
 	*hangup = FALSE;
 
-	if (socket->ssl) {
+	if (socket->ssl_started) {
 		status = _lm_ssl_read (socket->ssl, 
 				       buf, buf_size - 1, bytes_read);
 	} else {
@@ -336,13 +337,15 @@
 	_lm_sock_set_blocking (socket->fd, FALSE); 
 #endif
 
+	socket->ssl_started = TRUE;
+
   return TRUE;
 }
 
 gboolean
 lm_socket_starttls (LmSocket *socket)
 {
-	g_return_val_if_fail (lm_ssl_get_use_starttls (socket->ssl) == FALSE, FALSE);
+	g_return_val_if_fail (lm_ssl_get_use_starttls (socket->ssl) == TRUE, FALSE);
 
 	return _lm_socket_ssl_init (socket, TRUE);
 }
@@ -376,7 +379,7 @@
 	g_free (connect_data);
 
 	/* old-style ssl should be started immediately */
-	if (socket->ssl) {
+	if (socket->ssl && (lm_ssl_get_use_starttls (socket->ssl) == FALSE)) {
 		if (!_lm_socket_ssl_init (socket, FALSE))
 			return;
 	}
@@ -994,6 +997,7 @@
 	socket->port = port;
 	socket->cancel_open = FALSE;
 	socket->ssl = ssl;
+	socket->ssl_started = FALSE;
 	socket->proxy = NULL;
 	socket->blocking = blocking;
 	socket->data_func = data_func;
@@ -1009,11 +1013,6 @@
 		socket->proxy = lm_proxy_ref (proxy);
 	}
 
-	if (socket->ssl && !lm_ssl_get_use_starttls (socket->ssl)) {
-		_lm_ssl_initialize (socket->ssl);
-	}
-
-
 	if (!server) {
 		char          *srv;
 		srv = g_strdup_printf ("_xmpp-client._tcp.%s", socket->domain);