Strophe 0.9 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.
#define | LIBXMPP_VERSION_MINOR (0)
| The minor version number of Strophe.
#define | EVENT_LOOP_DEFAULT_TIMEOUT 1000
| The default timeout in milliseconds for the event loop.

## Functions
void | xmpp_initialize (void)
| Initialize the Strophe library.
void | xmpp_shutdown (void)
| Shutdown the Strophe library.
int | xmpp_version_check (int major, int minor)
| Check that Strophe supports a specific API version.
static void * | _malloc (const size_t size, void *const userdata)
static void | _free (void *p, void *const userdata)
static void * | _realloc (void *p, const size_t size, void *const userdata)
static void | xmpp_default_logger (void *const userdata, const xmpp_log_level_t level, const char *const area, const char *const msg)
| Log a message.
xmpp_log_t * | xmpp_get_default_logger (xmpp_log_level_t level)
| Get a default logger with filtering.
void * | xmpp_alloc (const xmpp_ctx_t *const ctx, const size_t size)
| Allocate memory in a Strophe context.
void | xmpp_free (const xmpp_ctx_t *const ctx, void *p)
| Free memory in a Strophe context.
void * | xmpp_realloc (const xmpp_ctx_t *const ctx, void *p, const size_t size)
| Reallocate memory in a Strophe context.
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)
| Write a log message to the logger.
void | xmpp_error (const xmpp_ctx_t *const ctx, const char *const area, const char *const fmt,...)
| Write to the log at the ERROR level.
void | xmpp_warn (const xmpp_ctx_t *const ctx, const char *const area, const char *const fmt,...)
| Write to the log at the WARN level.
void | xmpp_info (const xmpp_ctx_t *const ctx, const char *const area, const char *const fmt,...)
| Write to the log at the INFO level.
void | xmpp_debug (const xmpp_ctx_t *const ctx, const char *const area, const char *const fmt,...)
| Write to the log at the DEBUG level.
xmpp_ctx_t * | xmpp_ctx_new (const xmpp_mem_t *const mem, const xmpp_log_t *const log)
| Create and initialize a Strophe context object.
void | xmpp_ctx_free (xmpp_ctx_t *const ctx)
| Free a Strophe context object that is no longer in use.
void | xmpp_ctx_set_timeout (xmpp_ctx_t *const ctx, const unsigned long timeout)
| Set the timeout to use when calling xmpp_run().

## Variables
static xmpp_mem_t | xmpp_default_mem
static const char *const | _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,
|  |  | s ) (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 | ( | const size_t | size,
|  | void *const | userdata )
| static

## ◆ _free()

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

## ◆ _realloc()

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

## ◆ xmpp_default_logger()

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

Log a message.

The default logger writes to stderr.

Parameters

  userdata | the opaque data used by the default logger. This contains the filter level in the default logger.
  level | the level to log at
  area | the area the log message is for
  msg | the log message

## ◆ xmpp_alloc()

void * xmpp_alloc | ( | const xmpp_ctx_t *const | ctx,
|  | const size_t | size )

Allocate memory in a Strophe context.

All Strophe functions will use this to allocate memory.

Parameters

  ctx | a Strophe context object
  size | the number of bytes to allocate

Returns
  a pointer to the allocated memory or NULL on an error

## ◆ xmpp_free()

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

Free memory in a Strophe context.

All Strophe functions will use this to free allocated memory.

Parameters

  ctx | a Strophe context object
  p | a pointer referencing memory to be freed

## ◆ xmpp_realloc()

void * xmpp_realloc | ( | const xmpp_ctx_t *const | ctx,
|  | void * | p,
|  | const size_t | size )

Reallocate memory in a Strophe context.

All Strophe functions will use this to reallocate memory.

Parameters

  ctx | a Strophe context object
  p | a pointer to previously allocated memory
  size | the new size in bytes to allocate

Returns
  a pointer to the reallocated memory or NULL on an error

## ◆ xmpp_log()

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 )

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 xmpp_error, xmpp_warn, xmpp_info, and xmpp_debug.

Parameters

  ctx | a Strophe context object
  level | the level at which to log
  area | the area to log for
  fmt | a printf-style format string for the message
  ap | variable argument list supplied for the format string

## ◆ xmpp_error()

void xmpp_error | ( | const xmpp_ctx_t *const | ctx,
|  | const char *const | area,
|  | const char *const | 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

  ctx | a Strophe context object
  area | the area to log for
  fmt | a printf-style format string followed by a variable list of arguments to format

## ◆ xmpp_warn()

void xmpp_warn | ( | const xmpp_ctx_t *const | ctx,
|  | const char *const | area,
|  | const char *const | 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

  ctx | a Strophe context object
  area | the area to log for
  fmt | a printf-style format string followed by a variable list of arguments to format

## ◆ xmpp_info()

void xmpp_info | ( | const xmpp_ctx_t *const | ctx,
|  | const char *const | area,
|  | const char *const | 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

  ctx | a Strophe context object
  area | the area to log for
  fmt | a printf-style format string followed by a variable list of arguments to format

## ◆ xmpp_debug()

void xmpp_debug | ( | const xmpp_ctx_t *const | ctx,
|  | const char *const | area,
|  | const char *const | 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

  ctx | a Strophe context object
  area | the area to log for
  fmt | a 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:
= {
_malloc,
_free,
_realloc,
NULL
}
_free
static void _free(void *p, void *const userdata)
Definition ctx.c:126
_realloc
static void * _realloc(void *p, const size_t size, void *const userdata)
Definition ctx.c:131
_malloc
static void * _malloc(const size_t size, void *const userdata)
Definition ctx.c:121

## ◆ _xmpp_log_level_name

const char* const _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_DEBUG,
XMPP_LEVEL_INFO,
XMPP_LEVEL_WARN,
XMPP_LEVEL_ERROR}
XMPP_LEVEL_INFO
@ XMPP_LEVEL_INFO
Definition mesode.h:136
XMPP_LEVEL_ERROR
@ XMPP_LEVEL_ERROR
Definition mesode.h:138
XMPP_LEVEL_DEBUG
@ XMPP_LEVEL_DEBUG
Definition mesode.h:135
XMPP_LEVEL_WARN
@ XMPP_LEVEL_WARN
Definition mesode.h:137

## ◆ _xmpp_default_loggers

const xmpp_log_t _xmpp_default_loggers[]
| static

Initial value:
= {
{&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_levels
static const xmpp_log_level_t _xmpp_default_logger_levels[]
Definition ctx.c:146
xmpp_default_logger
static void xmpp_default_logger(void *const userdata, const xmpp_log_level_t level, const char *const area, const char *const msg)
Log a message.
Definition ctx.c:160

## ◆ xmpp_default_log

xmpp_log_t xmpp_default_log = { NULL, NULL }
| static