make alloc-class of functions private
Fixes #189 Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
This commit is contained in:
74
src/auth.c
74
src/auth.c
@@ -106,12 +106,12 @@ _handle_error(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void *userdata)
|
||||
if (conn->stream_error) {
|
||||
xmpp_stanza_release(conn->stream_error->stanza);
|
||||
if (conn->stream_error->text)
|
||||
xmpp_free(conn->ctx, conn->stream_error->text);
|
||||
xmpp_free(conn->ctx, conn->stream_error);
|
||||
strophe_free(conn->ctx, conn->stream_error->text);
|
||||
strophe_free(conn->ctx, conn->stream_error);
|
||||
}
|
||||
|
||||
/* create stream error structure */
|
||||
conn->stream_error = (xmpp_stream_error_t *)xmpp_alloc(
|
||||
conn->stream_error = (xmpp_stream_error_t *)strophe_alloc(
|
||||
conn->ctx, sizeof(xmpp_stream_error_t));
|
||||
|
||||
conn->stream_error->text = NULL;
|
||||
@@ -130,7 +130,7 @@ _handle_error(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void *userdata)
|
||||
name = xmpp_stanza_get_name(child);
|
||||
if (strcmp(name, "text") == 0) {
|
||||
if (conn->stream_error->text)
|
||||
xmpp_free(conn->ctx, conn->stream_error->text);
|
||||
strophe_free(conn->ctx, conn->stream_error->text);
|
||||
conn->stream_error->text = xmpp_stanza_get_text(child);
|
||||
} else if (strcmp(name, "bad-format") == 0)
|
||||
conn->stream_error->type = XMPP_SE_BAD_FORMAT;
|
||||
@@ -255,7 +255,7 @@ _handle_features(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void *userdata)
|
||||
else if (strcasecmp(text, "ANONYMOUS") == 0)
|
||||
conn->sasl_support |= SASL_MASK_ANONYMOUS;
|
||||
|
||||
xmpp_free(conn->ctx, text);
|
||||
strophe_free(conn->ctx, text);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -368,7 +368,7 @@ static int _handle_digestmd5_challenge(xmpp_conn_t *conn,
|
||||
disconnect_mem_error(conn);
|
||||
return 0;
|
||||
}
|
||||
xmpp_free(conn->ctx, text);
|
||||
strophe_free(conn->ctx, text);
|
||||
|
||||
auth = xmpp_stanza_new(conn->ctx);
|
||||
if (!auth) {
|
||||
@@ -385,7 +385,7 @@ static int _handle_digestmd5_challenge(xmpp_conn_t *conn,
|
||||
}
|
||||
|
||||
xmpp_stanza_set_text(authdata, response);
|
||||
xmpp_free(conn->ctx, response);
|
||||
strophe_free(conn->ctx, response);
|
||||
|
||||
xmpp_stanza_add_child(auth, authdata);
|
||||
xmpp_stanza_release(authdata);
|
||||
@@ -465,13 +465,13 @@ static int _handle_scram_challenge(xmpp_conn_t *conn,
|
||||
goto err;
|
||||
|
||||
challenge = xmpp_base64_decode_str(conn->ctx, text, strlen(text));
|
||||
xmpp_free(conn->ctx, text);
|
||||
strophe_free(conn->ctx, text);
|
||||
if (!challenge)
|
||||
goto err;
|
||||
|
||||
response = sasl_scram(conn->ctx, scram_ctx->alg, challenge,
|
||||
scram_ctx->scram_init, conn->jid, conn->pass);
|
||||
xmpp_free(conn->ctx, challenge);
|
||||
strophe_free(conn->ctx, challenge);
|
||||
if (!response)
|
||||
goto err;
|
||||
|
||||
@@ -485,7 +485,7 @@ static int _handle_scram_challenge(xmpp_conn_t *conn,
|
||||
if (!authdata)
|
||||
goto err_release_auth;
|
||||
xmpp_stanza_set_text(authdata, response);
|
||||
xmpp_free(conn->ctx, response);
|
||||
strophe_free(conn->ctx, response);
|
||||
|
||||
xmpp_stanza_add_child(auth, authdata);
|
||||
xmpp_stanza_release(authdata);
|
||||
@@ -506,8 +506,8 @@ static int _handle_scram_challenge(xmpp_conn_t *conn,
|
||||
*/
|
||||
rc = _handle_sasl_result(conn, stanza,
|
||||
(void *)scram_ctx->alg->scram_name);
|
||||
xmpp_free(conn->ctx, scram_ctx->scram_init);
|
||||
xmpp_free(conn->ctx, scram_ctx);
|
||||
strophe_free(conn->ctx, scram_ctx->scram_init);
|
||||
strophe_free(conn->ctx, scram_ctx);
|
||||
}
|
||||
|
||||
return rc;
|
||||
@@ -515,10 +515,10 @@ static int _handle_scram_challenge(xmpp_conn_t *conn,
|
||||
err_release_auth:
|
||||
xmpp_stanza_release(auth);
|
||||
err_free_response:
|
||||
xmpp_free(conn->ctx, response);
|
||||
strophe_free(conn->ctx, response);
|
||||
err:
|
||||
xmpp_free(conn->ctx, scram_ctx->scram_init);
|
||||
xmpp_free(conn->ctx, scram_ctx);
|
||||
strophe_free(conn->ctx, scram_ctx->scram_init);
|
||||
strophe_free(conn->ctx, scram_ctx);
|
||||
disconnect_mem_error(conn);
|
||||
return 0;
|
||||
}
|
||||
@@ -537,11 +537,11 @@ static char *_make_scram_init_msg(xmpp_conn_t *conn)
|
||||
}
|
||||
xmpp_rand_nonce(ctx->rand, nonce, sizeof(nonce));
|
||||
message_len = strlen(node) + strlen(nonce) + 8 + 1;
|
||||
message = xmpp_alloc(ctx, message_len);
|
||||
message = strophe_alloc(ctx, message_len);
|
||||
if (message) {
|
||||
xmpp_snprintf(message, message_len, "n,,n=%s,r=%s", node, nonce);
|
||||
}
|
||||
xmpp_free(ctx, node);
|
||||
strophe_free(ctx, node);
|
||||
|
||||
return message;
|
||||
}
|
||||
@@ -594,7 +594,7 @@ static void _auth(xmpp_conn_t *conn)
|
||||
if (str == NULL) {
|
||||
anonjid = 1;
|
||||
} else {
|
||||
xmpp_free(conn->ctx, str);
|
||||
strophe_free(conn->ctx, str);
|
||||
anonjid = 0;
|
||||
}
|
||||
|
||||
@@ -672,7 +672,7 @@ static void _auth(xmpp_conn_t *conn)
|
||||
strcmp(str, conn->jid) == 0)) {
|
||||
xmpp_stanza_set_text(authdata, "=");
|
||||
} else {
|
||||
xmpp_free(conn->ctx, str);
|
||||
strophe_free(conn->ctx, str);
|
||||
str = xmpp_base64_encode(conn->ctx, (void *)conn->jid,
|
||||
strlen(conn->jid));
|
||||
if (!str) {
|
||||
@@ -683,7 +683,7 @@ static void _auth(xmpp_conn_t *conn)
|
||||
}
|
||||
xmpp_stanza_set_text(authdata, str);
|
||||
}
|
||||
xmpp_free(conn->ctx, str);
|
||||
strophe_free(conn->ctx, str);
|
||||
|
||||
xmpp_stanza_add_child(auth, authdata);
|
||||
xmpp_stanza_release(authdata);
|
||||
@@ -705,7 +705,7 @@ static void _auth(xmpp_conn_t *conn)
|
||||
"Password hasn't been set, and SASL ANONYMOUS unsupported.");
|
||||
xmpp_disconnect(conn);
|
||||
} else if (conn->sasl_support & SASL_MASK_SCRAM) {
|
||||
scram_ctx = xmpp_alloc(conn->ctx, sizeof(*scram_ctx));
|
||||
scram_ctx = strophe_alloc(conn->ctx, sizeof(*scram_ctx));
|
||||
if (conn->sasl_support & SASL_MASK_SCRAMSHA512)
|
||||
scram_ctx->alg = &scram_sha512;
|
||||
else if (conn->sasl_support & SASL_MASK_SCRAMSHA256)
|
||||
@@ -721,7 +721,7 @@ static void _auth(xmpp_conn_t *conn)
|
||||
/* don't free scram_init on success */
|
||||
scram_ctx->scram_init = _make_scram_init_msg(conn);
|
||||
if (!scram_ctx->scram_init) {
|
||||
xmpp_free(conn->ctx, scram_ctx);
|
||||
strophe_free(conn->ctx, scram_ctx);
|
||||
xmpp_stanza_release(auth);
|
||||
disconnect_mem_error(conn);
|
||||
return;
|
||||
@@ -731,8 +731,8 @@ static void _auth(xmpp_conn_t *conn)
|
||||
(unsigned char *)scram_ctx->scram_init,
|
||||
strlen(scram_ctx->scram_init));
|
||||
if (!str) {
|
||||
xmpp_free(conn->ctx, scram_ctx->scram_init);
|
||||
xmpp_free(conn->ctx, scram_ctx);
|
||||
strophe_free(conn->ctx, scram_ctx->scram_init);
|
||||
strophe_free(conn->ctx, scram_ctx);
|
||||
xmpp_stanza_release(auth);
|
||||
disconnect_mem_error(conn);
|
||||
return;
|
||||
@@ -740,15 +740,15 @@ static void _auth(xmpp_conn_t *conn)
|
||||
|
||||
authdata = xmpp_stanza_new(conn->ctx);
|
||||
if (!authdata) {
|
||||
xmpp_free(conn->ctx, str);
|
||||
xmpp_free(conn->ctx, scram_ctx->scram_init);
|
||||
xmpp_free(conn->ctx, scram_ctx);
|
||||
strophe_free(conn->ctx, str);
|
||||
strophe_free(conn->ctx, scram_ctx->scram_init);
|
||||
strophe_free(conn->ctx, scram_ctx);
|
||||
xmpp_stanza_release(auth);
|
||||
disconnect_mem_error(conn);
|
||||
return;
|
||||
}
|
||||
xmpp_stanza_set_text(authdata, str);
|
||||
xmpp_free(conn->ctx, str);
|
||||
strophe_free(conn->ctx, str);
|
||||
xmpp_stanza_add_child(auth, authdata);
|
||||
xmpp_stanza_release(authdata);
|
||||
|
||||
@@ -797,8 +797,8 @@ static void _auth(xmpp_conn_t *conn)
|
||||
return;
|
||||
}
|
||||
xmpp_stanza_set_text(authdata, str);
|
||||
xmpp_free(conn->ctx, str);
|
||||
xmpp_free(conn->ctx, authid);
|
||||
strophe_free(conn->ctx, str);
|
||||
strophe_free(conn->ctx, authid);
|
||||
|
||||
xmpp_stanza_add_child(auth, authdata);
|
||||
xmpp_stanza_release(authdata);
|
||||
@@ -923,7 +923,7 @@ _handle_features_sasl(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void *userdata)
|
||||
resource = xmpp_jid_resource(conn->ctx, conn->jid);
|
||||
if ((resource != NULL) && (strlen(resource) == 0)) {
|
||||
/* jabberd2 doesn't handle an empty resource */
|
||||
xmpp_free(conn->ctx, resource);
|
||||
strophe_free(conn->ctx, resource);
|
||||
resource = NULL;
|
||||
}
|
||||
|
||||
@@ -951,7 +951,7 @@ _handle_features_sasl(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void *userdata)
|
||||
xmpp_stanza_release(text);
|
||||
xmpp_stanza_add_child(bind, res);
|
||||
xmpp_stanza_release(res);
|
||||
xmpp_free(conn->ctx, resource);
|
||||
strophe_free(conn->ctx, resource);
|
||||
}
|
||||
|
||||
xmpp_stanza_add_child(iq, bind);
|
||||
@@ -1191,7 +1191,7 @@ static void _auth_legacy(xmpp_conn_t *conn)
|
||||
goto err_free;
|
||||
}
|
||||
xmpp_stanza_set_text(authdata, str);
|
||||
xmpp_free(conn->ctx, str);
|
||||
strophe_free(conn->ctx, str);
|
||||
xmpp_stanza_add_child(child, authdata);
|
||||
xmpp_stanza_release(authdata);
|
||||
|
||||
@@ -1222,7 +1222,7 @@ static void _auth_legacy(xmpp_conn_t *conn)
|
||||
str = xmpp_jid_resource(conn->ctx, conn->jid);
|
||||
if (str) {
|
||||
xmpp_stanza_set_text(authdata, str);
|
||||
xmpp_free(conn->ctx, str);
|
||||
strophe_free(conn->ctx, str);
|
||||
} else {
|
||||
xmpp_stanza_release(authdata);
|
||||
xmpp_stanza_release(iq);
|
||||
@@ -1287,7 +1287,7 @@ int _handle_component_auth(xmpp_conn_t *conn)
|
||||
crypto_SHA1_Update(&mdctx, (uint8_t *)conn->pass, strlen(conn->pass));
|
||||
crypto_SHA1_Final(&mdctx, md_value);
|
||||
|
||||
digest = xmpp_alloc(conn->ctx, 2 * sizeof(md_value) + 1);
|
||||
digest = strophe_alloc(conn->ctx, 2 * sizeof(md_value) + 1);
|
||||
if (digest) {
|
||||
/* convert the digest into string representation */
|
||||
for (i = 0; i < sizeof(md_value); i++)
|
||||
@@ -1302,7 +1302,7 @@ int _handle_component_auth(xmpp_conn_t *conn)
|
||||
XMPP_NS_COMPONENT, digest);
|
||||
xmpp_debug(conn->ctx, "auth",
|
||||
"Sent component handshake to the server.");
|
||||
xmpp_free(conn->ctx, digest);
|
||||
strophe_free(conn->ctx, digest);
|
||||
} else {
|
||||
xmpp_debug(conn->ctx, "auth",
|
||||
"Couldn't allocate memory for component "
|
||||
@@ -1333,7 +1333,7 @@ int _handle_component_hs_response(xmpp_conn_t *conn,
|
||||
xmpp_stanza_to_text(stanza, &msg, &msg_size);
|
||||
if (msg) {
|
||||
xmpp_debug(conn->ctx, "auth", "Handshake failed: %s", msg);
|
||||
xmpp_free(conn->ctx, msg);
|
||||
strophe_free(conn->ctx, msg);
|
||||
}
|
||||
xmpp_disconnect(conn);
|
||||
return XMPP_EINT;
|
||||
|
||||
@@ -87,10 +87,11 @@ struct _xmpp_ctx_t {
|
||||
};
|
||||
|
||||
/* convenience functions for accessing the context */
|
||||
void *xmpp_alloc(const xmpp_ctx_t *ctx, size_t size);
|
||||
void *xmpp_realloc(const xmpp_ctx_t *ctx, void *p, size_t size);
|
||||
char *xmpp_strdup(const xmpp_ctx_t *ctx, const char *s);
|
||||
char *xmpp_strndup(const xmpp_ctx_t *ctx, const char *s, size_t len);
|
||||
void *strophe_alloc(const xmpp_ctx_t *ctx, size_t size);
|
||||
void *strophe_realloc(const xmpp_ctx_t *ctx, void *p, size_t size);
|
||||
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);
|
||||
void strophe_free(const xmpp_ctx_t *ctx, void *p);
|
||||
|
||||
void xmpp_log(const xmpp_ctx_t *ctx,
|
||||
const xmpp_log_level_t level,
|
||||
|
||||
116
src/conn.c
116
src/conn.c
@@ -105,7 +105,7 @@ xmpp_conn_t *xmpp_conn_new(xmpp_ctx_t *ctx)
|
||||
if (ctx == NULL)
|
||||
return NULL;
|
||||
|
||||
conn = xmpp_alloc(ctx, sizeof(xmpp_conn_t));
|
||||
conn = strophe_alloc(ctx, sizeof(xmpp_conn_t));
|
||||
if (conn != NULL) {
|
||||
conn->ctx = ctx;
|
||||
|
||||
@@ -129,9 +129,9 @@ xmpp_conn_t *xmpp_conn_new(xmpp_ctx_t *ctx)
|
||||
/* default timeouts */
|
||||
conn->connect_timeout = CONNECT_TIMEOUT;
|
||||
|
||||
conn->lang = xmpp_strdup(conn->ctx, "en");
|
||||
conn->lang = strophe_strdup(conn->ctx, "en");
|
||||
if (!conn->lang) {
|
||||
xmpp_free(conn->ctx, conn);
|
||||
strophe_free(conn->ctx, conn);
|
||||
return NULL;
|
||||
}
|
||||
conn->domain = NULL;
|
||||
@@ -180,12 +180,12 @@ xmpp_conn_t *xmpp_conn_new(xmpp_ctx_t *ctx)
|
||||
while (tail && tail->next)
|
||||
tail = tail->next;
|
||||
|
||||
item = xmpp_alloc(conn->ctx, sizeof(xmpp_connlist_t));
|
||||
item = strophe_alloc(conn->ctx, sizeof(xmpp_connlist_t));
|
||||
if (!item) {
|
||||
xmpp_error(conn->ctx, "xmpp", "failed to allocate memory");
|
||||
xmpp_free(conn->ctx, conn->lang);
|
||||
strophe_free(conn->ctx, conn->lang);
|
||||
parser_free(conn->parser);
|
||||
xmpp_free(conn->ctx, conn);
|
||||
strophe_free(conn->ctx, conn);
|
||||
conn = NULL;
|
||||
} else {
|
||||
item->conn = conn;
|
||||
@@ -277,7 +277,7 @@ int xmpp_conn_release(xmpp_conn_t *conn)
|
||||
if (ctx->connlist->conn == conn) {
|
||||
item = ctx->connlist;
|
||||
ctx->connlist = item->next;
|
||||
xmpp_free(ctx, item);
|
||||
strophe_free(ctx, item);
|
||||
} else {
|
||||
prev = NULL;
|
||||
item = ctx->connlist;
|
||||
@@ -290,7 +290,7 @@ int xmpp_conn_release(xmpp_conn_t *conn)
|
||||
xmpp_error(ctx, "xmpp", "Connection not in context's list\n");
|
||||
} else {
|
||||
prev->next = item->next;
|
||||
xmpp_free(ctx, item);
|
||||
strophe_free(ctx, item);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -306,7 +306,7 @@ int xmpp_conn_release(xmpp_conn_t *conn)
|
||||
thli = hlitem;
|
||||
hlitem = hlitem->next;
|
||||
|
||||
xmpp_free(ctx, thli);
|
||||
strophe_free(ctx, thli);
|
||||
}
|
||||
|
||||
/* id handlers
|
||||
@@ -318,8 +318,8 @@ int xmpp_conn_release(xmpp_conn_t *conn)
|
||||
while (hlitem) {
|
||||
thli = hlitem;
|
||||
hlitem = hlitem->next;
|
||||
xmpp_free(conn->ctx, thli->u.id);
|
||||
xmpp_free(conn->ctx, thli);
|
||||
strophe_free(conn->ctx, thli->u.id);
|
||||
strophe_free(conn->ctx, thli);
|
||||
}
|
||||
}
|
||||
hash_iter_release(iter);
|
||||
@@ -331,31 +331,31 @@ int xmpp_conn_release(xmpp_conn_t *conn)
|
||||
hlitem = hlitem->next;
|
||||
|
||||
if (thli->u.ns)
|
||||
xmpp_free(ctx, thli->u.ns);
|
||||
strophe_free(ctx, thli->u.ns);
|
||||
if (thli->u.name)
|
||||
xmpp_free(ctx, thli->u.name);
|
||||
strophe_free(ctx, thli->u.name);
|
||||
if (thli->u.type)
|
||||
xmpp_free(ctx, thli->u.type);
|
||||
xmpp_free(ctx, thli);
|
||||
strophe_free(ctx, thli->u.type);
|
||||
strophe_free(ctx, thli);
|
||||
}
|
||||
|
||||
parser_free(conn->parser);
|
||||
|
||||
if (conn->jid)
|
||||
xmpp_free(ctx, conn->jid);
|
||||
strophe_free(ctx, conn->jid);
|
||||
if (conn->pass)
|
||||
xmpp_free(ctx, conn->pass);
|
||||
strophe_free(ctx, conn->pass);
|
||||
if (conn->lang)
|
||||
xmpp_free(ctx, conn->lang);
|
||||
strophe_free(ctx, conn->lang);
|
||||
if (conn->tls_client_cert)
|
||||
xmpp_free(ctx, conn->tls_client_cert);
|
||||
strophe_free(ctx, conn->tls_client_cert);
|
||||
if (conn->tls_client_key)
|
||||
xmpp_free(ctx, conn->tls_client_key);
|
||||
strophe_free(ctx, conn->tls_client_key);
|
||||
if (conn->tls_cafile)
|
||||
xmpp_free(ctx, conn->tls_cafile);
|
||||
strophe_free(ctx, conn->tls_cafile);
|
||||
if (conn->tls_capath)
|
||||
xmpp_free(ctx, conn->tls_capath);
|
||||
xmpp_free(ctx, conn);
|
||||
strophe_free(ctx, conn->tls_capath);
|
||||
strophe_free(ctx, conn);
|
||||
released = 1;
|
||||
}
|
||||
|
||||
@@ -407,8 +407,8 @@ const char *xmpp_conn_get_bound_jid(const xmpp_conn_t *conn)
|
||||
void xmpp_conn_set_jid(xmpp_conn_t *conn, const char *jid)
|
||||
{
|
||||
if (conn->jid)
|
||||
xmpp_free(conn->ctx, conn->jid);
|
||||
conn->jid = xmpp_strdup(conn->ctx, jid);
|
||||
strophe_free(conn->ctx, conn->jid);
|
||||
conn->jid = strophe_strdup(conn->ctx, jid);
|
||||
}
|
||||
|
||||
/** Set the Handler function which will be called when the TLS stack can't
|
||||
@@ -434,7 +434,7 @@ void xmpp_conn_set_certfail_handler(xmpp_conn_t *const conn,
|
||||
*/
|
||||
void xmpp_conn_set_cafile(xmpp_conn_t *const conn, const char *path)
|
||||
{
|
||||
conn->tls_cafile = xmpp_strdup(conn->ctx, path);
|
||||
conn->tls_cafile = strophe_strdup(conn->ctx, path);
|
||||
}
|
||||
|
||||
/** Set the CApath
|
||||
@@ -446,7 +446,7 @@ void xmpp_conn_set_cafile(xmpp_conn_t *const conn, const char *path)
|
||||
*/
|
||||
void xmpp_conn_set_capath(xmpp_conn_t *const conn, const char *path)
|
||||
{
|
||||
conn->tls_capath = xmpp_strdup(conn->ctx, path);
|
||||
conn->tls_capath = strophe_strdup(conn->ctx, path);
|
||||
}
|
||||
|
||||
/** Retrieve the peer certificate
|
||||
@@ -483,11 +483,11 @@ void xmpp_conn_set_client_cert(xmpp_conn_t *const conn,
|
||||
{
|
||||
xmpp_debug(conn->ctx, "conn", "set client cert %s %s", cert, key);
|
||||
if (conn->tls_client_cert)
|
||||
xmpp_free(conn->ctx, conn->tls_client_cert);
|
||||
conn->tls_client_cert = xmpp_strdup(conn->ctx, cert);
|
||||
strophe_free(conn->ctx, conn->tls_client_cert);
|
||||
conn->tls_client_cert = strophe_strdup(conn->ctx, cert);
|
||||
if (conn->tls_client_key)
|
||||
xmpp_free(conn->ctx, conn->tls_client_key);
|
||||
conn->tls_client_key = xmpp_strdup(conn->ctx, key);
|
||||
strophe_free(conn->ctx, conn->tls_client_key);
|
||||
conn->tls_client_key = strophe_strdup(conn->ctx, key);
|
||||
}
|
||||
|
||||
/** Get the number of xmppAddr entries in the client certificate.
|
||||
@@ -542,8 +542,8 @@ const char *xmpp_conn_get_pass(const xmpp_conn_t *conn)
|
||||
void xmpp_conn_set_pass(xmpp_conn_t *conn, const char *pass)
|
||||
{
|
||||
if (conn->pass)
|
||||
xmpp_free(conn->ctx, conn->pass);
|
||||
conn->pass = pass ? xmpp_strdup(conn->ctx, pass) : NULL;
|
||||
strophe_free(conn->ctx, conn->pass);
|
||||
conn->pass = pass ? strophe_strdup(conn->ctx, pass) : NULL;
|
||||
}
|
||||
|
||||
/** Get the strophe context that the connection is associated with.
|
||||
@@ -649,7 +649,7 @@ int xmpp_connect_client(xmpp_conn_t *conn,
|
||||
userdata);
|
||||
} while (rc != 0 && rr != NULL);
|
||||
|
||||
xmpp_free(conn->ctx, domain);
|
||||
strophe_free(conn->ctx, domain);
|
||||
resolver_srv_free(conn->ctx, srv_rr_list);
|
||||
|
||||
return rc;
|
||||
@@ -924,7 +924,7 @@ void xmpp_send_raw_string(xmpp_conn_t *conn, const char *fmt, ...)
|
||||
/* we need more space for this data, so we allocate a big
|
||||
* enough buffer and print to that */
|
||||
len++; /* account for trailing \0 */
|
||||
bigbuf = xmpp_alloc(conn->ctx, len);
|
||||
bigbuf = strophe_alloc(conn->ctx, len);
|
||||
if (!bigbuf) {
|
||||
xmpp_debug(conn->ctx, "xmpp",
|
||||
"Could not allocate memory for send_raw_string");
|
||||
@@ -961,7 +961,7 @@ void xmpp_send_raw(xmpp_conn_t *conn, const char *data, size_t len)
|
||||
if (conn->state != XMPP_STATE_CONNECTED)
|
||||
return;
|
||||
|
||||
d = xmpp_strndup(conn->ctx, data, len);
|
||||
d = strophe_strndup(conn->ctx, data, len);
|
||||
if (!d) {
|
||||
xmpp_error(conn->ctx, "conn", "Failed to strndup");
|
||||
return;
|
||||
@@ -1027,7 +1027,7 @@ void conn_open_stream(xmpp_conn_t *conn)
|
||||
conn_disconnect(conn);
|
||||
}
|
||||
if (from)
|
||||
xmpp_free(conn->ctx, from);
|
||||
strophe_free(conn->ctx, from);
|
||||
}
|
||||
|
||||
int conn_tls_start(xmpp_conn_t *conn)
|
||||
@@ -1218,7 +1218,7 @@ static char *_conn_build_stream_tag(xmpp_conn_t *conn,
|
||||
len = strlen(tag_head) + strlen(tag_tail);
|
||||
for (i = 0; i < attributes_len; ++i)
|
||||
len += strlen(attributes[i]) + 2;
|
||||
tag = xmpp_alloc(conn->ctx, len + 1);
|
||||
tag = strophe_alloc(conn->ctx, len + 1);
|
||||
if (!tag)
|
||||
return NULL;
|
||||
|
||||
@@ -1239,7 +1239,7 @@ static char *_conn_build_stream_tag(xmpp_conn_t *conn,
|
||||
xmpp_error(conn->ctx, "xmpp",
|
||||
"Internal error in "
|
||||
"_conn_build_stream_tag().");
|
||||
xmpp_free(conn->ctx, tag);
|
||||
strophe_free(conn->ctx, tag);
|
||||
tag = NULL;
|
||||
}
|
||||
|
||||
@@ -1257,7 +1257,7 @@ static int _conn_open_stream_with_attributes(xmpp_conn_t *conn,
|
||||
return XMPP_EMEM;
|
||||
|
||||
xmpp_send_raw_string(conn, "<?xml version=\"1.0\"?>%s", tag);
|
||||
xmpp_free(conn->ctx, tag);
|
||||
strophe_free(conn->ctx, tag);
|
||||
|
||||
return XMPP_EOK;
|
||||
}
|
||||
@@ -1274,10 +1274,10 @@ static void _conn_attributes_new(xmpp_conn_t *conn,
|
||||
if (attrs) {
|
||||
for (; attrs[nr]; ++nr)
|
||||
;
|
||||
array = xmpp_alloc(conn->ctx, sizeof(*array) * nr);
|
||||
array = strophe_alloc(conn->ctx, sizeof(*array) * nr);
|
||||
for (i = 0; array && i < nr; ++i) {
|
||||
array[i] = (i & 1) == 0 ? parser_attr_name(conn->ctx, attrs[i])
|
||||
: xmpp_strdup(conn->ctx, attrs[i]);
|
||||
: strophe_strdup(conn->ctx, attrs[i]);
|
||||
if (array[i] == NULL)
|
||||
break;
|
||||
}
|
||||
@@ -1300,8 +1300,8 @@ static void _conn_attributes_destroy(xmpp_conn_t *conn,
|
||||
|
||||
if (attributes) {
|
||||
for (i = 0; i < attributes_len; ++i)
|
||||
xmpp_free(conn->ctx, attributes[i]);
|
||||
xmpp_free(conn->ctx, attributes);
|
||||
strophe_free(conn->ctx, attributes[i]);
|
||||
strophe_free(conn->ctx, attributes);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1315,7 +1315,7 @@ static void _log_open_tag(xmpp_conn_t *conn, char **attrs)
|
||||
tag = _conn_build_stream_tag(conn, attributes, nr);
|
||||
if (tag) {
|
||||
xmpp_debug(conn->ctx, "xmpp", "RECV: %s", tag);
|
||||
xmpp_free(conn->ctx, tag);
|
||||
strophe_free(conn->ctx, tag);
|
||||
}
|
||||
_conn_attributes_destroy(conn, attributes, nr);
|
||||
}
|
||||
@@ -1341,14 +1341,14 @@ static void _handle_stream_start(char *name, char **attrs, void *userdata)
|
||||
int failed = 0;
|
||||
|
||||
if (conn->stream_id)
|
||||
xmpp_free(conn->ctx, conn->stream_id);
|
||||
strophe_free(conn->ctx, conn->stream_id);
|
||||
conn->stream_id = NULL;
|
||||
|
||||
if (strcmp(name, "stream") == 0) {
|
||||
_log_open_tag(conn, attrs);
|
||||
id = _get_stream_attribute(attrs, "id");
|
||||
if (id)
|
||||
conn->stream_id = xmpp_strdup(conn->ctx, id);
|
||||
conn->stream_id = strophe_strdup(conn->ctx, id);
|
||||
|
||||
if (id && !conn->stream_id) {
|
||||
xmpp_error(conn->ctx, "conn", "Memory allocation failed.");
|
||||
@@ -1389,7 +1389,7 @@ static void _handle_stream_stanza(xmpp_stanza_t *stanza, void *userdata)
|
||||
|
||||
if (xmpp_stanza_to_text(stanza, &buf, &len) == 0) {
|
||||
xmpp_debug(conn->ctx, "xmpp", "RECV: %s", buf);
|
||||
xmpp_free(conn->ctx, buf);
|
||||
strophe_free(conn->ctx, buf);
|
||||
}
|
||||
|
||||
handler_fire_stanza(conn, stanza);
|
||||
@@ -1424,8 +1424,8 @@ static void _conn_reset(xmpp_conn_t *conn)
|
||||
while (sq) {
|
||||
tsq = sq;
|
||||
sq = sq->next;
|
||||
xmpp_free(ctx, tsq->data);
|
||||
xmpp_free(ctx, tsq);
|
||||
strophe_free(ctx, tsq->data);
|
||||
strophe_free(ctx, tsq);
|
||||
}
|
||||
conn->send_queue_head = NULL;
|
||||
conn->send_queue_tail = NULL;
|
||||
@@ -1434,17 +1434,17 @@ static void _conn_reset(xmpp_conn_t *conn)
|
||||
if (conn->stream_error) {
|
||||
xmpp_stanza_release(conn->stream_error->stanza);
|
||||
if (conn->stream_error->text)
|
||||
xmpp_free(ctx, conn->stream_error->text);
|
||||
xmpp_free(ctx, conn->stream_error);
|
||||
strophe_free(ctx, conn->stream_error->text);
|
||||
strophe_free(ctx, conn->stream_error);
|
||||
conn->stream_error = NULL;
|
||||
}
|
||||
|
||||
if (conn->domain)
|
||||
xmpp_free(ctx, conn->domain);
|
||||
strophe_free(ctx, conn->domain);
|
||||
if (conn->bound_jid)
|
||||
xmpp_free(ctx, conn->bound_jid);
|
||||
strophe_free(ctx, conn->bound_jid);
|
||||
if (conn->stream_id)
|
||||
xmpp_free(ctx, conn->stream_id);
|
||||
strophe_free(ctx, conn->stream_id);
|
||||
conn->domain = NULL;
|
||||
conn->bound_jid = NULL;
|
||||
conn->stream_id = NULL;
|
||||
@@ -1480,7 +1480,7 @@ static int _conn_connect(xmpp_conn_t *conn,
|
||||
_conn_reset(conn);
|
||||
|
||||
conn->type = type;
|
||||
conn->domain = xmpp_strdup(conn->ctx, domain);
|
||||
conn->domain = strophe_strdup(conn->ctx, domain);
|
||||
if (!conn->domain)
|
||||
return XMPP_EMEM;
|
||||
|
||||
@@ -1518,10 +1518,10 @@ static int _send_raw(xmpp_conn_t *conn, char *data, size_t len)
|
||||
xmpp_send_queue_t *item;
|
||||
|
||||
/* create send queue item for queue */
|
||||
item = xmpp_alloc(conn->ctx, sizeof(xmpp_send_queue_t));
|
||||
item = strophe_alloc(conn->ctx, sizeof(xmpp_send_queue_t));
|
||||
if (!item) {
|
||||
xmpp_error(conn->ctx, "conn", "DROPPED: %s", data);
|
||||
xmpp_free(conn->ctx, data);
|
||||
strophe_free(conn->ctx, data);
|
||||
return XMPP_EMEM;
|
||||
}
|
||||
|
||||
|
||||
16
src/crypto.c
16
src/crypto.c
@@ -53,7 +53,7 @@ static char *digest_to_string_alloc(xmpp_ctx_t *ctx, const uint8_t *digest)
|
||||
size_t slen;
|
||||
|
||||
slen = SHA1_DIGEST_SIZE * 2 + 1;
|
||||
s = xmpp_alloc(ctx, slen);
|
||||
s = strophe_alloc(ctx, slen);
|
||||
if (s) {
|
||||
s = digest_to_string(digest, s, slen);
|
||||
assert(s != NULL);
|
||||
@@ -122,7 +122,7 @@ xmpp_sha1_t *xmpp_sha1_new(xmpp_ctx_t *ctx)
|
||||
{
|
||||
xmpp_sha1_t *sha1;
|
||||
|
||||
sha1 = xmpp_alloc(ctx, sizeof(*sha1));
|
||||
sha1 = strophe_alloc(ctx, sizeof(*sha1));
|
||||
if (sha1) {
|
||||
memset(sha1, 0, sizeof(*sha1));
|
||||
crypto_SHA1_Init(&sha1->ctx);
|
||||
@@ -139,7 +139,7 @@ xmpp_sha1_t *xmpp_sha1_new(xmpp_ctx_t *ctx)
|
||||
*/
|
||||
void xmpp_sha1_free(xmpp_sha1_t *sha1)
|
||||
{
|
||||
xmpp_free(sha1->xmpp_ctx, sha1);
|
||||
strophe_free(sha1->xmpp_ctx, sha1);
|
||||
}
|
||||
|
||||
/** Update SHA1 context with the next portion of data.
|
||||
@@ -259,7 +259,7 @@ base64_encode(xmpp_ctx_t *ctx, const unsigned char *buffer, size_t len)
|
||||
size_t i;
|
||||
|
||||
clen = base64_encoded_len(len);
|
||||
cbuf = xmpp_alloc(ctx, clen + 1);
|
||||
cbuf = strophe_alloc(ctx, clen + 1);
|
||||
if (cbuf != NULL) {
|
||||
c = cbuf;
|
||||
/* loop over data, turning every 3 bytes into 4 characters */
|
||||
@@ -348,7 +348,7 @@ static void base64_decode(xmpp_ctx_t *ctx,
|
||||
if (dlen == 0)
|
||||
goto _base64_error;
|
||||
|
||||
dbuf = xmpp_alloc(ctx, dlen + 1);
|
||||
dbuf = strophe_alloc(ctx, dlen + 1);
|
||||
if (dbuf != NULL) {
|
||||
d = dbuf;
|
||||
/* loop over each set of 4 characters, decoding 3 bytes */
|
||||
@@ -427,7 +427,7 @@ static void base64_decode(xmpp_ctx_t *ctx,
|
||||
|
||||
_base64_decode_error:
|
||||
/* invalid character; abort decoding! */
|
||||
xmpp_free(ctx, dbuf);
|
||||
strophe_free(ctx, dbuf);
|
||||
_base64_error:
|
||||
*out = NULL;
|
||||
*outlen = 0;
|
||||
@@ -469,7 +469,7 @@ char *xmpp_base64_decode_str(xmpp_ctx_t *ctx, const char *base64, size_t len)
|
||||
|
||||
if (len == 0) {
|
||||
/* handle empty string */
|
||||
buf = xmpp_alloc(ctx, 1);
|
||||
buf = strophe_alloc(ctx, 1);
|
||||
if (buf)
|
||||
buf[0] = '\0';
|
||||
buflen = 0;
|
||||
@@ -478,7 +478,7 @@ char *xmpp_base64_decode_str(xmpp_ctx_t *ctx, const char *base64, size_t len)
|
||||
}
|
||||
if (buf) {
|
||||
if (buflen != strlen((char *)buf)) {
|
||||
xmpp_free(ctx, buf);
|
||||
strophe_free(ctx, buf);
|
||||
buf = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
26
src/ctx.c
26
src/ctx.c
@@ -211,7 +211,7 @@ static xmpp_log_t xmpp_default_log = {NULL, NULL};
|
||||
*
|
||||
* @return a pointer to the allocated memory or NULL on an error
|
||||
*/
|
||||
void *xmpp_alloc(const xmpp_ctx_t *ctx, size_t size)
|
||||
void *strophe_alloc(const xmpp_ctx_t *ctx, size_t size)
|
||||
{
|
||||
return ctx->mem->alloc(size, ctx->mem->userdata);
|
||||
}
|
||||
@@ -222,11 +222,21 @@ void *xmpp_alloc(const xmpp_ctx_t *ctx, size_t size)
|
||||
* @param ctx a Strophe context object
|
||||
* @param p a pointer referencing memory to be freed
|
||||
*/
|
||||
void xmpp_free(const xmpp_ctx_t *ctx, void *p)
|
||||
void strophe_free(const xmpp_ctx_t *ctx, void *p)
|
||||
{
|
||||
ctx->mem->free(p, ctx->mem->userdata);
|
||||
}
|
||||
|
||||
/** Trampoline to \ref strophe_free
|
||||
*
|
||||
* @param ctx \ref strophe_free
|
||||
* @param p \ref strophe_free
|
||||
*/
|
||||
void xmpp_free(const xmpp_ctx_t *ctx, void *p)
|
||||
{
|
||||
strophe_free(ctx, p);
|
||||
}
|
||||
|
||||
/** Reallocate memory in a Strophe context.
|
||||
* All Strophe functions will use this to reallocate memory.
|
||||
*
|
||||
@@ -236,7 +246,7 @@ void xmpp_free(const xmpp_ctx_t *ctx, void *p)
|
||||
*
|
||||
* @return a pointer to the reallocated memory or NULL on an error
|
||||
*/
|
||||
void *xmpp_realloc(const xmpp_ctx_t *ctx, void *p, size_t size)
|
||||
void *strophe_realloc(const xmpp_ctx_t *ctx, void *p, size_t size)
|
||||
{
|
||||
return ctx->mem->realloc(p, size, ctx->mem->userdata);
|
||||
}
|
||||
@@ -275,7 +285,7 @@ void xmpp_log(const xmpp_ctx_t *ctx,
|
||||
va_copy(copy, ap);
|
||||
ret = xmpp_vsnprintf(smbuf, sizeof(smbuf), fmt, ap);
|
||||
if (ret >= (int)sizeof(smbuf)) {
|
||||
buf = (char *)xmpp_alloc(ctx, ret + 1);
|
||||
buf = (char *)strophe_alloc(ctx, ret + 1);
|
||||
if (!buf) {
|
||||
buf = NULL;
|
||||
xmpp_error(ctx, "log", "Failed allocating memory for log message.");
|
||||
@@ -286,7 +296,7 @@ void xmpp_log(const xmpp_ctx_t *ctx,
|
||||
ret = xmpp_vsnprintf(buf, ret + 1, fmt, copy);
|
||||
if (ret > oldret) {
|
||||
xmpp_error(ctx, "log", "Unexpected error");
|
||||
xmpp_free(ctx, buf);
|
||||
strophe_free(ctx, buf);
|
||||
va_end(copy);
|
||||
return;
|
||||
}
|
||||
@@ -298,7 +308,7 @@ void xmpp_log(const xmpp_ctx_t *ctx,
|
||||
ctx->log->handler(ctx->log->userdata, level, area, buf);
|
||||
|
||||
if (buf != smbuf)
|
||||
xmpp_free(ctx, buf);
|
||||
strophe_free(ctx, buf);
|
||||
}
|
||||
|
||||
/** Write to the log at the ERROR level.
|
||||
@@ -442,7 +452,7 @@ xmpp_ctx_t *xmpp_ctx_new(const xmpp_mem_t *mem, const xmpp_log_t *log)
|
||||
ctx->timeout = EVENT_LOOP_DEFAULT_TIMEOUT;
|
||||
ctx->verbosity = 0;
|
||||
if (ctx->rand == NULL) {
|
||||
xmpp_free(ctx, ctx);
|
||||
strophe_free(ctx, ctx);
|
||||
ctx = NULL;
|
||||
}
|
||||
}
|
||||
@@ -460,7 +470,7 @@ void xmpp_ctx_free(xmpp_ctx_t *ctx)
|
||||
{
|
||||
/* mem and log are owned by their suppliers */
|
||||
xmpp_rand_free(ctx, ctx->rand);
|
||||
xmpp_free(ctx, ctx); /* pull the hole in after us */
|
||||
strophe_free(ctx, ctx); /* pull the hole in after us */
|
||||
}
|
||||
|
||||
/** Set the verbosity level of a Strophe context.
|
||||
|
||||
@@ -137,11 +137,11 @@ void xmpp_run_once(xmpp_ctx_t *ctx, unsigned long timeout)
|
||||
xmpp_debug(conn->ctx, "conn", "SENT: %s", sq->data);
|
||||
xmpp_debug_verbose(1, ctx, "xmpp",
|
||||
"Finished writing queue element: %p.", sq);
|
||||
xmpp_free(ctx, sq->data);
|
||||
strophe_free(ctx, sq->data);
|
||||
tsq = sq;
|
||||
sq = sq->next;
|
||||
conn->send_queue_len--;
|
||||
xmpp_free(ctx, tsq);
|
||||
strophe_free(ctx, tsq);
|
||||
|
||||
/* pop the top item */
|
||||
conn->send_queue_head = sq;
|
||||
|
||||
@@ -49,12 +49,12 @@ static void _handler_item_remove(xmpp_handlist_t **head, xmpp_handlist_t *item)
|
||||
static void _free_handlist_item(xmpp_ctx_t *ctx, xmpp_handlist_t *item)
|
||||
{
|
||||
if (item->u.ns)
|
||||
xmpp_free(ctx, item->u.ns);
|
||||
strophe_free(ctx, item->u.ns);
|
||||
if (item->u.name)
|
||||
xmpp_free(ctx, item->u.name);
|
||||
strophe_free(ctx, item->u.name);
|
||||
if (item->u.type)
|
||||
xmpp_free(ctx, item->u.type);
|
||||
xmpp_free(ctx, item);
|
||||
strophe_free(ctx, item->u.type);
|
||||
strophe_free(ctx, item);
|
||||
}
|
||||
|
||||
/** Fire off all stanza handlers that match.
|
||||
@@ -98,8 +98,8 @@ void handler_fire_stanza(xmpp_conn_t *conn, xmpp_stanza_t *stanza)
|
||||
/* replace old value */
|
||||
hash_add(conn->id_handlers, id, head);
|
||||
}
|
||||
xmpp_free(conn->ctx, item->u.id);
|
||||
xmpp_free(conn->ctx, item);
|
||||
strophe_free(conn->ctx, item->u.id);
|
||||
strophe_free(conn->ctx, item);
|
||||
}
|
||||
item = next;
|
||||
}
|
||||
@@ -194,7 +194,7 @@ uint64_t handler_fire_timed(xmpp_ctx_t *ctx)
|
||||
if (!ret) {
|
||||
/* delete handler if it returned false */
|
||||
_handler_item_remove(&conn->timed_handlers, item);
|
||||
xmpp_free(ctx, item);
|
||||
strophe_free(ctx, item);
|
||||
}
|
||||
} else if (min > (item->u.period - elapsed))
|
||||
min = item->u.period - elapsed;
|
||||
@@ -225,7 +225,7 @@ uint64_t handler_fire_timed(xmpp_ctx_t *ctx)
|
||||
if (!ret) {
|
||||
/* delete handler if it returned false */
|
||||
_handler_item_remove(&ctx->timed_handlers, item);
|
||||
xmpp_free(ctx, item);
|
||||
strophe_free(ctx, item);
|
||||
}
|
||||
} else if (min > (item->u.period - elapsed))
|
||||
min = item->u.period - elapsed;
|
||||
@@ -275,7 +275,7 @@ static void _timed_handler_add(xmpp_ctx_t *ctx,
|
||||
return;
|
||||
|
||||
/* build new item */
|
||||
item = xmpp_alloc(ctx, sizeof(xmpp_handlist_t));
|
||||
item = strophe_alloc(ctx, sizeof(xmpp_handlist_t));
|
||||
if (!item)
|
||||
return;
|
||||
|
||||
@@ -302,7 +302,7 @@ static void _timed_handler_delete(xmpp_ctx_t *ctx,
|
||||
item = *handlers_list;
|
||||
if (item->handler == handler) {
|
||||
*handlers_list = item->next;
|
||||
xmpp_free(ctx, item);
|
||||
strophe_free(ctx, item);
|
||||
} else {
|
||||
handlers_list = &item->next;
|
||||
}
|
||||
@@ -342,7 +342,7 @@ static void _id_handler_add(xmpp_conn_t *conn,
|
||||
return;
|
||||
|
||||
/* build new item */
|
||||
item = xmpp_alloc(conn->ctx, sizeof(xmpp_handlist_t));
|
||||
item = strophe_alloc(conn->ctx, sizeof(xmpp_handlist_t));
|
||||
if (!item)
|
||||
return;
|
||||
|
||||
@@ -352,9 +352,9 @@ static void _id_handler_add(xmpp_conn_t *conn,
|
||||
item->enabled = 0;
|
||||
item->next = NULL;
|
||||
|
||||
item->u.id = xmpp_strdup(conn->ctx, id);
|
||||
item->u.id = strophe_strdup(conn->ctx, id);
|
||||
if (!item->u.id) {
|
||||
xmpp_free(conn->ctx, item);
|
||||
strophe_free(conn->ctx, item);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -399,8 +399,8 @@ void xmpp_id_handler_delete(xmpp_conn_t *conn,
|
||||
hash_add(conn->id_handlers, id, next);
|
||||
}
|
||||
|
||||
xmpp_free(conn->ctx, item->u.id);
|
||||
xmpp_free(conn->ctx, item);
|
||||
strophe_free(conn->ctx, item->u.id);
|
||||
strophe_free(conn->ctx, item);
|
||||
item = next;
|
||||
} else {
|
||||
prev = item;
|
||||
@@ -412,7 +412,7 @@ void xmpp_id_handler_delete(xmpp_conn_t *conn,
|
||||
static int _dup_string(xmpp_ctx_t *ctx, const char *src, char **dest)
|
||||
{
|
||||
if (src) {
|
||||
*dest = xmpp_strdup(ctx, src);
|
||||
*dest = strophe_strdup(ctx, src);
|
||||
if (!(*dest))
|
||||
return 1;
|
||||
}
|
||||
@@ -443,7 +443,7 @@ static void _handler_add(xmpp_conn_t *conn,
|
||||
return;
|
||||
|
||||
/* build new item */
|
||||
item = (xmpp_handlist_t *)xmpp_alloc(conn->ctx, sizeof(xmpp_handlist_t));
|
||||
item = (xmpp_handlist_t *)strophe_alloc(conn->ctx, sizeof(xmpp_handlist_t));
|
||||
if (!item)
|
||||
return;
|
||||
|
||||
@@ -673,7 +673,7 @@ void handler_system_delete_all(xmpp_conn_t *conn)
|
||||
if (!item->user_handler) {
|
||||
next = item->next;
|
||||
_handler_item_remove(&conn->timed_handlers, item);
|
||||
xmpp_free(conn->ctx, item);
|
||||
strophe_free(conn->ctx, item);
|
||||
item = next;
|
||||
} else
|
||||
item = item->next;
|
||||
@@ -688,8 +688,8 @@ void handler_system_delete_all(xmpp_conn_t *conn)
|
||||
if (!item->user_handler) {
|
||||
next = item->next;
|
||||
_handler_item_remove(&head, item);
|
||||
xmpp_free(conn->ctx, item->u.id);
|
||||
xmpp_free(conn->ctx, item);
|
||||
strophe_free(conn->ctx, item->u.id);
|
||||
strophe_free(conn->ctx, item);
|
||||
item = next;
|
||||
} else
|
||||
item = item->next;
|
||||
|
||||
28
src/hash.c
28
src/hash.c
@@ -50,11 +50,11 @@ hash_t *hash_new(xmpp_ctx_t *ctx, int size, hash_free_func free_func)
|
||||
{
|
||||
hash_t *result = NULL;
|
||||
|
||||
result = xmpp_alloc(ctx, sizeof(hash_t));
|
||||
result = strophe_alloc(ctx, sizeof(hash_t));
|
||||
if (result != NULL) {
|
||||
result->entries = xmpp_alloc(ctx, size * sizeof(hashentry_t *));
|
||||
result->entries = strophe_alloc(ctx, size * sizeof(hashentry_t *));
|
||||
if (result->entries == NULL) {
|
||||
xmpp_free(ctx, result);
|
||||
strophe_free(ctx, result);
|
||||
return NULL;
|
||||
}
|
||||
memset(result->entries, 0, size * sizeof(hashentry_t *));
|
||||
@@ -91,15 +91,15 @@ void hash_release(hash_t *table)
|
||||
entry = table->entries[i];
|
||||
while (entry != NULL) {
|
||||
next = entry->next;
|
||||
xmpp_free(ctx, entry->key);
|
||||
strophe_free(ctx, entry->key);
|
||||
if (table->free)
|
||||
table->free(ctx, entry->value);
|
||||
xmpp_free(ctx, entry);
|
||||
strophe_free(ctx, entry);
|
||||
entry = next;
|
||||
}
|
||||
}
|
||||
xmpp_free(ctx, table->entries);
|
||||
xmpp_free(ctx, table);
|
||||
strophe_free(ctx, table->entries);
|
||||
strophe_free(ctx, table);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,12 +153,12 @@ int hash_add(hash_t *table, const char *key, void *data)
|
||||
|
||||
if (entry == NULL) {
|
||||
/* allocate and fill a new entry */
|
||||
entry = xmpp_alloc(ctx, sizeof(hashentry_t));
|
||||
entry = strophe_alloc(ctx, sizeof(hashentry_t));
|
||||
if (!entry)
|
||||
return -1;
|
||||
entry->key = xmpp_strdup(ctx, key);
|
||||
entry->key = strophe_strdup(ctx, key);
|
||||
if (!entry->key) {
|
||||
xmpp_free(ctx, entry);
|
||||
strophe_free(ctx, entry);
|
||||
return -1;
|
||||
}
|
||||
/* insert ourselves in the linked list */
|
||||
@@ -198,7 +198,7 @@ int hash_drop(hash_t *table, const char *key)
|
||||
/* traverse the linked list looking for the key */
|
||||
if (!strcmp(key, entry->key)) {
|
||||
/* match, remove the entry */
|
||||
xmpp_free(ctx, entry->key);
|
||||
strophe_free(ctx, entry->key);
|
||||
if (table->free)
|
||||
table->free(ctx, entry->value);
|
||||
if (prev == NULL) {
|
||||
@@ -206,7 +206,7 @@ int hash_drop(hash_t *table, const char *key)
|
||||
} else {
|
||||
prev->next = entry->next;
|
||||
}
|
||||
xmpp_free(ctx, entry);
|
||||
strophe_free(ctx, entry);
|
||||
table->num_keys--;
|
||||
return 0;
|
||||
}
|
||||
@@ -228,7 +228,7 @@ hash_iterator_t *hash_iter_new(hash_t *table)
|
||||
xmpp_ctx_t *ctx = table->ctx;
|
||||
hash_iterator_t *iter;
|
||||
|
||||
iter = xmpp_alloc(ctx, sizeof(*iter));
|
||||
iter = strophe_alloc(ctx, sizeof(*iter));
|
||||
if (iter != NULL) {
|
||||
iter->ref = 1;
|
||||
iter->table = hash_clone(table);
|
||||
@@ -248,7 +248,7 @@ void hash_iter_release(hash_iterator_t *iter)
|
||||
|
||||
if (iter->ref == 0) { // ref is unsigned!!!
|
||||
hash_release(iter->table);
|
||||
xmpp_free(ctx, iter);
|
||||
strophe_free(ctx, iter);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
10
src/jid.c
10
src/jid.c
@@ -47,7 +47,7 @@ char *xmpp_jid_new(xmpp_ctx_t *ctx,
|
||||
len = nlen + dlen + rlen;
|
||||
|
||||
/* concat components */
|
||||
result = xmpp_alloc(ctx, len + 1);
|
||||
result = strophe_alloc(ctx, len + 1);
|
||||
if (result != NULL) {
|
||||
if (node != NULL) {
|
||||
memcpy(result, node, nlen - 1);
|
||||
@@ -77,7 +77,7 @@ char *xmpp_jid_bare(xmpp_ctx_t *ctx, const char *jid)
|
||||
size_t len;
|
||||
|
||||
len = strcspn(jid, "/");
|
||||
result = xmpp_alloc(ctx, len + 1);
|
||||
result = strophe_alloc(ctx, len + 1);
|
||||
if (result != NULL) {
|
||||
memcpy(result, jid, len);
|
||||
result[len] = '\0';
|
||||
@@ -101,7 +101,7 @@ char *xmpp_jid_node(xmpp_ctx_t *ctx, const char *jid)
|
||||
|
||||
c = strchr(jid, '@');
|
||||
if (c != NULL) {
|
||||
result = xmpp_alloc(ctx, (c - jid) + 1);
|
||||
result = strophe_alloc(ctx, (c - jid) + 1);
|
||||
if (result != NULL) {
|
||||
memcpy(result, jid, (c - jid));
|
||||
result[c - jid] = '\0';
|
||||
@@ -133,7 +133,7 @@ char *xmpp_jid_domain(xmpp_ctx_t *ctx, const char *jid)
|
||||
c++;
|
||||
}
|
||||
dlen = strcspn(c, "/"); /* do not include resource */
|
||||
result = xmpp_alloc(ctx, dlen + 1);
|
||||
result = strophe_alloc(ctx, dlen + 1);
|
||||
if (result != NULL) {
|
||||
memcpy(result, c, dlen);
|
||||
result[dlen] = '\0';
|
||||
@@ -155,5 +155,5 @@ char *xmpp_jid_resource(xmpp_ctx_t *ctx, const char *jid)
|
||||
const char *c;
|
||||
|
||||
c = strchr(jid, '/');
|
||||
return c != NULL ? xmpp_strdup(ctx, c + 1) : NULL;
|
||||
return c != NULL ? strophe_strdup(ctx, c + 1) : NULL;
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ static xmpp_ctx_t *mem_ctx = NULL;
|
||||
static void *parser_mem_malloc(size_t size)
|
||||
{
|
||||
if (mem_ctx != NULL)
|
||||
return xmpp_alloc(mem_ctx, size);
|
||||
return strophe_alloc(mem_ctx, size);
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
@@ -68,7 +68,7 @@ static void *parser_mem_malloc(size_t size)
|
||||
static void *parser_mem_realloc(void *ptr, size_t size)
|
||||
{
|
||||
if (mem_ctx != NULL)
|
||||
return xmpp_realloc(mem_ctx, ptr, size);
|
||||
return strophe_realloc(mem_ctx, ptr, size);
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
@@ -76,7 +76,7 @@ static void *parser_mem_realloc(void *ptr, size_t size)
|
||||
static void parser_mem_free(void *ptr)
|
||||
{
|
||||
if (mem_ctx != NULL)
|
||||
xmpp_free(mem_ctx, ptr);
|
||||
strophe_free(mem_ctx, ptr);
|
||||
}
|
||||
|
||||
static const XML_Memory_Handling_Suite parser_mem_suite = {
|
||||
@@ -95,11 +95,11 @@ static char *_xml_name(xmpp_ctx_t *ctx, const char *nsname)
|
||||
|
||||
c = strchr(nsname, namespace_sep);
|
||||
if (c == NULL)
|
||||
return xmpp_strdup(ctx, nsname);
|
||||
return strophe_strdup(ctx, nsname);
|
||||
|
||||
c++;
|
||||
len = strlen(c);
|
||||
result = xmpp_alloc(ctx, len + 1);
|
||||
result = strophe_alloc(ctx, len + 1);
|
||||
if (result != NULL) {
|
||||
memcpy(result, c, len);
|
||||
result[len] = '\0';
|
||||
@@ -116,7 +116,7 @@ static char *_xml_namespace(xmpp_ctx_t *ctx, const char *nsname)
|
||||
|
||||
c = strchr(nsname, namespace_sep);
|
||||
if (c != NULL) {
|
||||
result = xmpp_alloc(ctx, (c - nsname) + 1);
|
||||
result = strophe_alloc(ctx, (c - nsname) + 1);
|
||||
if (result != NULL) {
|
||||
memcpy(result, nsname, (c - nsname));
|
||||
result[c - nsname] = '\0';
|
||||
@@ -138,7 +138,7 @@ static void _set_attributes(xmpp_stanza_t *stanza, const XML_Char **attrs)
|
||||
/* namespaced attributes aren't used in xmpp, discard namespace */
|
||||
attr = _xml_name(stanza->ctx, attrs[i]);
|
||||
xmpp_stanza_set_attribute(stanza, attr, attrs[i + 1]);
|
||||
xmpp_free(stanza->ctx, attr);
|
||||
strophe_free(stanza->ctx, attr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -155,7 +155,7 @@ static void complete_inner_text(parser_t *parser)
|
||||
xmpp_stanza_add_child(parser->stanza, stanza);
|
||||
xmpp_stanza_release(stanza);
|
||||
}
|
||||
xmpp_free(parser->ctx, parser->inner_text);
|
||||
strophe_free(parser->ctx, parser->inner_text);
|
||||
parser->inner_text = NULL;
|
||||
parser->inner_text_size = 0;
|
||||
parser->inner_text_used = 0;
|
||||
@@ -202,9 +202,9 @@ _start_element(void *userdata, const XML_Char *nsname, const XML_Char **attrs)
|
||||
}
|
||||
|
||||
if (ns)
|
||||
xmpp_free(parser->ctx, ns);
|
||||
strophe_free(parser->ctx, ns);
|
||||
if (name)
|
||||
xmpp_free(parser->ctx, name);
|
||||
strophe_free(parser->ctx, name);
|
||||
|
||||
parser->depth++;
|
||||
}
|
||||
@@ -246,10 +246,10 @@ static void _characters(void *userdata, const XML_Char *s, int len)
|
||||
if (parser->inner_text_used + len >= parser->inner_text_size) {
|
||||
parser->inner_text_size =
|
||||
parser->inner_text_used + len + 1 + INNER_TEXT_PADDING;
|
||||
p = xmpp_realloc(parser->ctx, parser->inner_text,
|
||||
parser->inner_text_size);
|
||||
p = strophe_realloc(parser->ctx, parser->inner_text,
|
||||
parser->inner_text_size);
|
||||
if (p == NULL) {
|
||||
xmpp_free(parser->ctx, parser->inner_text);
|
||||
strophe_free(parser->ctx, parser->inner_text);
|
||||
parser->inner_text = NULL;
|
||||
parser->inner_text_used = 0;
|
||||
parser->inner_text_size = 0;
|
||||
@@ -270,7 +270,7 @@ parser_t *parser_new(xmpp_ctx_t *ctx,
|
||||
{
|
||||
parser_t *parser;
|
||||
|
||||
parser = xmpp_alloc(ctx, sizeof(parser_t));
|
||||
parser = strophe_alloc(ctx, sizeof(parser_t));
|
||||
if (parser != NULL) {
|
||||
parser->ctx = ctx;
|
||||
parser->expat = NULL;
|
||||
@@ -316,11 +316,11 @@ void parser_free(parser_t *parser)
|
||||
}
|
||||
|
||||
if (parser->inner_text) {
|
||||
xmpp_free(parser->ctx, parser->inner_text);
|
||||
strophe_free(parser->ctx, parser->inner_text);
|
||||
parser->inner_text = NULL;
|
||||
}
|
||||
|
||||
xmpp_free(parser->ctx, parser);
|
||||
strophe_free(parser->ctx, parser);
|
||||
}
|
||||
|
||||
/* shuts down and restarts XML parser. true on success */
|
||||
@@ -349,7 +349,7 @@ int parser_reset(parser_t *parser)
|
||||
}
|
||||
|
||||
if (parser->inner_text) {
|
||||
xmpp_free(parser->ctx, parser->inner_text);
|
||||
strophe_free(parser->ctx, parser->inner_text);
|
||||
parser->inner_text = NULL;
|
||||
}
|
||||
|
||||
|
||||
@@ -48,12 +48,12 @@ _set_attributes(xmpp_stanza_t *stanza, int nattrs, const xmlChar **attrs)
|
||||
/* SAX2 uses array of localname/prefix/uri/value_begin/value_end */
|
||||
for (i = 0; i < nattrs * 5; i += 5) {
|
||||
len = attrs[i + 4] - attrs[i + 3];
|
||||
value = xmpp_alloc(stanza->ctx, len + 1);
|
||||
value = strophe_alloc(stanza->ctx, len + 1);
|
||||
if (value) {
|
||||
memcpy(value, attrs[i + 3], len);
|
||||
value[len] = '\0';
|
||||
xmpp_stanza_set_attribute(stanza, (const char *)attrs[i], value);
|
||||
xmpp_free(stanza->ctx, value);
|
||||
strophe_free(stanza->ctx, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -70,7 +70,7 @@ _convert_attrs(parser_t *parser, int nattrs, const xmlChar **attrs)
|
||||
if (!attrs)
|
||||
return NULL;
|
||||
|
||||
ret = xmpp_alloc(parser->ctx, (nattrs + 1) * 2 * sizeof(char *));
|
||||
ret = strophe_alloc(parser->ctx, (nattrs + 1) * 2 * sizeof(char *));
|
||||
if (!ret)
|
||||
return NULL;
|
||||
memset(ret, 0, (nattrs + 1) * 2 * sizeof(char *));
|
||||
@@ -80,11 +80,11 @@ _convert_attrs(parser_t *parser, int nattrs, const xmlChar **attrs)
|
||||
o = c * 2;
|
||||
|
||||
len = attrs[i + 4] - attrs[i + 3];
|
||||
value = xmpp_alloc(parser->ctx, len + 1);
|
||||
value = strophe_alloc(parser->ctx, len + 1);
|
||||
if (value) {
|
||||
memcpy(value, attrs[i + 3], len);
|
||||
value[len] = '\0';
|
||||
ret[o] = xmpp_strdup(parser->ctx, (char *)attrs[i]);
|
||||
ret[o] = strophe_strdup(parser->ctx, (char *)attrs[i]);
|
||||
ret[o + 1] = value;
|
||||
}
|
||||
}
|
||||
@@ -101,12 +101,12 @@ static void _free_cbattrs(parser_t *parser, char **attrs)
|
||||
|
||||
for (i = 0; attrs[i]; i += 2) {
|
||||
if (attrs[i])
|
||||
xmpp_free(parser->ctx, attrs[i]);
|
||||
strophe_free(parser->ctx, attrs[i]);
|
||||
if (attrs[i + 1])
|
||||
xmpp_free(parser->ctx, attrs[i + 1]);
|
||||
strophe_free(parser->ctx, attrs[i + 1]);
|
||||
}
|
||||
|
||||
xmpp_free(parser->ctx, attrs);
|
||||
strophe_free(parser->ctx, attrs);
|
||||
}
|
||||
|
||||
static void _start_element(void *userdata,
|
||||
@@ -235,7 +235,7 @@ parser_t *parser_new(xmpp_ctx_t *ctx,
|
||||
{
|
||||
parser_t *parser;
|
||||
|
||||
parser = xmpp_alloc(ctx, sizeof(parser_t));
|
||||
parser = strophe_alloc(ctx, sizeof(parser_t));
|
||||
if (parser != NULL) {
|
||||
parser->ctx = ctx;
|
||||
parser->xmlctx = NULL;
|
||||
@@ -259,7 +259,7 @@ parser_t *parser_new(xmpp_ctx_t *ctx,
|
||||
|
||||
char *parser_attr_name(xmpp_ctx_t *ctx, char *nsname)
|
||||
{
|
||||
return xmpp_strdup(ctx, nsname);
|
||||
return strophe_strdup(ctx, nsname);
|
||||
}
|
||||
|
||||
static void _free_parent_stanza(xmpp_stanza_t *stanza)
|
||||
@@ -278,7 +278,7 @@ void parser_free(parser_t *parser)
|
||||
xmlFreeParserCtxt(parser->xmlctx);
|
||||
if (parser->stanza)
|
||||
_free_parent_stanza(parser->stanza);
|
||||
xmpp_free(parser->ctx, parser);
|
||||
strophe_free(parser->ctx, parser);
|
||||
}
|
||||
|
||||
/* shuts down and restarts XML parser. true on success */
|
||||
|
||||
@@ -269,7 +269,7 @@ static void xmpp_rand_reseed(xmpp_rand_t *rand)
|
||||
|
||||
xmpp_rand_t *xmpp_rand_new(xmpp_ctx_t *ctx)
|
||||
{
|
||||
xmpp_rand_t *out = xmpp_alloc(ctx, sizeof(*out));
|
||||
xmpp_rand_t *out = strophe_alloc(ctx, sizeof(*out));
|
||||
if (out != NULL) {
|
||||
memset(out, 0, sizeof(*out));
|
||||
}
|
||||
@@ -278,7 +278,7 @@ xmpp_rand_t *xmpp_rand_new(xmpp_ctx_t *ctx)
|
||||
|
||||
void xmpp_rand_free(xmpp_ctx_t *ctx, xmpp_rand_t *rand)
|
||||
{
|
||||
xmpp_free(ctx, rand);
|
||||
strophe_free(ctx, rand);
|
||||
}
|
||||
|
||||
void xmpp_rand_bytes(xmpp_rand_t *rand, unsigned char *output, size_t len)
|
||||
|
||||
@@ -196,7 +196,7 @@ int resolver_srv_lookup(xmpp_ctx_t *ctx,
|
||||
return set;
|
||||
#endif /* _WIN32 */
|
||||
|
||||
buf = xmpp_alloc(ctx, RESOLVER_BUF_MAX);
|
||||
buf = strophe_alloc(ctx, RESOLVER_BUF_MAX);
|
||||
if (buf == NULL)
|
||||
return XMPP_DOMAIN_NOT_FOUND;
|
||||
|
||||
@@ -210,7 +210,7 @@ int resolver_srv_lookup(xmpp_ctx_t *ctx,
|
||||
if (len > 0)
|
||||
set = resolver_srv_lookup_buf(ctx, buf, (size_t)len, srv_rr_list);
|
||||
|
||||
xmpp_free(ctx, buf);
|
||||
strophe_free(ctx, buf);
|
||||
|
||||
#endif /* HAVE_CARES */
|
||||
|
||||
@@ -223,7 +223,7 @@ void resolver_srv_free(xmpp_ctx_t *ctx, resolver_srv_rr_t *srv_rr_list)
|
||||
|
||||
while (srv_rr_list != NULL) {
|
||||
rr = srv_rr_list->next;
|
||||
xmpp_free(ctx, srv_rr_list);
|
||||
strophe_free(ctx, srv_rr_list);
|
||||
srv_rr_list = rr;
|
||||
}
|
||||
}
|
||||
@@ -431,7 +431,7 @@ static int resolver_raw_srv_lookup_buf(xmpp_ctx_t *ctx,
|
||||
rdlength = xmpp_ntohs_ptr(&buf[j + 8]);
|
||||
j += 10;
|
||||
if (type == MESSAGE_T_SRV && class == MESSAGE_C_IN) {
|
||||
rr = xmpp_alloc(ctx, sizeof(*rr));
|
||||
rr = strophe_alloc(ctx, sizeof(*rr));
|
||||
rr->next = *srv_rr_list;
|
||||
rr->priority = xmpp_ntohs_ptr(&buf[j]);
|
||||
rr->weight = xmpp_ntohs_ptr(&buf[j + 2]);
|
||||
@@ -441,7 +441,7 @@ static int resolver_raw_srv_lookup_buf(xmpp_ctx_t *ctx,
|
||||
if (name_len > 0)
|
||||
*srv_rr_list = rr;
|
||||
else
|
||||
xmpp_free(ctx, rr); /* skip broken record */
|
||||
strophe_free(ctx, rr); /* skip broken record */
|
||||
}
|
||||
j += rdlength;
|
||||
}
|
||||
@@ -480,7 +480,7 @@ static int resolver_ares_srv_lookup_buf(xmpp_ctx_t *ctx,
|
||||
|
||||
item = srv;
|
||||
while (item != NULL) {
|
||||
rr = xmpp_alloc(ctx, sizeof(*rr));
|
||||
rr = strophe_alloc(ctx, sizeof(*rr));
|
||||
if (rr == NULL)
|
||||
break;
|
||||
rr->next = *srv_rr_list;
|
||||
@@ -705,7 +705,7 @@ static int resolver_win32_srv_lookup(xmpp_ctx_t *ctx,
|
||||
|
||||
while (current) {
|
||||
if (current->wType == DNS_TYPE_SRV) {
|
||||
rr = xmpp_alloc(ctx, sizeof(*rr));
|
||||
rr = strophe_alloc(ctx, sizeof(*rr));
|
||||
if (rr == NULL)
|
||||
break;
|
||||
rr->next = *srv_rr_list;
|
||||
|
||||
60
src/sasl.c
60
src/sasl.c
@@ -48,14 +48,14 @@ char *sasl_plain(xmpp_ctx_t *ctx, const char *authid, const char *password)
|
||||
idlen = strlen(authid);
|
||||
passlen = strlen(password);
|
||||
msglen = 2 + idlen + passlen;
|
||||
msg = xmpp_alloc(ctx, msglen);
|
||||
msg = strophe_alloc(ctx, msglen);
|
||||
if (msg != NULL) {
|
||||
msg[0] = '\0';
|
||||
memcpy(msg + 1, authid, idlen);
|
||||
msg[1 + idlen] = '\0';
|
||||
memcpy(msg + 1 + idlen + 1, password, passlen);
|
||||
result = xmpp_base64_encode(ctx, (unsigned char *)msg, msglen);
|
||||
xmpp_free(ctx, msg);
|
||||
strophe_free(ctx, msg);
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -68,7 +68,7 @@ static char *_make_string(xmpp_ctx_t *ctx, const char *s, unsigned len)
|
||||
{
|
||||
char *result;
|
||||
|
||||
result = xmpp_alloc(ctx, len + 1);
|
||||
result = strophe_alloc(ctx, len + 1);
|
||||
if (result != NULL) {
|
||||
memcpy(result, s, len);
|
||||
result[len] = '\0';
|
||||
@@ -82,7 +82,7 @@ static char *_make_quoted(xmpp_ctx_t *ctx, const char *s)
|
||||
char *result;
|
||||
size_t len = strlen(s);
|
||||
|
||||
result = xmpp_alloc(ctx, len + 3);
|
||||
result = strophe_alloc(ctx, len + 3);
|
||||
if (result != NULL) {
|
||||
result[0] = '"';
|
||||
memcpy(result + 1, s, len);
|
||||
@@ -106,7 +106,7 @@ static hash_t *_parse_digest_challenge(xmpp_ctx_t *ctx, const char *msg)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
result = hash_new(ctx, 10, xmpp_free);
|
||||
result = hash_new(ctx, 10, strophe_free);
|
||||
if (result != NULL) {
|
||||
s = text;
|
||||
while (*s != '\0') {
|
||||
@@ -144,16 +144,16 @@ static hash_t *_parse_digest_challenge(xmpp_ctx_t *ctx, const char *msg)
|
||||
s = t;
|
||||
}
|
||||
if (value == NULL) {
|
||||
xmpp_free(ctx, key);
|
||||
strophe_free(ctx, key);
|
||||
break;
|
||||
}
|
||||
/* TODO: check for collisions per spec */
|
||||
hash_add(result, key, value);
|
||||
/* hash table now owns the value, free the key */
|
||||
xmpp_free(ctx, key);
|
||||
strophe_free(ctx, key);
|
||||
}
|
||||
}
|
||||
xmpp_free(ctx, text);
|
||||
strophe_free(ctx, text);
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -181,7 +181,7 @@ _add_key(xmpp_ctx_t *ctx, hash_t *table, const char *key, char *buf, int quote)
|
||||
|
||||
/* allocate a zero-length string if necessary */
|
||||
if (buf == NULL) {
|
||||
buf = xmpp_alloc(ctx, 1);
|
||||
buf = strophe_alloc(ctx, 1);
|
||||
buf[0] = '\0';
|
||||
}
|
||||
if (buf == NULL)
|
||||
@@ -204,7 +204,7 @@ _add_key(xmpp_ctx_t *ctx, hash_t *table, const char *key, char *buf, int quote)
|
||||
keylen = strlen(key);
|
||||
valuelen = strlen(qvalue);
|
||||
nlen = (olen ? 1 : 0) + keylen + 1 + valuelen + 1;
|
||||
buf = xmpp_realloc(ctx, buf, olen + nlen);
|
||||
buf = strophe_realloc(ctx, buf, olen + nlen);
|
||||
|
||||
if (buf != NULL) {
|
||||
c = buf + olen;
|
||||
@@ -219,7 +219,7 @@ _add_key(xmpp_ctx_t *ctx, hash_t *table, const char *key, char *buf, int quote)
|
||||
}
|
||||
|
||||
if (quote)
|
||||
xmpp_free(ctx, (char *)qvalue);
|
||||
strophe_free(ctx, (char *)qvalue);
|
||||
|
||||
return buf;
|
||||
}
|
||||
@@ -265,18 +265,18 @@ char *sasl_digest_md5(xmpp_ctx_t *ctx,
|
||||
server */
|
||||
realm = hash_get(table, "realm");
|
||||
if (realm == NULL || strlen(realm) == 0) {
|
||||
hash_add(table, "realm", xmpp_strdup(ctx, domain));
|
||||
hash_add(table, "realm", strophe_strdup(ctx, domain));
|
||||
realm = hash_get(table, "realm");
|
||||
}
|
||||
|
||||
/* add our response fields */
|
||||
hash_add(table, "username", xmpp_strdup(ctx, node));
|
||||
hash_add(table, "username", strophe_strdup(ctx, node));
|
||||
xmpp_rand_nonce(ctx->rand, cnonce, sizeof(cnonce));
|
||||
hash_add(table, "cnonce", xmpp_strdup(ctx, cnonce));
|
||||
hash_add(table, "nc", xmpp_strdup(ctx, "00000001"));
|
||||
hash_add(table, "cnonce", strophe_strdup(ctx, cnonce));
|
||||
hash_add(table, "nc", strophe_strdup(ctx, "00000001"));
|
||||
if (hash_get(table, "qop") == NULL)
|
||||
hash_add(table, "qop", xmpp_strdup(ctx, "auth"));
|
||||
value = xmpp_alloc(ctx, 5 + strlen(domain) + 1);
|
||||
hash_add(table, "qop", strophe_strdup(ctx, "auth"));
|
||||
value = strophe_alloc(ctx, 5 + strlen(domain) + 1);
|
||||
memcpy(value, "xmpp/", 5);
|
||||
memcpy(value + 5, domain, strlen(domain));
|
||||
value[5 + strlen(domain)] = '\0';
|
||||
@@ -342,7 +342,7 @@ char *sasl_digest_md5(xmpp_ctx_t *ctx,
|
||||
MD5Update(&MD5, (unsigned char *)hex, 32);
|
||||
MD5Final(digest, &MD5);
|
||||
|
||||
response = xmpp_alloc(ctx, 32 + 1);
|
||||
response = strophe_alloc(ctx, 32 + 1);
|
||||
_digest_to_hex((char *)digest, hex);
|
||||
memcpy(response, hex, 32);
|
||||
response[32] = '\0';
|
||||
@@ -360,13 +360,13 @@ char *sasl_digest_md5(xmpp_ctx_t *ctx,
|
||||
result = _add_key(ctx, table, "response", result, 0);
|
||||
result = _add_key(ctx, table, "charset", result, 0);
|
||||
|
||||
xmpp_free(ctx, node);
|
||||
xmpp_free(ctx, domain);
|
||||
strophe_free(ctx, node);
|
||||
strophe_free(ctx, domain);
|
||||
hash_release(table); /* also frees value strings */
|
||||
|
||||
/* reuse response for the base64 encode of our result */
|
||||
response = xmpp_base64_encode(ctx, (unsigned char *)result, strlen(result));
|
||||
xmpp_free(ctx, result);
|
||||
strophe_free(ctx, result);
|
||||
|
||||
return response;
|
||||
}
|
||||
@@ -400,7 +400,7 @@ char *sasl_scram(xmpp_ctx_t *ctx,
|
||||
|
||||
UNUSED(jid);
|
||||
|
||||
tmp = xmpp_strdup(ctx, challenge);
|
||||
tmp = strophe_strdup(ctx, challenge);
|
||||
if (!tmp) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -428,14 +428,14 @@ char *sasl_scram(xmpp_ctx_t *ctx,
|
||||
ival = strtol(i, &saveptr, 10);
|
||||
|
||||
auth_len = 10 + strlen(r) + strlen(first_bare) + strlen(challenge);
|
||||
auth = xmpp_alloc(ctx, auth_len);
|
||||
auth = strophe_alloc(ctx, auth_len);
|
||||
if (!auth) {
|
||||
goto out_sval;
|
||||
}
|
||||
|
||||
/* "c=biws," + r + ",p=" + sign_b64 + '\0' */
|
||||
response_len = 7 + strlen(r) + 3 + ((alg->digest_size + 2) / 3 * 4) + 1;
|
||||
response = xmpp_alloc(ctx, response_len);
|
||||
response = strophe_alloc(ctx, response_len);
|
||||
if (!response) {
|
||||
goto out_auth;
|
||||
}
|
||||
@@ -456,12 +456,12 @@ char *sasl_scram(xmpp_ctx_t *ctx,
|
||||
|
||||
/* Check for buffer overflow */
|
||||
if (strlen(response) + strlen(sign_b64) + 3 + 1 > response_len) {
|
||||
xmpp_free(ctx, sign_b64);
|
||||
strophe_free(ctx, sign_b64);
|
||||
goto out_response;
|
||||
}
|
||||
strcat(response, ",p=");
|
||||
strcat(response, sign_b64);
|
||||
xmpp_free(ctx, sign_b64);
|
||||
strophe_free(ctx, sign_b64);
|
||||
|
||||
response_b64 =
|
||||
xmpp_base64_encode(ctx, (unsigned char *)response, strlen(response));
|
||||
@@ -471,12 +471,12 @@ char *sasl_scram(xmpp_ctx_t *ctx,
|
||||
result = response_b64;
|
||||
|
||||
out_response:
|
||||
xmpp_free(ctx, response);
|
||||
strophe_free(ctx, response);
|
||||
out_auth:
|
||||
xmpp_free(ctx, auth);
|
||||
strophe_free(ctx, auth);
|
||||
out_sval:
|
||||
xmpp_free(ctx, sval);
|
||||
strophe_free(ctx, sval);
|
||||
out:
|
||||
xmpp_free(ctx, tmp);
|
||||
strophe_free(ctx, tmp);
|
||||
return result;
|
||||
}
|
||||
|
||||
52
src/stanza.c
52
src/stanza.c
@@ -39,7 +39,7 @@ xmpp_stanza_t *xmpp_stanza_new(xmpp_ctx_t *ctx)
|
||||
{
|
||||
xmpp_stanza_t *stanza;
|
||||
|
||||
stanza = xmpp_alloc(ctx, sizeof(xmpp_stanza_t));
|
||||
stanza = strophe_alloc(ctx, sizeof(xmpp_stanza_t));
|
||||
if (stanza != NULL) {
|
||||
stanza->ref = 1;
|
||||
stanza->ctx = ctx;
|
||||
@@ -124,7 +124,7 @@ xmpp_stanza_t *xmpp_stanza_copy(const xmpp_stanza_t *stanza)
|
||||
copy->type = stanza->type;
|
||||
|
||||
if (stanza->data) {
|
||||
copy->data = xmpp_strdup(stanza->ctx, stanza->data);
|
||||
copy->data = strophe_strdup(stanza->ctx, stanza->data);
|
||||
if (!copy->data)
|
||||
goto copy_error;
|
||||
}
|
||||
@@ -188,8 +188,8 @@ int xmpp_stanza_release(xmpp_stanza_t *stanza)
|
||||
if (stanza->attributes)
|
||||
hash_release(stanza->attributes);
|
||||
if (stanza->data)
|
||||
xmpp_free(stanza->ctx, stanza->data);
|
||||
xmpp_free(stanza->ctx, stanza);
|
||||
strophe_free(stanza->ctx, stanza->data);
|
||||
strophe_free(stanza->ctx, stanza);
|
||||
released = 1;
|
||||
}
|
||||
|
||||
@@ -263,7 +263,7 @@ static char *_escape_xml(xmpp_ctx_t *ctx, char *text)
|
||||
len++;
|
||||
}
|
||||
}
|
||||
if ((buf = xmpp_alloc(ctx, (len + 1) * sizeof(char))) == NULL)
|
||||
if ((buf = strophe_alloc(ctx, (len + 1) * sizeof(char))) == NULL)
|
||||
return NULL; /* Error */
|
||||
dst = buf;
|
||||
for (src = text; *src != '\0'; src++) {
|
||||
@@ -337,7 +337,7 @@ _render_stanza_recursive(xmpp_stanza_t *stanza, char *buf, size_t buflen)
|
||||
if (tmp == NULL)
|
||||
return XMPP_EMEM;
|
||||
ret = xmpp_snprintf(ptr, left, "%s", tmp);
|
||||
xmpp_free(stanza->ctx, tmp);
|
||||
strophe_free(stanza->ctx, tmp);
|
||||
if (ret < 0)
|
||||
return XMPP_EMEM;
|
||||
_render_update(&written, buflen, ret, &left, &ptr);
|
||||
@@ -375,7 +375,7 @@ _render_stanza_recursive(xmpp_stanza_t *stanza, char *buf, size_t buflen)
|
||||
return XMPP_EMEM;
|
||||
}
|
||||
ret = xmpp_snprintf(ptr, left, " %s=\"%s\"", key, tmp);
|
||||
xmpp_free(stanza->ctx, tmp);
|
||||
strophe_free(stanza->ctx, tmp);
|
||||
if (ret < 0) {
|
||||
hash_iter_release(iter);
|
||||
return XMPP_EMEM;
|
||||
@@ -447,7 +447,7 @@ int xmpp_stanza_to_text(xmpp_stanza_t *stanza, char **buf, size_t *buflen)
|
||||
|
||||
/* allocate a default sized buffer and attempt to render */
|
||||
length = 1024;
|
||||
buffer = xmpp_alloc(stanza->ctx, length);
|
||||
buffer = strophe_alloc(stanza->ctx, length);
|
||||
if (!buffer) {
|
||||
*buf = NULL;
|
||||
*buflen = 0;
|
||||
@@ -456,16 +456,16 @@ int xmpp_stanza_to_text(xmpp_stanza_t *stanza, char **buf, size_t *buflen)
|
||||
|
||||
ret = _render_stanza_recursive(stanza, buffer, length);
|
||||
if (ret < 0) {
|
||||
xmpp_free(stanza->ctx, buffer);
|
||||
strophe_free(stanza->ctx, buffer);
|
||||
*buf = NULL;
|
||||
*buflen = 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
if ((size_t)ret > length - 1) {
|
||||
tmp = xmpp_realloc(stanza->ctx, buffer, ret + 1);
|
||||
tmp = strophe_realloc(stanza->ctx, buffer, ret + 1);
|
||||
if (!tmp) {
|
||||
xmpp_free(stanza->ctx, buffer);
|
||||
strophe_free(stanza->ctx, buffer);
|
||||
*buf = NULL;
|
||||
*buflen = 0;
|
||||
return XMPP_EMEM;
|
||||
@@ -475,7 +475,7 @@ int xmpp_stanza_to_text(xmpp_stanza_t *stanza, char **buf, size_t *buflen)
|
||||
|
||||
ret = _render_stanza_recursive(stanza, buffer, length);
|
||||
if ((size_t)ret > length - 1) {
|
||||
xmpp_free(stanza->ctx, buffer);
|
||||
strophe_free(stanza->ctx, buffer);
|
||||
*buf = NULL;
|
||||
*buflen = 0;
|
||||
return XMPP_EMEM;
|
||||
@@ -506,10 +506,10 @@ int xmpp_stanza_set_name(xmpp_stanza_t *stanza, const char *name)
|
||||
return XMPP_EINVOP;
|
||||
|
||||
if (stanza->data)
|
||||
xmpp_free(stanza->ctx, stanza->data);
|
||||
strophe_free(stanza->ctx, stanza->data);
|
||||
|
||||
stanza->type = XMPP_STANZA_TAG;
|
||||
stanza->data = xmpp_strdup(stanza->ctx, name);
|
||||
stanza->data = strophe_strdup(stanza->ctx, name);
|
||||
|
||||
return stanza->data == NULL ? XMPP_EMEM : XMPP_EOK;
|
||||
}
|
||||
@@ -615,19 +615,19 @@ int xmpp_stanza_set_attribute(xmpp_stanza_t *stanza,
|
||||
return XMPP_EINVOP;
|
||||
|
||||
if (!stanza->attributes) {
|
||||
stanza->attributes = hash_new(stanza->ctx, 8, xmpp_free);
|
||||
stanza->attributes = hash_new(stanza->ctx, 8, strophe_free);
|
||||
if (!stanza->attributes)
|
||||
return XMPP_EMEM;
|
||||
}
|
||||
|
||||
val = xmpp_strdup(stanza->ctx, value);
|
||||
val = strophe_strdup(stanza->ctx, value);
|
||||
if (!val) {
|
||||
return XMPP_EMEM;
|
||||
}
|
||||
|
||||
rc = hash_add(stanza->attributes, key, val);
|
||||
if (rc < 0) {
|
||||
xmpp_free(stanza->ctx, val);
|
||||
strophe_free(stanza->ctx, val);
|
||||
return XMPP_EMEM;
|
||||
}
|
||||
|
||||
@@ -728,8 +728,8 @@ int xmpp_stanza_set_text(xmpp_stanza_t *stanza, const char *text)
|
||||
stanza->type = XMPP_STANZA_TEXT;
|
||||
|
||||
if (stanza->data)
|
||||
xmpp_free(stanza->ctx, stanza->data);
|
||||
stanza->data = xmpp_strdup(stanza->ctx, text);
|
||||
strophe_free(stanza->ctx, stanza->data);
|
||||
stanza->data = strophe_strdup(stanza->ctx, text);
|
||||
|
||||
return stanza->data == NULL ? XMPP_EMEM : XMPP_EOK;
|
||||
}
|
||||
@@ -758,8 +758,8 @@ int xmpp_stanza_set_text_with_size(xmpp_stanza_t *stanza,
|
||||
stanza->type = XMPP_STANZA_TEXT;
|
||||
|
||||
if (stanza->data)
|
||||
xmpp_free(stanza->ctx, stanza->data);
|
||||
stanza->data = xmpp_alloc(stanza->ctx, size + 1);
|
||||
strophe_free(stanza->ctx, stanza->data);
|
||||
stanza->data = strophe_alloc(stanza->ctx, size + 1);
|
||||
if (!stanza->data)
|
||||
return XMPP_EMEM;
|
||||
|
||||
@@ -877,7 +877,7 @@ xmpp_stanza_t *xmpp_stanza_get_child_by_path(xmpp_stanza_t *stanza, ...)
|
||||
va_start(ap, stanza);
|
||||
|
||||
while ((p = va_arg(ap, char *)) != NULL) {
|
||||
tok = xmpp_strdup(stanza->ctx, p);
|
||||
tok = strophe_strdup(stanza->ctx, p);
|
||||
if (!tok) {
|
||||
child = NULL;
|
||||
break;
|
||||
@@ -910,7 +910,7 @@ xmpp_stanza_t *xmpp_stanza_get_child_by_path(xmpp_stanza_t *stanza, ...)
|
||||
child = xmpp_stanza_get_child_by_name_and_ns(child, tok, ns);
|
||||
}
|
||||
error_out:
|
||||
xmpp_free(stanza->ctx, tok);
|
||||
strophe_free(stanza->ctx, tok);
|
||||
if (!child)
|
||||
break;
|
||||
}
|
||||
@@ -1053,7 +1053,7 @@ char *xmpp_stanza_get_text(xmpp_stanza_t *stanza)
|
||||
|
||||
if (stanza->type == XMPP_STANZA_TEXT) {
|
||||
if (stanza->data)
|
||||
return xmpp_strdup(stanza->ctx, stanza->data);
|
||||
return strophe_strdup(stanza->ctx, stanza->data);
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
@@ -1066,7 +1066,7 @@ char *xmpp_stanza_get_text(xmpp_stanza_t *stanza)
|
||||
if (len == 0)
|
||||
return NULL;
|
||||
|
||||
text = (char *)xmpp_alloc(stanza->ctx, len + 1);
|
||||
text = (char *)strophe_alloc(stanza->ctx, len + 1);
|
||||
if (!text)
|
||||
return NULL;
|
||||
|
||||
@@ -1241,7 +1241,7 @@ xmpp_stanza_t *xmpp_stanza_reply(xmpp_stanza_t *stanza)
|
||||
copy->type = stanza->type;
|
||||
|
||||
if (stanza->data) {
|
||||
copy->data = xmpp_strdup(stanza->ctx, stanza->data);
|
||||
copy->data = strophe_strdup(stanza->ctx, stanza->data);
|
||||
if (!copy->data)
|
||||
goto copy_error;
|
||||
}
|
||||
|
||||
26
src/tls.c
26
src/tls.c
@@ -145,14 +145,14 @@ const char *xmpp_tlscert_get_description(xmpp_cert_element_t elmnt)
|
||||
*/
|
||||
xmpp_tlscert_t *tlscert_new(xmpp_ctx_t *ctx)
|
||||
{
|
||||
xmpp_tlscert_t *tlscert = xmpp_alloc(ctx, sizeof(*tlscert));
|
||||
xmpp_tlscert_t *tlscert = strophe_alloc(ctx, sizeof(*tlscert));
|
||||
if (!tlscert)
|
||||
return NULL;
|
||||
memset(tlscert, 0, sizeof(*tlscert));
|
||||
|
||||
tlscert->dnsnames = xmpp_alloc(ctx, sizeof(*tlscert->dnsnames));
|
||||
tlscert->dnsnames = strophe_alloc(ctx, sizeof(*tlscert->dnsnames));
|
||||
if (!tlscert->dnsnames) {
|
||||
xmpp_free(ctx, tlscert);
|
||||
strophe_free(ctx, tlscert);
|
||||
return NULL;
|
||||
}
|
||||
memset(tlscert->dnsnames, 0, sizeof(*tlscert->dnsnames));
|
||||
@@ -173,19 +173,19 @@ void xmpp_tlscert_free(xmpp_tlscert_t *cert)
|
||||
size_t n;
|
||||
for (n = 0; n < ARRAY_SIZE(cert->elements); ++n) {
|
||||
if (cert->elements[n])
|
||||
xmpp_free(cert->ctx, cert->elements[n]);
|
||||
strophe_free(cert->ctx, cert->elements[n]);
|
||||
}
|
||||
if (cert->dnsnames->data) {
|
||||
for (n = 0; n < cert->dnsnames->cur; ++n) {
|
||||
if (cert->dnsnames->data[n])
|
||||
xmpp_free(cert->ctx, cert->dnsnames->data[n]);
|
||||
strophe_free(cert->ctx, cert->dnsnames->data[n]);
|
||||
}
|
||||
}
|
||||
xmpp_free(cert->ctx, cert->dnsnames->data);
|
||||
xmpp_free(cert->ctx, cert->dnsnames);
|
||||
strophe_free(cert->ctx, cert->dnsnames->data);
|
||||
strophe_free(cert->ctx, cert->dnsnames);
|
||||
if (cert->pem)
|
||||
xmpp_free(cert->ctx, cert->pem);
|
||||
xmpp_free(cert->ctx, cert);
|
||||
strophe_free(cert->ctx, cert->pem);
|
||||
strophe_free(cert->ctx, cert);
|
||||
}
|
||||
|
||||
/** Add a dnsName to the Strophe TLS certificate object.
|
||||
@@ -199,15 +199,15 @@ int tlscert_add_dnsname(xmpp_tlscert_t *cert, const char *dnsname)
|
||||
{
|
||||
if ((cert->dnsnames->cur + 1) >= cert->dnsnames->max) {
|
||||
char **dnsnames =
|
||||
xmpp_realloc(cert->ctx, cert->dnsnames->data,
|
||||
(cert->dnsnames->max + tlscert_dnsnames_increment) *
|
||||
sizeof(char **));
|
||||
strophe_realloc(cert->ctx, cert->dnsnames->data,
|
||||
(cert->dnsnames->max + tlscert_dnsnames_increment) *
|
||||
sizeof(char **));
|
||||
if (!dnsnames)
|
||||
return 1;
|
||||
cert->dnsnames->data = dnsnames;
|
||||
cert->dnsnames->max += tlscert_dnsnames_increment;
|
||||
}
|
||||
cert->dnsnames->data[cert->dnsnames->cur++] =
|
||||
xmpp_strdup(cert->ctx, dnsname);
|
||||
strophe_strdup(cert->ctx, dnsname);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ static int _tls_get_id_on_xmppaddr(xmpp_conn_t *conn,
|
||||
* https://gitlab.com/gnutls/gnutls/-/merge_requests/1397
|
||||
*/
|
||||
if (ret) {
|
||||
*ret = xmpp_strdup(conn->ctx, name);
|
||||
*ret = strophe_strdup(conn->ctx, name);
|
||||
}
|
||||
return GNUTLS_SAN_OTHERNAME_XMPP;
|
||||
}
|
||||
@@ -112,7 +112,7 @@ static int _tls_get_id_on_xmppaddr(xmpp_conn_t *conn,
|
||||
return GNUTLS_E_MEMORY_ERROR;
|
||||
}
|
||||
if (ret) {
|
||||
*ret = xmpp_strdup(conn->ctx, (char *)xmpp_addr.data);
|
||||
*ret = strophe_strdup(conn->ctx, (char *)xmpp_addr.data);
|
||||
}
|
||||
gnutls_free(xmpp_addr.data);
|
||||
return GNUTLS_SAN_OTHERNAME_XMPP;
|
||||
@@ -181,51 +181,53 @@ static xmpp_tlscert_t *_x509_to_tlscert(xmpp_ctx_t *ctx, gnutls_x509_crt_t cert)
|
||||
xmpp_tlscert_t *tlscert = tlscert_new(ctx);
|
||||
|
||||
gnutls_x509_crt_export2(cert, GNUTLS_X509_FMT_PEM, &data);
|
||||
tlscert->pem = xmpp_alloc(ctx, data.size + 1);
|
||||
tlscert->pem = strophe_alloc(ctx, data.size + 1);
|
||||
memcpy(tlscert->pem, data.data, data.size);
|
||||
tlscert->pem[data.size] = '\0';
|
||||
gnutls_free(data.data);
|
||||
|
||||
size = sizeof(buf);
|
||||
gnutls_x509_crt_get_dn(cert, buf, &size);
|
||||
tlscert->elements[XMPP_CERT_SUBJECT] = xmpp_strdup(ctx, buf);
|
||||
tlscert->elements[XMPP_CERT_SUBJECT] = strophe_strdup(ctx, buf);
|
||||
size = sizeof(buf);
|
||||
gnutls_x509_crt_get_issuer_dn(cert, buf, &size);
|
||||
tlscert->elements[XMPP_CERT_ISSUER] = xmpp_strdup(ctx, buf);
|
||||
tlscert->elements[XMPP_CERT_ISSUER] = strophe_strdup(ctx, buf);
|
||||
|
||||
time_val = gnutls_x509_crt_get_activation_time(cert);
|
||||
tlscert->elements[XMPP_CERT_NOTBEFORE] = xmpp_strdup(ctx, ctime(&time_val));
|
||||
tlscert->elements[XMPP_CERT_NOTBEFORE] =
|
||||
strophe_strdup(ctx, ctime(&time_val));
|
||||
tlscert->elements[XMPP_CERT_NOTBEFORE]
|
||||
[strlen(tlscert->elements[XMPP_CERT_NOTBEFORE]) - 1] =
|
||||
'\0';
|
||||
time_val = gnutls_x509_crt_get_expiration_time(cert);
|
||||
tlscert->elements[XMPP_CERT_NOTAFTER] = xmpp_strdup(ctx, ctime(&time_val));
|
||||
tlscert->elements[XMPP_CERT_NOTAFTER] =
|
||||
strophe_strdup(ctx, ctime(&time_val));
|
||||
tlscert->elements[XMPP_CERT_NOTAFTER]
|
||||
[strlen(tlscert->elements[XMPP_CERT_NOTAFTER]) - 1] = '\0';
|
||||
|
||||
size = sizeof(smallbuf);
|
||||
gnutls_x509_crt_get_fingerprint(cert, GNUTLS_DIG_SHA1, smallbuf, &size);
|
||||
hex_encode(buf, smallbuf, size);
|
||||
tlscert->elements[XMPP_CERT_FINGERPRINT_SHA1] = xmpp_strdup(ctx, buf);
|
||||
tlscert->elements[XMPP_CERT_FINGERPRINT_SHA1] = strophe_strdup(ctx, buf);
|
||||
size = sizeof(smallbuf);
|
||||
gnutls_x509_crt_get_fingerprint(cert, GNUTLS_DIG_SHA256, smallbuf, &size);
|
||||
hex_encode(buf, smallbuf, size);
|
||||
tlscert->elements[XMPP_CERT_FINGERPRINT_SHA256] = xmpp_strdup(ctx, buf);
|
||||
tlscert->elements[XMPP_CERT_FINGERPRINT_SHA256] = strophe_strdup(ctx, buf);
|
||||
|
||||
xmpp_snprintf(buf, sizeof(buf), "%d", gnutls_x509_crt_get_version(cert));
|
||||
tlscert->elements[XMPP_CERT_VERSION] = xmpp_strdup(ctx, buf);
|
||||
tlscert->elements[XMPP_CERT_VERSION] = strophe_strdup(ctx, buf);
|
||||
|
||||
algo = gnutls_x509_crt_get_pk_algorithm(cert, NULL);
|
||||
tlscert->elements[XMPP_CERT_KEYALG] =
|
||||
xmpp_strdup(ctx, gnutls_pk_algorithm_get_name(algo));
|
||||
strophe_strdup(ctx, gnutls_pk_algorithm_get_name(algo));
|
||||
algo = gnutls_x509_crt_get_signature_algorithm(cert);
|
||||
tlscert->elements[XMPP_CERT_SIGALG] =
|
||||
xmpp_strdup(ctx, gnutls_sign_get_name(algo));
|
||||
strophe_strdup(ctx, gnutls_sign_get_name(algo));
|
||||
|
||||
size = sizeof(smallbuf);
|
||||
gnutls_x509_crt_get_serial(cert, smallbuf, &size);
|
||||
hex_encode(buf, smallbuf, size);
|
||||
tlscert->elements[XMPP_CERT_SERIALNUMBER] = xmpp_strdup(ctx, buf);
|
||||
tlscert->elements[XMPP_CERT_SERIALNUMBER] = strophe_strdup(ctx, buf);
|
||||
|
||||
for (n = 0, m = 0, res = 0; res != GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE;
|
||||
++n) {
|
||||
@@ -310,7 +312,7 @@ static int _tls_verify(gnutls_session_t session)
|
||||
|
||||
tls_t *tls_new(xmpp_conn_t *conn)
|
||||
{
|
||||
tls_t *tls = xmpp_alloc(conn->ctx, sizeof(tls_t));
|
||||
tls_t *tls = strophe_alloc(conn->ctx, sizeof(tls_t));
|
||||
|
||||
if (tls) {
|
||||
memset(tls, 0, sizeof(*tls));
|
||||
@@ -328,7 +330,7 @@ tls_t *tls_new(xmpp_conn_t *conn)
|
||||
"could not read client certificate");
|
||||
gnutls_certificate_free_credentials(tls->cred);
|
||||
gnutls_deinit(tls->session);
|
||||
xmpp_free(tls->ctx, tls);
|
||||
strophe_free(tls->ctx, tls);
|
||||
return NULL;
|
||||
}
|
||||
gnutls_certificate_set_x509_key_file(
|
||||
@@ -354,7 +356,7 @@ void tls_free(tls_t *tls)
|
||||
gnutls_x509_crt_deinit(tls->client_cert);
|
||||
gnutls_deinit(tls->session);
|
||||
gnutls_certificate_free_credentials(tls->cred);
|
||||
xmpp_free(tls->ctx, tls);
|
||||
strophe_free(tls->ctx, tls);
|
||||
}
|
||||
|
||||
xmpp_tlscert_t *tls_peer_cert(xmpp_conn_t *conn)
|
||||
|
||||
@@ -271,7 +271,7 @@ char *tls_id_on_xmppaddr(xmpp_conn_t *conn, unsigned int n)
|
||||
if (j == (int)n) {
|
||||
xmpp_debug(conn->ctx, "tls", "extracted jid %s from id-on-xmppAddr",
|
||||
res);
|
||||
ret = xmpp_strdup(conn->ctx, res);
|
||||
ret = strophe_strdup(conn->ctx, res);
|
||||
OPENSSL_free(res);
|
||||
break;
|
||||
}
|
||||
@@ -321,7 +321,7 @@ static char *_asn1_time_to_str(const xmpp_ctx_t *ctx, ASN1_TIME *t)
|
||||
char buf[128];
|
||||
int res = _convert_ASN1TIME(t, buf, sizeof(buf));
|
||||
if (res) {
|
||||
return xmpp_strdup(ctx, buf);
|
||||
return strophe_strdup(ctx, buf);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
@@ -345,7 +345,7 @@ _get_fingerprint(const xmpp_ctx_t *ctx, X509 *err_cert, xmpp_cert_element_t el)
|
||||
if (X509_digest(err_cert, digest, buf, &len) != 0) {
|
||||
char fingerprint[4 * EVP_MAX_MD_SIZE];
|
||||
hex_encode(fingerprint, buf, len);
|
||||
return xmpp_strdup(ctx, fingerprint);
|
||||
return strophe_strdup(ctx, fingerprint);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
@@ -384,7 +384,7 @@ _get_alg(const xmpp_ctx_t *ctx, X509 *err_cert, xmpp_cert_element_t el)
|
||||
if (alg_nid != NID_undef) {
|
||||
const char *alg = OBJ_nid2ln(alg_nid);
|
||||
if (alg) {
|
||||
return xmpp_strdup(ctx, alg);
|
||||
return strophe_strdup(ctx, alg);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
@@ -403,7 +403,7 @@ static xmpp_tlscert_t *_x509_to_tlscert(xmpp_ctx_t *ctx, X509 *cert)
|
||||
PEM_write_bio_X509(b, cert);
|
||||
BUF_MEM *bptr;
|
||||
BIO_get_mem_ptr(b, &bptr);
|
||||
tlscert->pem = xmpp_alloc(ctx, bptr->length + 1);
|
||||
tlscert->pem = strophe_alloc(ctx, bptr->length + 1);
|
||||
if (!tlscert->pem)
|
||||
goto error_out;
|
||||
memcpy(tlscert->pem, bptr->data, bptr->length);
|
||||
@@ -413,12 +413,12 @@ static xmpp_tlscert_t *_x509_to_tlscert(xmpp_ctx_t *ctx, X509 *cert)
|
||||
subject = X509_NAME_oneline(X509_get_subject_name(cert), NULL, 0);
|
||||
if (!subject)
|
||||
goto error_out;
|
||||
tlscert->elements[XMPP_CERT_SUBJECT] = xmpp_strdup(ctx, subject);
|
||||
tlscert->elements[XMPP_CERT_SUBJECT] = strophe_strdup(ctx, subject);
|
||||
OPENSSL_free(subject);
|
||||
issuer = X509_NAME_oneline(X509_get_issuer_name(cert), NULL, 0);
|
||||
if (!issuer)
|
||||
goto error_out;
|
||||
tlscert->elements[XMPP_CERT_ISSUER] = xmpp_strdup(ctx, issuer);
|
||||
tlscert->elements[XMPP_CERT_ISSUER] = strophe_strdup(ctx, issuer);
|
||||
OPENSSL_free(issuer);
|
||||
|
||||
tlscert->elements[XMPP_CERT_NOTBEFORE] =
|
||||
@@ -432,7 +432,7 @@ static xmpp_tlscert_t *_x509_to_tlscert(xmpp_ctx_t *ctx, X509 *cert)
|
||||
_get_fingerprint(ctx, cert, XMPP_CERT_FINGERPRINT_SHA256);
|
||||
|
||||
xmpp_snprintf(buf, sizeof(buf), "%ld", X509_get_version(cert) + 1);
|
||||
tlscert->elements[XMPP_CERT_VERSION] = xmpp_strdup(ctx, buf);
|
||||
tlscert->elements[XMPP_CERT_VERSION] = strophe_strdup(ctx, buf);
|
||||
|
||||
tlscert->elements[XMPP_CERT_KEYALG] = _get_alg(ctx, cert, XMPP_CERT_KEYALG);
|
||||
tlscert->elements[XMPP_CERT_SIGALG] = _get_alg(ctx, cert, XMPP_CERT_SIGALG);
|
||||
@@ -443,7 +443,7 @@ static xmpp_tlscert_t *_x509_to_tlscert(xmpp_ctx_t *ctx, X509 *cert)
|
||||
char *serialnumber = BN_bn2hex(bn);
|
||||
if (serialnumber) {
|
||||
tlscert->elements[XMPP_CERT_SERIALNUMBER] =
|
||||
xmpp_strdup(ctx, serialnumber);
|
||||
strophe_strdup(ctx, serialnumber);
|
||||
OPENSSL_free(serialnumber);
|
||||
}
|
||||
BN_free(bn);
|
||||
@@ -509,7 +509,7 @@ static int _tls_verify(int preverify_ok, X509_STORE_CTX *x509_ctx)
|
||||
|
||||
tls_t *tls_new(xmpp_conn_t *conn)
|
||||
{
|
||||
tls_t *tls = xmpp_alloc(conn->ctx, sizeof(*tls));
|
||||
tls_t *tls = strophe_alloc(conn->ctx, sizeof(*tls));
|
||||
|
||||
if (tls) {
|
||||
int ret;
|
||||
@@ -623,7 +623,7 @@ err_free_cert:
|
||||
err_free_ctx:
|
||||
SSL_CTX_free(tls->ssl_ctx);
|
||||
err:
|
||||
xmpp_free(conn->ctx, tls);
|
||||
strophe_free(conn->ctx, tls);
|
||||
_tls_log_error(conn->ctx);
|
||||
return NULL;
|
||||
}
|
||||
@@ -633,7 +633,7 @@ void tls_free(tls_t *tls)
|
||||
SSL_free(tls->ssl);
|
||||
X509_free(tls->client_cert);
|
||||
SSL_CTX_free(tls->ssl_ctx);
|
||||
xmpp_free(tls->ctx, tls);
|
||||
strophe_free(tls->ctx, tls);
|
||||
}
|
||||
|
||||
xmpp_tlscert_t *tls_peer_cert(xmpp_conn_t *conn)
|
||||
|
||||
@@ -38,9 +38,9 @@
|
||||
*
|
||||
* @return a newly allocated string with the same data as s or NULL on error
|
||||
*/
|
||||
char *xmpp_strdup(const xmpp_ctx_t *ctx, const char *s)
|
||||
char *strophe_strdup(const xmpp_ctx_t *ctx, const char *s)
|
||||
{
|
||||
return xmpp_strndup(ctx, s, SIZE_MAX);
|
||||
return strophe_strndup(ctx, s, SIZE_MAX);
|
||||
}
|
||||
|
||||
/** Duplicate a string with a maximum length.
|
||||
@@ -54,7 +54,7 @@ char *xmpp_strdup(const xmpp_ctx_t *ctx, const char *s)
|
||||
* @return a newly allocated string that contains at most `len` symbols
|
||||
* of the original string or NULL on error
|
||||
*/
|
||||
char *xmpp_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)
|
||||
{
|
||||
char *copy;
|
||||
size_t l;
|
||||
@@ -63,7 +63,7 @@ char *xmpp_strndup(const xmpp_ctx_t *ctx, const char *s, size_t len)
|
||||
if (l > len)
|
||||
l = len;
|
||||
|
||||
copy = xmpp_alloc(ctx, l + 1);
|
||||
copy = strophe_alloc(ctx, l + 1);
|
||||
if (!copy) {
|
||||
xmpp_error(ctx, "xmpp", "failed to allocate required memory");
|
||||
return NULL;
|
||||
|
||||
@@ -64,7 +64,7 @@ char *xmpp_uuid_gen(xmpp_ctx_t *ctx)
|
||||
{
|
||||
char *uuid;
|
||||
|
||||
uuid = xmpp_alloc(ctx, XMPP_UUID_LEN + 1);
|
||||
uuid = strophe_alloc(ctx, XMPP_UUID_LEN + 1);
|
||||
if (uuid != NULL) {
|
||||
crypto_uuid_gen(ctx, uuid);
|
||||
}
|
||||
|
||||
@@ -83,20 +83,20 @@ int main()
|
||||
ctx = xmpp_ctx_new(&mymem, &mylog);
|
||||
xmpp_debug(ctx, "test", "hello");
|
||||
|
||||
testptr1 = xmpp_alloc(ctx, 1024);
|
||||
testptr1 = strophe_alloc(ctx, 1024);
|
||||
if (testptr1 == NULL) {
|
||||
xmpp_ctx_free(ctx);
|
||||
return 1;
|
||||
}
|
||||
|
||||
testptr2 = xmpp_realloc(ctx, testptr1, 2048);
|
||||
testptr2 = strophe_realloc(ctx, testptr1, 2048);
|
||||
if (testptr2 == NULL) {
|
||||
xmpp_free(ctx, testptr1);
|
||||
strophe_free(ctx, testptr1);
|
||||
xmpp_ctx_free(ctx);
|
||||
return 1;
|
||||
}
|
||||
|
||||
xmpp_free(ctx, testptr2);
|
||||
strophe_free(ctx, testptr2);
|
||||
|
||||
xmpp_ctx_free(ctx);
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ int main(int argc, char **argv)
|
||||
}
|
||||
|
||||
/* allocate a hash table */
|
||||
table = hash_new(ctx, TABLESIZE, xmpp_free);
|
||||
table = hash_new(ctx, TABLESIZE, strophe_free);
|
||||
if (table == NULL) {
|
||||
/* table allocation failed! */
|
||||
return 1;
|
||||
@@ -63,7 +63,7 @@ int main(int argc, char **argv)
|
||||
|
||||
/* test insertion */
|
||||
for (i = 0; i < nkeys; i++) {
|
||||
err = hash_add(table, keys[i], xmpp_strdup(ctx, values[i]));
|
||||
err = hash_add(table, keys[i], strophe_strdup(ctx, values[i]));
|
||||
if (err)
|
||||
return err;
|
||||
}
|
||||
@@ -76,7 +76,7 @@ int main(int argc, char **argv)
|
||||
|
||||
/* test replacing old values */
|
||||
for (i = 0; i < nkeys; i++) {
|
||||
err = hash_add(table, keys[0], xmpp_strdup(ctx, values[i]));
|
||||
err = hash_add(table, keys[0], strophe_strdup(ctx, values[i]));
|
||||
if (err)
|
||||
return err;
|
||||
if (hash_num_keys(table) != nkeys)
|
||||
@@ -88,7 +88,7 @@ int main(int argc, char **argv)
|
||||
return 1;
|
||||
}
|
||||
/* restore value for the 1st key */
|
||||
hash_add(table, keys[0], xmpp_strdup(ctx, values[0]));
|
||||
hash_add(table, keys[0], strophe_strdup(ctx, values[0]));
|
||||
|
||||
/* test cloning */
|
||||
clone = hash_clone(table);
|
||||
|
||||
@@ -47,13 +47,13 @@ int test_jid(xmpp_ctx_t *ctx)
|
||||
if (resource != NULL)
|
||||
return 1;
|
||||
if (bare)
|
||||
xmpp_free(ctx, bare);
|
||||
strophe_free(ctx, bare);
|
||||
if (node)
|
||||
xmpp_free(ctx, node);
|
||||
strophe_free(ctx, node);
|
||||
if (domain)
|
||||
xmpp_free(ctx, domain);
|
||||
strophe_free(ctx, domain);
|
||||
if (resource)
|
||||
xmpp_free(ctx, resource);
|
||||
strophe_free(ctx, resource);
|
||||
|
||||
bare = xmpp_jid_bare(ctx, jid2);
|
||||
node = xmpp_jid_node(ctx, jid2);
|
||||
@@ -70,13 +70,13 @@ int test_jid(xmpp_ctx_t *ctx)
|
||||
if (resource == NULL || strcmp(resource, "hullo"))
|
||||
return 1;
|
||||
if (bare)
|
||||
xmpp_free(ctx, bare);
|
||||
strophe_free(ctx, bare);
|
||||
if (node)
|
||||
xmpp_free(ctx, node);
|
||||
strophe_free(ctx, node);
|
||||
if (domain)
|
||||
xmpp_free(ctx, domain);
|
||||
strophe_free(ctx, domain);
|
||||
if (resource)
|
||||
xmpp_free(ctx, resource);
|
||||
strophe_free(ctx, resource);
|
||||
|
||||
bare = xmpp_jid_bare(ctx, jid3);
|
||||
node = xmpp_jid_node(ctx, jid3);
|
||||
@@ -93,13 +93,13 @@ int test_jid(xmpp_ctx_t *ctx)
|
||||
if (resource == NULL || strcmp(resource, "frob"))
|
||||
return 1;
|
||||
if (bare)
|
||||
xmpp_free(ctx, bare);
|
||||
strophe_free(ctx, bare);
|
||||
if (node)
|
||||
xmpp_free(ctx, node);
|
||||
strophe_free(ctx, node);
|
||||
if (domain)
|
||||
xmpp_free(ctx, domain);
|
||||
strophe_free(ctx, domain);
|
||||
if (resource)
|
||||
xmpp_free(ctx, resource);
|
||||
strophe_free(ctx, resource);
|
||||
|
||||
bare = xmpp_jid_bare(ctx, jid4);
|
||||
node = xmpp_jid_node(ctx, jid4);
|
||||
@@ -116,13 +116,13 @@ int test_jid(xmpp_ctx_t *ctx)
|
||||
if (resource != NULL)
|
||||
return 1;
|
||||
if (bare)
|
||||
xmpp_free(ctx, bare);
|
||||
strophe_free(ctx, bare);
|
||||
if (node)
|
||||
xmpp_free(ctx, node);
|
||||
strophe_free(ctx, node);
|
||||
if (domain)
|
||||
xmpp_free(ctx, domain);
|
||||
strophe_free(ctx, domain);
|
||||
if (resource)
|
||||
xmpp_free(ctx, resource);
|
||||
strophe_free(ctx, resource);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -135,13 +135,13 @@ int test_jid_new(xmpp_ctx_t *ctx)
|
||||
printf("new jid: '%s'\n", jid);
|
||||
if (strcmp(jid, "node@domain/resource"))
|
||||
return 1;
|
||||
xmpp_free(ctx, jid);
|
||||
strophe_free(ctx, jid);
|
||||
|
||||
jid = xmpp_jid_new(ctx, "foo", "bar.com", NULL);
|
||||
printf("new jid: '%s'\n", jid);
|
||||
if (strcmp(jid, "foo@bar.com"))
|
||||
return 1;
|
||||
xmpp_free(ctx, jid);
|
||||
strophe_free(ctx, jid);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -20,17 +20,15 @@
|
||||
/* include rand.c to access private structures and functions */
|
||||
#include "rand.c"
|
||||
|
||||
#ifndef USE_GETRANDOM
|
||||
|
||||
/* stubs to build test without whole libstrophe */
|
||||
void *xmpp_alloc(const xmpp_ctx_t *ctx, size_t size)
|
||||
void *strophe_alloc(const xmpp_ctx_t *ctx, size_t size)
|
||||
{
|
||||
(void)ctx;
|
||||
(void)size;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void xmpp_free(const xmpp_ctx_t *ctx, void *p)
|
||||
void strophe_free(const xmpp_ctx_t *ctx, void *p)
|
||||
{
|
||||
(void)ctx;
|
||||
(void)p;
|
||||
@@ -51,6 +49,8 @@ uint64_t time_stamp(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifndef USE_GETRANDOM
|
||||
|
||||
static struct {
|
||||
const char *entropy_input;
|
||||
const char *nonce;
|
||||
|
||||
@@ -216,14 +216,14 @@ int main()
|
||||
rand = xmpp_rand_new(ctx);
|
||||
assert(rand != NULL);
|
||||
assert(sizeof(data2) > 64);
|
||||
buf = xmpp_alloc(ctx, sizeof(data2));
|
||||
buf = strophe_alloc(ctx, sizeof(data2));
|
||||
assert(buf != NULL);
|
||||
memcpy(buf, data2, 64);
|
||||
xmpp_rand_bytes(rand, &buf[64], sizeof(data2) - 64);
|
||||
ret = resolver_srv_lookup_buf(ctx, buf, sizeof(data2), &srv_rr_list);
|
||||
if (ret == XMPP_DOMAIN_FOUND && srv_rr_list != NULL)
|
||||
resolver_srv_free(ctx, srv_rr_list);
|
||||
xmpp_free(ctx, buf);
|
||||
strophe_free(ctx, buf);
|
||||
xmpp_rand_free(ctx, rand);
|
||||
printf("ok\n");
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ int test_plain(xmpp_ctx_t *ctx)
|
||||
/* SASL PLAIN returned incorrect string! */
|
||||
return 2;
|
||||
}
|
||||
xmpp_free(ctx, result);
|
||||
strophe_free(ctx, result);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ static int test_strdup_one(xmpp_ctx_t *ctx, const char *s)
|
||||
int rc = 0;
|
||||
|
||||
s1 = strdup(s);
|
||||
s2 = xmpp_strdup(ctx, s);
|
||||
s2 = strophe_strdup(ctx, s);
|
||||
|
||||
if (!s1 || !s2 || strcmp(s1, s2) != 0) {
|
||||
rc = -1;
|
||||
@@ -81,7 +81,7 @@ static int test_strdup_one(xmpp_ctx_t *ctx, const char *s)
|
||||
|
||||
free(s1);
|
||||
if (s2)
|
||||
xmpp_free(ctx, s2);
|
||||
strophe_free(ctx, s2);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user