
#include <util/basicDefs.h>#include <pthread.h>Include dependency graph for helper.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.
Data Structures | |
| struct | XmlBlasterReadFromSocketFuncHolder |
| Holds a callback function pointer and its user pointer (the 'this' pointer). More... | |
| struct | XmlBlasterWriteToSocketFuncHolder |
| Holds a callback function pointer and its user pointer (the 'this' pointer, first argument). More... | |
| struct | BlobHolder |
| Holds arbitrary raw data and its length. More... | |
| struct | ExceptionStruct |
| Holds error text. More... | |
Defines | |
| #define | XB_USE_PTHREADS 1 |
| #define | EXCEPTIONSTRUCT_ERRORCODE_LEN 56 |
| #define | EXCEPTIONSTRUCT_MESSAGE_LEN 1024 |
Typedefs | |
| typedef ssize_t(*) | XmlBlasterWriteToSocketFunc (void *xb, const int fd, const char *ptr, const size_t nbytes) |
| Declare function pointer to write to socket. | |
| typedef ssize_t(*) | XmlBlasterReadFromSocketFunc (void *xb, const int fd, char *ptr, const size_t nbytes, XmlBlasterNumReadFunc fpNumRead, void *userP2) |
| Declare function pointer to read from socket. | |
| typedef enum XMLBLASTER_LOG_LEVEL_ENUM | XMLBLASTER_LOG_LEVEL |
| typedef void(*) | XmlBlasterLogging (void *logUserP, XMLBLASTER_LOG_LEVEL currLevel, XMLBLASTER_LOG_LEVEL level, const char *location, const char *fmt,...) |
Enumerations | |
| enum | XMLBLASTER_LOG_LEVEL_ENUM { XMLBLASTER_LOG_ERROR = 1, XMLBLASTER_LOG_WARN = 2, XMLBLASTER_LOG_INFO = 3, XMLBLASTER_LOG_TRACE = 6, XMLBLASTER_LOG_DUMP = 7 } |
Functions | |
| void | initializeExceptionStruct (ExceptionStruct *exception) |
| Should be called on any ExceptionStruct before using it. | |
| void | embedException (ExceptionStruct *exception, const char *newErrorCode, const char *newMessage, const ExceptionStruct *embed) |
| const char * | getExceptionStr (char *out, int outSize, const ExceptionStruct *exception) |
| void | xmlBlasterDefaultLogging (void *logUserP, XMLBLASTER_LOG_LEVEL currLevel, XMLBLASTER_LOG_LEVEL level, const char *location, const char *fmt,...) |
| XMLBLASTER_LOG_LEVEL | parseLogLevel (const char *logLevelStr) |
| const char * | getLogLevelStr (XMLBLASTER_LOG_LEVEL logLevel) |
| |
| int | doLog (XMLBLASTER_LOG_LEVEL currLevel, XMLBLASTER_LOG_LEVEL level) |
| Check if logging is necessary. | |
| char * | getStackTrace (int maxNumOfLines) |
| Add for GCC compilation: "-rdynamic -export-dynamic -D_ENABLE_STACK_TRACE_". | |
| void | sleepMillis (long millis) |
| Sleep for given milliseconds, on none real time systems expect ~ 10 millisecs tolerance. | |
| int64_t | getTimestamp (void) |
| Create a timestamp in nano seconds elapsed since 1970-01-01. | |
| int | getAbsoluteTime (long relativeTimeFromNow, struct timespec *abstime) |
| Fills the given abstime with absolute time, using the given timeout relativeTimeFromNow in milliseconds On Linux < 2.5.64 does not support high resolution timers clock_gettime(), but patches are available at http://sourceforge.net/projects/high-res-timers. | |
| void | getCurrentTimeStr (char *timeStr, int bufSize) |
| Get a human readable time string for logging. | |
| char ** | convertWcsArgv (wchar_t **argv_wcs, int argc) |
| Converts the given wide char pwcs to multibyte argv. | |
| void | freeArgv (char **argv, int argc) |
| Frees the allocated argv from convertWcsArgv(). | |
| char * | strFromBlobAlloc (const char *blob, const size_t len) |
| char * | strcpyAlloc (const char *src) |
| char * | strcpyRealloc (char **dest, const char *src) |
| char * | strcatAlloc (char **dest, const char *src) |
| char * | strncpy0 (char *const to, const char *const from, const size_t maxLen) |
| char * | strncat0 (char *const to, const char *const from, const size_t max) |
| int | snprintf0 (char *buffer, size_t sizeOfBuffer, const char *format,...) |
| void | trim (char *s) |
| strip leading and trailing spaces of the given string | |
| void | trimStart (char *s) |
| strip leading spaces of the given string | |
| void | trimEnd (char *s) |
| strip trailing spaces of the given string | |
| void | xb_strerror (char *errnoStr, size_t sizeInBytes, int errnum) |
| Convert the errnum to a human readable errnoStr. | |
| char * | toReadableDump (char *data, size_t len) |
| Converts the given binary data to a more readable string, the zero bytes are replaced by '*'. | |
| const char * | int64ToStr (char *const buf, int64_t val) |
| Convert a 64 bit integer to a string. | |
| int | strToInt64 (int64_t *val, const char *const str) |
| int | strToLong (long *val, const char *const str) |
| int | strToULong (unsigned long *val, const char *const str) |
| int | strToInt (int *val, const char *const str) |
| BlobHolder * | blobcpyAlloc (BlobHolder *blob, const char *data, size_t dataLen) |
| BlobHolder * | freeBlobHolderContent (BlobHolder *blob) |
| free()'s the data in the given blob, does not free the blob itself. | |
| char * | blobDump (BlobHolder *blob) |
| Converts the given binary data to a more readable string, the zero bytes are replaced by '*'. | |
| void | freeBlobDump (char *blobDump) |
| long | get_pthread_id (pthread_t t) |
| Cast the thread identifier to an long value. | |
| #define EXCEPTIONSTRUCT_ERRORCODE_LEN 56 |
Definition at line 80 of file helper.h.
Referenced by checkArgs(), compilePreparedQuery(), embedException(), execSilent(), interceptUpdate(), parseCacheInfo(), parseQueueEntryArr(), persistentQueueDestroy(), persistentQueueInitialize(), persistentQueuePeekWithSamePriority(), and persistentQueuePut().
| #define EXCEPTIONSTRUCT_MESSAGE_LEN 1024 |
Definition at line 81 of file helper.h.
Referenced by checkArgs(), compilePreparedQuery(), createCallbackServer(), embedException(), execSilent(), interceptUpdate(), parseCacheInfo(), parseQueueEntryArr(), parseSocketData(), persistentQueueDestroy(), persistentQueueInitialize(), persistentQueuePeekWithSamePriority(), and persistentQueuePut().
| typedef enum XMLBLASTER_LOG_LEVEL_ENUM XMLBLASTER_LOG_LEVEL |
| typedef void( * ) XmlBlasterLogging(void *logUserP, XMLBLASTER_LOG_LEVEL currLevel, XMLBLASTER_LOG_LEVEL level, const char *location, const char *fmt,...) |
| typedef ssize_t( * ) XmlBlasterReadFromSocketFunc(void *xb, const int fd, char *ptr, const size_t nbytes, XmlBlasterNumReadFunc fpNumRead, void *userP2) |
| typedef ssize_t( * ) XmlBlasterWriteToSocketFunc(void *xb, const int fd, const char *ptr, const size_t nbytes) |
| BlobHolder* blobcpyAlloc | ( | BlobHolder * | blob, | |
| const char * | data, | |||
| size_t | dataLen | |||
| ) |
| char* blobDump | ( | BlobHolder * | blob | ) |
Converts the given binary data to a more readable string, the zero bytes are replaced by '*'.
| blob | The binary data |
Definition at line 984 of file helper.c.
References BlobHolder::data, BlobHolder::dataLen, and toReadableDump().
Referenced by sendData().
Here is the call graph for this function:

