From 8ff46add8cc7f96ed324c464ab75675a1afb0f70 Mon Sep 17 00:00:00 2001 From: Dmitry Podgorny Date: Tue, 13 Oct 2015 00:44:23 +0300 Subject: [PATCH] conn: don't remember tls state from old connection * Clear conn->secured and conn->tls_failed. These values could be saved after re-connect. * conn is not secured if conn->tls is NULL. This condition handles disconnected connections. --- src/conn.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/conn.c b/src/conn.c index 15b0662..7b78bd6 100644 --- a/src/conn.c +++ b/src/conn.c @@ -400,8 +400,12 @@ int xmpp_connect_client(xmpp_conn_t * const conn, const char *prefdomain = NULL; int found; - conn->type = XMPP_CLIENT; + if (conn->state != XMPP_STATE_DISCONNECTED) + return -1; + conn->type = XMPP_CLIENT; + conn->secured = 0; + conn->tls_failed = 0; conn->domain = xmpp_jid_domain(conn->ctx, conn->jid); if (!conn->domain) return -1; @@ -479,7 +483,12 @@ int xmpp_connect_component(xmpp_conn_t * const conn, const char * const server, { int connectport; + if (conn->state != XMPP_STATE_DISCONNECTED) + return -1; + conn->type = XMPP_COMPONENT; + conn->secured = 0; + conn->tls_failed = 0; /* JID serves as an identificator here and will be used as "to" attribute of the stream */ conn->domain = xmpp_strdup(conn->ctx, conn->jid); @@ -487,7 +496,6 @@ int xmpp_connect_component(xmpp_conn_t * const conn, const char * const server, /* The server domain, jid and password MUST be specified. */ if (!(server && conn->jid && conn->pass)) return -1; - connectport = port ? port : _conn_default_port(conn); xmpp_debug(conn->ctx, "xmpp", "Connecting via %s", server); @@ -791,7 +799,7 @@ void xmpp_conn_set_old_style_ssl(xmpp_conn_t * const conn) /** Returns whether TLS session is established or not. */ int xmpp_conn_is_secured(xmpp_conn_t * const conn) { - return conn->secured && !conn->tls_failed ? 1 : 0; + return conn->secured && !conn->tls_failed && conn->tls != NULL ? 1 : 0; } static void _log_open_tag(xmpp_conn_t *conn, char **attrs)