Strophe 0.12
XMPP client library
Macros | Functions | Variables
ctx.c File Reference

Runtime contexts, library initialization and shutdown, and versioning. More...

Macros

#define va_copy(d, s)   (memcpy(&d, &s, sizeof(va_list)))
 
#define LIBXMPP_VERSION_MAJOR   (0)
 The major version number of Strophe. More...
 
#define LIBXMPP_VERSION_MINOR   (0)
 The minor version number of Strophe. More...
 
#define EVENT_LOOP_DEFAULT_TIMEOUT   1000
 The default timeout in milliseconds for the event loop. More...
 

Functions

void xmpp_initialize (void)
 Initialize the Strophe library. More...
 
void xmpp_shutdown (void)
 Shutdown the Strophe library. More...
 
int xmpp_version_check (int major, int minor)
 Check that Strophe supports a specific API version. More...
 
static void * _malloc (size_t size, void *userdata)
 
static void _free (void *p, void *userdata)
 
static void * _realloc (void *p, size_t size, void *userdata)
 
static void xmpp_default_logger (void *userdata, xmpp_log_level_t level, const char *area, const char *msg)
 Log a message. More...
 
xmpp_log_t * xmpp_get_default_logger (xmpp_log_level_t level)
 Get a default logger with filtering. More...
 
void * strophe_alloc (const xmpp_ctx_t *ctx, size_t size)
 Allocate memory in a Strophe context. More...
 
void strophe_free (const xmpp_ctx_t *ctx, void *p)
 Free memory in a Strophe context. More...
 
void xmpp_free (const xmpp_ctx_t *ctx, void *p)
 Trampoline to strophe_free. More...
 
void * strophe_realloc (const xmpp_ctx_t *ctx, void *p, size_t size)
 Reallocate memory in a Strophe context. More...
 
static void _strophe_log (const xmpp_ctx_t *ctx, xmpp_log_level_t level, const char *area, const char *fmt, va_list ap)
 Write a log message to the logger. More...
 
void strophe_log_internal (const xmpp_ctx_t *ctx, xmpp_log_level_t level, const char *area, const char *fmt, va_list ap)
 
void strophe_error (const xmpp_ctx_t *ctx, const char *area, const char *fmt,...)
 Write to the log at the ERROR level. More...
 
void strophe_warn (const xmpp_ctx_t *ctx, const char *area, const char *fmt,...)
 Write to the log at the WARN level. More...
 
void strophe_info (const xmpp_ctx_t *ctx, const char *area, const char *fmt,...)
 Write to the log at the INFO level. More...
 
void strophe_debug (const xmpp_ctx_t *ctx, const char *area, const char *fmt,...)
 Write to the log at the DEBUG level. More...
 
void strophe_debug_verbose (int level, const xmpp_ctx_t *ctx, const char *area, const char *fmt,...)
 Write to the log at the DEBUG level if verbosity is enabled. More...
 
xmpp_ctx_t * xmpp_ctx_new (const xmpp_mem_t *mem, const xmpp_log_t *log)
 Create and initialize a Strophe context object. More...
 
void xmpp_ctx_free (xmpp_ctx_t *ctx)
 Free a Strophe context object that is no longer in use. More...
 
void xmpp_ctx_set_verbosity (xmpp_ctx_t *ctx, int level)
 Set the verbosity level of a Strophe context. More...
 

Variables

static xmpp_mem_t xmpp_default_mem
 
static const char * _xmpp_log_level_name [4] = {"DEBUG", "INFO", "WARN", "ERROR"}
 
static const xmpp_log_level_t _xmpp_default_logger_levels []
 
static const xmpp_log_t _xmpp_default_loggers []
 
static xmpp_log_t xmpp_default_log = {NULL, NULL}
 

Detailed Description

Runtime contexts, library initialization and shutdown, and versioning.

Macro Definition Documentation

◆ va_copy

#define va_copy (   d,
 
)    (memcpy(&d, &s, sizeof(va_list)))

◆ LIBXMPP_VERSION_MAJOR

#define LIBXMPP_VERSION_MAJOR   (0)

The major version number of Strophe.

◆ LIBXMPP_VERSION_MINOR

#define LIBXMPP_VERSION_MINOR   (0)

The minor version number of Strophe.

◆ EVENT_LOOP_DEFAULT_TIMEOUT

#define EVENT_LOOP_DEFAULT_TIMEOUT   1000

The default timeout in milliseconds for the event loop.

This is set to 1 second.

Function Documentation

◆ _malloc()

static void * _malloc ( size_t  size,
void *  userdata 
)
static

◆ _free()

static void _free ( void *  p,
void *  userdata 
)
static

◆ _realloc()

static void * _realloc ( void *  p,
size_t  size,
void *  userdata 
)
static

◆ xmpp_default_logger()

static void xmpp_default_logger ( void *  userdata,
xmpp_log_level_t  level,
const char *  area,
const char *  msg 
)
static

Log a message.

The default logger writes to stderr.

Parameters
userdatathe opaque data used by the default logger. This contains the filter level in the default logger.
levelthe level to log at
areathe area the log message is for
msgthe log message

◆ strophe_alloc()

void * strophe_alloc ( const xmpp_ctx_t *  ctx,
size_t  size 
)

Allocate memory in a Strophe context.