| char** convertWcsArgv | ( | wchar_t ** | argv_wcs, | |
| int | argc | |||
| ) |
Converts the given wide char pwcs to multibyte argv.
Call freeWcsArgv() to free the memory again.
| pwcs | In parameter: Wide char command line arguments | |
| argc | The number of strings in pwcs |
Definition at line 224 of file helper.c.
References argv.
| int doLog | ( | XMLBLASTER_LOG_LEVEL | currLevel, | |
| XMLBLASTER_LOG_LEVEL | level | |||
| ) |
| void embedException | ( | ExceptionStruct * | exception, | |
| const char * | newErrorCode, | |||
| const char * | newMessage, | |||
| const ExceptionStruct * | embed | |||
| ) |
| void freeArgv | ( | char ** | argv, | |
| int | argc | |||
| ) |
Frees the allocated argv from convertWcsArgv().
| argv | The main(argv) | |
| argc | The number of strings in argv |
Definition at line 249 of file helper.c.
Referenced by main().
| void freeBlobDump | ( | char * | blobDump | ) |
| BlobHolder* freeBlobHolderContent | ( | BlobHolder * | blob | ) |
free()'s the data in the given blob, does not free the blob itself.
| blob | if NULL we return NULL |
Definition at line 967 of file helper.c.
References BlobHolder::data, and BlobHolder::dataLen.
Referenced by handleMessage(), postSendEvent(), sendData(), xmlBlasterConnect(), xmlBlasterDisconnect(), xmlBlasterErase(), xmlBlasterGet(), xmlBlasterPing(), xmlBlasterPublish(), xmlBlasterSubscribe(), and xmlBlasterUnSubscribe().
| long get_pthread_id | ( | pthread_t | t | ) |
Cast the thread identifier to an long value.
| t | The pthread_t type |
Definition at line 648 of file helper.c.
Referenced by freeXmlBlasterAccessUnparsed(), interceptUpdate(), runUpdate(), and xmlBlasterDefaultLogging().
| int getAbsoluteTime | ( | long | relativeTimeFromNow, | |
| struct timespec * | abstime | |||
| ) |
Fills the given abstime with absolute time, using the given timeout relativeTimeFromNow in milliseconds On Linux < 2.5.64 does not support high resolution timers clock_gettime(), but patches are available at http://sourceforge.net/projects/high-res-timers.
| relativeTimeFromNow | the relative time from now in milliseconds | |
| abstime |
Definition at line 266 of file helper.c.
References NANO_SECS_PER_SECOND.
Referenced by getTimestamp(), and postSendEvent().
| void getCurrentTimeStr | ( | char * | timeStr, | |
| int | bufSize | |||
| ) |
Get a human readable time string for logging.
| timeStr | out parameter, e.g. "2006-11-14 12:34:46" | |
| bufSize | The size of timeStr |
Definition at line 663 of file helper.c.
References snprintf0(), and strncpy0().
Referenced by xmlBlasterDefaultLogging().
Here is the call graph for this function:

