LmConnection: take starttls settings from LmSSL object
authorDafydd Harries <daf@rhydd.org>
Thu, 25 Oct 2007 17:39:25 +0100
changeset 289 839adca0d863
parent 288 8f7aaf4d2f13
child 290 4ab72c1064e9
LmConnection: take starttls settings from LmSSL object
loudmouth/lm-connection.c
--- a/loudmouth/lm-connection.c	Thu Oct 25 16:27:01 2007 +0100
+++ b/loudmouth/lm-connection.c	Thu Oct 25 17:39:25 2007 +0100
@@ -76,11 +76,7 @@
 	LmSASL       *sasl;
 	gchar        *resource;
 	LmMessageHandler *features_cb;
-	gboolean      use_starttls;
 	LmMessageHandler *starttls_cb;
-	LmSSLFunction     ssl_fail_cb;
-	gpointer          ssl_fail_cb_data;
-	gboolean      require_starttls;
 
 	/* Communication */
 	guint         open_id;
@@ -884,16 +880,6 @@
 	}
 }
 
-static LmSSLResponse
-connection_tls_error (LmSSL        *ssl,
-		      LmSSLStatus   status,
-		      gpointer      user_data)
-{
-	LmConnection *conn = (LmConnection *) user_data;
-
-	return conn->ssl_fail_cb (ssl, status, conn->ssl_fail_cb_data);
-}
-
 static LmHandlerResult
 connection_bind_reply (LmMessageHandler *handler,
 			LmConnection    *connection,
@@ -941,8 +927,6 @@
 			    LmMessage *message,
 			    gpointer user_data)
 {
-	connection->ssl = lm_ssl_new (NULL, connection_tls_error, connection, NULL);
-	lm_ssl_ref (connection->ssl);
 	if (lm_socket_starttls (connection->socket, connection->ssl)) {
 		connection_send_stream_header (connection);
 	} else {
@@ -964,27 +948,31 @@
 	LmMessageNode    *starttls_node;
 	
 	starttls_node = lm_message_node_find_child (message->node, "starttls");
-	if (connection->use_starttls && starttls_node) {
-		LmMessage        *msg;
+	if (connection->ssl && lm_ssl_get_use_starttls (connection->ssl)) {
+		if (starttls_node) {
+			LmMessage        *msg;
 
-		msg = lm_message_new (NULL, LM_MESSAGE_TYPE_STARTTLS);
+			msg = lm_message_new (NULL, LM_MESSAGE_TYPE_STARTTLS);
 
-		lm_message_node_set_attributes (msg->node,
-						"xmlns", XMPP_NS_STARTTLS,
-						NULL);
+			lm_message_node_set_attributes (
+				msg->node,
+				"xmlns", XMPP_NS_STARTTLS,
+				NULL);
 
-		lm_connection_send (connection, msg, NULL);
-		lm_message_unref (msg);
+			lm_connection_send (connection, msg, NULL);
+			lm_message_unref (msg);
 
-		return LM_HANDLER_RESULT_REMOVE_MESSAGE;
-	} else if (!connection->ssl && connection->require_starttls) {
-		/* If we don't have ssl set up already, and there
-		 * were no starttls features present, and we do
-		 * require it, this is the place to scream */
+			return LM_HANDLER_RESULT_REMOVE_MESSAGE;
+		} else if (lm_ssl_get_require_starttls (connection->ssl)) {
+			/* If there were no starttls features present and we require it, this is
+			 * the place to scream. */
 
-		g_debug ("%s: required StartTLS feature not supported by server", G_STRFUNC);
-		connection_do_close (connection);
-		return LM_HANDLER_RESULT_REMOVE_MESSAGE;
+			g_debug ("%s: required StartTLS feature not supported by server", G_STRFUNC);
+			connection_do_close (connection);
+			connection_signal_disconnect (connection,
+				LM_DISCONNECT_REASON_ERROR);
+			return LM_HANDLER_RESULT_REMOVE_MESSAGE;
+		}
 	}
 
 	bind_node = lm_message_node_find_child (message->node, "bind");
@@ -1340,7 +1328,7 @@
 			LM_MESSAGE_TYPE_STREAM_FEATURES,
 			LM_HANDLER_PRIORITY_FIRST);
 
-		if (connection->use_starttls) {
+		if (connection->ssl && lm_ssl_get_use_starttls (connection->ssl)) {
 			connection->starttls_cb  =
 				lm_message_handler_new (_lm_connection_starttls_cb,
 					NULL, NULL);