make logging functions private
Fixes #189 Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
This commit is contained in:
135
src/auth.c
135
src/auth.c
@@ -194,7 +194,7 @@ static int _handle_missing_features(xmpp_conn_t *conn, void *userdata)
|
|||||||
{
|
{
|
||||||
UNUSED(userdata);
|
UNUSED(userdata);
|
||||||
|
|
||||||
xmpp_debug(conn->ctx, "xmpp", "didn't get stream features");
|
strophe_debug(conn->ctx, "xmpp", "didn't get stream features");
|
||||||
|
|
||||||
/* legacy auth will be attempted */
|
/* legacy auth will be attempted */
|
||||||
_auth(conn);
|
_auth(conn);
|
||||||
@@ -294,10 +294,10 @@ static int _handle_proceedtls_default(xmpp_conn_t *conn,
|
|||||||
UNUSED(userdata);
|
UNUSED(userdata);
|
||||||
|
|
||||||
name = xmpp_stanza_get_name(stanza);
|
name = xmpp_stanza_get_name(stanza);
|
||||||
xmpp_debug(conn->ctx, "xmpp", "handle proceedtls called for %s", name);
|
strophe_debug(conn->ctx, "xmpp", "handle proceedtls called for %s", name);
|
||||||
|
|
||||||
if (strcmp(name, "proceed") == 0) {
|
if (strcmp(name, "proceed") == 0) {
|
||||||
xmpp_debug(conn->ctx, "xmpp", "proceeding with TLS");
|
strophe_debug(conn->ctx, "xmpp", "proceeding with TLS");
|
||||||
|
|
||||||
if (conn_tls_start(conn) == 0) {
|
if (conn_tls_start(conn) == 0) {
|
||||||
conn_prepare_reset(conn, _handle_open_tls);
|
conn_prepare_reset(conn, _handle_open_tls);
|
||||||
@@ -320,14 +320,15 @@ _handle_sasl_result(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void *userdata)
|
|||||||
|
|
||||||
/* the server should send a <success> or <failure> stanza */
|
/* the server should send a <success> or <failure> stanza */
|
||||||
if (strcmp(name, "failure") == 0) {
|
if (strcmp(name, "failure") == 0) {
|
||||||
xmpp_debug(conn->ctx, "xmpp", "SASL %s auth failed", (char *)userdata);
|
strophe_debug(conn->ctx, "xmpp", "SASL %s auth failed",
|
||||||
|
(char *)userdata);
|
||||||
|
|
||||||
/* 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 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",
|
strophe_debug(conn->ctx, "xmpp", "SASL %s auth successful",
|
||||||
(char *)userdata);
|
(char *)userdata);
|
||||||
|
|
||||||
/* reset parser */
|
/* reset parser */
|
||||||
conn_prepare_reset(conn, _handle_open_sasl);
|
conn_prepare_reset(conn, _handle_open_sasl);
|
||||||
@@ -336,9 +337,9 @@ _handle_sasl_result(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void *userdata)
|
|||||||
conn_open_stream(conn);
|
conn_open_stream(conn);
|
||||||
} else {
|
} else {
|
||||||
/* got unexpected reply */
|
/* got unexpected reply */
|
||||||
xmpp_error(conn->ctx, "xmpp",
|
strophe_error(conn->ctx, "xmpp",
|
||||||
"Got unexpected reply to SASL %s authentication.",
|
"Got unexpected reply to SASL %s authentication.",
|
||||||
(char *)userdata);
|
(char *)userdata);
|
||||||
xmpp_disconnect(conn);
|
xmpp_disconnect(conn);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -358,8 +359,8 @@ static int _handle_digestmd5_challenge(xmpp_conn_t *conn,
|
|||||||
UNUSED(userdata);
|
UNUSED(userdata);
|
||||||
|
|
||||||
name = xmpp_stanza_get_name(stanza);
|
name = xmpp_stanza_get_name(stanza);
|
||||||
xmpp_debug(conn->ctx, "xmpp", "handle digest-md5 (challenge) called for %s",
|
strophe_debug(conn->ctx, "xmpp",
|
||||||
name);
|
"handle digest-md5 (challenge) called for %s", name);
|
||||||
|
|
||||||
if (strcmp(name, "challenge") == 0) {
|
if (strcmp(name, "challenge") == 0) {
|
||||||
text = xmpp_stanza_get_text(stanza);
|
text = xmpp_stanza_get_text(stanza);
|
||||||
@@ -415,8 +416,8 @@ static int _handle_digestmd5_rspauth(xmpp_conn_t *conn,
|
|||||||
UNUSED(userdata);
|
UNUSED(userdata);
|
||||||
|
|
||||||
name = xmpp_stanza_get_name(stanza);
|
name = xmpp_stanza_get_name(stanza);
|
||||||
xmpp_debug(conn->ctx, "xmpp", "handle digest-md5 (rspauth) called for %s",
|
strophe_debug(conn->ctx, "xmpp",
|
||||||
name);
|
"handle digest-md5 (rspauth) called for %s", name);
|
||||||
|
|
||||||
if (strcmp(name, "challenge") == 0) {
|
if (strcmp(name, "challenge") == 0) {
|
||||||
/* assume it's an rspauth response */
|
/* assume it's an rspauth response */
|
||||||
@@ -456,8 +457,8 @@ static int _handle_scram_challenge(xmpp_conn_t *conn,
|
|||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
name = xmpp_stanza_get_name(stanza);
|
name = xmpp_stanza_get_name(stanza);
|
||||||
xmpp_debug(conn->ctx, "xmpp", "handle %s (challenge) called for %s",
|
strophe_debug(conn->ctx, "xmpp", "handle %s (challenge) called for %s",
|
||||||
scram_ctx->alg->scram_name, name);
|
scram_ctx->alg->scram_name, name);
|
||||||
|
|
||||||
if (strcmp(name, "challenge") == 0) {
|
if (strcmp(name, "challenge") == 0) {
|
||||||
text = xmpp_stanza_get_text(stanza);
|
text = xmpp_stanza_get_text(stanza);
|
||||||
@@ -630,9 +631,9 @@ static void _auth(xmpp_conn_t *conn)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (conn->tls_mandatory && !xmpp_conn_is_secured(conn)) {
|
if (conn->tls_mandatory && !xmpp_conn_is_secured(conn)) {
|
||||||
xmpp_error(conn->ctx, "xmpp",
|
strophe_error(conn->ctx, "xmpp",
|
||||||
"TLS is not supported, but set as "
|
"TLS is not supported, but set as "
|
||||||
"mandatory for this connection");
|
"mandatory for this connection");
|
||||||
conn_disconnect(conn);
|
conn_disconnect(conn);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -697,12 +698,13 @@ static void _auth(xmpp_conn_t *conn)
|
|||||||
/* SASL EXTERNAL was tried, unset flag */
|
/* SASL EXTERNAL was tried, unset flag */
|
||||||
conn->sasl_support &= ~SASL_MASK_EXTERNAL;
|
conn->sasl_support &= ~SASL_MASK_EXTERNAL;
|
||||||
} else if (anonjid) {
|
} else if (anonjid) {
|
||||||
xmpp_error(conn->ctx, "auth",
|
strophe_error(conn->ctx, "auth",
|
||||||
"No node in JID, and SASL ANONYMOUS unsupported.");
|
"No node in JID, and SASL ANONYMOUS unsupported.");
|
||||||
xmpp_disconnect(conn);
|
xmpp_disconnect(conn);
|
||||||
} else if (conn->pass == NULL) {
|
} else if (conn->pass == NULL) {
|
||||||
xmpp_error(conn->ctx, "auth",
|
strophe_error(
|
||||||
"Password hasn't been set, and SASL ANONYMOUS unsupported.");
|
conn->ctx, "auth",
|
||||||
|
"Password hasn't been set, and SASL ANONYMOUS unsupported.");
|
||||||
xmpp_disconnect(conn);
|
xmpp_disconnect(conn);
|
||||||
} else if (conn->sasl_support & SASL_MASK_SCRAM) {
|
} else if (conn->sasl_support & SASL_MASK_SCRAM) {
|
||||||
scram_ctx = strophe_alloc(conn->ctx, sizeof(*scram_ctx));
|
scram_ctx = strophe_alloc(conn->ctx, sizeof(*scram_ctx));
|
||||||
@@ -815,7 +817,8 @@ static void _auth(xmpp_conn_t *conn)
|
|||||||
/* legacy client authentication */
|
/* legacy client authentication */
|
||||||
_auth_legacy(conn);
|
_auth_legacy(conn);
|
||||||
} else {
|
} else {
|
||||||
xmpp_error(conn->ctx, "auth", "Cannot authenticate with known methods");
|
strophe_error(conn->ctx, "auth",
|
||||||
|
"Cannot authenticate with known methods");
|
||||||
xmpp_disconnect(conn);
|
xmpp_disconnect(conn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -856,7 +859,7 @@ static void _handle_open_tls(xmpp_conn_t *conn)
|
|||||||
/* called when stream:stream tag received after SASL auth */
|
/* called when stream:stream tag received after SASL auth */
|
||||||
static void _handle_open_sasl(xmpp_conn_t *conn)
|
static void _handle_open_sasl(xmpp_conn_t *conn)
|
||||||
{
|
{
|
||||||
xmpp_debug(conn->ctx, "xmpp", "Reopened stream successfully.");
|
strophe_debug(conn->ctx, "xmpp", "Reopened stream successfully.");
|
||||||
|
|
||||||
/* setup stream:features handlers */
|
/* setup stream:features handlers */
|
||||||
handler_add(conn, _handle_features_sasl, XMPP_NS_STREAMS, "features", NULL,
|
handler_add(conn, _handle_features_sasl, XMPP_NS_STREAMS, "features", NULL,
|
||||||
@@ -962,9 +965,9 @@ _handle_features_sasl(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void *userdata)
|
|||||||
xmpp_stanza_release(iq);
|
xmpp_stanza_release(iq);
|
||||||
} else {
|
} else {
|
||||||
/* can't bind, disconnect */
|
/* can't bind, disconnect */
|
||||||
xmpp_error(conn->ctx, "xmpp",
|
strophe_error(conn->ctx, "xmpp",
|
||||||
"Stream features does not allow "
|
"Stream features does not allow "
|
||||||
"resource bind.");
|
"resource bind.");
|
||||||
xmpp_disconnect(conn);
|
xmpp_disconnect(conn);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -975,9 +978,9 @@ static int _handle_missing_features_sasl(xmpp_conn_t *conn, void *userdata)
|
|||||||
{
|
{
|
||||||
UNUSED(userdata);
|
UNUSED(userdata);
|
||||||
|
|
||||||
xmpp_error(conn->ctx, "xmpp",
|
strophe_error(conn->ctx, "xmpp",
|
||||||
"Did not receive stream features "
|
"Did not receive stream features "
|
||||||
"after SASL authentication.");
|
"after SASL authentication.");
|
||||||
xmpp_disconnect(conn);
|
xmpp_disconnect(conn);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -996,11 +999,11 @@ _handle_bind(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void *userdata)
|
|||||||
/* server has replied to bind request */
|
/* server has replied to bind request */
|
||||||
type = xmpp_stanza_get_type(stanza);
|
type = xmpp_stanza_get_type(stanza);
|
||||||
if (type && strcmp(type, "error") == 0) {
|
if (type && strcmp(type, "error") == 0) {
|
||||||
xmpp_error(conn->ctx, "xmpp", "Binding failed.");
|
strophe_error(conn->ctx, "xmpp", "Binding failed.");
|
||||||
xmpp_disconnect(conn);
|
xmpp_disconnect(conn);
|
||||||
} else if (type && strcmp(type, "result") == 0) {
|
} else if (type && strcmp(type, "result") == 0) {
|
||||||
xmpp_stanza_t *binding = xmpp_stanza_get_child_by_name(stanza, "bind");
|
xmpp_stanza_t *binding = xmpp_stanza_get_child_by_name(stanza, "bind");
|
||||||
xmpp_debug(conn->ctx, "xmpp", "Bind successful.");
|
strophe_debug(conn->ctx, "xmpp", "Bind successful.");
|
||||||
|
|
||||||
if (binding) {
|
if (binding) {
|
||||||
xmpp_stanza_t *jid_stanza =
|
xmpp_stanza_t *jid_stanza =
|
||||||
@@ -1048,7 +1051,7 @@ _handle_bind(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void *userdata)
|
|||||||
conn->userdata);
|
conn->userdata);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
xmpp_error(conn->ctx, "xmpp", "Server sent malformed bind reply.");
|
strophe_error(conn->ctx, "xmpp", "Server sent malformed bind reply.");
|
||||||
xmpp_disconnect(conn);
|
xmpp_disconnect(conn);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1059,7 +1062,7 @@ static int _handle_missing_bind(xmpp_conn_t *conn, void *userdata)
|
|||||||
{
|
{
|
||||||
UNUSED(userdata);
|
UNUSED(userdata);
|
||||||
|
|
||||||
xmpp_error(conn->ctx, "xmpp", "Server did not reply to bind request.");
|
strophe_error(conn->ctx, "xmpp", "Server did not reply to bind request.");
|
||||||
xmpp_disconnect(conn);
|
xmpp_disconnect(conn);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -1077,17 +1080,18 @@ _handle_session(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void *userdata)
|
|||||||
/* server has replied to the session request */
|
/* server has replied to the session request */
|
||||||
type = xmpp_stanza_get_type(stanza);
|
type = xmpp_stanza_get_type(stanza);
|
||||||
if (type && strcmp(type, "error") == 0) {
|
if (type && strcmp(type, "error") == 0) {
|
||||||
xmpp_error(conn->ctx, "xmpp", "Session establishment failed.");
|
strophe_error(conn->ctx, "xmpp", "Session establishment failed.");
|
||||||
xmpp_disconnect(conn);
|
xmpp_disconnect(conn);
|
||||||
} else if (type && strcmp(type, "result") == 0) {
|
} else if (type && strcmp(type, "result") == 0) {
|
||||||
xmpp_debug(conn->ctx, "xmpp", "Session establishment successful.");
|
strophe_debug(conn->ctx, "xmpp", "Session establishment successful.");
|
||||||
|
|
||||||
conn->authenticated = 1;
|
conn->authenticated = 1;
|
||||||
|
|
||||||
/* call connection handler */
|
/* call connection handler */
|
||||||
conn->conn_handler(conn, XMPP_CONN_CONNECT, 0, NULL, conn->userdata);
|
conn->conn_handler(conn, XMPP_CONN_CONNECT, 0, NULL, conn->userdata);
|
||||||
} else {
|
} else {
|
||||||
xmpp_error(conn->ctx, "xmpp", "Server sent malformed session reply.");
|
strophe_error(conn->ctx, "xmpp",
|
||||||
|
"Server sent malformed session reply.");
|
||||||
xmpp_disconnect(conn);
|
xmpp_disconnect(conn);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1098,7 +1102,8 @@ static int _handle_missing_session(xmpp_conn_t *conn, void *userdata)
|
|||||||
{
|
{
|
||||||
UNUSED(userdata);
|
UNUSED(userdata);
|
||||||
|
|
||||||
xmpp_error(conn->ctx, "xmpp", "Server did not reply to session request.");
|
strophe_error(conn->ctx, "xmpp",
|
||||||
|
"Server did not reply to session request.");
|
||||||
xmpp_disconnect(conn);
|
xmpp_disconnect(conn);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -1107,9 +1112,9 @@ static int _handle_missing_legacy(xmpp_conn_t *conn, void *userdata)
|
|||||||
{
|
{
|
||||||
UNUSED(userdata);
|
UNUSED(userdata);
|
||||||
|
|
||||||
xmpp_error(conn->ctx, "xmpp",
|
strophe_error(conn->ctx, "xmpp",
|
||||||
"Server did not reply to legacy "
|
"Server did not reply to legacy "
|
||||||
"authentication request.");
|
"authentication request.");
|
||||||
xmpp_disconnect(conn);
|
xmpp_disconnect(conn);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -1129,24 +1134,25 @@ _handle_legacy(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void *userdata)
|
|||||||
type = xmpp_stanza_get_type(stanza);
|
type = xmpp_stanza_get_type(stanza);
|
||||||
name = xmpp_stanza_get_name(stanza);
|
name = xmpp_stanza_get_name(stanza);
|
||||||
if (!type || strcmp(name, "iq") != 0) {
|
if (!type || strcmp(name, "iq") != 0) {
|
||||||
xmpp_error(conn->ctx, "xmpp",
|
strophe_error(conn->ctx, "xmpp",
|
||||||
"Server sent us an unexpected response "
|
"Server sent us an unexpected response "
|
||||||
"to legacy authentication request.");
|
"to legacy authentication request.");
|
||||||
xmpp_disconnect(conn);
|
xmpp_disconnect(conn);
|
||||||
} else if (strcmp(type, "error") == 0) {
|
} else if (strcmp(type, "error") == 0) {
|
||||||
/* legacy client auth failed, no more fallbacks */
|
/* legacy client auth failed, no more fallbacks */
|
||||||
xmpp_error(conn->ctx, "xmpp", "Legacy client authentication failed.");
|
strophe_error(conn->ctx, "xmpp",
|
||||||
|
"Legacy client authentication failed.");
|
||||||
xmpp_disconnect(conn);
|
xmpp_disconnect(conn);
|
||||||
} else if (strcmp(type, "result") == 0) {
|
} else if (strcmp(type, "result") == 0) {
|
||||||
/* auth succeeded */
|
/* auth succeeded */
|
||||||
xmpp_debug(conn->ctx, "xmpp", "Legacy auth succeeded.");
|
strophe_debug(conn->ctx, "xmpp", "Legacy auth succeeded.");
|
||||||
|
|
||||||
conn->authenticated = 1;
|
conn->authenticated = 1;
|
||||||
conn->conn_handler(conn, XMPP_CONN_CONNECT, 0, NULL, conn->userdata);
|
conn->conn_handler(conn, XMPP_CONN_CONNECT, 0, NULL, conn->userdata);
|
||||||
} else {
|
} else {
|
||||||
xmpp_error(conn->ctx, "xmpp",
|
strophe_error(conn->ctx, "xmpp",
|
||||||
"Server sent us a legacy authentication "
|
"Server sent us a legacy authentication "
|
||||||
"response with a bad type.");
|
"response with a bad type.");
|
||||||
xmpp_disconnect(conn);
|
xmpp_disconnect(conn);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1161,7 +1167,7 @@ static void _auth_legacy(xmpp_conn_t *conn)
|
|||||||
xmpp_stanza_t *child;
|
xmpp_stanza_t *child;
|
||||||
char *str;
|
char *str;
|
||||||
|
|
||||||
xmpp_debug(conn->ctx, "auth", "Legacy authentication request");
|
strophe_debug(conn->ctx, "auth", "Legacy authentication request");
|
||||||
|
|
||||||
iq = xmpp_iq_new(conn->ctx, "set", "_xmpp_auth1");
|
iq = xmpp_iq_new(conn->ctx, "set", "_xmpp_auth1");
|
||||||
if (!iq)
|
if (!iq)
|
||||||
@@ -1226,7 +1232,8 @@ static void _auth_legacy(xmpp_conn_t *conn)
|
|||||||
} else {
|
} else {
|
||||||
xmpp_stanza_release(authdata);
|
xmpp_stanza_release(authdata);
|
||||||
xmpp_stanza_release(iq);
|
xmpp_stanza_release(iq);
|
||||||
xmpp_error(conn->ctx, "auth", "Cannot authenticate without resource");
|
strophe_error(conn->ctx, "auth",
|
||||||
|
"Cannot authenticate without resource");
|
||||||
xmpp_disconnect(conn);
|
xmpp_disconnect(conn);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -1260,7 +1267,7 @@ void auth_handle_component_open(xmpp_conn_t *conn)
|
|||||||
|
|
||||||
rc = _handle_component_auth(conn);
|
rc = _handle_component_auth(conn);
|
||||||
if (rc != 0) {
|
if (rc != 0) {
|
||||||
xmpp_error(conn->ctx, "auth", "Component authentication failed.");
|
strophe_error(conn->ctx, "auth", "Component authentication failed.");
|
||||||
xmpp_disconnect(conn);
|
xmpp_disconnect(conn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1274,7 +1281,8 @@ int _handle_component_auth(xmpp_conn_t *conn)
|
|||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
if (conn->stream_id == NULL) {
|
if (conn->stream_id == NULL) {
|
||||||
xmpp_error(conn->ctx, "auth", "Received no stream id from the server.");
|
strophe_error(conn->ctx, "auth",
|
||||||
|
"Received no stream id from the server.");
|
||||||
return XMPP_EINT;
|
return XMPP_EINT;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1294,19 +1302,19 @@ int _handle_component_auth(xmpp_conn_t *conn)
|
|||||||
xmpp_snprintf(digest + i * 2, 3, "%02x", md_value[i]);
|
xmpp_snprintf(digest + i * 2, 3, "%02x", md_value[i]);
|
||||||
digest[2 * sizeof(md_value)] = '\0';
|
digest[2 * sizeof(md_value)] = '\0';
|
||||||
|
|
||||||
xmpp_debug(conn->ctx, "auth", "Digest: %s, len: %d", digest,
|
strophe_debug(conn->ctx, "auth", "Digest: %s, len: %d", digest,
|
||||||
strlen(digest));
|
strlen(digest));
|
||||||
|
|
||||||
/* Send the digest to the server */
|
/* Send the digest to the server */
|
||||||
xmpp_send_raw_string(conn, "<handshake xmlns='%s'>%s</handshake>",
|
xmpp_send_raw_string(conn, "<handshake xmlns='%s'>%s</handshake>",
|
||||||
XMPP_NS_COMPONENT, digest);
|
XMPP_NS_COMPONENT, digest);
|
||||||
xmpp_debug(conn->ctx, "auth",
|
strophe_debug(conn->ctx, "auth",
|
||||||
"Sent component handshake to the server.");
|
"Sent component handshake to the server.");
|
||||||
strophe_free(conn->ctx, digest);
|
strophe_free(conn->ctx, digest);
|
||||||
} else {
|
} else {
|
||||||
xmpp_debug(conn->ctx, "auth",
|
strophe_debug(conn->ctx, "auth",
|
||||||
"Couldn't allocate memory for component "
|
"Couldn't allocate memory for component "
|
||||||
"handshake digest.");
|
"handshake digest.");
|
||||||
return XMPP_EMEM;
|
return XMPP_EMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1332,7 +1340,7 @@ int _handle_component_hs_response(xmpp_conn_t *conn,
|
|||||||
size_t msg_size;
|
size_t msg_size;
|
||||||
xmpp_stanza_to_text(stanza, &msg, &msg_size);
|
xmpp_stanza_to_text(stanza, &msg, &msg_size);
|
||||||
if (msg) {
|
if (msg) {
|
||||||
xmpp_debug(conn->ctx, "auth", "Handshake failed: %s", msg);
|
strophe_debug(conn->ctx, "auth", "Handshake failed: %s", msg);
|
||||||
strophe_free(conn->ctx, msg);
|
strophe_free(conn->ctx, msg);
|
||||||
}
|
}
|
||||||
xmpp_disconnect(conn);
|
xmpp_disconnect(conn);
|
||||||
@@ -1352,7 +1360,8 @@ int _handle_missing_handshake(xmpp_conn_t *conn, void *userdata)
|
|||||||
{
|
{
|
||||||
UNUSED(userdata);
|
UNUSED(userdata);
|
||||||
|
|
||||||
xmpp_error(conn->ctx, "xmpp", "Server did not reply to handshake request.");
|
strophe_error(conn->ctx, "xmpp",
|
||||||
|
"Server did not reply to handshake request.");
|
||||||
xmpp_disconnect(conn);
|
xmpp_disconnect(conn);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -1367,5 +1376,5 @@ void auth_handle_open_raw(xmpp_conn_t *conn)
|
|||||||
|
|
||||||
void auth_handle_open_stub(xmpp_conn_t *conn)
|
void auth_handle_open_stub(xmpp_conn_t *conn)
|
||||||
{
|
{
|
||||||
xmpp_warn(conn->ctx, "auth", "Stub callback is called.");
|
strophe_warn(conn->ctx, "auth", "Stub callback is called.");
|
||||||
}
|
}
|
||||||
|
|||||||
28
src/common.h
28
src/common.h
@@ -93,18 +93,24 @@ char *strophe_strdup(const xmpp_ctx_t *ctx, const char *s);
|
|||||||
char *strophe_strndup(const xmpp_ctx_t *ctx, const char *s, size_t len);
|
char *strophe_strndup(const xmpp_ctx_t *ctx, const char *s, size_t len);
|
||||||
void strophe_free(const xmpp_ctx_t *ctx, void *p);
|
void strophe_free(const xmpp_ctx_t *ctx, void *p);
|
||||||
|
|
||||||
void xmpp_log(const xmpp_ctx_t *ctx,
|
|
||||||
const xmpp_log_level_t level,
|
|
||||||
const char *area,
|
|
||||||
const char *fmt,
|
|
||||||
va_list ap);
|
|
||||||
|
|
||||||
/* wrappers for xmpp_log at specific levels */
|
/* wrappers for xmpp_log at specific levels */
|
||||||
void xmpp_error(const xmpp_ctx_t *ctx, const char *area, const char *fmt, ...);
|
void strophe_error(const xmpp_ctx_t *ctx,
|
||||||
void xmpp_warn(const xmpp_ctx_t *ctx, const char *area, const char *fmt, ...);
|
const char *area,
|
||||||
void xmpp_info(const xmpp_ctx_t *ctx, const char *area, const char *fmt, ...);
|
const char *fmt,
|
||||||
void xmpp_debug(const xmpp_ctx_t *ctx, const char *area, const char *fmt, ...);
|
...);
|
||||||
void xmpp_debug_verbose(
|
void strophe_warn(const xmpp_ctx_t *ctx,
|
||||||
|
const char *area,
|
||||||
|
const char *fmt,
|
||||||
|
...);
|
||||||
|
void strophe_info(const xmpp_ctx_t *ctx,
|
||||||
|
const char *area,
|
||||||
|
const char *fmt,
|
||||||
|
...);
|
||||||
|
void strophe_debug(const xmpp_ctx_t *ctx,
|
||||||
|
const char *area,
|
||||||
|
const char *fmt,
|
||||||
|
...);
|
||||||
|
void strophe_debug_verbose(
|
||||||
int level, const xmpp_ctx_t *ctx, const char *area, const char *fmt, ...);
|
int level, const xmpp_ctx_t *ctx, const char *area, const char *fmt, ...);
|
||||||
|
|
||||||
/** connection **/
|
/** connection **/
|
||||||
|
|||||||
110
src/conn.c
110
src/conn.c
@@ -182,7 +182,7 @@ xmpp_conn_t *xmpp_conn_new(xmpp_ctx_t *ctx)
|
|||||||
|
|
||||||
item = strophe_alloc(conn->ctx, sizeof(xmpp_connlist_t));
|
item = strophe_alloc(conn->ctx, sizeof(xmpp_connlist_t));
|
||||||
if (!item) {
|
if (!item) {
|
||||||
xmpp_error(conn->ctx, "xmpp", "failed to allocate memory");
|
strophe_error(conn->ctx, "xmpp", "failed to allocate memory");
|
||||||
strophe_free(conn->ctx, conn->lang);
|
strophe_free(conn->ctx, conn->lang);
|
||||||
parser_free(conn->parser);
|
parser_free(conn->parser);
|
||||||
strophe_free(conn->ctx, conn);
|
strophe_free(conn->ctx, conn);
|
||||||
@@ -239,8 +239,9 @@ void xmpp_conn_set_keepalive(xmpp_conn_t *conn, int timeout, int interval)
|
|||||||
ret = sock_set_keepalive(conn->sock, timeout, interval);
|
ret = sock_set_keepalive(conn->sock, timeout, interval);
|
||||||
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
xmpp_error(conn->ctx, "xmpp", "Setting TCP keepalive (%d,%d) error: %d",
|
strophe_error(conn->ctx, "xmpp",
|
||||||
timeout, interval, sock_error());
|
"Setting TCP keepalive (%d,%d) error: %d", timeout,
|
||||||
|
interval, sock_error());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -287,7 +288,8 @@ int xmpp_conn_release(xmpp_conn_t *conn)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!item) {
|
if (!item) {
|
||||||
xmpp_error(ctx, "xmpp", "Connection not in context's list\n");
|
strophe_error(ctx, "xmpp",
|
||||||
|
"Connection not in context's list\n");
|
||||||
} else {
|
} else {
|
||||||
prev->next = item->next;
|
prev->next = item->next;
|
||||||
strophe_free(ctx, item);
|
strophe_free(ctx, item);
|
||||||
@@ -481,7 +483,7 @@ void xmpp_conn_set_client_cert(xmpp_conn_t *const conn,
|
|||||||
const char *const cert,
|
const char *const cert,
|
||||||
const char *const key)
|
const char *const key)
|
||||||
{
|
{
|
||||||
xmpp_debug(conn->ctx, "conn", "set client cert %s %s", cert, key);
|
strophe_debug(conn->ctx, "conn", "set client cert %s %s", cert, key);
|
||||||
if (conn->tls_client_cert)
|
if (conn->tls_client_cert)
|
||||||
strophe_free(conn->ctx, conn->tls_client_cert);
|
strophe_free(conn->ctx, conn->tls_client_cert);
|
||||||
conn->tls_client_cert = strophe_strdup(conn->ctx, cert);
|
conn->tls_client_cert = strophe_strdup(conn->ctx, cert);
|
||||||
@@ -595,20 +597,20 @@ int xmpp_connect_client(xmpp_conn_t *conn,
|
|||||||
|
|
||||||
if (!conn->jid && conn->tls_client_cert) {
|
if (!conn->jid && conn->tls_client_cert) {
|
||||||
if (tls_id_on_xmppaddr_num(conn) != 1) {
|
if (tls_id_on_xmppaddr_num(conn) != 1) {
|
||||||
xmpp_debug(conn->ctx, "xmpp",
|
strophe_debug(conn->ctx, "xmpp",
|
||||||
"Client certificate contains multiple or no xmppAddr "
|
"Client certificate contains multiple or no xmppAddr "
|
||||||
"and no JID was given to be used.");
|
"and no JID was given to be used.");
|
||||||
return XMPP_EINVOP;
|
return XMPP_EINVOP;
|
||||||
}
|
}
|
||||||
conn->jid = tls_id_on_xmppaddr(conn, 0);
|
conn->jid = tls_id_on_xmppaddr(conn, 0);
|
||||||
if (!conn->jid)
|
if (!conn->jid)
|
||||||
return XMPP_EMEM;
|
return XMPP_EMEM;
|
||||||
xmpp_debug(conn->ctx, "xmpp", "Use jid %s from id-on-xmppAddr.",
|
strophe_debug(conn->ctx, "xmpp", "Use jid %s from id-on-xmppAddr.",
|
||||||
conn->jid);
|
conn->jid);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!conn->jid) {
|
if (!conn->jid) {
|
||||||
xmpp_error(conn->ctx, "xmpp", "JID is not set.");
|
strophe_error(conn->ctx, "xmpp", "JID is not set.");
|
||||||
return XMPP_EINVOP;
|
return XMPP_EINVOP;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -617,7 +619,7 @@ int xmpp_connect_client(xmpp_conn_t *conn,
|
|||||||
return XMPP_EMEM;
|
return XMPP_EMEM;
|
||||||
|
|
||||||
if (altdomain != NULL) {
|
if (altdomain != NULL) {
|
||||||
xmpp_debug(conn->ctx, "xmpp", "Connecting via altdomain.");
|
strophe_debug(conn->ctx, "xmpp", "Connecting via altdomain.");
|
||||||
host = altdomain;
|
host = altdomain;
|
||||||
port = altport ? altport : _conn_default_port(conn, XMPP_CLIENT);
|
port = altport ? altport : _conn_default_port(conn, XMPP_CLIENT);
|
||||||
found = XMPP_DOMAIN_ALTDOMAIN;
|
found = XMPP_DOMAIN_ALTDOMAIN;
|
||||||
@@ -630,9 +632,9 @@ int xmpp_connect_client(xmpp_conn_t *conn,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (XMPP_DOMAIN_NOT_FOUND == found) {
|
if (XMPP_DOMAIN_NOT_FOUND == found) {
|
||||||
xmpp_debug(conn->ctx, "xmpp",
|
strophe_debug(conn->ctx, "xmpp",
|
||||||
"SRV lookup failed, "
|
"SRV lookup failed, "
|
||||||
"connecting via domain.");
|
"connecting via domain.");
|
||||||
host = domain;
|
host = domain;
|
||||||
port = altport ? altport : _conn_default_port(conn, XMPP_CLIENT);
|
port = altport ? altport : _conn_default_port(conn, XMPP_CLIENT);
|
||||||
found = XMPP_DOMAIN_ALTDOMAIN;
|
found = XMPP_DOMAIN_ALTDOMAIN;
|
||||||
@@ -691,9 +693,9 @@ int xmpp_connect_component(xmpp_conn_t *conn,
|
|||||||
/* XEP-0114 does not support TLS */
|
/* XEP-0114 does not support TLS */
|
||||||
xmpp_conn_disable_tls(conn);
|
xmpp_conn_disable_tls(conn);
|
||||||
if (!conn->tls_disabled) {
|
if (!conn->tls_disabled) {
|
||||||
xmpp_error(conn->ctx, "conn",
|
strophe_error(conn->ctx, "conn",
|
||||||
"Failed to disable TLS. "
|
"Failed to disable TLS. "
|
||||||
"XEP-0114 does not support TLS");
|
"XEP-0114 does not support TLS");
|
||||||
return XMPP_EINT;
|
return XMPP_EINT;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -739,7 +741,7 @@ int xmpp_connect_raw(xmpp_conn_t *conn,
|
|||||||
void conn_established(xmpp_conn_t *conn)
|
void conn_established(xmpp_conn_t *conn)
|
||||||
{
|
{
|
||||||
if (conn->tls_legacy_ssl && !conn->is_raw) {
|
if (conn->tls_legacy_ssl && !conn->is_raw) {
|
||||||
xmpp_debug(conn->ctx, "xmpp", "using legacy SSL connection");
|
strophe_debug(conn->ctx, "xmpp", "using legacy SSL connection");
|
||||||
if (conn_tls_start(conn) != 0) {
|
if (conn_tls_start(conn) != 0) {
|
||||||
conn_disconnect(conn);
|
conn_disconnect(conn);
|
||||||
return;
|
return;
|
||||||
@@ -842,7 +844,7 @@ void conn_disconnect_clean(xmpp_conn_t *conn)
|
|||||||
*/
|
*/
|
||||||
void conn_disconnect(xmpp_conn_t *conn)
|
void conn_disconnect(xmpp_conn_t *conn)
|
||||||
{
|
{
|
||||||
xmpp_debug(conn->ctx, "xmpp", "Closing socket.");
|
strophe_debug(conn->ctx, "xmpp", "Closing socket.");
|
||||||
conn->state = XMPP_STATE_DISCONNECTED;
|
conn->state = XMPP_STATE_DISCONNECTED;
|
||||||
if (conn->tls) {
|
if (conn->tls) {
|
||||||
tls_stop(conn->tls);
|
tls_stop(conn->tls);
|
||||||
@@ -926,8 +928,8 @@ void xmpp_send_raw_string(xmpp_conn_t *conn, const char *fmt, ...)
|
|||||||
len++; /* account for trailing \0 */
|
len++; /* account for trailing \0 */
|
||||||
bigbuf = strophe_alloc(conn->ctx, len);
|
bigbuf = strophe_alloc(conn->ctx, len);
|
||||||
if (!bigbuf) {
|
if (!bigbuf) {
|
||||||
xmpp_debug(conn->ctx, "xmpp",
|
strophe_debug(conn->ctx, "xmpp",
|
||||||
"Could not allocate memory for send_raw_string");
|
"Could not allocate memory for send_raw_string");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
@@ -963,7 +965,7 @@ void xmpp_send_raw(xmpp_conn_t *conn, const char *data, size_t len)
|
|||||||
|
|
||||||
d = strophe_strndup(conn->ctx, data, len);
|
d = strophe_strndup(conn->ctx, data, len);
|
||||||
if (!d) {
|
if (!d) {
|
||||||
xmpp_error(conn->ctx, "conn", "Failed to strndup");
|
strophe_error(conn->ctx, "conn", "Failed to strndup");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -988,7 +990,7 @@ void xmpp_send(xmpp_conn_t *conn, xmpp_stanza_t *stanza)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
if (xmpp_stanza_to_text(stanza, &buf, &len) != 0) {
|
if (xmpp_stanza_to_text(stanza, &buf, &len) != 0) {
|
||||||
xmpp_error(conn->ctx, "conn", "Failed to stanza_to_text");
|
strophe_error(conn->ctx, "conn", "Failed to stanza_to_text");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1023,7 +1025,8 @@ void conn_open_stream(xmpp_conn_t *conn)
|
|||||||
|
|
||||||
rc = _conn_open_stream_with_attributes(conn, attributes, attributes_len);
|
rc = _conn_open_stream_with_attributes(conn, attributes, attributes_len);
|
||||||
if (rc != XMPP_EOK) {
|
if (rc != XMPP_EOK) {
|
||||||
xmpp_error(conn->ctx, "conn", "Cannot build stream tag: memory error");
|
strophe_error(conn->ctx, "conn",
|
||||||
|
"Cannot build stream tag: memory error");
|
||||||
conn_disconnect(conn);
|
conn_disconnect(conn);
|
||||||
}
|
}
|
||||||
if (from)
|
if (from)
|
||||||
@@ -1054,10 +1057,10 @@ int conn_tls_start(xmpp_conn_t *conn)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (rc != 0) {
|
if (rc != 0) {
|
||||||
xmpp_debug(conn->ctx, "conn",
|
strophe_debug(conn->ctx, "conn",
|
||||||
"Couldn't start TLS! "
|
"Couldn't start TLS! "
|
||||||
"error %d tls_error %d",
|
"error %d tls_error %d",
|
||||||
rc, conn->error);
|
rc, conn->error);
|
||||||
}
|
}
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
@@ -1108,15 +1111,15 @@ long xmpp_conn_get_flags(const xmpp_conn_t *conn)
|
|||||||
int xmpp_conn_set_flags(xmpp_conn_t *conn, long flags)
|
int xmpp_conn_set_flags(xmpp_conn_t *conn, long flags)
|
||||||
{
|
{
|
||||||
if (conn->state != XMPP_STATE_DISCONNECTED) {
|
if (conn->state != XMPP_STATE_DISCONNECTED) {
|
||||||
xmpp_error(conn->ctx, "conn",
|
strophe_error(conn->ctx, "conn",
|
||||||
"Flags can be set only "
|
"Flags can be set only "
|
||||||
"for disconnected connection");
|
"for disconnected connection");
|
||||||
return XMPP_EINVOP;
|
return XMPP_EINVOP;
|
||||||
}
|
}
|
||||||
if (flags & XMPP_CONN_FLAG_DISABLE_TLS &&
|
if (flags & XMPP_CONN_FLAG_DISABLE_TLS &&
|
||||||
flags & (XMPP_CONN_FLAG_MANDATORY_TLS | XMPP_CONN_FLAG_LEGACY_SSL |
|
flags & (XMPP_CONN_FLAG_MANDATORY_TLS | XMPP_CONN_FLAG_LEGACY_SSL |
|
||||||
XMPP_CONN_FLAG_TRUST_TLS)) {
|
XMPP_CONN_FLAG_TRUST_TLS)) {
|
||||||
xmpp_error(conn->ctx, "conn", "Flags 0x%04lx conflict", flags);
|
strophe_error(conn->ctx, "conn", "Flags 0x%04lx conflict", flags);
|
||||||
return XMPP_EINVOP;
|
return XMPP_EINVOP;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1194,7 +1197,7 @@ static int _disconnect_cleanup(xmpp_conn_t *conn, void *userdata)
|
|||||||
{
|
{
|
||||||
UNUSED(userdata);
|
UNUSED(userdata);
|
||||||
|
|
||||||
xmpp_debug(conn->ctx, "xmpp", "disconnection forced by cleanup timeout");
|
strophe_debug(conn->ctx, "xmpp", "disconnection forced by cleanup timeout");
|
||||||
|
|
||||||
conn_disconnect(conn);
|
conn_disconnect(conn);
|
||||||
|
|
||||||
@@ -1236,9 +1239,9 @@ static char *_conn_build_stream_tag(xmpp_conn_t *conn,
|
|||||||
strcat(tag, tag_tail);
|
strcat(tag, tag_tail);
|
||||||
|
|
||||||
if (strlen(tag) != len) {
|
if (strlen(tag) != len) {
|
||||||
xmpp_error(conn->ctx, "xmpp",
|
strophe_error(conn->ctx, "xmpp",
|
||||||
"Internal error in "
|
"Internal error in "
|
||||||
"_conn_build_stream_tag().");
|
"_conn_build_stream_tag().");
|
||||||
strophe_free(conn->ctx, tag);
|
strophe_free(conn->ctx, tag);
|
||||||
tag = NULL;
|
tag = NULL;
|
||||||
}
|
}
|
||||||
@@ -1282,7 +1285,7 @@ static void _conn_attributes_new(xmpp_conn_t *conn,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (!array || i < nr) {
|
if (!array || i < nr) {
|
||||||
xmpp_error(conn->ctx, "xmpp", "Memory allocation error.");
|
strophe_error(conn->ctx, "xmpp", "Memory allocation error.");
|
||||||
_conn_attributes_destroy(conn, array, i);
|
_conn_attributes_destroy(conn, array, i);
|
||||||
array = NULL;
|
array = NULL;
|
||||||
nr = 0;
|
nr = 0;
|
||||||
@@ -1314,7 +1317,7 @@ static void _log_open_tag(xmpp_conn_t *conn, char **attrs)
|
|||||||
_conn_attributes_new(conn, attrs, &attributes, &nr);
|
_conn_attributes_new(conn, attrs, &attributes, &nr);
|
||||||
tag = _conn_build_stream_tag(conn, attributes, nr);
|
tag = _conn_build_stream_tag(conn, attributes, nr);
|
||||||
if (tag) {
|
if (tag) {
|
||||||
xmpp_debug(conn->ctx, "xmpp", "RECV: %s", tag);
|
strophe_debug(conn->ctx, "xmpp", "RECV: %s", tag);
|
||||||
strophe_free(conn->ctx, tag);
|
strophe_free(conn->ctx, tag);
|
||||||
}
|
}
|
||||||
_conn_attributes_destroy(conn, attributes, nr);
|
_conn_attributes_destroy(conn, attributes, nr);
|
||||||
@@ -1351,14 +1354,14 @@ static void _handle_stream_start(char *name, char **attrs, void *userdata)
|
|||||||
conn->stream_id = strophe_strdup(conn->ctx, id);
|
conn->stream_id = strophe_strdup(conn->ctx, id);
|
||||||
|
|
||||||
if (id && !conn->stream_id) {
|
if (id && !conn->stream_id) {
|
||||||
xmpp_error(conn->ctx, "conn", "Memory allocation failed.");
|
strophe_error(conn->ctx, "conn", "Memory allocation failed.");
|
||||||
failed = 1;
|
failed = 1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
xmpp_error(conn->ctx, "conn",
|
strophe_error(conn->ctx, "conn",
|
||||||
"Server did not open valid stream."
|
"Server did not open valid stream."
|
||||||
" name = %s.",
|
" name = %s.",
|
||||||
name);
|
name);
|
||||||
failed = 1;
|
failed = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1377,7 +1380,7 @@ static void _handle_stream_end(char *name, void *userdata)
|
|||||||
UNUSED(name);
|
UNUSED(name);
|
||||||
|
|
||||||
/* stream is over */
|
/* stream is over */
|
||||||
xmpp_debug(conn->ctx, "xmpp", "RECV: </stream:stream>");
|
strophe_debug(conn->ctx, "xmpp", "RECV: </stream:stream>");
|
||||||
conn_disconnect_clean(conn);
|
conn_disconnect_clean(conn);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1388,7 +1391,7 @@ static void _handle_stream_stanza(xmpp_stanza_t *stanza, void *userdata)
|
|||||||
size_t len;
|
size_t len;
|
||||||
|
|
||||||
if (xmpp_stanza_to_text(stanza, &buf, &len) == 0) {
|
if (xmpp_stanza_to_text(stanza, &buf, &len) == 0) {
|
||||||
xmpp_debug(conn->ctx, "xmpp", "RECV: %s", buf);
|
strophe_debug(conn->ctx, "xmpp", "RECV: %s", buf);
|
||||||
strophe_free(conn->ctx, buf);
|
strophe_free(conn->ctx, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1415,7 +1418,7 @@ static void _conn_reset(xmpp_conn_t *conn)
|
|||||||
xmpp_send_queue_t *sq, *tsq;
|
xmpp_send_queue_t *sq, *tsq;
|
||||||
|
|
||||||
if (conn->state != XMPP_STATE_DISCONNECTED) {
|
if (conn->state != XMPP_STATE_DISCONNECTED) {
|
||||||
xmpp_debug(ctx, "conn", "Can't reset connected object.");
|
strophe_debug(ctx, "conn", "Can't reset connected object.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1485,8 +1488,8 @@ static int _conn_connect(xmpp_conn_t *conn,
|
|||||||
return XMPP_EMEM;
|
return XMPP_EMEM;
|
||||||
|
|
||||||
conn->sock = sock_connect(host, port);
|
conn->sock = sock_connect(host, port);
|
||||||
xmpp_debug(conn->ctx, "xmpp", "sock_connect() to %s:%u returned %d", host,
|
strophe_debug(conn->ctx, "xmpp", "sock_connect() to %s:%u returned %d",
|
||||||
port, conn->sock);
|
host, port, conn->sock);
|
||||||
if (conn->sock == -1)
|
if (conn->sock == -1)
|
||||||
return XMPP_EINT;
|
return XMPP_EINT;
|
||||||
if (conn->ka_timeout || conn->ka_interval)
|
if (conn->ka_timeout || conn->ka_interval)
|
||||||
@@ -1508,7 +1511,7 @@ static int _conn_connect(xmpp_conn_t *conn,
|
|||||||
|
|
||||||
conn->state = XMPP_STATE_CONNECTING;
|
conn->state = XMPP_STATE_CONNECTING;
|
||||||
conn->timeout_stamp = time_stamp();
|
conn->timeout_stamp = time_stamp();
|
||||||
xmpp_debug(conn->ctx, "xmpp", "Attempting to connect to %s", host);
|
strophe_debug(conn->ctx, "xmpp", "Attempting to connect to %s", host);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -1520,7 +1523,7 @@ static int _send_raw(xmpp_conn_t *conn, char *data, size_t len)
|
|||||||
/* create send queue item for queue */
|
/* create send queue item for queue */
|
||||||
item = strophe_alloc(conn->ctx, sizeof(xmpp_send_queue_t));
|
item = strophe_alloc(conn->ctx, sizeof(xmpp_send_queue_t));
|
||||||
if (!item) {
|
if (!item) {
|
||||||
xmpp_error(conn->ctx, "conn", "DROPPED: %s", data);
|
strophe_error(conn->ctx, "conn", "DROPPED: %s", data);
|
||||||
strophe_free(conn->ctx, data);
|
strophe_free(conn->ctx, data);
|
||||||
return XMPP_EMEM;
|
return XMPP_EMEM;
|
||||||
}
|
}
|
||||||
@@ -1541,7 +1544,8 @@ static int _send_raw(xmpp_conn_t *conn, char *data, size_t len)
|
|||||||
conn->send_queue_tail = item;
|
conn->send_queue_tail = item;
|
||||||
}
|
}
|
||||||
conn->send_queue_len++;
|
conn->send_queue_len++;
|
||||||
xmpp_debug_verbose(2, conn->ctx, "conn", "QUEUED: %s", data);
|
strophe_debug_verbose(2, conn->ctx, "conn", "QUEUED: %s", data);
|
||||||
xmpp_debug_verbose(1, conn->ctx, "conn", "Added queue element: %p", item);
|
strophe_debug_verbose(1, conn->ctx, "conn", "Added queue element: %p",
|
||||||
|
item);
|
||||||
return XMPP_EOK;
|
return XMPP_EOK;
|
||||||
}
|
}
|
||||||
|
|||||||
41
src/ctx.c
41
src/ctx.c
@@ -264,11 +264,11 @@ void *strophe_realloc(const xmpp_ctx_t *ctx, void *p, size_t size)
|
|||||||
* @param fmt a printf-style format string for the message
|
* @param fmt a printf-style format string for the message
|
||||||
* @param ap variable argument list supplied for the format string
|
* @param ap variable argument list supplied for the format string
|
||||||
*/
|
*/
|
||||||
void xmpp_log(const xmpp_ctx_t *ctx,
|
static void _strophe_log(const xmpp_ctx_t *ctx,
|
||||||
xmpp_log_level_t level,
|
xmpp_log_level_t level,
|
||||||
const char *area,
|
const char *area,
|
||||||
const char *fmt,
|
const char *fmt,
|
||||||
va_list ap)
|
va_list ap)
|
||||||
{
|
{
|
||||||
int oldret, ret;
|
int oldret, ret;
|
||||||
char smbuf[1024];
|
char smbuf[1024];
|
||||||
@@ -288,14 +288,15 @@ void xmpp_log(const xmpp_ctx_t *ctx,
|
|||||||
buf = (char *)strophe_alloc(ctx, ret + 1);
|
buf = (char *)strophe_alloc(ctx, ret + 1);
|
||||||
if (!buf) {
|
if (!buf) {
|
||||||
buf = NULL;
|
buf = NULL;
|
||||||
xmpp_error(ctx, "log", "Failed allocating memory for log message.");
|
strophe_error(ctx, "log",
|
||||||
|
"Failed allocating memory for log message.");
|
||||||
va_end(copy);
|
va_end(copy);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
oldret = ret;
|
oldret = ret;
|
||||||
ret = xmpp_vsnprintf(buf, ret + 1, fmt, copy);
|
ret = xmpp_vsnprintf(buf, ret + 1, fmt, copy);
|
||||||
if (ret > oldret) {
|
if (ret > oldret) {
|
||||||
xmpp_error(ctx, "log", "Unexpected error");
|
strophe_error(ctx, "log", "Unexpected error");
|
||||||
strophe_free(ctx, buf);
|
strophe_free(ctx, buf);
|
||||||
va_end(copy);
|
va_end(copy);
|
||||||
return;
|
return;
|
||||||
@@ -321,12 +322,15 @@ void xmpp_log(const xmpp_ctx_t *ctx,
|
|||||||
* @param fmt a printf-style format string followed by a variable list of
|
* @param fmt a printf-style format string followed by a variable list of
|
||||||
* arguments to format
|
* arguments to format
|
||||||
*/
|
*/
|
||||||
void xmpp_error(const xmpp_ctx_t *ctx, const char *area, const char *fmt, ...)
|
void strophe_error(const xmpp_ctx_t *ctx,
|
||||||
|
const char *area,
|
||||||
|
const char *fmt,
|
||||||
|
...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
xmpp_log(ctx, XMPP_LEVEL_ERROR, area, fmt, ap);
|
_strophe_log(ctx, XMPP_LEVEL_ERROR, area, fmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -340,12 +344,12 @@ void xmpp_error(const xmpp_ctx_t *ctx, const char *area, const char *fmt, ...)
|
|||||||
* @param fmt a printf-style format string followed by a variable list of
|
* @param fmt a printf-style format string followed by a variable list of
|
||||||
* arguments to format
|
* arguments to format
|
||||||
*/
|
*/
|
||||||
void xmpp_warn(const xmpp_ctx_t *ctx, const char *area, const char *fmt, ...)
|
void strophe_warn(const xmpp_ctx_t *ctx, const char *area, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
xmpp_log(ctx, XMPP_LEVEL_WARN, area, fmt, ap);
|
_strophe_log(ctx, XMPP_LEVEL_WARN, area, fmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -359,12 +363,12 @@ void xmpp_warn(const xmpp_ctx_t *ctx, const char *area, const char *fmt, ...)
|
|||||||
* @param fmt a printf-style format string followed by a variable list of
|
* @param fmt a printf-style format string followed by a variable list of
|
||||||
* arguments to format
|
* arguments to format
|
||||||
*/
|
*/
|
||||||
void xmpp_info(const xmpp_ctx_t *ctx, const char *area, const char *fmt, ...)
|
void strophe_info(const xmpp_ctx_t *ctx, const char *area, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
xmpp_log(ctx, XMPP_LEVEL_INFO, area, fmt, ap);
|
_strophe_log(ctx, XMPP_LEVEL_INFO, area, fmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -378,12 +382,15 @@ void xmpp_info(const xmpp_ctx_t *ctx, const char *area, const char *fmt, ...)
|
|||||||
* @param fmt a printf-style format string followed by a variable list of
|
* @param fmt a printf-style format string followed by a variable list of
|
||||||
* arguments to format
|
* arguments to format
|
||||||
*/
|
*/
|
||||||
void xmpp_debug(const xmpp_ctx_t *ctx, const char *area, const char *fmt, ...)
|
void strophe_debug(const xmpp_ctx_t *ctx,
|
||||||
|
const char *area,
|
||||||
|
const char *fmt,
|
||||||
|
...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
xmpp_log(ctx, XMPP_LEVEL_DEBUG, area, fmt, ap);
|
_strophe_log(ctx, XMPP_LEVEL_DEBUG, area, fmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -398,7 +405,7 @@ void xmpp_debug(const xmpp_ctx_t *ctx, const char *area, const char *fmt, ...)
|
|||||||
* @param fmt a printf-style format string followed by a variable list of
|
* @param fmt a printf-style format string followed by a variable list of
|
||||||
* arguments to format
|
* arguments to format
|
||||||
*/
|
*/
|
||||||
void xmpp_debug_verbose(
|
void strophe_debug_verbose(
|
||||||
int level, const xmpp_ctx_t *ctx, const char *area, const char *fmt, ...)
|
int level, const xmpp_ctx_t *ctx, const char *area, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
@@ -407,7 +414,7 @@ void xmpp_debug_verbose(
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
xmpp_log(ctx, XMPP_LEVEL_DEBUG, area, fmt, ap);
|
_strophe_log(ctx, XMPP_LEVEL_DEBUG, area, fmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
38
src/event.c
38
src/event.c
@@ -107,7 +107,8 @@ void xmpp_run_once(xmpp_ctx_t *ctx, unsigned long timeout)
|
|||||||
|
|
||||||
if (ret < 0 && !tls_is_recoverable(tls_error(conn->tls))) {
|
if (ret < 0 && !tls_is_recoverable(tls_error(conn->tls))) {
|
||||||
/* an error occurred */
|
/* an error occurred */
|
||||||
xmpp_debug(ctx, "xmpp", "Send error occurred, disconnecting.");
|
strophe_debug(ctx, "xmpp",
|
||||||
|
"Send error occurred, disconnecting.");
|
||||||
conn->error = ECONNABORTED;
|
conn->error = ECONNABORTED;
|
||||||
conn_disconnect(conn);
|
conn_disconnect(conn);
|
||||||
goto next_item;
|
goto next_item;
|
||||||
@@ -134,9 +135,9 @@ void xmpp_run_once(xmpp_ctx_t *ctx, unsigned long timeout)
|
|||||||
break; /* partial write or an error */
|
break; /* partial write or an error */
|
||||||
|
|
||||||
/* all data for this queue item written, delete and move on */
|
/* all data for this queue item written, delete and move on */
|
||||||
xmpp_debug(conn->ctx, "conn", "SENT: %s", sq->data);
|
strophe_debug(conn->ctx, "conn", "SENT: %s", sq->data);
|
||||||
xmpp_debug_verbose(1, ctx, "xmpp",
|
strophe_debug_verbose(1, ctx, "xmpp",
|
||||||
"Finished writing queue element: %p.", sq);
|
"Finished writing queue element: %p.", sq);
|
||||||
strophe_free(ctx, sq->data);
|
strophe_free(ctx, sq->data);
|
||||||
tsq = sq;
|
tsq = sq;
|
||||||
sq = sq->next;
|
sq = sq->next;
|
||||||
@@ -154,7 +155,7 @@ void xmpp_run_once(xmpp_ctx_t *ctx, unsigned long timeout)
|
|||||||
if (conn->error) {
|
if (conn->error) {
|
||||||
/* FIXME: need to tear down send queues and random other things
|
/* FIXME: need to tear down send queues and random other things
|
||||||
* maybe this should be abstracted */
|
* maybe this should be abstracted */
|
||||||
xmpp_debug(ctx, "xmpp", "Send error occurred, disconnecting.");
|
strophe_debug(ctx, "xmpp", "Send error occurred, disconnecting.");
|
||||||
conn->error = ECONNABORTED;
|
conn->error = ECONNABORTED;
|
||||||
conn_disconnect(conn);
|
conn_disconnect(conn);
|
||||||
}
|
}
|
||||||
@@ -195,7 +196,7 @@ next_item:
|
|||||||
FD_SET(conn->sock, &wfds);
|
FD_SET(conn->sock, &wfds);
|
||||||
else {
|
else {
|
||||||
conn->error = ETIMEDOUT;
|
conn->error = ETIMEDOUT;
|
||||||
xmpp_info(ctx, "xmpp", "Connection attempt timed out.");
|
strophe_info(ctx, "xmpp", "Connection attempt timed out.");
|
||||||
conn_disconnect(conn);
|
conn_disconnect(conn);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -232,8 +233,8 @@ next_item:
|
|||||||
/* select errored */
|
/* select errored */
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
if (!sock_is_recoverable(sock_error()))
|
if (!sock_is_recoverable(sock_error()))
|
||||||
xmpp_error(ctx, "xmpp", "event watcher internal error %d",
|
strophe_error(ctx, "xmpp", "event watcher internal error %d",
|
||||||
sock_error());
|
sock_error());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -255,13 +256,14 @@ next_item:
|
|||||||
ret = sock_connect_error(conn->sock);
|
ret = sock_connect_error(conn->sock);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
/* connection failed */
|
/* connection failed */
|
||||||
xmpp_debug(ctx, "xmpp", "connection failed, error %d", ret);
|
strophe_debug(ctx, "xmpp", "connection failed, error %d",
|
||||||
|
ret);
|
||||||
conn_disconnect(conn);
|
conn_disconnect(conn);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
conn->state = XMPP_STATE_CONNECTED;
|
conn->state = XMPP_STATE_CONNECTED;
|
||||||
xmpp_debug(ctx, "xmpp", "connection successful");
|
strophe_debug(ctx, "xmpp", "connection successful");
|
||||||
conn_established(conn);
|
conn_established(conn);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -279,23 +281,23 @@ next_item:
|
|||||||
if (ret > 0) {
|
if (ret > 0) {
|
||||||
ret = parser_feed(conn->parser, buf, ret);
|
ret = parser_feed(conn->parser, buf, ret);
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
xmpp_debug(ctx, "xmpp", "parse error [%s]", buf);
|
strophe_debug(ctx, "xmpp", "parse error [%s]", buf);
|
||||||
xmpp_send_error(conn, XMPP_SE_INVALID_XML,
|
xmpp_send_error(conn, XMPP_SE_INVALID_XML,
|
||||||
"parse error");
|
"parse error");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (conn->tls) {
|
if (conn->tls) {
|
||||||
if (!tls_is_recoverable(tls_error(conn->tls))) {
|
if (!tls_is_recoverable(tls_error(conn->tls))) {
|
||||||
xmpp_debug(ctx, "xmpp",
|
strophe_debug(ctx, "xmpp",
|
||||||
"Unrecoverable TLS error, %d.",
|
"Unrecoverable TLS error, %d.",
|
||||||
tls_error(conn->tls));
|
tls_error(conn->tls));
|
||||||
conn->error = tls_error(conn->tls);
|
conn->error = tls_error(conn->tls);
|
||||||
conn_disconnect(conn);
|
conn_disconnect(conn);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* return of 0 means socket closed by server */
|
/* return of 0 means socket closed by server */
|
||||||
xmpp_debug(ctx, "xmpp",
|
strophe_debug(ctx, "xmpp",
|
||||||
"Socket closed by remote host.");
|
"Socket closed by remote host.");
|
||||||
conn->error = ECONNRESET;
|
conn->error = ECONNRESET;
|
||||||
conn_disconnect(conn);
|
conn_disconnect(conn);
|
||||||
}
|
}
|
||||||
@@ -337,7 +339,7 @@ void xmpp_run(xmpp_ctx_t *ctx)
|
|||||||
/* make it possible to start event loop again */
|
/* make it possible to start event loop again */
|
||||||
ctx->loop_status = XMPP_LOOP_NOTSTARTED;
|
ctx->loop_status = XMPP_LOOP_NOTSTARTED;
|
||||||
|
|
||||||
xmpp_debug(ctx, "event", "Event loop completed.");
|
strophe_debug(ctx, "event", "Event loop completed.");
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Stop the event loop.
|
/** Stop the event loop.
|
||||||
@@ -350,7 +352,7 @@ void xmpp_run(xmpp_ctx_t *ctx)
|
|||||||
*/
|
*/
|
||||||
void xmpp_stop(xmpp_ctx_t *ctx)
|
void xmpp_stop(xmpp_ctx_t *ctx)
|
||||||
{
|
{
|
||||||
xmpp_debug(ctx, "event", "Stopping event loop.");
|
strophe_debug(ctx, "event", "Stopping event loop.");
|
||||||
|
|
||||||
if (ctx->loop_status == XMPP_LOOP_RUNNING)
|
if (ctx->loop_status == XMPP_LOOP_RUNNING)
|
||||||
ctx->loop_status = XMPP_LOOP_QUIT;
|
ctx->loop_status = XMPP_LOOP_QUIT;
|
||||||
|
|||||||
@@ -267,7 +267,7 @@ static void _timed_handler_add(xmpp_ctx_t *ctx,
|
|||||||
/* check if handler is already in the list */
|
/* check if handler is already in the list */
|
||||||
for (item = *handlers_list; item; item = item->next) {
|
for (item = *handlers_list; item; item = item->next) {
|
||||||
if (item->handler == handler && item->userdata == userdata) {
|
if (item->handler == handler && item->userdata == userdata) {
|
||||||
xmpp_warn(ctx, "xmpp", "Timed handler already exists.");
|
strophe_warn(ctx, "xmpp", "Timed handler already exists.");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -333,7 +333,7 @@ static void _id_handler_add(xmpp_conn_t *conn,
|
|||||||
item = (xmpp_handlist_t *)hash_get(conn->id_handlers, id);
|
item = (xmpp_handlist_t *)hash_get(conn->id_handlers, id);
|
||||||
while (item) {
|
while (item) {
|
||||||
if (item->handler == handler && item->userdata == userdata) {
|
if (item->handler == handler && item->userdata == userdata) {
|
||||||
xmpp_warn(conn->ctx, "xmpp", "Id handler already exists.");
|
strophe_warn(conn->ctx, "xmpp", "Id handler already exists.");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
item = item->next;
|
item = item->next;
|
||||||
@@ -435,7 +435,7 @@ static void _handler_add(xmpp_conn_t *conn,
|
|||||||
/* same handler function can process different stanzas and
|
/* same handler function can process different stanzas and
|
||||||
distinguish them according to userdata. */
|
distinguish them according to userdata. */
|
||||||
if (item->handler == handler && item->userdata == userdata) {
|
if (item->handler == handler && item->userdata == userdata) {
|
||||||
xmpp_warn(conn->ctx, "xmpp", "Stanza handler already exists.");
|
strophe_warn(conn->ctx, "xmpp", "Stanza handler already exists.");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -181,7 +181,8 @@ _start_element(void *userdata, const XML_Char *nsname, const XML_Char **attrs)
|
|||||||
if (!parser->stanza && parser->depth != 1) {
|
if (!parser->stanza && parser->depth != 1) {
|
||||||
/* something terrible happened */
|
/* something terrible happened */
|
||||||
/* FIXME: shutdown disconnect */
|
/* FIXME: shutdown disconnect */
|
||||||
xmpp_error(parser->ctx, "parser", "oops, where did our stanza go?");
|
strophe_error(parser->ctx, "parser",
|
||||||
|
"oops, where did our stanza go?");
|
||||||
} else {
|
} else {
|
||||||
child = xmpp_stanza_new(parser->ctx);
|
child = xmpp_stanza_new(parser->ctx);
|
||||||
if (!child) {
|
if (!child) {
|
||||||
|
|||||||
@@ -140,7 +140,8 @@ static void _start_element(void *userdata,
|
|||||||
if (!parser->stanza && parser->depth != 1) {
|
if (!parser->stanza && parser->depth != 1) {
|
||||||
/* something terrible happened */
|
/* something terrible happened */
|
||||||
/* FIXME: we should probably trigger a disconnect */
|
/* FIXME: we should probably trigger a disconnect */
|
||||||
xmpp_error(parser->ctx, "parser", "oops, where did our stanza go?");
|
strophe_error(parser->ctx, "parser",
|
||||||
|
"oops, where did our stanza go?");
|
||||||
} else if (!parser->stanza) {
|
} else if (!parser->stanza) {
|
||||||
/* starting a new toplevel stanza */
|
/* starting a new toplevel stanza */
|
||||||
parser->stanza = xmpp_stanza_new(parser->ctx);
|
parser->stanza = xmpp_stanza_new(parser->ctx);
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ static hash_t *_parse_digest_challenge(xmpp_ctx_t *ctx, const char *msg)
|
|||||||
|
|
||||||
text = (unsigned char *)xmpp_base64_decode_str(ctx, msg, strlen(msg));
|
text = (unsigned char *)xmpp_base64_decode_str(ctx, msg, strlen(msg));
|
||||||
if (text == NULL) {
|
if (text == NULL) {
|
||||||
xmpp_error(ctx, "SASL", "couldn't Base64 decode challenge!");
|
strophe_error(ctx, "SASL", "couldn't Base64 decode challenge!");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -191,7 +191,7 @@ _add_key(xmpp_ctx_t *ctx, hash_t *table, const char *key, char *buf, int quote)
|
|||||||
olen = strlen(buf);
|
olen = strlen(buf);
|
||||||
value = hash_get(table, key);
|
value = hash_get(table, key);
|
||||||
if (value == NULL) {
|
if (value == NULL) {
|
||||||
xmpp_error(ctx, "SASL", "couldn't retrieve value for '%s'", key);
|
strophe_error(ctx, "SASL", "couldn't retrieve value for '%s'", key);
|
||||||
value = "";
|
value = "";
|
||||||
}
|
}
|
||||||
if (quote) {
|
if (quote) {
|
||||||
@@ -254,7 +254,7 @@ char *sasl_digest_md5(xmpp_ctx_t *ctx,
|
|||||||
/* parse the challenge */
|
/* parse the challenge */
|
||||||
table = _parse_digest_challenge(ctx, challenge);
|
table = _parse_digest_challenge(ctx, challenge);
|
||||||
if (table == NULL) {
|
if (table == NULL) {
|
||||||
xmpp_error(ctx, "SASL", "couldn't parse digest challenge");
|
strophe_error(ctx, "SASL", "couldn't parse digest challenge");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -235,7 +235,8 @@ static xmpp_tlscert_t *_x509_to_tlscert(xmpp_ctx_t *ctx, gnutls_x509_crt_t cert)
|
|||||||
res = gnutls_x509_crt_get_subject_alt_name(cert, n, buf, &size, NULL);
|
res = gnutls_x509_crt_get_subject_alt_name(cert, n, buf, &size, NULL);
|
||||||
if (res == GNUTLS_SAN_DNSNAME) {
|
if (res == GNUTLS_SAN_DNSNAME) {
|
||||||
if (tlscert_add_dnsname(tlscert, buf))
|
if (tlscert_add_dnsname(tlscert, buf))
|
||||||
xmpp_debug(ctx, "tls", "Can't store dnsName(%zu): %s", m, buf);
|
strophe_debug(ctx, "tls", "Can't store dnsName(%zu): %s", m,
|
||||||
|
buf);
|
||||||
m++;
|
m++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -256,13 +257,13 @@ static int _tls_verify(gnutls_session_t session)
|
|||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (gnutls_certificate_verify_peers2(session, &status) < 0) {
|
if (gnutls_certificate_verify_peers2(session, &status) < 0) {
|
||||||
xmpp_error(tls->ctx, "tls", "Verify peers failed");
|
strophe_error(tls->ctx, "tls", "Verify peers failed");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
type = gnutls_certificate_type_get(session);
|
type = gnutls_certificate_type_get(session);
|
||||||
if (gnutls_certificate_verification_status_print(status, type, &out, 0) <
|
if (gnutls_certificate_verification_status_print(status, type, &out, 0) <
|
||||||
0) {
|
0) {
|
||||||
xmpp_error(tls->ctx, "tls", "Status print failed");
|
strophe_error(tls->ctx, "tls", "Status print failed");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -272,8 +273,8 @@ static int _tls_verify(gnutls_session_t session)
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (!tls->conn->certfail_handler) {
|
if (!tls->conn->certfail_handler) {
|
||||||
xmpp_error(tls->ctx, "tls",
|
strophe_error(tls->ctx, "tls",
|
||||||
"No certfail handler set, canceling connection attempt");
|
"No certfail handler set, canceling connection attempt");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -326,8 +327,8 @@ tls_t *tls_new(xmpp_conn_t *conn)
|
|||||||
if (conn->tls_client_cert && conn->tls_client_key) {
|
if (conn->tls_client_cert && conn->tls_client_key) {
|
||||||
tls->client_cert = _tls_load_cert(conn);
|
tls->client_cert = _tls_load_cert(conn);
|
||||||
if (!tls->client_cert) {
|
if (!tls->client_cert) {
|
||||||
xmpp_error(tls->ctx, "tls",
|
strophe_error(tls->ctx, "tls",
|
||||||
"could not read client certificate");
|
"could not read client certificate");
|
||||||
gnutls_certificate_free_credentials(tls->cred);
|
gnutls_certificate_free_credentials(tls->cred);
|
||||||
gnutls_deinit(tls->session);
|
gnutls_deinit(tls->session);
|
||||||
strophe_free(tls->ctx, tls);
|
strophe_free(tls->ctx, tls);
|
||||||
|
|||||||
@@ -269,8 +269,8 @@ char *tls_id_on_xmppaddr(xmpp_conn_t *conn, unsigned int n)
|
|||||||
if (_tls_xmppaddr_to_string(name, &res))
|
if (_tls_xmppaddr_to_string(name, &res))
|
||||||
continue;
|
continue;
|
||||||
if (j == (int)n) {
|
if (j == (int)n) {
|
||||||
xmpp_debug(conn->ctx, "tls", "extracted jid %s from id-on-xmppAddr",
|
strophe_debug(conn->ctx, "tls",
|
||||||
res);
|
"extracted jid %s from id-on-xmppAddr", res);
|
||||||
ret = strophe_strdup(conn->ctx, res);
|
ret = strophe_strdup(conn->ctx, res);
|
||||||
OPENSSL_free(res);
|
OPENSSL_free(res);
|
||||||
break;
|
break;
|
||||||
@@ -459,7 +459,8 @@ static xmpp_tlscert_t *_x509_to_tlscert(xmpp_ctx_t *ctx, X509 *cert)
|
|||||||
if (_tls_dnsname_to_string(name, &res))
|
if (_tls_dnsname_to_string(name, &res))
|
||||||
continue;
|
continue;
|
||||||
if (tlscert_add_dnsname(tlscert, res))
|
if (tlscert_add_dnsname(tlscert, res))
|
||||||
xmpp_debug(ctx, "tls", "Can't store dnsName(%zu): %s", n, res);
|
strophe_debug(ctx, "tls", "Can't store dnsName(%zu): %s", n,
|
||||||
|
res);
|
||||||
n++;
|
n++;
|
||||||
OPENSSL_free(res);
|
OPENSSL_free(res);
|
||||||
}
|
}
|
||||||
@@ -482,8 +483,8 @@ static int _tls_verify(int preverify_ok, X509_STORE_CTX *x509_ctx)
|
|||||||
xmpp_conn_t *conn = SSL_get_app_data(ssl);
|
xmpp_conn_t *conn = SSL_get_app_data(ssl);
|
||||||
|
|
||||||
if (!conn->certfail_handler) {
|
if (!conn->certfail_handler) {
|
||||||
xmpp_error(conn->ctx, "tls",
|
strophe_error(conn->ctx, "tls",
|
||||||
"No certfail handler set, canceling connection attempt");
|
"No certfail handler set, canceling connection attempt");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -494,9 +495,9 @@ static int _tls_verify(int preverify_ok, X509_STORE_CTX *x509_ctx)
|
|||||||
if (!tlscert)
|
if (!tlscert)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
xmpp_debug(conn->ctx, "tls", "preverify_ok:%d\nSubject: %s\nIssuer: %s",
|
strophe_debug(conn->ctx, "tls", "preverify_ok:%d\nSubject: %s\nIssuer: %s",
|
||||||
preverify_ok, tlscert->elements[XMPP_CERT_SUBJECT],
|
preverify_ok, tlscert->elements[XMPP_CERT_SUBJECT],
|
||||||
tlscert->elements[XMPP_CERT_ISSUER]);
|
tlscert->elements[XMPP_CERT_ISSUER]);
|
||||||
|
|
||||||
int ret = conn->certfail_handler(
|
int ret = conn->certfail_handler(
|
||||||
tlscert,
|
tlscert,
|
||||||
@@ -540,8 +541,8 @@ tls_t *tls_new(xmpp_conn_t *conn)
|
|||||||
if (conn->tls_client_cert && conn->tls_client_key) {
|
if (conn->tls_client_cert && conn->tls_client_key) {
|
||||||
tls->client_cert = _tls_cert_read(conn);
|
tls->client_cert = _tls_cert_read(conn);
|
||||||
if (!tls->client_cert) {
|
if (!tls->client_cert) {
|
||||||
xmpp_error(tls->ctx, "tls",
|
strophe_error(tls->ctx, "tls",
|
||||||
"could not read client certificate");
|
"could not read client certificate");
|
||||||
goto err_free_ctx;
|
goto err_free_ctx;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -563,16 +564,16 @@ tls_t *tls_new(xmpp_conn_t *conn)
|
|||||||
* location is still treated as a success.
|
* location is still treated as a success.
|
||||||
* Ignore errors when XMPP_CONN_FLAG_TRUST_TLS is set.
|
* Ignore errors when XMPP_CONN_FLAG_TRUST_TLS is set.
|
||||||
*/
|
*/
|
||||||
xmpp_error(tls->ctx, "tls",
|
strophe_error(tls->ctx, "tls",
|
||||||
"SSL_CTX_set_default_verify_paths() failed");
|
"SSL_CTX_set_default_verify_paths() failed");
|
||||||
goto err_free_cert;
|
goto err_free_cert;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (conn->tls_cafile || conn->tls_capath) {
|
if (conn->tls_cafile || conn->tls_capath) {
|
||||||
if (SSL_CTX_load_verify_locations(tls->ssl_ctx, conn->tls_cafile,
|
if (SSL_CTX_load_verify_locations(tls->ssl_ctx, conn->tls_cafile,
|
||||||
conn->tls_capath) == 0) {
|
conn->tls_capath) == 0) {
|
||||||
xmpp_error(tls->ctx, "tls",
|
strophe_error(tls->ctx, "tls",
|
||||||
"SSL_CTX_load_verify_locations() failed");
|
"SSL_CTX_load_verify_locations() failed");
|
||||||
goto err_free_cert;
|
goto err_free_cert;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -680,13 +681,13 @@ int tls_start(tls_t *tls)
|
|||||||
|
|
||||||
x509_res = SSL_get_verify_result(tls->ssl);
|
x509_res = SSL_get_verify_result(tls->ssl);
|
||||||
if (x509_res == X509_V_OK) {
|
if (x509_res == X509_V_OK) {
|
||||||
xmpp_debug(tls->ctx, "tls", "Certificate verification passed");
|
strophe_debug(tls->ctx, "tls", "Certificate verification passed");
|
||||||
} else {
|
} else {
|
||||||
xmpp_debug(tls->ctx, "tls",
|
strophe_debug(tls->ctx, "tls",
|
||||||
"Certificate verification FAILED, result=%s(%ld)",
|
"Certificate verification FAILED, result=%s(%ld)",
|
||||||
TLS_ERROR_STR((int)x509_res, cert_errors), x509_res);
|
TLS_ERROR_STR((int)x509_res, cert_errors), x509_res);
|
||||||
if (ret > 0)
|
if (ret > 0)
|
||||||
xmpp_debug(tls->ctx, "tls", "User decided to connect anyways");
|
strophe_debug(tls->ctx, "tls", "User decided to connect anyways");
|
||||||
}
|
}
|
||||||
_tls_dump_cert_info(tls);
|
_tls_dump_cert_info(tls);
|
||||||
|
|
||||||
@@ -801,8 +802,8 @@ static const char *_tls_error_str(int error, const char **tbl, size_t tbl_size)
|
|||||||
static void _tls_set_error(tls_t *tls, int error)
|
static void _tls_set_error(tls_t *tls, int error)
|
||||||
{
|
{
|
||||||
if (error != 0 && !tls_is_recoverable(error)) {
|
if (error != 0 && !tls_is_recoverable(error)) {
|
||||||
xmpp_debug(tls->ctx, "tls", "error=%s(%d) errno=%d",
|
strophe_debug(tls->ctx, "tls", "error=%s(%d) errno=%d",
|
||||||
TLS_ERROR_STR(error, tls_errors), error, errno);
|
TLS_ERROR_STR(error, tls_errors), error, errno);
|
||||||
_tls_log_error(tls->ctx);
|
_tls_log_error(tls->ctx);
|
||||||
}
|
}
|
||||||
tls->lasterror = error;
|
tls->lasterror = error;
|
||||||
@@ -815,9 +816,9 @@ static void _tls_log_error(xmpp_ctx_t *ctx)
|
|||||||
do {
|
do {
|
||||||
e = ERR_get_error();
|
e = ERR_get_error();
|
||||||
if (e != 0) {
|
if (e != 0) {
|
||||||
xmpp_debug(ctx, "tls", "error:%08uX:%s:%s:%s", e,
|
strophe_debug(ctx, "tls", "error:%08uX:%s:%s:%s", e,
|
||||||
ERR_lib_error_string(e), ERR_func_error_string(e),
|
ERR_lib_error_string(e), ERR_func_error_string(e),
|
||||||
ERR_reason_error_string(e));
|
ERR_reason_error_string(e));
|
||||||
}
|
}
|
||||||
} while (e != 0);
|
} while (e != 0);
|
||||||
}
|
}
|
||||||
@@ -829,16 +830,16 @@ static void _tls_dump_cert_info(tls_t *tls)
|
|||||||
|
|
||||||
cert = SSL_get_peer_certificate(tls->ssl);
|
cert = SSL_get_peer_certificate(tls->ssl);
|
||||||
if (cert == NULL)
|
if (cert == NULL)
|
||||||
xmpp_debug(tls->ctx, "tls", "Certificate was not presented by peer");
|
strophe_debug(tls->ctx, "tls", "Certificate was not presented by peer");
|
||||||
else {
|
else {
|
||||||
name = X509_NAME_oneline(X509_get_subject_name(cert), NULL, 0);
|
name = X509_NAME_oneline(X509_get_subject_name(cert), NULL, 0);
|
||||||
if (name != NULL) {
|
if (name != NULL) {
|
||||||
xmpp_debug(tls->ctx, "tls", "Subject=%s", name);
|
strophe_debug(tls->ctx, "tls", "Subject=%s", name);
|
||||||
OPENSSL_free(name);
|
OPENSSL_free(name);
|
||||||
}
|
}
|
||||||
name = X509_NAME_oneline(X509_get_issuer_name(cert), NULL, 0);
|
name = X509_NAME_oneline(X509_get_issuer_name(cert), NULL, 0);
|
||||||
if (name != NULL) {
|
if (name != NULL) {
|
||||||
xmpp_debug(tls->ctx, "tls", "Issuer=%s", name);
|
strophe_debug(tls->ctx, "tls", "Issuer=%s", name);
|
||||||
OPENSSL_free(name);
|
OPENSSL_free(name);
|
||||||
}
|
}
|
||||||
X509_free(cert);
|
X509_free(cert);
|
||||||
@@ -851,7 +852,7 @@ static X509 *_tls_cert_read(xmpp_conn_t *conn)
|
|||||||
return conn->tls->client_cert;
|
return conn->tls->client_cert;
|
||||||
BIO *f = BIO_new_file(conn->tls_client_cert, "r");
|
BIO *f = BIO_new_file(conn->tls_client_cert, "r");
|
||||||
if (!f) {
|
if (!f) {
|
||||||
xmpp_debug(conn->ctx, "tls", "f == NULL");
|
strophe_debug(conn->ctx, "tls", "f == NULL");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
X509 *c = PEM_read_bio_X509(f, NULL, NULL, NULL);
|
X509 *c = PEM_read_bio_X509(f, NULL, NULL, NULL);
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ char *strophe_strndup(const xmpp_ctx_t *ctx, const char *s, size_t len)
|
|||||||
|
|
||||||
copy = strophe_alloc(ctx, l + 1);
|
copy = strophe_alloc(ctx, l + 1);
|
||||||
if (!copy) {
|
if (!copy) {
|
||||||
xmpp_error(ctx, "xmpp", "failed to allocate required memory");
|
strophe_error(ctx, "xmpp", "failed to allocate required memory");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,7 +157,7 @@ uint64_t time_elapsed(uint64_t t1, uint64_t t2)
|
|||||||
*/
|
*/
|
||||||
void disconnect_mem_error(xmpp_conn_t *conn)
|
void disconnect_mem_error(xmpp_conn_t *conn)
|
||||||
{
|
{
|
||||||
xmpp_error(conn->ctx, "xmpp", "Memory allocation error");
|
strophe_error(conn->ctx, "xmpp", "Memory allocation error");
|
||||||
xmpp_disconnect(conn);
|
xmpp_disconnect(conn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ int main()
|
|||||||
mylog.userdata = my_str;
|
mylog.userdata = my_str;
|
||||||
|
|
||||||
ctx = xmpp_ctx_new(&mymem, &mylog);
|
ctx = xmpp_ctx_new(&mymem, &mylog);
|
||||||
xmpp_debug(ctx, "test", "hello");
|
strophe_debug(ctx, "test", "hello");
|
||||||
|
|
||||||
testptr1 = strophe_alloc(ctx, 1024);
|
testptr1 = strophe_alloc(ctx, 1024);
|
||||||
if (testptr1 == NULL) {
|
if (testptr1 == NULL) {
|
||||||
|
|||||||
Reference in New Issue
Block a user