Fix spacing in ctx.c and common.h
This commit is contained in:
100
src/common.h
100
src/common.h
@@ -1,7 +1,7 @@
|
||||
/* common.h
|
||||
** strophe XMPP client library -- internal common structures
|
||||
**
|
||||
** Copyright (C) 2005-2009 Collecta, Inc.
|
||||
** Copyright (C) 2005-2009 Collecta, Inc.
|
||||
**
|
||||
** This software is provided AS-IS with no warranty, either express or
|
||||
** implied.
|
||||
@@ -56,32 +56,32 @@ struct _xmpp_ctx_t {
|
||||
/* convenience functions for accessing the context */
|
||||
void *xmpp_alloc(const xmpp_ctx_t * const ctx, const size_t size);
|
||||
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);
|
||||
|
||||
void xmpp_log(const xmpp_ctx_t * const ctx,
|
||||
const xmpp_log_level_t level,
|
||||
const char * const area,
|
||||
const char * const fmt,
|
||||
va_list ap);
|
||||
void xmpp_log(const xmpp_ctx_t * const ctx,
|
||||
const xmpp_log_level_t level,
|
||||
const char * const area,
|
||||
const char * const fmt,
|
||||
va_list ap);
|
||||
|
||||
/* wrappers for xmpp_log at specific levels */
|
||||
void xmpp_error(const xmpp_ctx_t * const ctx,
|
||||
const char * const area,
|
||||
const char * const fmt,
|
||||
...);
|
||||
const char * const area,
|
||||
const char * const fmt,
|
||||
...);
|
||||
void xmpp_warn(const xmpp_ctx_t * const ctx,
|
||||
const char * const area,
|
||||
const char * const fmt,
|
||||
...);
|
||||
const char * const area,
|
||||
const char * const fmt,
|
||||
...);
|
||||
void xmpp_info(const xmpp_ctx_t * const ctx,
|
||||
const char * const area,
|
||||
const char * const fmt,
|
||||
...);
|
||||
const char * const area,
|
||||
const char * const fmt,
|
||||
...);
|
||||
void xmpp_debug(const xmpp_ctx_t * const ctx,
|
||||
const char * const area,
|
||||
const char * const fmt,
|
||||
...);
|
||||
const char * const area,
|
||||
const char * const fmt,
|
||||
...);
|
||||
|
||||
/** connection **/
|
||||
|
||||
@@ -108,26 +108,26 @@ struct _xmpp_handlist_t {
|
||||
void *handler;
|
||||
void *userdata;
|
||||
int enabled; /* handlers are added disabled and enabled after the
|
||||
* handler chain is processed to prevent stanzas from
|
||||
* getting processed by newly added handlers */
|
||||
* handler chain is processed to prevent stanzas from
|
||||
* getting processed by newly added handlers */
|
||||
xmpp_handlist_t *next;
|
||||
|
||||
union {
|
||||
/* timed handlers */
|
||||
struct {
|
||||
unsigned long period;
|
||||
uint64_t last_stamp;
|
||||
};
|
||||
/* id handlers */
|
||||
struct {
|
||||
char *id;
|
||||
};
|
||||
/* normal handlers */
|
||||
struct {
|
||||
char *ns;
|
||||
char *name;
|
||||
char *type;
|
||||
};
|
||||
/* timed handlers */
|
||||
struct {
|
||||
unsigned long period;
|
||||
uint64_t last_stamp;
|
||||
};
|
||||
/* id handlers */
|
||||
struct {
|
||||
char *id;
|
||||
};
|
||||
/* normal handlers */
|
||||
struct {
|
||||
char *ns;
|
||||
char *name;
|
||||
char *type;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
@@ -168,7 +168,7 @@ struct _xmpp_conn_t {
|
||||
int tls_legacy_ssl;
|
||||
int tls_failed; /* set when tls fails, so we don't try again */
|
||||
int sasl_support; /* if true, field is a bitfield of supported
|
||||
mechanisms */
|
||||
mechanisms */
|
||||
int secured; /* set when stream is secured with TLS */
|
||||
|
||||
/* if server returns <bind/> or <session/> we must do them */
|
||||
@@ -196,7 +196,7 @@ struct _xmpp_conn_t {
|
||||
/* timeouts */
|
||||
unsigned int connect_timeout;
|
||||
|
||||
/* event handlers */
|
||||
/* event handlers */
|
||||
|
||||
/* stream open handler */
|
||||
xmpp_open_handler open_handler;
|
||||
@@ -247,23 +247,23 @@ struct _xmpp_stanza_t {
|
||||
|
||||
/* handler management */
|
||||
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);
|
||||
void handler_reset_timed(xmpp_conn_t *conn, int user_only);
|
||||
void handler_add_timed(xmpp_conn_t * const conn,
|
||||
xmpp_timed_handler handler,
|
||||
const unsigned long period,
|
||||
void * const userdata);
|
||||
xmpp_timed_handler handler,
|
||||
const unsigned long period,
|
||||
void * const userdata);
|
||||
void handler_add_id(xmpp_conn_t * const conn,
|
||||
xmpp_handler handler,
|
||||
const char * const id,
|
||||
void * const userdata);
|
||||
xmpp_handler handler,
|
||||
const char * const id,
|
||||
void * const userdata);
|
||||
void handler_add(xmpp_conn_t * const conn,
|
||||
xmpp_handler handler,
|
||||
const char * const ns,
|
||||
const char * const name,
|
||||
const char * const type,
|
||||
void * const userdata);
|
||||
xmpp_handler handler,
|
||||
const char * const ns,
|
||||
const char * const name,
|
||||
const char * const type,
|
||||
void * const userdata);
|
||||
|
||||
/* utility functions */
|
||||
void disconnect_mem_error(xmpp_conn_t * const conn);
|
||||
|
||||
118
src/ctx.c
118
src/ctx.c
@@ -1,9 +1,9 @@
|
||||
/* ctx.c
|
||||
** strophe XMPP client library -- run-time context implementation
|
||||
**
|
||||
** Copyright (C) 2005-2009 Collecta, Inc.
|
||||
** Copyright (C) 2005-2009 Collecta, Inc.
|
||||
**
|
||||
** This software is provided AS-IS with no warranty, either express
|
||||
** This software is provided AS-IS with no warranty, either express
|
||||
** or implied.
|
||||
**
|
||||
** This program is dual licensed under the MIT and GPLv3 licenses.
|
||||
@@ -36,7 +36,7 @@
|
||||
* result in strange (and platform dependent) behavior.
|
||||
*
|
||||
* Specifically, the socket library on Win32 platforms must be initialized
|
||||
* before use (although this is not the case on POSIX systems). The TLS
|
||||
* before use (although this is not the case on POSIX systems). The TLS
|
||||
* subsystem must also seed the random number generator.
|
||||
*/
|
||||
|
||||
@@ -103,12 +103,12 @@ void xmpp_shutdown(void)
|
||||
int xmpp_version_check(int major, int minor)
|
||||
{
|
||||
return (major == LIBXMPP_VERSION_MAJOR) &&
|
||||
(minor >= LIBXMPP_VERSION_MINOR);
|
||||
(minor >= LIBXMPP_VERSION_MINOR);
|
||||
}
|
||||
|
||||
/* We define the global default allocator, logger, and context here. */
|
||||
|
||||
/* Wrap stdlib routines malloc, free, and realloc for default memory
|
||||
/* Wrap stdlib routines malloc, free, and realloc for default memory
|
||||
* management.
|
||||
*/
|
||||
static void *_malloc(const size_t size, void * const userdata)
|
||||
@@ -137,9 +137,9 @@ static xmpp_mem_t xmpp_default_mem = {
|
||||
/* log levels and names */
|
||||
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,
|
||||
XMPP_LEVEL_INFO,
|
||||
XMPP_LEVEL_WARN,
|
||||
XMPP_LEVEL_ERROR};
|
||||
XMPP_LEVEL_INFO,
|
||||
XMPP_LEVEL_WARN,
|
||||
XMPP_LEVEL_ERROR};
|
||||
|
||||
/** Log a message.
|
||||
* 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
|
||||
*/
|
||||
static void xmpp_default_logger(void * const userdata,
|
||||
const xmpp_log_level_t level,
|
||||
const char * const area,
|
||||
const char * const msg)
|
||||
const xmpp_log_level_t level,
|
||||
const char * const area,
|
||||
const char * const msg)
|
||||
{
|
||||
xmpp_log_level_t filter_level = * (xmpp_log_level_t*)userdata;
|
||||
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[] = {
|
||||
{&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_WARN]},
|
||||
{&xmpp_default_logger, (void*)&_xmpp_default_logger_levels[XMPP_LEVEL_ERROR]}
|
||||
{&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_WARN]},
|
||||
{&xmpp_default_logger, (void*)&_xmpp_default_logger_levels[XMPP_LEVEL_ERROR]}
|
||||
};
|
||||
|
||||
/** Get a default logger with filtering.
|
||||
@@ -192,7 +192,7 @@ static xmpp_log_t xmpp_default_log = { NULL, NULL };
|
||||
/* convenience functions for accessing the context */
|
||||
|
||||
/** Allocate memory in a Strophe context.
|
||||
* All Strophe functions will use this to allocate memory.
|
||||
* All Strophe functions will use this to allocate memory.
|
||||
*
|
||||
* @param ctx a Strophe context object
|
||||
* @param size the number of bytes to allocate
|
||||
@@ -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
|
||||
*/
|
||||
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);
|
||||
}
|
||||
@@ -234,7 +234,7 @@ void *xmpp_realloc(const xmpp_ctx_t * const ctx, void *p,
|
||||
* Write a log message to the logger for the context for the specified
|
||||
* level and area. This function takes a printf-style format string and a
|
||||
* variable argument list (in va_list) format. This function is not meant
|
||||
* to be called directly, but is used via xmpp_error, xmpp_warn, xmpp_info,
|
||||
* to be called directly, but is used via xmpp_error, xmpp_warn, xmpp_info,
|
||||
* and xmpp_debug.
|
||||
*
|
||||
* @param ctx a Strophe context object
|
||||
@@ -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
|
||||
*/
|
||||
void xmpp_log(const xmpp_ctx_t * const ctx,
|
||||
const xmpp_log_level_t level,
|
||||
const char * const area,
|
||||
const char * const fmt,
|
||||
va_list ap)
|
||||
const xmpp_log_level_t level,
|
||||
const char * const area,
|
||||
const char * const fmt,
|
||||
va_list ap)
|
||||
{
|
||||
int oldret, ret;
|
||||
char smbuf[1024];
|
||||
@@ -257,23 +257,23 @@ void xmpp_log(const xmpp_ctx_t * const 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);
|
||||
if (!buf) {
|
||||
buf = NULL;
|
||||
xmpp_error(ctx, "log", "Failed allocating memory for log message.");
|
||||
va_end(copy);
|
||||
return;
|
||||
}
|
||||
oldret = ret;
|
||||
ret = xmpp_vsnprintf(buf, ret + 1, fmt, copy);
|
||||
if (ret > oldret) {
|
||||
xmpp_error(ctx, "log", "Unexpected error");
|
||||
xmpp_free(ctx, buf);
|
||||
va_end(copy);
|
||||
return;
|
||||
}
|
||||
buf = (char *)xmpp_alloc(ctx, ret + 1);
|
||||
if (!buf) {
|
||||
buf = NULL;
|
||||
xmpp_error(ctx, "log", "Failed allocating memory for log message.");
|
||||
va_end(copy);
|
||||
return;
|
||||
}
|
||||
oldret = ret;
|
||||
ret = xmpp_vsnprintf(buf, ret + 1, fmt, copy);
|
||||
if (ret > oldret) {
|
||||
xmpp_error(ctx, "log", "Unexpected error");
|
||||
xmpp_free(ctx, buf);
|
||||
va_end(copy);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
buf = smbuf;
|
||||
buf = smbuf;
|
||||
}
|
||||
va_end(copy);
|
||||
|
||||
@@ -286,7 +286,7 @@ void xmpp_log(const xmpp_ctx_t * const ctx,
|
||||
|
||||
/** Write to the log at the ERROR level.
|
||||
* This is a convenience function for writing to the log at the
|
||||
* ERROR level. It takes a printf-style format string followed by a
|
||||
* ERROR level. It takes a printf-style format string followed by a
|
||||
* variable list of arguments for formatting.
|
||||
*
|
||||
* @param ctx a Strophe context object
|
||||
@@ -386,34 +386,34 @@ void xmpp_debug(const xmpp_ctx_t * const ctx,
|
||||
*
|
||||
* @ingroup Context
|
||||
*/
|
||||
xmpp_ctx_t *xmpp_ctx_new(const xmpp_mem_t * const mem,
|
||||
const xmpp_log_t * const log)
|
||||
xmpp_ctx_t *xmpp_ctx_new(const xmpp_mem_t * const mem,
|
||||
const xmpp_log_t * const log)
|
||||
{
|
||||
xmpp_ctx_t *ctx = 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
|
||||
ctx = mem->alloc(sizeof(xmpp_ctx_t), mem->userdata);
|
||||
ctx = mem->alloc(sizeof(xmpp_ctx_t), mem->userdata);
|
||||
|
||||
if (ctx != NULL) {
|
||||
if (mem != NULL)
|
||||
ctx->mem = mem;
|
||||
else
|
||||
ctx->mem = &xmpp_default_mem;
|
||||
if (mem != NULL)
|
||||
ctx->mem = mem;
|
||||
else
|
||||
ctx->mem = &xmpp_default_mem;
|
||||
|
||||
if (log == NULL)
|
||||
ctx->log = &xmpp_default_log;
|
||||
else
|
||||
ctx->log = log;
|
||||
if (log == NULL)
|
||||
ctx->log = &xmpp_default_log;
|
||||
else
|
||||
ctx->log = log;
|
||||
|
||||
ctx->connlist = NULL;
|
||||
ctx->loop_status = XMPP_LOOP_NOTSTARTED;
|
||||
ctx->rand = xmpp_rand_new(ctx);
|
||||
if (ctx->rand == NULL) {
|
||||
xmpp_free(ctx, ctx);
|
||||
ctx = NULL;
|
||||
}
|
||||
ctx->connlist = NULL;
|
||||
ctx->loop_status = XMPP_LOOP_NOTSTARTED;
|
||||
ctx->rand = xmpp_rand_new(ctx);
|
||||
if (ctx->rand == NULL) {
|
||||
xmpp_free(ctx, ctx);
|
||||
ctx = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return ctx;
|
||||
|
||||
Reference in New Issue
Block a user