All Strophe functions will use this to allocate memory.

Parameters
ctxa Strophe context object
sizethe number of bytes to allocate
Returns
a pointer to the allocated memory or NULL on an error

◆ strophe_free()

void strophe_free ( const xmpp_ctx_t *  ctx,
void *  p 
)

Free memory in a Strophe context.

All Strophe functions will use this to free allocated memory.

Parameters
ctxa Strophe context object
pa pointer referencing memory to be freed

◆ xmpp_free()

void xmpp_free ( const xmpp_ctx_t *  ctx,
void *  p 
)

Trampoline to strophe_free.

Parameters
ctxstrophe_free
pstrophe_free

◆ strophe_realloc()

void * strophe_realloc ( const xmpp_ctx_t *  ctx,
void *  p,
size_t  size 
)

Reallocate memory in a Strophe context.

All Strophe functions will use this to reallocate memory.

Parameters
ctxa Strophe context object
pa pointer to previously allocated memory
sizethe new size in bytes to allocate
Returns
a pointer to the reallocated memory or NULL on an error

◆ _strophe_log()

static void _strophe_log ( const xmpp_ctx_t *  ctx,
xmpp_log_level_t  level,
const char *  area,
const char *  fmt,
va_list  ap 
)
static

Write a log message to the logger.

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 strophe_error, strophe_warn, strophe_info, and strophe_debug.

Parameters
ctxa Strophe context object
levelthe level at which to log
areathe area to log for
fmta printf-style format string for the message
apvariable argument list supplied for the format string

◆ strophe_log_internal()

void strophe_log_internal ( const xmpp_ctx_t *  ctx,
xmpp_log_level_t  level,
const char *  area,
const char *  fmt,
va_list  ap 
)

◆ strophe_error()

void strophe_error ( const xmpp_ctx_t *  ctx,
const char *  area,
const char *  fmt,
  ... 
)

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 variable list of arguments for formatting.

Parameters
ctxa Strophe context object
areathe area to log for
fmta printf-style format string followed by a variable list of arguments to format

◆ strophe_warn()

void strophe_warn ( const xmpp_ctx_t *  ctx,
const char *  area,
const char *  fmt,
  ... 
)

Write to the log at the WARN level.

This is a convenience function for writing to the log at the WARN level. It takes a printf-style format string followed by a variable list of arguments for formatting.

Parameters
ctxa Strophe context object
areathe area to log for
fmta printf-style format string followed by a variable list of arguments to format

◆ strophe_info()

void strophe_info ( const xmpp_ctx_t *  ctx,
const char *  area,
const char *  fmt,
  ... 
)

Write to the log at the INFO level.

This is a convenience function for writing to the log at the INFO level. It takes a printf-style format string followed by a variable list of arguments for formatting.

Parameters
ctxa Strophe context object
areathe area to log for
fmta printf-style format string followed by a variable list of arguments to format

◆ strophe_debug()

void strophe_debug ( const xmpp_ctx_t *  ctx,
const char *  area,
const char *  fmt,
  ... 
)

Write to the log at the DEBUG level.

This is a convenience function for writing to the log at the DEBUG level. It takes a printf-style format string followed by a variable list of arguments for formatting.

Parameters
ctxa Strophe context object
areathe area to log for
fmta printf-style format string followed by a variable list of arguments to format

◆ strophe_debug_verbose()

void strophe_debug_verbose ( int  level,
const xmpp_ctx_t *  ctx,
const char *  area,
const char *  fmt,
  ... 
)

Write to the log at the DEBUG level if verbosity is enabled.

This is a convenience function for writing to the log at the DEBUG level. It takes a printf-style format string followed by a variable list of arguments for formatting.

Parameters
levelthe verbosity level
ctxa Strophe context object
areathe area to log for
fmta printf-style format string followed by a variable list of arguments to format

Variable Documentation

◆ xmpp_default_mem

xmpp_mem_t xmpp_default_mem
static
Initial value:
= {
_free, _realloc, NULL}
static void * _realloc(void *p, size_t size, void *userdata)
Definition: ctx.c:137
static void _free(void *p, void *userdata)
Definition: ctx.c:131
static void * _malloc(size_t size, void *userdata)
Definition: ctx.c:125

◆ _xmpp_log_level_name

const char* _xmpp_log_level_name[4] = {"DEBUG", "INFO", "WARN", "ERROR"}
static

◆ _xmpp_default_logger_levels

const xmpp_log_level_t _xmpp_default_logger_levels[]
static
Initial value:
= {
@ XMPP_LEVEL_INFO
Definition: strophe.h:150
@ XMPP_LEVEL_ERROR
Definition: strophe.h:152
@ XMPP_LEVEL_DEBUG
Definition: strophe.h:149
@ XMPP_LEVEL_WARN
Definition: strophe.h:151

◆ _xmpp_default_loggers

const xmpp_log_t _xmpp_default_loggers[]
static
Initial value:
= {
static const xmpp_log_level_t _xmpp_default_logger_levels[]
Definition: ctx.c:150
static void xmpp_default_logger(void *userdata, xmpp_log_level_t level, const char *area, const char *msg)
Log a message.
Definition: ctx.c:162

◆ xmpp_default_log

xmpp_log_t xmpp_default_log = {NULL, NULL}
static