X-Git-Url: http://git.silcnet.org/gitweb/?a=blobdiff_plain;f=lib%2Fsilcutil%2Fsilclog.h;h=56c58ec345691f9b74964a78ebcc7d541d644d5b;hb=e7b6c157b80152bf9fb9266e6bdd93f9fb0db776;hp=af8358501e4d3bc849d6900ef031f02492b85546;hpb=d1e71f42379e8b5cd0748a7aeae8561b02cfe53d;p=silc.git diff --git a/lib/silcutil/silclog.h b/lib/silcutil/silclog.h index af835850..56c58ec3 100644 --- a/lib/silcutil/silclog.h +++ b/lib/silcutil/silclog.h @@ -4,7 +4,7 @@ Author: Pekka Riikonen - Copyright (C) 1997 - 2005 Pekka Riikonen + Copyright (C) 1997 - 2007 Pekka Riikonen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -55,8 +55,8 @@ typedef enum { * * SYNOPSIS * - * typedef bool (*SilcLogCb)(SilcLogType type, char *message, - * void *context); + * typedef SilcBool (*SilcLogCb)(SilcLogType type, char *message, + * void *context); * * DESCRIPTION * @@ -67,19 +67,21 @@ typedef enum { * The `message' parameter points to a null-terminated buffer containing * the received message, while `context' is the caller-specified context. * The message must not be modified or freed by the callback function. + * If the function returns TRUE, SilcLog will assume the message was + * handled and won't run its default handler. * * SEE ALSO * silc_log_set_callback * ***/ -typedef bool (*SilcLogCb)(SilcLogType type, char *message, void *context); +typedef SilcBool (*SilcLogCb)(SilcLogType type, char *message, void *context); /****f* silcutil/SilcLogAPI/SilcLogDebugCb * * SYNOPSIS * - * typedef bool (*SilcLogDebugCb)(char *file, char *function, int line, - * char *message, void *context); + * typedef SilcBool (*SilcLogDebugCb)(char *file, char *function, int line, + * char *message, void *context); * * DESCRIPTION * @@ -97,17 +99,18 @@ typedef bool (*SilcLogCb)(SilcLogType type, char *message, void *context); * silc_debug, silc_log_set_debug_callbacks * ***/ -typedef bool (*SilcLogDebugCb)(char *file, char *function, int line, - char *message, void *context); +typedef SilcBool (*SilcLogDebugCb)(char *file, char *function, int line, + char *message, void *context); /****f* silcutil/SilcLogAPI/SilcLogHexdumpCb * * SYNOPSIS * - * typedef bool (*SilcDebugHexdumpCb)(char *file, char *function, int line, - * unsigned char *data, - * SilcUInt32 data_len, - * char *message, void *context; + * typedef SilcBool + * (*SilcDebugHexdumpCb)(char *file, char *function, int line, + * unsigned char *data, + * SilcUInt32 data_len, + * char *message, void *context; * * DESCRIPTION * @@ -127,9 +130,9 @@ typedef bool (*SilcLogDebugCb)(char *file, char *function, int line, * silc_debug_hexdump, silc_log_set_debug_callbacks * ***/ -typedef bool (*SilcLogHexdumpCb)(char *file, char *function, int line, - unsigned char *data, SilcUInt32 data_len, - char *message, void *context); +typedef SilcBool (*SilcLogHexdumpCb)(char *file, char *function, int line, + unsigned char *data, SilcUInt32 data_len, + char *message, void *context); /* Macros */ @@ -285,15 +288,66 @@ typedef bool (*SilcLogHexdumpCb)(char *file, char *function, int line, #endif /* SILC_DEBUG */ /***/ +/****d* silcutil/SilcLogAPI/SILC_ASSERT + * + * NAME + * + * #define SILC_ASSERT(experssion) + * + * DESCRIPTION + * + * Assert macro that prints error message to stderr and calls abort() + * if the `expression' is false (ie. compares equal to zero). If + * SILC_DEBUG is not defined this macro has no effect. + * + * SOURCE + */ +#if defined(SILC_DEBUG) +#define SILC_ASSERT(expr) assert((expr)); +#else +#define SILC_ASSERT(expr) do { } while(0) +#endif /* SILC_DEBUG */ +/***/ + +/****d* silcutil/SilcLogAPI/SILC_VERIFY + * + * NAME + * + * #define SILC_VERIFY(experssion) + * + * DESCRIPTION + * + * Verification macro that prints error message to stderr and calls + * abort() if the `expression' is false (ie. compares equal to zero) + * on debug builds (SILC_DEBUG defined), and prints error message to + * stderr on release builds (SILC_DEBUG undefined) but does not abort(). + * This macro is always compiled even if debugging (SILC_DEBUG) is not + * defined. + * + * SOURCE + */ +#if defined(SILC_DEBUG) +#define SILC_VERIFY(expr) assert((expr)); +#else +#define SILC_VERIFY(expr) \ + if (silc_unlikely(!(expr))) { \ + SILC_LOG_ERROR(("SILC_VERIFY %s:%s:%d", \ + __FILE__, __FUNCTION__, __LINE__)); \ + silc_set_errno_reason_nofail(SILC_ERR_ASSERT, "SILC_VERIFY %s:%s:%d", \ + __FILE__, __FUNCTION__, __LINE__); \ + } +#endif /* SILC_DEBUG */ +/***/ + /* Prototypes */ /****f* silcutil/SilcLogAPI/silc_log_set_file * * SYNOPSIS * - * bool silc_log_set_file(SilcLogType type, char *filename, - * SilcUInt32 maxsize, - * SilcSchedule scheduler); + * SilcBool silc_log_set_file(SilcLogType type, char *filename, + * SilcUInt32 maxsize, + * SilcSchedule scheduler); * * DESCRIPTION * @@ -305,11 +359,12 @@ typedef bool (*SilcLogHexdumpCb)(char *file, char *function, int line, * You can disable logging for a channel by specifying NULL filename, the * maxsize in this case is not important. The `scheduler' parameter is * needed by the internal logging to allow buffered output and thus to - * save HD activity. + * save HD activity. If `scheduler' is NULL this will call + * silc_schedule_get_global to try to get global scheduler. * ***/ -bool silc_log_set_file(SilcLogType type, char *filename, SilcUInt32 maxsize, - SilcSchedule scheduler); +SilcBool silc_log_set_file(SilcLogType type, char *filename, + SilcUInt32 maxsize, SilcSchedule scheduler); /****f* silcutil/SilcLogAPI/silc_log_get_file * @@ -465,7 +520,7 @@ void silc_log_set_debug_string(const char *debug_string); * * NAME * - * void silc_log_timestamp(bool enable); + * void silc_log_timestamp(SilcBool enable); * * DESCRIPTION * @@ -473,7 +528,7 @@ void silc_log_set_debug_string(const char *debug_string); * timestamp and to FALSE to disable it. Default is TRUE. * ***/ -void silc_log_timestamp(bool enable); +void silc_log_timestamp(SilcBool enable); /****f* silcutil/SilcLogAPI/silc_log_flushdelay * @@ -492,7 +547,7 @@ void silc_log_flushdelay(SilcUInt32 flushdelay); * * NAME * - * void silc_log_quick(bool enable); + * void silc_log_quick(SilcBool enable); * * DESCRIPTION * @@ -510,13 +565,13 @@ void silc_log_flushdelay(SilcUInt32 flushdelay); * Default is FALSE. * ***/ -void silc_log_quick(bool enable); +void silc_log_quick(SilcBool enable); /****v* silcutil/SilcLogAPI/silc_log_debug * * NAME * - * void silc_log_debug(bool enable); + * void silc_log_debug(SilcBool enable); * * DESCRIPTION * @@ -528,13 +583,13 @@ void silc_log_quick(bool enable); * SILC_LOG_DEBUG * ***/ -void silc_log_debug(bool enable); +void silc_log_debug(SilcBool enable); /****v* silcutil/SilcLogAPI/silc_log_debug_hexdump * * NAME * - * void silc_log_debug_hexdump(bool enable); + * void silc_log_debug_hexdump(SilcBool enable); * * DESCRIPTION * @@ -546,6 +601,6 @@ void silc_log_debug(bool enable); * SILC_LOG_HEXDUMP * ***/ -void silc_log_debug_hexdump(bool enable); +void silc_log_debug_hexdump(SilcBool enable); #endif /* !SILCLOG_H */