make alloc-class of functions private

Fixes #189

Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
This commit is contained in:
Steffen Jaeckel
2022-02-01 13:25:31 +01:00
parent 118087f2a1
commit a97714da18
27 changed files with 343 additions and 330 deletions

View File

@@ -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);

View File

@@ -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);

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -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");

View File

@@ -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;
}

View File

@@ -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;
}