11/* ctx.c
22** strophe XMPP client library -- run-time context implementation
33**
4- ** Copyright (C) 2005-2009 Collecta, Inc.
4+ ** Copyright (C) 2005-2009 Collecta, Inc.
55**
6- ** This software is provided AS-IS with no warranty, either express
6+ ** This software is provided AS-IS with no warranty, either express
77** or implied.
88**
99** This program is dual licensed under the MIT and GPLv3 licenses.
3636 * result in strange (and platform dependent) behavior.
3737 *
3838 * Specifically, the socket library on Win32 platforms must be initialized
39- * before use (although this is not the case on POSIX systems). The TLS
39+ * before use (although this is not the case on POSIX systems). The TLS
4040 * subsystem must also seed the random number generator.
4141 */
4242
@@ -103,12 +103,12 @@ void xmpp_shutdown(void)
103103int xmpp_version_check (int major , int minor )
104104{
105105 return (major == LIBXMPP_VERSION_MAJOR ) &&
106- (minor >= LIBXMPP_VERSION_MINOR );
106+ (minor >= LIBXMPP_VERSION_MINOR );
107107}
108108
109109/* We define the global default allocator, logger, and context here. */
110110
111- /* Wrap stdlib routines malloc, free, and realloc for default memory
111+ /* Wrap stdlib routines malloc, free, and realloc for default memory
112112 * management.
113113 */
114114static void * _malloc (const size_t size , void * const userdata )
@@ -137,9 +137,9 @@ static xmpp_mem_t xmpp_default_mem = {
137137/* log levels and names */
138138static const char * const _xmpp_log_level_name [4 ] = {"DEBUG" , "INFO" , "WARN" , "ERROR" };
139139static const xmpp_log_level_t _xmpp_default_logger_levels [] = {XMPP_LEVEL_DEBUG ,
140- XMPP_LEVEL_INFO ,
141- XMPP_LEVEL_WARN ,
142- XMPP_LEVEL_ERROR };
140+ XMPP_LEVEL_INFO ,
141+ XMPP_LEVEL_WARN ,
142+ XMPP_LEVEL_ERROR };
143143
144144/** Log a message.
145145 * The default logger writes to stderr.
@@ -151,20 +151,20 @@ static const xmpp_log_level_t _xmpp_default_logger_levels[] = {XMPP_LEVEL_DEBUG,
151151 * @param msg the log message
152152 */
153153static void xmpp_default_logger (void * const userdata ,
154- const xmpp_log_level_t level ,
155- const char * const area ,
156- const char * const msg )
154+ const xmpp_log_level_t level ,
155+ const char * const area ,
156+ const char * const msg )
157157{
158158 xmpp_log_level_t filter_level = * (xmpp_log_level_t * )userdata ;
159159 if (level >= filter_level )
160- fprintf (stderr , "%s %s %s\n" , area , _xmpp_log_level_name [level ], msg );
160+ fprintf (stderr , "%s %s %s\n" , area , _xmpp_log_level_name [level ], msg );
161161}
162162
163163static const xmpp_log_t _xmpp_default_loggers [] = {
164- {& xmpp_default_logger , (void * )& _xmpp_default_logger_levels [XMPP_LEVEL_DEBUG ]},
165- {& xmpp_default_logger , (void * )& _xmpp_default_logger_levels [XMPP_LEVEL_INFO ]},
166- {& xmpp_default_logger , (void * )& _xmpp_default_logger_levels [XMPP_LEVEL_WARN ]},
167- {& xmpp_default_logger , (void * )& _xmpp_default_logger_levels [XMPP_LEVEL_ERROR ]}
164+ {& xmpp_default_logger , (void * )& _xmpp_default_logger_levels [XMPP_LEVEL_DEBUG ]},
165+ {& xmpp_default_logger , (void * )& _xmpp_default_logger_levels [XMPP_LEVEL_INFO ]},
166+ {& xmpp_default_logger , (void * )& _xmpp_default_logger_levels [XMPP_LEVEL_WARN ]},
167+ {& xmpp_default_logger , (void * )& _xmpp_default_logger_levels [XMPP_LEVEL_ERROR ]}
168168};
169169
170170/** Get a default logger with filtering.
@@ -192,7 +192,7 @@ static xmpp_log_t xmpp_default_log = { NULL, NULL };
192192/* convenience functions for accessing the context */
193193
194194/** Allocate memory in a Strophe context.
195- * All Strophe functions will use this to allocate memory.
195+ * All Strophe functions will use this to allocate memory.
196196 *
197197 * @param ctx a Strophe context object
198198 * @param size the number of bytes to allocate
@@ -225,7 +225,7 @@ void xmpp_free(const xmpp_ctx_t * const ctx, void *p)
225225 * @return a pointer to the reallocated memory or NULL on an error
226226 */
227227void * xmpp_realloc (const xmpp_ctx_t * const ctx , void * p ,
228- const size_t size )
228+ const size_t size )
229229{
230230 return ctx -> mem -> realloc (p , size , ctx -> mem -> userdata );
231231}
@@ -234,7 +234,7 @@ void *xmpp_realloc(const xmpp_ctx_t * const ctx, void *p,
234234 * Write a log message to the logger for the context for the specified
235235 * level and area. This function takes a printf-style format string and a
236236 * variable argument list (in va_list) format. This function is not meant
237- * to be called directly, but is used via xmpp_error, xmpp_warn, xmpp_info,
237+ * to be called directly, but is used via xmpp_error, xmpp_warn, xmpp_info,
238238 * and xmpp_debug.
239239 *
240240 * @param ctx a Strophe context object
@@ -244,10 +244,10 @@ void *xmpp_realloc(const xmpp_ctx_t * const ctx, void *p,
244244 * @param ap variable argument list supplied for the format string
245245 */
246246void xmpp_log (const xmpp_ctx_t * const ctx ,
247- const xmpp_log_level_t level ,
248- const char * const area ,
249- const char * const fmt ,
250- va_list ap )
247+ const xmpp_log_level_t level ,
248+ const char * const area ,
249+ const char * const fmt ,
250+ va_list ap )
251251{
252252 int oldret , ret ;
253253 char smbuf [1024 ];
@@ -257,23 +257,23 @@ void xmpp_log(const xmpp_ctx_t * const ctx,
257257 va_copy (copy , ap );
258258 ret = xmpp_vsnprintf (smbuf , sizeof (smbuf ), fmt , ap );
259259 if (ret >= (int )sizeof (smbuf )) {
260- buf = (char * )xmpp_alloc (ctx , ret + 1 );
261- if (!buf ) {
262- buf = NULL ;
263- xmpp_error (ctx , "log" , "Failed allocating memory for log message." );
264- va_end (copy );
265- return ;
266- }
267- oldret = ret ;
268- ret = xmpp_vsnprintf (buf , ret + 1 , fmt , copy );
269- if (ret > oldret ) {
270- xmpp_error (ctx , "log" , "Unexpected error" );
271- xmpp_free (ctx , buf );
272- va_end (copy );
273- return ;
274- }
260+ buf = (char * )xmpp_alloc (ctx , ret + 1 );
261+ if (!buf ) {
262+ buf = NULL ;
263+ xmpp_error (ctx , "log" , "Failed allocating memory for log message." );
264+ va_end (copy );
265+ return ;
266+ }
267+ oldret = ret ;
268+ ret = xmpp_vsnprintf (buf , ret + 1 , fmt , copy );
269+ if (ret > oldret ) {
270+ xmpp_error (ctx , "log" , "Unexpected error" );
271+ xmpp_free (ctx , buf );
272+ va_end (copy );
273+ return ;
274+ }
275275 } else {
276- buf = smbuf ;
276+ buf = smbuf ;
277277 }
278278 va_end (copy );
279279
@@ -286,7 +286,7 @@ void xmpp_log(const xmpp_ctx_t * const ctx,
286286
287287/** Write to the log at the ERROR level.
288288 * This is a convenience function for writing to the log at the
289- * ERROR level. It takes a printf-style format string followed by a
289+ * ERROR level. It takes a printf-style format string followed by a
290290 * variable list of arguments for formatting.
291291 *
292292 * @param ctx a Strophe context object
@@ -386,34 +386,34 @@ void xmpp_debug(const xmpp_ctx_t * const ctx,
386386 *
387387 * @ingroup Context
388388 */
389- xmpp_ctx_t * xmpp_ctx_new (const xmpp_mem_t * const mem ,
390- const xmpp_log_t * const log )
389+ xmpp_ctx_t * xmpp_ctx_new (const xmpp_mem_t * const mem ,
390+ const xmpp_log_t * const log )
391391{
392392 xmpp_ctx_t * ctx = NULL ;
393393
394394 if (mem == NULL )
395- ctx = xmpp_default_mem .alloc (sizeof (xmpp_ctx_t ), NULL );
395+ ctx = xmpp_default_mem .alloc (sizeof (xmpp_ctx_t ), NULL );
396396 else
397- ctx = mem -> alloc (sizeof (xmpp_ctx_t ), mem -> userdata );
397+ ctx = mem -> alloc (sizeof (xmpp_ctx_t ), mem -> userdata );
398398
399399 if (ctx != NULL ) {
400- if (mem != NULL )
401- ctx -> mem = mem ;
402- else
403- ctx -> mem = & xmpp_default_mem ;
404-
405- if (log == NULL )
406- ctx -> log = & xmpp_default_log ;
407- else
408- ctx -> log = log ;
409-
410- ctx -> connlist = NULL ;
411- ctx -> loop_status = XMPP_LOOP_NOTSTARTED ;
412- ctx -> rand = xmpp_rand_new (ctx );
413- if (ctx -> rand == NULL ) {
414- xmpp_free (ctx , ctx );
415- ctx = NULL ;
416- }
400+ if (mem != NULL )
401+ ctx -> mem = mem ;
402+ else
403+ ctx -> mem = & xmpp_default_mem ;
404+
405+ if (log == NULL )
406+ ctx -> log = & xmpp_default_log ;
407+ else
408+ ctx -> log = log ;
409+
410+ ctx -> connlist = NULL ;
411+ ctx -> loop_status = XMPP_LOOP_NOTSTARTED ;
412+ ctx -> rand = xmpp_rand_new (ctx );
413+ if (ctx -> rand == NULL ) {
414+ xmpp_free (ctx , ctx );
415+ ctx = NULL ;
416+ }
417417 }
418418
419419 return ctx ;
0 commit comments