Skip to content

Commit

Permalink
Merge pull request #20 from boothj5/master
Browse files Browse the repository at this point in the history
Option to disable TLS
  • Loading branch information
metajack committed May 20, 2012
2 parents cc979d4 + 5875390 commit 5f174b6
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/auth.c
Expand Up @@ -209,9 +209,13 @@ static int _handle_features(xmpp_conn_t * const conn,

/* check for TLS */
if (!conn->secured) {
child = xmpp_stanza_get_child_by_name(stanza, "starttls");
if (child && (strcmp(xmpp_stanza_get_ns(child), XMPP_NS_TLS) == 0))
conn->tls_support = 1;
if (!conn->tls_disabled) {
child = xmpp_stanza_get_child_by_name(stanza, "starttls");
if (child && (strcmp(xmpp_stanza_get_ns(child), XMPP_NS_TLS) == 0))
conn->tls_support = 1;
} else {
conn->tls_support = 0;
}
}

/* check for SASL */
Expand Down
1 change: 1 addition & 0 deletions src/common.h
Expand Up @@ -163,6 +163,7 @@ struct _xmpp_conn_t {
tls_t *tls;

int tls_support;
int tls_disabled;
int tls_failed; /* set when tls fails, so we don't try again */
int sasl_support; /* if true, field is a bitfield of supported
mechanisms */
Expand Down
12 changes: 12 additions & 0 deletions src/conn.c
Expand Up @@ -109,6 +109,7 @@ xmpp_conn_t *xmpp_conn_new(xmpp_ctx_t * const ctx)
conn->bound_jid = NULL;

conn->tls_support = 0;
conn->tls_disabled = 0;
conn->tls_failed = 0;
conn->sasl_support = 0;
conn->secured = 0;
Expand Down Expand Up @@ -666,6 +667,17 @@ void conn_open_stream(xmpp_conn_t * const conn)
XMPP_NS_STREAMS);
}

/** Disable TLS for this connection, called by users of the library.
* Occasionally a server will be misconfigured to send the starttls
* feature, but wil not support the handshake.
*
* @param conn a Strophe connection object
*/
void xmpp_conn_disable_tls(xmpp_conn_t * const conn)
{
conn->tls_disabled = 1;
}

static void _log_open_tag(xmpp_conn_t *conn, char **attrs)
{
char buf[4096];
Expand Down
1 change: 1 addition & 0 deletions strophe.h
Expand Up @@ -217,6 +217,7 @@ void xmpp_conn_set_jid(xmpp_conn_t * const conn, const char * const jid);
const char *xmpp_conn_get_pass(const xmpp_conn_t * const conn);
void xmpp_conn_set_pass(xmpp_conn_t * const conn, const char * const pass);
xmpp_ctx_t* xmpp_conn_get_context(xmpp_conn_t * const conn);
void xmpp_conn_disable_tls(xmpp_conn_t * const conn);

int xmpp_connect_client(xmpp_conn_t * const conn,
const char * const altdomain,
Expand Down

0 comments on commit 5f174b6

Please sign in to comment.