Another pass at C++ification.
This commit is contained in:
@@ -110,13 +110,14 @@ xmpp_conn_t * xmpp_conn_clone(xmpp_conn_t * const conn)
|
||||
return conn;
|
||||
}
|
||||
|
||||
void xmpp_conn_release(xmpp_conn_t * const conn)
|
||||
int xmpp_conn_release(xmpp_conn_t * const conn)
|
||||
{
|
||||
xmpp_ctx_t *ctx;
|
||||
xmpp_connlist_t *item, *prev;
|
||||
xmpp_handlist_t *hlitem, *thli;
|
||||
hash_iterator_t *iter;
|
||||
const char *key;
|
||||
int released = 0;
|
||||
|
||||
if (conn->ref > 1)
|
||||
conn->ref--;
|
||||
@@ -196,7 +197,10 @@ void xmpp_conn_release(xmpp_conn_t * const conn)
|
||||
if (conn->pass) xmpp_free(ctx, conn->pass);
|
||||
if (conn->stream_id) xmpp_free(ctx, conn->stream_id);
|
||||
xmpp_free(ctx, conn);
|
||||
released = 1;
|
||||
}
|
||||
|
||||
return released;
|
||||
}
|
||||
|
||||
const char *xmpp_conn_get_jid(const xmpp_conn_t * const conn)
|
||||
|
||||
33
src/ctx.c
33
src/ctx.c
@@ -57,10 +57,27 @@ int xmpp_version_check(int major, int minor)
|
||||
|
||||
/* define the global default allocator, logger and context here */
|
||||
|
||||
/* wrap stdlib routines to deal with userdata pointer */
|
||||
static void *_malloc(const size_t size, void * const userdata)
|
||||
{
|
||||
return malloc(size);
|
||||
}
|
||||
|
||||
static void _free(void *p, void * const userdata)
|
||||
{
|
||||
free(p);
|
||||
}
|
||||
|
||||
static void *_realloc(void *p, const size_t size, void * const userdata)
|
||||
{
|
||||
return realloc(p, size);
|
||||
}
|
||||
|
||||
static xmpp_mem_t xmpp_default_mem = {
|
||||
malloc, /* use the stdlib routines by default */
|
||||
free,
|
||||
realloc
|
||||
_malloc, /* use the thinly wrapped stdlib routines by default */
|
||||
_free,
|
||||
_realloc,
|
||||
NULL
|
||||
};
|
||||
|
||||
static const char * const _xmpp_log_level_name[4] = {"DEBUG", "INFO", "WARN", "ERROR"};
|
||||
@@ -103,18 +120,18 @@ static xmpp_log_t xmpp_default_log = { NULL, NULL };
|
||||
|
||||
void *xmpp_alloc(const xmpp_ctx_t * const ctx, const size_t size)
|
||||
{
|
||||
return ctx->mem->alloc(size);
|
||||
return ctx->mem->alloc(size, ctx->mem->userdata);
|
||||
}
|
||||
|
||||
void xmpp_free(const xmpp_ctx_t * const ctx, void *p)
|
||||
{
|
||||
ctx->mem->free(p);
|
||||
ctx->mem->free(p, ctx->mem->userdata);
|
||||
}
|
||||
|
||||
void *xmpp_realloc(const xmpp_ctx_t * const ctx, void *p,
|
||||
const size_t size)
|
||||
{
|
||||
return ctx->mem->realloc(p, size);
|
||||
return ctx->mem->realloc(p, size, ctx->mem->userdata);
|
||||
}
|
||||
|
||||
/* logger */
|
||||
@@ -190,9 +207,9 @@ xmpp_ctx_t *xmpp_ctx_new(const xmpp_mem_t * const mem,
|
||||
xmpp_ctx_t *ctx = NULL;
|
||||
|
||||
if (mem == NULL)
|
||||
ctx = xmpp_default_mem.alloc(sizeof(xmpp_ctx_t));
|
||||
ctx = xmpp_default_mem.alloc(sizeof(xmpp_ctx_t), NULL);
|
||||
else
|
||||
ctx = mem->alloc(sizeof(xmpp_ctx_t));
|
||||
ctx = mem->alloc(sizeof(xmpp_ctx_t), mem->userdata);
|
||||
|
||||
if (ctx != NULL) {
|
||||
if (mem != NULL)
|
||||
|
||||
@@ -139,7 +139,8 @@ void xmpp_run_once(xmpp_ctx_t *ctx, const unsigned long timeout)
|
||||
|
||||
/* select errored */
|
||||
if (ret < 0) {
|
||||
xmpp_error(ctx, "xmpp", "event watcher internal error");
|
||||
xmpp_error(ctx, "xmpp", "event watcher internal error %d",
|
||||
sock_error());
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -120,8 +120,9 @@ copy_error:
|
||||
}
|
||||
|
||||
/* free a stanza object and it's contents */
|
||||
void xmpp_stanza_release(xmpp_stanza_t * const stanza)
|
||||
int xmpp_stanza_release(xmpp_stanza_t * const stanza)
|
||||
{
|
||||
int released = 0;
|
||||
xmpp_stanza_t *child, *tchild;
|
||||
|
||||
/* release all children */
|
||||
@@ -139,7 +140,10 @@ void xmpp_stanza_release(xmpp_stanza_t * const stanza)
|
||||
if (stanza->attributes) hash_release(stanza->attributes);
|
||||
if (stanza->data) xmpp_free(stanza->ctx, stanza->data);
|
||||
xmpp_free(stanza->ctx, stanza);
|
||||
released = 1;
|
||||
}
|
||||
|
||||
return released;
|
||||
}
|
||||
|
||||
/* small helper function */
|
||||
|
||||
Reference in New Issue
Block a user