| const char* getExceptionStr | ( | char * | out, | |
| int | outSize, | |||
| const ExceptionStruct * | exception | |||
| ) |
| const char* getLogLevelStr | ( | XMLBLASTER_LOG_LEVEL | logLevel | ) |
"ERROR"
Definition at line 800 of file helper.c.
References LOG_TEXT.
Referenced by getXmlBlasterAccessUnparsed(), and myLogger().
| char* getStackTrace | ( | int | maxNumOfLines | ) |
Add for GCC compilation: "-rdynamic -export-dynamic -D_ENABLE_STACK_TRACE_".
Definition at line 94 of file helper.c.
References strcatAlloc(), and strcpyAlloc().
Referenced by checkArgs(), freeXmlBlasterAccessUnparsed(), and xmlBlasterDefaultLogging().
Here is the call graph for this function:

| int64_t getTimestamp | ( | void | ) |
Create a timestamp in nano seconds elapsed since 1970-01-01.
The timestamp is guaranteed to be ascending and unique.
Definition at line 199 of file helper.c.
References getAbsoluteTime(), and NANO_SECS_PER_SECOND.
Referenced by myUpdate().
Here is the call graph for this function:

| void initializeExceptionStruct | ( | ExceptionStruct * | exception | ) |
Should be called on any ExceptionStruct before using it.
Nulls all fields
Definition at line 843 of file helper.c.
References ExceptionStruct::errorCode, ExceptionStruct::message, and ExceptionStruct::remote.
Referenced by checkArgs().
| const char* int64ToStr | ( | char * | buf, | |
| int64_t | val | |||
| ) |
Convert a 64 bit integer to a string.
This helper concentrates this conversion to one place to simplify porting to compilers with no int64_t = long long support
| buf | You need to pass this buffer with at least INT64_STRLEN_MAX=22 bytes of size |
< Size of a max int64_t dumped to a string including an optional LL and termination '': LLONG_MAX from limits.h 9223372036854775807LL
Definition at line 874 of file helper.c.
References INT64_STRLEN_MAX, PRINTF_PREFIX_INT64_T, and snprintf0().
Referenced by fillCache(), parseQueueEntryArr(), persistentQueuePeekWithSamePriority(), persistentQueuePut(), persistentQueueRandomRemove(), queueEntryToXml(), test_overflow(), and test_queue().
Here is the call graph for this function:

