send_stanza() now takes ownership of the stanza
Instead of always releasing the stanza after calling `send_stanza()`, this is done inside the function now. Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
This commit is contained in:
14
src/auth.c
14
src/auth.c
@@ -398,7 +398,6 @@ static int _handle_digestmd5_challenge(xmpp_conn_t *conn,
|
|||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
send_stanza(conn, auth, XMPP_QUEUE_STROPHE);
|
send_stanza(conn, auth, XMPP_QUEUE_STROPHE);
|
||||||
xmpp_stanza_release(auth);
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
return _handle_sasl_result(conn, stanza, "DIGEST-MD5");
|
return _handle_sasl_result(conn, stanza, "DIGEST-MD5");
|
||||||
@@ -432,7 +431,6 @@ static int _handle_digestmd5_rspauth(xmpp_conn_t *conn,
|
|||||||
xmpp_stanza_set_name(auth, "response");
|
xmpp_stanza_set_name(auth, "response");
|
||||||
xmpp_stanza_set_ns(auth, XMPP_NS_SASL);
|
xmpp_stanza_set_ns(auth, XMPP_NS_SASL);
|
||||||
send_stanza(conn, auth, XMPP_QUEUE_STROPHE);
|
send_stanza(conn, auth, XMPP_QUEUE_STROPHE);
|
||||||
xmpp_stanza_release(auth);
|
|
||||||
} else {
|
} else {
|
||||||
return _handle_sasl_result(conn, stanza, "DIGEST-MD5");
|
return _handle_sasl_result(conn, stanza, "DIGEST-MD5");
|
||||||
}
|
}
|
||||||
@@ -495,7 +493,6 @@ static int _handle_scram_challenge(xmpp_conn_t *conn,
|
|||||||
xmpp_stanza_release(authdata);
|
xmpp_stanza_release(authdata);
|
||||||
|
|
||||||
send_stanza(conn, auth, XMPP_QUEUE_STROPHE);
|
send_stanza(conn, auth, XMPP_QUEUE_STROPHE);
|
||||||
xmpp_stanza_release(auth);
|
|
||||||
|
|
||||||
rc = 1; /* Keep handler */
|
rc = 1; /* Keep handler */
|
||||||
} else {
|
} else {
|
||||||
@@ -625,7 +622,6 @@ static void _auth(xmpp_conn_t *conn)
|
|||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
send_stanza(conn, auth, XMPP_QUEUE_STROPHE);
|
send_stanza(conn, auth, XMPP_QUEUE_STROPHE);
|
||||||
xmpp_stanza_release(auth);
|
|
||||||
|
|
||||||
/* TLS was tried, unset flag */
|
/* TLS was tried, unset flag */
|
||||||
conn->tls_support = 0;
|
conn->tls_support = 0;
|
||||||
@@ -653,7 +649,6 @@ static void _auth(xmpp_conn_t *conn)
|
|||||||
"ANONYMOUS");
|
"ANONYMOUS");
|
||||||
|
|
||||||
send_stanza(conn, auth, XMPP_QUEUE_STROPHE);
|
send_stanza(conn, auth, XMPP_QUEUE_STROPHE);
|
||||||
xmpp_stanza_release(auth);
|
|
||||||
|
|
||||||
/* SASL ANONYMOUS was tried, unset flag */
|
/* SASL ANONYMOUS was tried, unset flag */
|
||||||
conn->sasl_support &= ~SASL_MASK_ANONYMOUS;
|
conn->sasl_support &= ~SASL_MASK_ANONYMOUS;
|
||||||
@@ -696,7 +691,6 @@ static void _auth(xmpp_conn_t *conn)
|
|||||||
"EXTERNAL");
|
"EXTERNAL");
|
||||||
|
|
||||||
send_stanza(conn, auth, XMPP_QUEUE_STROPHE);
|
send_stanza(conn, auth, XMPP_QUEUE_STROPHE);
|
||||||
xmpp_stanza_release(auth);
|
|
||||||
|
|
||||||
/* SASL EXTERNAL was tried, unset flag */
|
/* SASL EXTERNAL was tried, unset flag */
|
||||||
conn->sasl_support &= ~SASL_MASK_EXTERNAL;
|
conn->sasl_support &= ~SASL_MASK_EXTERNAL;
|
||||||
@@ -761,7 +755,6 @@ static void _auth(xmpp_conn_t *conn)
|
|||||||
(void *)scram_ctx);
|
(void *)scram_ctx);
|
||||||
|
|
||||||
send_stanza(conn, auth, XMPP_QUEUE_STROPHE);
|
send_stanza(conn, auth, XMPP_QUEUE_STROPHE);
|
||||||
xmpp_stanza_release(auth);
|
|
||||||
|
|
||||||
/* SASL SCRAM-SHA-1 was tried, unset flag */
|
/* SASL SCRAM-SHA-1 was tried, unset flag */
|
||||||
conn->sasl_support &= ~scram_ctx->alg->mask;
|
conn->sasl_support &= ~scram_ctx->alg->mask;
|
||||||
@@ -776,7 +769,6 @@ static void _auth(xmpp_conn_t *conn)
|
|||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
send_stanza(conn, auth, XMPP_QUEUE_STROPHE);
|
send_stanza(conn, auth, XMPP_QUEUE_STROPHE);
|
||||||
xmpp_stanza_release(auth);
|
|
||||||
|
|
||||||
/* SASL DIGEST-MD5 was tried, unset flag */
|
/* SASL DIGEST-MD5 was tried, unset flag */
|
||||||
conn->sasl_support &= ~SASL_MASK_DIGESTMD5;
|
conn->sasl_support &= ~SASL_MASK_DIGESTMD5;
|
||||||
@@ -812,7 +804,6 @@ static void _auth(xmpp_conn_t *conn)
|
|||||||
"PLAIN");
|
"PLAIN");
|
||||||
|
|
||||||
send_stanza(conn, auth, XMPP_QUEUE_STROPHE);
|
send_stanza(conn, auth, XMPP_QUEUE_STROPHE);
|
||||||
xmpp_stanza_release(auth);
|
|
||||||
|
|
||||||
/* SASL PLAIN was tried */
|
/* SASL PLAIN was tried */
|
||||||
conn->sasl_support &= ~SASL_MASK_PLAIN;
|
conn->sasl_support &= ~SASL_MASK_PLAIN;
|
||||||
@@ -935,7 +926,6 @@ static int _do_bind(xmpp_conn_t *conn, xmpp_stanza_t *bind)
|
|||||||
|
|
||||||
/* send bind request */
|
/* send bind request */
|
||||||
send_stanza(conn, iq, XMPP_QUEUE_STROPHE);
|
send_stanza(conn, iq, XMPP_QUEUE_STROPHE);
|
||||||
xmpp_stanza_release(iq);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -999,7 +989,6 @@ _handle_features_sasl(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void *userdata)
|
|||||||
strophe_snprintf(h, sizeof(h), "%u", conn->sm_state->sm_handled_nr);
|
strophe_snprintf(h, sizeof(h), "%u", conn->sm_state->sm_handled_nr);
|
||||||
xmpp_stanza_set_attribute(resume, "h", h);
|
xmpp_stanza_set_attribute(resume, "h", h);
|
||||||
send_stanza(conn, resume, XMPP_QUEUE_SM_STROPHE);
|
send_stanza(conn, resume, XMPP_QUEUE_SM_STROPHE);
|
||||||
xmpp_stanza_release(resume);
|
|
||||||
handler_add(conn, _handle_sm, XMPP_NS_SM, NULL, NULL, NULL);
|
handler_add(conn, _handle_sm, XMPP_NS_SM, NULL, NULL, NULL);
|
||||||
}
|
}
|
||||||
/* if bind is required, go ahead and start it */
|
/* if bind is required, go ahead and start it */
|
||||||
@@ -1085,7 +1074,6 @@ _handle_bind(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void *userdata)
|
|||||||
|
|
||||||
/* send session establishment request */
|
/* send session establishment request */
|
||||||
send_stanza(conn, iq, XMPP_QUEUE_STROPHE);
|
send_stanza(conn, iq, XMPP_QUEUE_STROPHE);
|
||||||
xmpp_stanza_release(iq);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (conn->sm_state->sm_support && !conn->sm_disable) {
|
if (conn->sm_state->sm_support && !conn->sm_disable) {
|
||||||
@@ -1100,7 +1088,6 @@ _handle_bind(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void *userdata)
|
|||||||
xmpp_stanza_set_attribute(enable, "resume", "true");
|
xmpp_stanza_set_attribute(enable, "resume", "true");
|
||||||
handler_add(conn, _handle_sm, XMPP_NS_SM, NULL, NULL, NULL);
|
handler_add(conn, _handle_sm, XMPP_NS_SM, NULL, NULL, NULL);
|
||||||
send_stanza(conn, enable, XMPP_QUEUE_SM_STROPHE);
|
send_stanza(conn, enable, XMPP_QUEUE_SM_STROPHE);
|
||||||
xmpp_stanza_release(enable);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!conn->session_required) {
|
if (!conn->session_required) {
|
||||||
@@ -1425,7 +1412,6 @@ static void _auth_legacy(xmpp_conn_t *conn)
|
|||||||
handler_add_timed(conn, _handle_missing_legacy, LEGACY_TIMEOUT, NULL);
|
handler_add_timed(conn, _handle_missing_legacy, LEGACY_TIMEOUT, NULL);
|
||||||
|
|
||||||
send_stanza(conn, iq, XMPP_QUEUE_STROPHE);
|
send_stanza(conn, iq, XMPP_QUEUE_STROPHE);
|
||||||
xmpp_stanza_release(iq);
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
err_free:
|
err_free:
|
||||||
|
|||||||
11
src/conn.c
11
src/conn.c
@@ -123,8 +123,6 @@ void xmpp_send_error(xmpp_conn_t *conn, xmpp_error_type_t type, char *text)
|
|||||||
xmpp_stanza_t *error = xmpp_error_new(conn->ctx, type, text);
|
xmpp_stanza_t *error = xmpp_error_new(conn->ctx, type, text);
|
||||||
|
|
||||||
send_stanza(conn, error, XMPP_QUEUE_STROPHE);
|
send_stanza(conn, error, XMPP_QUEUE_STROPHE);
|
||||||
|
|
||||||
xmpp_stanza_release(error);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Create a new Strophe connection object.
|
/** Create a new Strophe connection object.
|
||||||
@@ -1073,7 +1071,7 @@ void xmpp_send_raw(xmpp_conn_t *conn, const char *data, size_t len)
|
|||||||
*/
|
*/
|
||||||
void xmpp_send(xmpp_conn_t *conn, xmpp_stanza_t *stanza)
|
void xmpp_send(xmpp_conn_t *conn, xmpp_stanza_t *stanza)
|
||||||
{
|
{
|
||||||
send_stanza(conn, stanza, XMPP_QUEUE_USER);
|
send_stanza(conn, xmpp_stanza_clone(stanza), XMPP_QUEUE_USER);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Send the opening <stream:stream> tag to the server.
|
/** Send the opening <stream:stream> tag to the server.
|
||||||
@@ -1738,7 +1736,6 @@ static void _conn_sm_handle_stanza(xmpp_conn_t *const conn,
|
|||||||
strophe_snprintf(h, sizeof(h), "%u", conn->sm_state->sm_handled_nr);
|
strophe_snprintf(h, sizeof(h), "%u", conn->sm_state->sm_handled_nr);
|
||||||
xmpp_stanza_set_attribute(a, "h", h);
|
xmpp_stanza_set_attribute(a, "h", h);
|
||||||
send_stanza(conn, a, XMPP_QUEUE_SM_STROPHE);
|
send_stanza(conn, a, XMPP_QUEUE_SM_STROPHE);
|
||||||
xmpp_stanza_release(a);
|
|
||||||
} else if (strcmp(name, "a") == 0) {
|
} else if (strcmp(name, "a") == 0) {
|
||||||
attr_h = xmpp_stanza_get_attribute(stanza, "h");
|
attr_h = xmpp_stanza_get_attribute(stanza, "h");
|
||||||
if (!attr_h) {
|
if (!attr_h) {
|
||||||
@@ -1972,14 +1969,16 @@ void send_stanza(xmpp_conn_t *conn,
|
|||||||
size_t len;
|
size_t len;
|
||||||
|
|
||||||
if (conn->state != XMPP_STATE_CONNECTED)
|
if (conn->state != XMPP_STATE_CONNECTED)
|
||||||
return;
|
goto out;
|
||||||
|
|
||||||
if (xmpp_stanza_to_text(stanza, &buf, &len) != 0) {
|
if (xmpp_stanza_to_text(stanza, &buf, &len) != 0) {
|
||||||
strophe_error(conn->ctx, "conn", "Failed to stanza_to_text");
|
strophe_error(conn->ctx, "conn", "Failed to stanza_to_text");
|
||||||
return;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
_send_raw(conn, buf, len, owner, NULL);
|
_send_raw(conn, buf, len, owner, NULL);
|
||||||
|
out:
|
||||||
|
xmpp_stanza_release(stanza);
|
||||||
}
|
}
|
||||||
|
|
||||||
void add_queue_back(xmpp_queue_t *queue, xmpp_send_queue_t *item)
|
void add_queue_back(xmpp_queue_t *queue, xmpp_send_queue_t *item)
|
||||||
|
|||||||
Reference in New Issue
Block a user