auth: don't delete stream:error handler

Instead, keep the same handler until connection is disconnected. Stream
is opened 3 times during usual workflow. Deleting/restoring the handler
every time brings more places for possible mistakes.
This commit is contained in:
Dmitry Podgorny
2017-06-24 02:04:22 +03:00
parent 182695d1ca
commit da8dc2d3cb

View File

@@ -62,6 +62,7 @@
static void _auth(xmpp_conn_t * const conn); static void _auth(xmpp_conn_t * const conn);
static void _handle_open_sasl(xmpp_conn_t * const conn); static void _handle_open_sasl(xmpp_conn_t * const conn);
static void _handle_open_tls(xmpp_conn_t * const conn);
static int _handle_component_auth(xmpp_conn_t * const conn); static int _handle_component_auth(xmpp_conn_t * const conn);
static int _handle_component_hs_response(xmpp_conn_t * const conn, static int _handle_component_hs_response(xmpp_conn_t * const conn,
@@ -288,9 +289,7 @@ static int _handle_proceedtls_default(xmpp_conn_t * const conn,
xmpp_debug(conn->ctx, "xmpp", "proceeding with TLS"); xmpp_debug(conn->ctx, "xmpp", "proceeding with TLS");
if (conn_tls_start(conn) == 0) { if (conn_tls_start(conn) == 0) {
/* we are about to re-open stream, add new error handler after */ conn_prepare_reset(conn, _handle_open_tls);
xmpp_handler_delete(conn, _handle_error);
conn_prepare_reset(conn, auth_handle_open);
conn_open_stream(conn); conn_open_stream(conn);
} else { } else {
/* failed tls spoils the connection, so disconnect */ /* failed tls spoils the connection, so disconnect */
@@ -317,7 +316,7 @@ static int _handle_sasl_result(xmpp_conn_t * const conn,
/* fall back to next auth method */ /* fall back to next auth method */
_auth(conn); _auth(conn);
} else if (strcmp(name, "success") == 0) { } else if (strcmp(name, "success") == 0) {
/* SASL PLAIN auth successful, we need to restart the stream */ /* SASL auth successful, we need to restart the stream */
xmpp_debug(conn->ctx, "xmpp", "SASL %s auth successful", xmpp_debug(conn->ctx, "xmpp", "SASL %s auth successful",
(char *)userdata); (char *)userdata);
@@ -840,15 +839,23 @@ void auth_handle_open(xmpp_conn_t * const conn)
/* reset all timed handlers */ /* reset all timed handlers */
handler_reset_timed(conn, 0); handler_reset_timed(conn, 0);
/* setup handler for stream:error */ /* setup handler for stream:error, we will keep this handler
handler_add(conn, _handle_error, * for reopened streams until connection is disconnected */
XMPP_NS_STREAMS, "error", NULL, NULL); handler_add(conn, _handle_error, XMPP_NS_STREAMS, "error", NULL, NULL);
/* setup handlers for incoming <stream:features> */ /* setup handlers for incoming <stream:features> */
handler_add(conn, _handle_features, handler_add(conn, _handle_features,
XMPP_NS_STREAMS, "features", NULL, NULL); XMPP_NS_STREAMS, "features", NULL, NULL);
handler_add_timed(conn, _handle_missing_features, handler_add_timed(conn, _handle_missing_features, FEATURES_TIMEOUT, NULL);
FEATURES_TIMEOUT, NULL); }
/* called when stream:stream tag received after TLS establishment */
static void _handle_open_tls(xmpp_conn_t * const conn)
{
/* setup handlers for incoming <stream:features> */
handler_add(conn, _handle_features,
XMPP_NS_STREAMS, "features", NULL, NULL);
handler_add_timed(conn, _handle_missing_features, FEATURES_TIMEOUT, NULL);
} }
/* called when stream:stream tag received after SASL auth */ /* called when stream:stream tag received after SASL auth */