# HG changeset patch # User Senko Rasic # Date 1197208922 -3600 # Node ID 02b814ccc5350c031db984d16e93c16f1c20b5aa # Parent 2a892980f78b3b12653b28b9c89235d3887e08bd Register starttls handler at the proper moment, when the stream is received. diff -r 2a892980f78b -r 02b814ccc535 loudmouth/lm-connection.c --- a/loudmouth/lm-connection.c Sun Dec 09 14:26:44 2007 +0100 +++ b/loudmouth/lm-connection.c Sun Dec 09 15:02:02 2007 +0100 @@ -691,6 +691,24 @@ } +static LmHandlerResult +_lm_connection_starttls_cb (LmMessageHandler *handler, + LmConnection *connection, + LmMessage *message, + gpointer user_data) +{ + if (lm_socket_starttls (connection->socket)) { + connection->tls_started = TRUE; + connection_send_stream_header (connection); + } else { + connection_do_close (connection); + connection_signal_disconnect (connection, + LM_DISCONNECT_REASON_ERROR); + } + + return LM_HANDLER_RESULT_REMOVE_MESSAGE; +} + static void connection_stream_received (LmConnection *connection, LmMessage *m) { @@ -714,6 +732,20 @@ * one sasl mechanism */ if (!connection->sasl) connection->sasl = lm_sasl_new(connection); + + /* if we'd like to use tls and we didn't already start + * it, prepare for it now */ + if (connection->ssl && + lm_ssl_get_use_starttls (connection->ssl) && + !connection->starttls_cb) { + connection->starttls_cb = + lm_message_handler_new (_lm_connection_starttls_cb, + NULL, NULL); + lm_connection_register_message_handler (connection, + connection->starttls_cb, + LM_MESSAGE_TYPE_PROCEED, + LM_HANDLER_PRIORITY_FIRST); + } } else { lm_verbose ("Old Jabber stream received: %s\n", connection->stream_id); @@ -988,24 +1020,6 @@ } static LmHandlerResult -_lm_connection_starttls_cb (LmMessageHandler *handler, - LmConnection *connection, - LmMessage *message, - gpointer user_data) -{ - if (lm_socket_starttls (connection->socket)) { - connection_send_stream_header (connection); - connection->tls_started = TRUE; - } else { - connection_do_close (connection); - connection_signal_disconnect (connection, - LM_DISCONNECT_REASON_ERROR); - } - - return LM_HANDLER_RESULT_REMOVE_MESSAGE; -} - -static LmHandlerResult connection_features_cb (LmMessageHandler *handler, LmConnection *connection, LmMessage *message, @@ -1400,16 +1414,6 @@ LM_MESSAGE_TYPE_STREAM_FEATURES, LM_HANDLER_PRIORITY_FIRST); - if (connection->ssl && lm_ssl_get_use_starttls (connection->ssl)) { - connection->starttls_cb = - lm_message_handler_new (_lm_connection_starttls_cb, - NULL, NULL); - lm_connection_register_message_handler (connection, - connection->starttls_cb, - LM_MESSAGE_TYPE_PROCEED, - LM_HANDLER_PRIORITY_FIRST); - } - return TRUE; }