Strophe 0.13
XMPP client library
Functions
util.c File Reference

Utility functions. More...

Functions

char * strophe_strdup (const xmpp_ctx_t *ctx, const char *s)
 implement our own strdup that uses the ctx allocator
 
char * strophe_strndup (const xmpp_ctx_t *ctx, const char *s, size_t len)
 Duplicate a string with a maximum length.
 
char * strophe_strtok_r (char *s, const char *delim, char **saveptr)
 strtok_r(3) implementation.
 
uint64_t time_stamp (void)
 Return an integer based time stamp.
 
uint64_t time_elapsed (uint64_t t1, uint64_t t2)
 Get the time elapsed between two time stamps.
 
void disconnect_mem_error (xmpp_conn_t *conn)
 Disconnect the stream with a memory error.
 
int string_to_ul (const char *s, unsigned long *ul)
 
void hex_encode (char *writebuf, void *readbuf, size_t len)
 

Detailed Description

Utility functions.

Function Documentation

◆ strophe_strdup()

char * strophe_strdup ( const xmpp_ctx_t *  ctx,
const char *  s 
)

implement our own strdup that uses the ctx allocator

Duplicate a string. This function replaces the standard strdup library call with a version that uses the Strophe context object's allocator.

Parameters
ctxa Strophe context object
sa string
Returns
a newly allocated string with the same data as s or NULL on error

◆ strophe_strndup()

char * strophe_strndup ( const xmpp_ctx_t *  ctx,
const char *  s,
size_t  len 
)

Duplicate a string with a maximum length.

This function replaces the standard strndup library call with a version that uses the Strophe context object's allocator.

Parameters
ctxa Strophe context object
sa string
lenthe maximum length of the string to copy
Returns
a newly allocated string that contains at most len symbols of the original string or NULL on error

◆ strophe_strtok_r()

char * strophe_strtok_r ( char *  s,
const char *  delim,
char **  saveptr 
)

strtok_r(3) implementation.

This function has appeared in POSIX.1-2001, but not in C standard. For example, visual studio older than 2005 doesn't provide strtok_r() nor strtok_s().

◆ time_stamp()

uint64_t time_stamp ( void  )

Return an integer based time stamp.

This function uses gettimeofday or timeGetTime (on Win32 platforms) to compute an integer based time stamp. This is used internally by the event loop and timed handlers.

Returns
an integer time stamp

◆ time_elapsed()

uint64_t time_elapsed ( uint64_t  t1,
uint64_t  t2 
)

Get the time elapsed between two time stamps.

This function returns the time elapsed between t1 and t2 by subtracting t1 from t2. If t2 happened before t1, the result will be negative. This function is used internally by the event loop and timed handlers.

Parameters
t1first time stamp
t2second time stamp
Returns
number of milliseconds between the stamps

◆ disconnect_mem_error()

void disconnect_mem_error ( xmpp_conn_t *  conn)

Disconnect the stream with a memory error.

This is a convenience function used internally by various parts of the Strophe library for terminating the connection because of a memory error.

Parameters
conna Strophe connection object

◆ string_to_ul()

int string_to_ul ( const char *  s,
unsigned long *  ul 
)

◆ hex_encode()

void hex_encode ( char *  writebuf,
void *  readbuf,
size_t  len 
)