Refactored some of the SSL code in LmConnection.
Added functions to wrap LmSSL functions in LmOldSocket to minimize the number
of calls from LmConnection to LmSSL directly.
Also split out function to register a STARTTLS handler if it is not already
registered and we are using STARTTLS.
--- a/loudmouth/lm-connection.c Sun Jul 13 11:12:26 2008 +0200
+++ b/loudmouth/lm-connection.c Sun Jul 13 19:02:02 2008 +0200
@@ -785,6 +785,24 @@
}
static void
+connection_possibly_register_starttls_handler (LmConnection *connection)
+{
+ /* if we'd like to use tls and we didn't already start
+ * it, prepare for it now */
+ if (connection->ssl &&
+ lm_old_socket_get_use_starttls (connection->socket) &&
+ !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);
+ }
+}
+
+static void
connection_stream_received (LmConnection *connection, LmMessage *m)
{
gboolean result;
@@ -805,23 +823,12 @@
/* stream is started multiple times, but we only want
* one sasl mechanism */
- if (!connection->sasl)
+ 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 {
+ connection_possibly_register_starttls_handler (connection);
+ } else {
lm_verbose ("Old Jabber stream received: %s\n",
connection->stream_id);
}
@@ -1107,7 +1114,7 @@
LmMessageNode *old_auth;
starttls_node = lm_message_node_find_child (message->node, "starttls");
- if (connection->ssl && lm_ssl_get_use_starttls (connection->ssl)) {
+ if (connection->ssl && lm_old_socket_get_use_starttls (connection->socket)) {
if (starttls_node) {
LmMessage *msg;
@@ -1123,7 +1130,7 @@
return LM_HANDLER_RESULT_REMOVE_MESSAGE;
} else if (!connection->tls_started &&
- lm_ssl_get_require_starttls (connection->ssl)) {
+ lm_old_socket_get_require_starttls (connection->socket)) {
/* If there were no starttls features present and we require it, this is
* the place to scream. */
--- a/loudmouth/lm-old-socket.c Sun Jul 13 11:12:26 2008 +0200
+++ b/loudmouth/lm-old-socket.c Sun Jul 13 19:02:02 2008 +0200
@@ -1244,4 +1244,25 @@
#endif /* HAVE_ASYNCNS */
}
+gboolean
+lm_old_socket_get_use_starttls (LmOldSocket *socket)
+{
+ if (!socket->ssl) {
+ return FALSE;
+ }
+ return lm_ssl_get_use_starttls (socket->ssl);
+}
+
+gboolean
+lm_old_socket_get_require_starttls (LmOldSocket *socket)
+{
+ if (!socket->ssl) {
+ return FALSE;
+ }
+
+ return lm_ssl_get_require_starttls (socket->ssl);
+}
+
+
+
--- a/loudmouth/lm-old-socket.h Sun Jul 13 11:12:26 2008 +0200
+++ b/loudmouth/lm-old-socket.h Sun Jul 13 19:02:02 2008 +0200
@@ -65,5 +65,8 @@
gchar * lm_old_socket_get_local_host (LmOldSocket *socket);
void lm_old_socket_asyncns_cancel (LmOldSocket *socket);
+gboolean lm_old_socket_get_use_starttls (LmOldSocket *socket);
+gboolean lm_old_socket_get_require_starttls (LmOldSocket *socket);
+
#endif /* __LM_OLD_SOCKET_H__ */