| XMLBLASTER_LOG_LEVEL parseLogLevel | ( | const char * | logLevelStr | ) |
| void sleepMillis | ( | long | millis | ) |
Sleep for given milliseconds, on none real time systems expect ~ 10 millisecs tolerance.
Definition at line 150 of file helper.c.
Referenced by compilePreparedQuery(), freeXmlBlasterAccessUnparsed(), getResultRows(), main(), and myUpdate().
| int snprintf0 | ( | char * | buffer, | |
| size_t | sizeOfBuffer, | |||
| const char * | format, | |||
| ... | ||||
| ) |
| char* strcatAlloc | ( | char ** | dest, | |
| const char * | src | |||
| ) |
| char* strcpyAlloc | ( | const char * | src | ) |
| char* strcpyRealloc | ( | char ** | dest, | |
| const char * | src | |||
| ) |
| char* strFromBlobAlloc | ( | const char * | blob, | |
| const size_t | len | |||
| ) |
| char* strncat0 | ( | char *const | to, | |
| const char *const | from, | |||
| const size_t | max | |||
| ) |
| char* strncpy0 | ( | char *const | to, | |
| const char *const | from, | |||
| const size_t | maxLen | |||
| ) |
| int strToInt | ( | int * | val, | |
| const char *const | str | |||
| ) |
| int strToInt64 | ( | int64_t * | val, | |
| const char *const | str | |||
| ) |
| int strToLong | ( | long * | val, | |
| const char *const | str | |||
| ) |
| int strToULong | ( | unsigned long * | val, | |
| const char *const | str | |||
| ) |
| char* toReadableDump | ( | char * | data, | |
| size_t | len | |||
| ) |
Converts the given binary data to a more readable string, the zero bytes are replaced by '*'.
| data | The data to convert | |
| len | The length of the binary data |
Definition at line 623 of file helper.c.
Referenced by blobDump(), encodeSocketMessage(), and parseSocketData().
| void trim | ( | char * | s | ) |
strip leading and trailing spaces of the given string
Definition at line 540 of file helper.c.
Referenced by convertToXmlBlasterException(), parseMsgUnitArr(), and parseSocketData().
| void trimEnd | ( | char * | s | ) |
| void trimStart | ( | char * | s | ) |
| void xb_strerror | ( | char * | errnoStr, | |
| size_t | sizeInBytes, | |||
| int | errnum | |||
| ) |
Convert the errnum to a human readable errnoStr.
| errnoStr | Out parameter holding the string | |
| sizeInBytes | Size of the buffer | |
| errnum | The error number (errno) |
Definition at line 437 of file helper.c.
References snprintf0(), and strncpy0().
Referenced by initConnection().
Here is the call graph for this function:

| void xmlBlasterDefaultLogging | ( | void * | logUserP, | |
| XMLBLASTER_LOG_LEVEL | currLevel, | |||
| XMLBLASTER_LOG_LEVEL | level, | |||
| const char * | location, | |||
| const char * | fmt, | |||
| ... | ||||
| ) |