Fix spacing in ctx.c and common.h

This commit is contained in:
Dmitry Podgorny
2016-09-20 19:42:29 +03:00
parent d1a41c9d7d
commit d2c1daf4d5
2 changed files with 109 additions and 109 deletions

View File

@@ -56,32 +56,32 @@ struct _xmpp_ctx_t {
/* convenience functions for accessing the context */ /* convenience functions for accessing the context */
void *xmpp_alloc(const xmpp_ctx_t * const ctx, const size_t size); void *xmpp_alloc(const xmpp_ctx_t * const ctx, const size_t size);
void *xmpp_realloc(const xmpp_ctx_t * const ctx, void *p, void *xmpp_realloc(const xmpp_ctx_t * const ctx, void *p,
const size_t size); const size_t size);
char *xmpp_strdup(const xmpp_ctx_t * const ctx, const char * const s); char *xmpp_strdup(const xmpp_ctx_t * const ctx, const char * const s);
void xmpp_log(const xmpp_ctx_t * const ctx, void xmpp_log(const xmpp_ctx_t * const ctx,
const xmpp_log_level_t level, const xmpp_log_level_t level,
const char * const area, const char * const area,
const char * const fmt, const char * const fmt,
va_list ap); va_list ap);
/* wrappers for xmpp_log at specific levels */ /* wrappers for xmpp_log at specific levels */
void xmpp_error(const xmpp_ctx_t * const ctx, void xmpp_error(const xmpp_ctx_t * const ctx,
const char * const area, const char * const area,
const char * const fmt, const char * const fmt,
...); ...);
void xmpp_warn(const xmpp_ctx_t * const ctx, void xmpp_warn(const xmpp_ctx_t * const ctx,
const char * const area, const char * const area,
const char * const fmt, const char * const fmt,
...); ...);
void xmpp_info(const xmpp_ctx_t * const ctx, void xmpp_info(const xmpp_ctx_t * const ctx,
const char * const area, const char * const area,
const char * const fmt, const char * const fmt,
...); ...);
void xmpp_debug(const xmpp_ctx_t * const ctx, void xmpp_debug(const xmpp_ctx_t * const ctx,
const char * const area, const char * const area,
const char * const fmt, const char * const fmt,
...); ...);
/** connection **/ /** connection **/
@@ -108,26 +108,26 @@ struct _xmpp_handlist_t {
void *handler; void *handler;
void *userdata; void *userdata;
int enabled; /* handlers are added disabled and enabled after the int enabled; /* handlers are added disabled and enabled after the
* handler chain is processed to prevent stanzas from * handler chain is processed to prevent stanzas from
* getting processed by newly added handlers */ * getting processed by newly added handlers */
xmpp_handlist_t *next; xmpp_handlist_t *next;
union { union {
/* timed handlers */ /* timed handlers */
struct { struct {
unsigned long period; unsigned long period;
uint64_t last_stamp; uint64_t last_stamp;
}; };
/* id handlers */ /* id handlers */
struct { struct {
char *id; char *id;
}; };
/* normal handlers */ /* normal handlers */
struct { struct {
char *ns; char *ns;
char *name; char *name;
char *type; char *type;
}; };
}; };
}; };
@@ -168,7 +168,7 @@ struct _xmpp_conn_t {
int tls_legacy_ssl; int tls_legacy_ssl;
int tls_failed; /* set when tls fails, so we don't try again */ int tls_failed; /* set when tls fails, so we don't try again */
int sasl_support; /* if true, field is a bitfield of supported int sasl_support; /* if true, field is a bitfield of supported
mechanisms */ mechanisms */
int secured; /* set when stream is secured with TLS */ int secured; /* set when stream is secured with TLS */
/* if server returns <bind/> or <session/> we must do them */ /* if server returns <bind/> or <session/> we must do them */
@@ -247,23 +247,23 @@ struct _xmpp_stanza_t {
/* handler management */ /* handler management */
void handler_fire_stanza(xmpp_conn_t * const conn, void handler_fire_stanza(xmpp_conn_t * const conn,
xmpp_stanza_t * const stanza); xmpp_stanza_t * const stanza);
uint64_t handler_fire_timed(xmpp_ctx_t * const ctx); uint64_t handler_fire_timed(xmpp_ctx_t * const ctx);
void handler_reset_timed(xmpp_conn_t *conn, int user_only); void handler_reset_timed(xmpp_conn_t *conn, int user_only);
void handler_add_timed(xmpp_conn_t * const conn, void handler_add_timed(xmpp_conn_t * const conn,
xmpp_timed_handler handler, xmpp_timed_handler handler,
const unsigned long period, const unsigned long period,
void * const userdata); void * const userdata);
void handler_add_id(xmpp_conn_t * const conn, void handler_add_id(xmpp_conn_t * const conn,
xmpp_handler handler, xmpp_handler handler,
const char * const id, const char * const id,
void * const userdata); void * const userdata);
void handler_add(xmpp_conn_t * const conn, void handler_add(xmpp_conn_t * const conn,
xmpp_handler handler, xmpp_handler handler,
const char * const ns, const char * const ns,
const char * const name, const char * const name,
const char * const type, const char * const type,
void * const userdata); void * const userdata);
/* utility functions */ /* utility functions */
void disconnect_mem_error(xmpp_conn_t * const conn); void disconnect_mem_error(xmpp_conn_t * const conn);

102
src/ctx.c
View File

@@ -103,7 +103,7 @@ void xmpp_shutdown(void)
int xmpp_version_check(int major, int minor) int xmpp_version_check(int major, int minor)
{ {
return (major == LIBXMPP_VERSION_MAJOR) && return (major == LIBXMPP_VERSION_MAJOR) &&
(minor >= LIBXMPP_VERSION_MINOR); (minor >= LIBXMPP_VERSION_MINOR);
} }
/* We define the global default allocator, logger, and context here. */ /* We define the global default allocator, logger, and context here. */
@@ -137,9 +137,9 @@ static xmpp_mem_t xmpp_default_mem = {
/* log levels and names */ /* log levels and names */
static const char * const _xmpp_log_level_name[4] = {"DEBUG", "INFO", "WARN", "ERROR"}; static const char * const _xmpp_log_level_name[4] = {"DEBUG", "INFO", "WARN", "ERROR"};
static const xmpp_log_level_t _xmpp_default_logger_levels[] = {XMPP_LEVEL_DEBUG, static const xmpp_log_level_t _xmpp_default_logger_levels[] = {XMPP_LEVEL_DEBUG,
XMPP_LEVEL_INFO, XMPP_LEVEL_INFO,
XMPP_LEVEL_WARN, XMPP_LEVEL_WARN,
XMPP_LEVEL_ERROR}; XMPP_LEVEL_ERROR};
/** Log a message. /** Log a message.
* The default logger writes to stderr. * The default logger writes to stderr.
@@ -151,20 +151,20 @@ static const xmpp_log_level_t _xmpp_default_logger_levels[] = {XMPP_LEVEL_DEBUG,
* @param msg the log message * @param msg the log message
*/ */
static void xmpp_default_logger(void * const userdata, static void xmpp_default_logger(void * const userdata,
const xmpp_log_level_t level, const xmpp_log_level_t level,
const char * const area, const char * const area,
const char * const msg) const char * const msg)
{ {
xmpp_log_level_t filter_level = * (xmpp_log_level_t*)userdata; xmpp_log_level_t filter_level = * (xmpp_log_level_t*)userdata;
if (level >= filter_level) if (level >= filter_level)
fprintf(stderr, "%s %s %s\n", area, _xmpp_log_level_name[level], msg); fprintf(stderr, "%s %s %s\n", area, _xmpp_log_level_name[level], msg);
} }
static const xmpp_log_t _xmpp_default_loggers[] = { static const xmpp_log_t _xmpp_default_loggers[] = {
{&xmpp_default_logger, (void*)&_xmpp_default_logger_levels[XMPP_LEVEL_DEBUG]}, {&xmpp_default_logger, (void*)&_xmpp_default_logger_levels[XMPP_LEVEL_DEBUG]},
{&xmpp_default_logger, (void*)&_xmpp_default_logger_levels[XMPP_LEVEL_INFO]}, {&xmpp_default_logger, (void*)&_xmpp_default_logger_levels[XMPP_LEVEL_INFO]},
{&xmpp_default_logger, (void*)&_xmpp_default_logger_levels[XMPP_LEVEL_WARN]}, {&xmpp_default_logger, (void*)&_xmpp_default_logger_levels[XMPP_LEVEL_WARN]},
{&xmpp_default_logger, (void*)&_xmpp_default_logger_levels[XMPP_LEVEL_ERROR]} {&xmpp_default_logger, (void*)&_xmpp_default_logger_levels[XMPP_LEVEL_ERROR]}
}; };
/** Get a default logger with filtering. /** Get a default logger with filtering.
@@ -225,7 +225,7 @@ void xmpp_free(const xmpp_ctx_t * const ctx, void *p)
* @return a pointer to the reallocated memory or NULL on an error * @return a pointer to the reallocated memory or NULL on an error
*/ */
void *xmpp_realloc(const xmpp_ctx_t * const ctx, void *p, void *xmpp_realloc(const xmpp_ctx_t * const ctx, void *p,
const size_t size) const size_t size)
{ {
return ctx->mem->realloc(p, size, ctx->mem->userdata); return ctx->mem->realloc(p, size, ctx->mem->userdata);
} }
@@ -244,10 +244,10 @@ void *xmpp_realloc(const xmpp_ctx_t * const ctx, void *p,
* @param ap variable argument list supplied for the format string * @param ap variable argument list supplied for the format string
*/ */
void xmpp_log(const xmpp_ctx_t * const ctx, void xmpp_log(const xmpp_ctx_t * const ctx,
const xmpp_log_level_t level, const xmpp_log_level_t level,
const char * const area, const char * const area,
const char * const fmt, const char * const fmt,
va_list ap) va_list ap)
{ {
int oldret, ret; int oldret, ret;
char smbuf[1024]; char smbuf[1024];
@@ -257,23 +257,23 @@ void xmpp_log(const xmpp_ctx_t * const ctx,
va_copy(copy, ap); va_copy(copy, ap);
ret = xmpp_vsnprintf(smbuf, sizeof(smbuf), fmt, ap); ret = xmpp_vsnprintf(smbuf, sizeof(smbuf), fmt, ap);
if (ret >= (int)sizeof(smbuf)) { if (ret >= (int)sizeof(smbuf)) {
buf = (char *)xmpp_alloc(ctx, ret + 1); buf = (char *)xmpp_alloc(ctx, ret + 1);
if (!buf) { if (!buf) {
buf = NULL; buf = NULL;
xmpp_error(ctx, "log", "Failed allocating memory for log message."); xmpp_error(ctx, "log", "Failed allocating memory for log message.");
va_end(copy); va_end(copy);
return; return;
} }
oldret = ret; oldret = ret;
ret = xmpp_vsnprintf(buf, ret + 1, fmt, copy); ret = xmpp_vsnprintf(buf, ret + 1, fmt, copy);
if (ret > oldret) { if (ret > oldret) {
xmpp_error(ctx, "log", "Unexpected error"); xmpp_error(ctx, "log", "Unexpected error");
xmpp_free(ctx, buf); xmpp_free(ctx, buf);
va_end(copy); va_end(copy);
return; return;
} }
} else { } else {
buf = smbuf; buf = smbuf;
} }
va_end(copy); va_end(copy);
@@ -387,33 +387,33 @@ void xmpp_debug(const xmpp_ctx_t * const ctx,
* @ingroup Context * @ingroup Context
*/ */
xmpp_ctx_t *xmpp_ctx_new(const xmpp_mem_t * const mem, xmpp_ctx_t *xmpp_ctx_new(const xmpp_mem_t * const mem,
const xmpp_log_t * const log) const xmpp_log_t * const log)
{ {
xmpp_ctx_t *ctx = NULL; xmpp_ctx_t *ctx = NULL;
if (mem == NULL) if (mem == NULL)
ctx = xmpp_default_mem.alloc(sizeof(xmpp_ctx_t), NULL); ctx = xmpp_default_mem.alloc(sizeof(xmpp_ctx_t), NULL);
else else
ctx = mem->alloc(sizeof(xmpp_ctx_t), mem->userdata); ctx = mem->alloc(sizeof(xmpp_ctx_t), mem->userdata);
if (ctx != NULL) { if (ctx != NULL) {
if (mem != NULL) if (mem != NULL)
ctx->mem = mem; ctx->mem = mem;
else else
ctx->mem = &xmpp_default_mem; ctx->mem = &xmpp_default_mem;
if (log == NULL) if (log == NULL)
ctx->log = &xmpp_default_log; ctx->log = &xmpp_default_log;
else else
ctx->log = log; ctx->log = log;
ctx->connlist = NULL; ctx->connlist = NULL;
ctx->loop_status = XMPP_LOOP_NOTSTARTED; ctx->loop_status = XMPP_LOOP_NOTSTARTED;
ctx->rand = xmpp_rand_new(ctx); ctx->rand = xmpp_rand_new(ctx);
if (ctx->rand == NULL) { if (ctx->rand == NULL) {
xmpp_free(ctx, ctx); xmpp_free(ctx, ctx);
ctx = NULL; ctx = NULL;
} }
} }
return ctx; return ctx;