diff --git a/.gitignore b/.gitignore index 3e70a287..ab42bdd7 100644 --- a/.gitignore +++ b/.gitignore @@ -122,3 +122,6 @@ debian/libssl3* !debian/*.triggers !debian/shlib.local +# clangd +.cache/ +compile_commands.json diff --git a/include/wolfprovider/wp_logging.h b/include/wolfprovider/wp_logging.h index 882cc931..7dfc0ddd 100644 --- a/include/wolfprovider/wp_logging.h +++ b/include/wolfprovider/wp_logging.h @@ -114,98 +114,107 @@ * When modifying the enum values, ensure the corresponding strings in the * wp_logging.c file are updated to match. */ -enum wolfProv_LogLevels { - WP_LOG_LEVEL_ERROR = 0x0001, /* logs errors */ - WP_LOG_LEVEL_ENTER = 0x0002, /* logs function enter*/ - WP_LOG_LEVEL_LEAVE = 0x0004, /* logs function leave */ - WP_LOG_LEVEL_INFO = 0x0008, /* logs informative messages */ - WP_LOG_LEVEL_VERBOSE = 0x0010, /* logs encrypted/decrypted/digested data */ - /* To see the return code from wolfssl, you must add WP_LOG_LEVEL_DEBUG to the - * WOLFPROV_LOG_LEVEL_FILTER */ - WP_LOG_LEVEL_DEBUG = 0x0020, /* logs debug-level detailed information */ - WP_LOG_LEVEL_TRACE = 0x0040, /* logs trace-level ultra-detailed information */ - - /* default log level when logging is turned on */ - WP_LOG_LEVEL_DEFAULT = (WP_LOG_LEVEL_ERROR | WP_LOG_LEVEL_LEAVE | WP_LOG_LEVEL_INFO), - - /* log all, including verbose */ - WP_LOG_LEVEL_ALL = (WP_LOG_LEVEL_ERROR - | WP_LOG_LEVEL_ENTER - | WP_LOG_LEVEL_LEAVE - | WP_LOG_LEVEL_INFO - | WP_LOG_LEVEL_VERBOSE - | WP_LOG_LEVEL_DEBUG - | WP_LOG_LEVEL_TRACE) -}; - -enum wolfProv_LogComponents { - /* Legacy component categories */ - WP_LOG_COMP_RNG = 0x0001, /* random number generation */ - WP_LOG_COMP_DIGEST = 0x0002, /* digest (SHA-1/2/3) */ - WP_LOG_COMP_MAC = 0x0004, /* mac functions: HMAC, CMAC */ - WP_LOG_COMP_CIPHER = 0x0008, /* cipher (AES, 3DES) */ - WP_LOG_COMP_PK = 0x0010, /* public key algorithms (RSA, ECC) */ - WP_LOG_COMP_KE = 0x0020, /* key agreement (DH, ECDH) */ - WP_LOG_COMP_KDF = 0x0040, /* password base key derivation algorithms */ - WP_LOG_COMP_PROVIDER = 0x0080, /* all provider specific logs */ - - /* Granular algorithm family categories */ - WP_LOG_COMP_RSA = 0x0100, /* RSA operations */ - WP_LOG_COMP_ECC = 0x0200, /* ECC operations */ - WP_LOG_COMP_DH = 0x0400, /* Diffie-Hellman operations */ - WP_LOG_COMP_AES = 0x0800, /* AES cipher operations */ - WP_LOG_COMP_DES = 0x1000, /* 3DES cipher operations */ - WP_LOG_COMP_SHA = 0x2000, /* SHA digest operations */ - WP_LOG_COMP_MD5 = 0x4000, /* MD5 digest operations */ - WP_LOG_COMP_HMAC = 0x8000, /* HMAC operations */ - WP_LOG_COMP_CMAC = 0x10000, /* CMAC operations */ - WP_LOG_COMP_HKDF = 0x20000, /* HKDF operations */ - WP_LOG_COMP_PBKDF2 = 0x40000, /* PBKDF2 operations */ - WP_LOG_COMP_KRB5KDF = 0x80000, /* KRB5KDF operations */ - WP_LOG_COMP_DRBG = 0x100000, /* DRBG operations */ - WP_LOG_COMP_ECDSA = 0x200000, /* ECDSA signature operations */ - WP_LOG_COMP_ECDH = 0x400000, /* ECDH key exchange operations */ - WP_LOG_COMP_ED25519 = 0x800000, /* Ed25519 operations */ - WP_LOG_COMP_ED448 = 0x1000000, /* Ed448 operations */ - WP_LOG_COMP_X25519 = 0x2000000, /* X25519 operations */ - WP_LOG_COMP_X448 = 0x4000000, /* X448 operations */ - WP_LOG_COMP_QUERY = 0x8000000, /* wolfprov_query operations */ - WP_LOG_COMP_TLS1_PRF = 0x10000000, /* TLS1 PRF operations */ - - /* log all components */ - WP_LOG_COMP_ALL = (WP_LOG_COMP_RNG - | WP_LOG_COMP_DIGEST - | WP_LOG_COMP_MAC - | WP_LOG_COMP_CIPHER - | WP_LOG_COMP_PK - | WP_LOG_COMP_KE - | WP_LOG_COMP_KDF - | WP_LOG_COMP_PROVIDER - | WP_LOG_COMP_RSA - | WP_LOG_COMP_ECC - | WP_LOG_COMP_DH - | WP_LOG_COMP_AES - | WP_LOG_COMP_DES - | WP_LOG_COMP_SHA - | WP_LOG_COMP_MD5 - | WP_LOG_COMP_HMAC - | WP_LOG_COMP_CMAC - | WP_LOG_COMP_HKDF - | WP_LOG_COMP_PBKDF2 - | WP_LOG_COMP_KRB5KDF - | WP_LOG_COMP_DRBG - | WP_LOG_COMP_ECDSA - | WP_LOG_COMP_ECDH - | WP_LOG_COMP_ED25519 - | WP_LOG_COMP_ED448 - | WP_LOG_COMP_X25519 - | WP_LOG_COMP_X448 - | WP_LOG_COMP_QUERY - | WP_LOG_COMP_TLS1_PRF), - - /* default components logged */ - WP_LOG_COMP_DEFAULT = WP_LOG_COMP_ALL -}; +/*-------------------------------------------------------------* + * wolfProv_LogLevels + *-------------------------------------------------------------*/ + +#define WP_LOG_LEVEL_ERROR 0x0001 /* logs errors */ +#define WP_LOG_LEVEL_ENTER 0x0002 /* logs function enter */ +#define WP_LOG_LEVEL_LEAVE 0x0004 /* logs function leave */ +#define WP_LOG_LEVEL_INFO 0x0008 /* logs informative messages */ +#define WP_LOG_LEVEL_VERBOSE 0x0010 /* logs encrypted/decrypted/digested data */ +/* To see the return code from wolfssl, you must add WP_LOG_LEVEL_DEBUG to the + * WOLFPROV_LOG_LEVEL_FILTER */ +#define WP_LOG_LEVEL_DEBUG 0x0020 /* logs debug-level detailed information */ +#define WP_LOG_LEVEL_TRACE 0x0040 /* logs trace-level ultra-detailed information */ + +/* default log level when logging is turned on */ +#define WP_LOG_LEVEL_DEFAULT ( \ + WP_LOG_LEVEL_ERROR | \ + WP_LOG_LEVEL_LEAVE | \ + WP_LOG_LEVEL_INFO) + +/* log all, including verbose */ +#define WP_LOG_LEVEL_ALL ( \ + WP_LOG_LEVEL_ERROR | \ + WP_LOG_LEVEL_ENTER | \ + WP_LOG_LEVEL_LEAVE | \ + WP_LOG_LEVEL_INFO | \ + WP_LOG_LEVEL_VERBOSE | \ + WP_LOG_LEVEL_DEBUG | \ + WP_LOG_LEVEL_TRACE ) + +/*-------------------------------------------------------------* + * wolfProv_LogComponents + *-------------------------------------------------------------*/ + +/* Legacy component categories */ +#define WP_LOG_COMP_RNG 0x0001 /* random number generation */ +#define WP_LOG_COMP_DIGEST 0x0002 /* digest (SHA-1/2/3) */ +#define WP_LOG_COMP_MAC 0x0004 /* mac functions: HMAC, CMAC */ +#define WP_LOG_COMP_CIPHER 0x0008 /* cipher (AES, 3DES) */ +#define WP_LOG_COMP_PK 0x0010 /* public key algorithms (RSA, ECC) */ +#define WP_LOG_COMP_KE 0x0020 /* key agreement (DH, ECDH) */ +#define WP_LOG_COMP_KDF 0x0040 /* password base key derivation algorithms */ +#define WP_LOG_COMP_PROVIDER 0x0080 /* all provider specific logs */ + +/* Granular algorithm family categories */ +#define WP_LOG_COMP_RSA 0x0100 /* RSA operations */ +#define WP_LOG_COMP_ECC 0x0200 /* ECC operations */ +#define WP_LOG_COMP_DH 0x0400 /* Diffie-Hellman operations */ +#define WP_LOG_COMP_AES 0x0800 /* AES cipher operations */ +#define WP_LOG_COMP_DES 0x1000 /* 3DES cipher operations */ +#define WP_LOG_COMP_SHA 0x2000 /* SHA digest operations */ +#define WP_LOG_COMP_MD5 0x4000 /* MD5 digest operations */ +#define WP_LOG_COMP_HMAC 0x8000 /* HMAC operations */ +#define WP_LOG_COMP_CMAC 0x10000 /* CMAC operations */ +#define WP_LOG_COMP_HKDF 0x20000 /* HKDF operations */ +#define WP_LOG_COMP_PBKDF2 0x40000 /* PBKDF2 operations */ +#define WP_LOG_COMP_KRB5KDF 0x80000 /* KRB5KDF operations */ +#define WP_LOG_COMP_DRBG 0x100000 /* DRBG operations */ +#define WP_LOG_COMP_ECDSA 0x200000 /* ECDSA signature operations */ +#define WP_LOG_COMP_ECDH 0x400000 /* ECDH key exchange operations */ +#define WP_LOG_COMP_ED25519 0x800000 /* Ed25519 operations */ +#define WP_LOG_COMP_ED448 0x1000000 /* Ed448 operations */ +#define WP_LOG_COMP_X25519 0x2000000 /* X25519 operations */ +#define WP_LOG_COMP_X448 0x4000000 /* X448 operations */ +#define WP_LOG_COMP_QUERY 0x8000000 /* wolfprov_query operations */ +#define WP_LOG_COMP_TLS1_PRF 0x10000000 /* TLS1 PRF operations */ + +/* log all components */ +#define WP_LOG_COMP_ALL ( \ + WP_LOG_COMP_RNG | \ + WP_LOG_COMP_DIGEST | \ + WP_LOG_COMP_MAC | \ + WP_LOG_COMP_CIPHER | \ + WP_LOG_COMP_PK | \ + WP_LOG_COMP_KE | \ + WP_LOG_COMP_KDF | \ + WP_LOG_COMP_PROVIDER | \ + WP_LOG_COMP_RSA | \ + WP_LOG_COMP_ECC | \ + WP_LOG_COMP_DH | \ + WP_LOG_COMP_AES | \ + WP_LOG_COMP_DES | \ + WP_LOG_COMP_SHA | \ + WP_LOG_COMP_MD5 | \ + WP_LOG_COMP_HMAC | \ + WP_LOG_COMP_CMAC | \ + WP_LOG_COMP_HKDF | \ + WP_LOG_COMP_PBKDF2 | \ + WP_LOG_COMP_KRB5KDF | \ + WP_LOG_COMP_DRBG | \ + WP_LOG_COMP_ECDSA | \ + WP_LOG_COMP_ECDH | \ + WP_LOG_COMP_ED25519 | \ + WP_LOG_COMP_ED448 | \ + WP_LOG_COMP_X25519 | \ + WP_LOG_COMP_X448 | \ + WP_LOG_COMP_QUERY | \ + WP_LOG_COMP_TLS1_PRF ) + +/* default components logged */ +#define WP_LOG_COMP_DEFAULT WP_LOG_COMP_ALL /* Manually set the log level */ #ifndef WOLFPROV_LOG_LEVEL_FILTER @@ -247,36 +256,61 @@ int wolfProv_LogInit(void); #define WOLFPROV_STRINGIZE_HELPER(x) #x #define WOLFPROV_STRINGIZE(x) WOLFPROV_STRINGIZE_HELPER(x) -#define WOLFPROV_ERROR(type, err) \ - WOLFPROV_ERROR_LINE(type, err, __FILE__, __LINE__) -#define WOLFPROV_ERROR_MSG(type, msg) \ - WOLFPROV_ERROR_MSG_LINE(type, msg, __FILE__, __LINE__) -#define WOLFPROV_ERROR_FUNC(type, funcName, ret) \ - WOLFPROV_ERROR_FUNC_LINE(type, funcName, ret, __FILE__, __LINE__) -#define WOLFPROV_ERROR_FUNC_NULL(type, funcName, ret) \ - WOLFPROV_ERROR_FUNC_NULL_LINE(type, funcName, ret, __FILE__, __LINE__) -void WOLFPROV_ENTER(int type, const char* msg); -void WOLFPROV_ENTER_SILENT(int type, const char* msg); -#define WOLFPROV_LEAVE(type, msg, ret) \ - WOLFPROV_LEAVE_EX(type, WOLFPROV_FUNC_NAME, msg, ret) -void WOLFPROV_LEAVE_EX(int type, const char* func, const char* msg, int ret); -#define WOLFPROV_LEAVE_SILENT(type, msg, ret) \ - WOLFPROV_LEAVE_SILENT_EX(type, WOLFPROV_FUNC_NAME, msg, ret) -void WOLFPROV_LEAVE_SILENT_EX(int type, const char* func, const char* msg, +void wolfprovider_msg(int component, int logLevel, const char *fmt, ...); + +/* Common macro which implements the compile-time check to strip disabled logs */ +#define WOLFPROV_MSG_EX(component, level, fmt, ...) \ + do { if (WOLFPROV_COMPILE_TIME_CHECK(component, level)) { \ + wolfprovider_msg(component, level, fmt, ##__VA_ARGS__); \ + } } while(0) + +#define WOLFPROV_MSG(component, fmt, ...) \ + WOLFPROV_MSG_EX(component, WP_LOG_LEVEL_INFO, fmt, ##__VA_ARGS__) + +#define WOLFPROV_ERROR(component, err) \ + WOLFPROV_ERROR_LINE(component, err, __FILE__, __LINE__) +#define WOLFPROV_ERROR_MSG(component, msg) \ + WOLFPROV_ERROR_MSG_LINE(component, msg, __FILE__, __LINE__) +#define WOLFPROV_ERROR_FUNC(component, funcName, ret) \ + WOLFPROV_ERROR_FUNC_LINE(component, funcName, ret, __FILE__, __LINE__) +#define WOLFPROV_ERROR_FUNC_NULL(component, funcName, ret) \ + WOLFPROV_ERROR_FUNC_NULL_LINE(component, funcName, ret, __FILE__, __LINE__) + +#define WOLFPROV_LEAVE(component, msg, ret) \ + WOLFPROV_LEAVE_EX(component, WOLFPROV_FUNC_NAME, msg, ret) +void WOLFPROV_LEAVE_EX(int component, const char* func, const char* msg, int ret); +#define WOLFPROV_LEAVE_SILENT(component, msg, ret) \ + WOLFPROV_LEAVE_SILENT_EX(component, WOLFPROV_FUNC_NAME, msg, ret) +void WOLFPROV_LEAVE_SILENT_EX(int component, const char* func, const char* msg, int ret); -void WOLFPROV_MSG(int type, const char* fmt, ...); -void WOLFPROV_MSG_VERBOSE(int type, const char* fmt, ...); -void WOLFPROV_MSG_DEBUG(int type, const char* fmt, ...); -void WOLFPROV_MSG_DEBUG_RETCODE(int type, const char* func_name, int rc); -void WOLFPROV_MSG_TRACE(int type, const char* fmt, ...); -void WOLFPROV_ERROR_LINE(int type, int err, const char* file, int line); -void WOLFPROV_ERROR_MSG_LINE(int type, const char* msg, const char* file, + +#define WOLFPROV_ENTER(component, msg) \ + WOLFPROV_MSG_EX(component, WP_LOG_LEVEL_ENTER, "wolfProv Entering %s", msg) +#ifdef WOLFPROV_LEAVE_SILENT_MODE +#define WOLFPROV_ENTER_SILENT(component, msg) \ + WOLFPROV_ENTER_SILENT(component, msg) +#else +#define WOLFPROV_ENTER_SILENT(component, msg) \ + WOLFPROV_MSG_EX(component, WP_LOG_LEVEL_ENTER, "wolfProv Entering [leaving silently] %s", msg) +#endif + +#define WOLFPROV_MSG_VERBOSE(component, fmt, ...) \ + WOLFPROV_MSG_EX(component, WP_LOG_LEVEL_VERBOSE, fmt, ##__VA_ARGS__) +#define WOLFPROV_MSG_DEBUG(component, fmt, ...) \ + WOLFPROV_MSG_EX(component, WP_LOG_LEVEL_DEBUG, fmt, ##__VA_ARGS__) +#define WOLFPROV_MSG_DEBUG_RETCODE(component, func_name, rc) \ + WOLFPROV_MSG_DEBUG(component, "%s failed with rc=%d", func_name, rc) +#define WOLFPROV_MSG_TRACE(component, fmt, ...) \ + WOLFPROV_MSG_EX(component, WP_LOG_LEVEL_TRACE, fmt, ##__VA_ARGS__) + +void WOLFPROV_ERROR_LINE(int component, int err, const char* file, int line); +void WOLFPROV_ERROR_MSG_LINE(int component, const char* msg, const char* file, int line); -void WOLFPROV_ERROR_FUNC_LINE(int type, const char* funcName, int ret, +void WOLFPROV_ERROR_FUNC_LINE(int component, const char* funcName, int ret, const char* file, int line); -void WOLFPROV_ERROR_FUNC_NULL_LINE(int type, const char* funcName, +void WOLFPROV_ERROR_FUNC_NULL_LINE(int component, const char* funcName, const void *ret, const char* file, int line); -void WOLFPROV_BUFFER(int type, const unsigned char* buffer, +void WOLFPROV_BUFFER(int component, const unsigned char* buffer, unsigned int length); #else /* WOLFPROV_DEBUG */ @@ -299,4 +333,3 @@ void WOLFPROV_BUFFER(int type, const unsigned char* buffer, #endif /* WOLFPROV_DEBUG */ #endif /* WP_LOGGING_H */ - diff --git a/src/wp_logging.c b/src/wp_logging.c index 1a9acedd..404c73c2 100644 --- a/src/wp_logging.c +++ b/src/wp_logging.c @@ -197,16 +197,14 @@ int wolfProv_SetLogComponents(int componentMask) * Calls either default log mechanism or application-registered logging * callback. * - * @param logLevel [IN] Log level. * @param logMessage [IN] Log message. + * @param logLevel [IN] Log level. */ -static void wolfprovider_log(const int logLevel, const int component, - const char *const logMessage) +WP_PRINTF_FUNC(3, 0) +static void wolfprovider_log(const int component, const int logLevel, + const char* fmt, va_list vlist) { - /* Check compile-time configuration first */ - if (!WOLFPROV_COMPILE_TIME_CHECK(component, logLevel)) { - return; - } + char logMessage[WOLFPROV_MAX_LOG_WIDTH]; /* Don't log messages that do not match our current logging level */ if ((providerLogLevel & logLevel) != logLevel) { @@ -218,6 +216,8 @@ static void wolfprovider_log(const int logLevel, const int component, return; } + XVSNPRINTF(logMessage, sizeof(logMessage), fmt, vlist); + if (log_function) { log_function(logLevel, component, logMessage); } @@ -265,140 +265,21 @@ static void wolfprovider_log(const int logLevel, const int component, /** * Internal log function for printing varg messages to a specific - * log level. Used by WOLFPROV_MSG and WOLFPROV_MSG_VERBOSE. + * log level. Used by various LOG macros. * * @param component [IN] Component type, from wolfProv_LogComponents enum. * @param logLevel [IN] Log level, from wolfProv_LogLevels enum. * @param fmt [IN] Log message format string. * @param vargs [IN] Variable arguments, used with format string, fmt. */ -WP_PRINTF_FUNC(3, 0) -static void wolfprovider_msg_internal(int component, int logLevel, - const char* fmt, va_list vlist) -{ - char msgStr[WOLFPROV_MAX_LOG_WIDTH]; - - if (loggingEnabled) { - XVSNPRINTF(msgStr, sizeof(msgStr), fmt, vlist); - wolfprovider_log(logLevel, component, msgStr); - } -} - -/** - * Log function for general messages. - * - * @param component [IN] Component type, from wolfProv_LogComponents enum. - * @param fmt [IN] Log message format string. - * @param vargs [IN] Variable arguments, used with format string, fmt. - */ -WP_PRINTF_FUNC(2, 3) -void WOLFPROV_MSG(int component, const char* fmt, ...) -{ - va_list vlist; - va_start(vlist, fmt); - wolfprovider_msg_internal(component, WP_LOG_LEVEL_INFO, fmt, vlist); - va_end(vlist); -} - -/** - * Log function for general messages, prints to WP_LOG_LEVEL_VERBOSE level. - * - * @param component [IN] Component type, from wolfProv_LogComponents enum. - * @param fmt [IN] Log message format string. - * @param vargs [IN] Variable arguments, used with format string, fmt. - */ -WP_PRINTF_FUNC(2, 3) -void WOLFPROV_MSG_VERBOSE(int component, const char* fmt, ...) -{ - va_list vlist; - va_start(vlist, fmt); - wolfprovider_msg_internal(component, WP_LOG_LEVEL_VERBOSE, fmt, vlist); - va_end(vlist); -} - -/** - * Log function for debug messages, prints to WP_LOG_LEVEL_DEBUG level. - * - * @param component [IN] Component type, from wolfProv_LogComponents enum. - * @param fmt [IN] Log message format string. - * @param vargs [IN] Variable arguments, used with format string, fmt. - */ -WP_PRINTF_FUNC(2, 3) -void WOLFPROV_MSG_DEBUG(int component, const char* fmt, ...) -{ - va_list vlist; - va_start(vlist, fmt); - wolfprovider_msg_internal(component, WP_LOG_LEVEL_DEBUG, fmt, vlist); - va_end(vlist); -} - -/** - * Log function for trace messages, prints to WP_LOG_LEVEL_TRACE level. - * - * @param component [IN] Component type, from wolfProv_LogComponents enum. - * @param fmt [IN] Log message format string. - * @param vargs [IN] Variable arguments, used with format string, fmt. - */ -WP_PRINTF_FUNC(2, 3) -void WOLFPROV_MSG_TRACE(int component, const char* fmt, ...) +void wolfprovider_msg(int component, int logLevel, const char *fmt, ...) { va_list vlist; va_start(vlist, fmt); - wolfprovider_msg_internal(component, WP_LOG_LEVEL_TRACE, fmt, vlist); + wolfprovider_log(component, logLevel, fmt, vlist); va_end(vlist); } -/** - * Log function for debug messages with return code, prints to WP_LOG_LEVEL_DEBUG level. - * Unified function to reduce code duplication for common "function failed with rc=%d" pattern. - * - * @param component [IN] Component type, from wolfProv_LogComponents enum. - * @param func_name [IN] Name of the function that failed. - * @param rc [IN] Return code value. - */ -void WOLFPROV_MSG_DEBUG_RETCODE(int component, const char* func_name, int rc) -{ - WOLFPROV_MSG_DEBUG(component, "%s failed with rc=%d", func_name, rc); -} - -/** - * Log function used to record function entry. - * - * @param component [IN] Component type, from wolfProv_LogComponents enum. - * @param msg [IN] Log message. - */ -void WOLFPROV_ENTER(int component, const char* msg) -{ - if (loggingEnabled) { - char buffer[WOLFPROV_MAX_LOG_WIDTH]; - XSNPRINTF(buffer, sizeof(buffer), - "wolfProv Entering %s", msg); - wolfprovider_log(WP_LOG_LEVEL_ENTER, component, buffer); - } -} - -/** - * Log function used to record function entry for check functions. - * These functions use WOLFPROV_LEAVE_SILENT and may not show up in logs. - * The "[leaving silently]" prefix indicates that exit logging may be suppressed. - * - * @param component [IN] Component type, from wolfProv_LogComponents enum. - * @param msg [IN] Log message. - */ -void WOLFPROV_ENTER_SILENT(int component, const char* msg) -{ -#ifdef WOLFPROV_LEAVE_SILENT_MODE - if (loggingEnabled) { - char buffer[WOLFPROV_MAX_LOG_WIDTH]; - XSNPRINTF(buffer, sizeof(buffer), - "wolfProv Entering [leaving silently] %s", msg); - wolfprovider_log(WP_LOG_LEVEL_ENTER, component, buffer); - } -#else - WOLFPROV_ENTER(component, msg); -#endif -} - /** * Log function used to record function exit. Extended for function name. * @@ -410,12 +291,8 @@ void WOLFPROV_ENTER_SILENT(int component, const char* msg) void WOLFPROV_LEAVE_EX(int component, const char* func, const char* msg, int ret) { - if (loggingEnabled) { - char buffer[WOLFPROV_MAX_LOG_WIDTH]; - XSNPRINTF(buffer, sizeof(buffer), - "wolfProv Leaving %s, return %d (%s)", msg, ret, func); - wolfprovider_log(WP_LOG_LEVEL_LEAVE, component, buffer); - } + wolfprovider_msg(component, WP_LOG_LEVEL_LEAVE, + "wolfProv Leaving %s, return %d (%s)", msg, ret, func); } /** @@ -455,13 +332,8 @@ void WOLFPROV_LEAVE_SILENT_EX(int component, const char* func, */ void WOLFPROV_ERROR_LINE(int component, int error, const char* file, int line) { - if (loggingEnabled) { - char buffer[WOLFPROV_MAX_LOG_WIDTH]; - XSNPRINTF(buffer, sizeof(buffer), - "%s:%d - wolfProv error occurred, error = %d", file, line, - error); - wolfprovider_log(WP_LOG_LEVEL_ERROR, component, buffer); - } + wolfprovider_msg(component, WP_LOG_LEVEL_ERROR, + "%s:%d - wolfProv error occurred, error = %d", file, line, error); } /** @@ -475,12 +347,8 @@ void WOLFPROV_ERROR_LINE(int component, int error, const char* file, int line) void WOLFPROV_ERROR_MSG_LINE(int component, const char* msg, const char* file, int line) { - if (loggingEnabled) { - char buffer[WOLFPROV_MAX_LOG_WIDTH]; - XSNPRINTF(buffer, sizeof(buffer), - "%s:%d - wolfProv Error %s", file, line, msg); - wolfprovider_log(WP_LOG_LEVEL_ERROR, component, buffer); - } + wolfprovider_msg(component, WP_LOG_LEVEL_ERROR, + "%s:%d - wolfProv Error %s", file, line, msg); } /** @@ -496,13 +364,8 @@ void WOLFPROV_ERROR_MSG_LINE(int component, const char* msg, void WOLFPROV_ERROR_FUNC_LINE(int component, const char* funcName, int ret, const char* file, int line) { - if (loggingEnabled) { - char buffer[WOLFPROV_MAX_LOG_WIDTH]; - XSNPRINTF(buffer, sizeof(buffer), - "%s:%d - Error calling %s: ret = %d", file, line, funcName, - ret); - wolfprovider_log(WP_LOG_LEVEL_ERROR, component, buffer); - } + wolfprovider_msg(component, WP_LOG_LEVEL_ERROR, + "%s:%d - Error calling %s: ret = %d", file, line, funcName, ret); } /** @@ -519,13 +382,8 @@ void WOLFPROV_ERROR_FUNC_NULL_LINE(int component, const char* funcName, const void *ret, const char* file, int line) { - if (loggingEnabled) { - char buffer[WOLFPROV_MAX_LOG_WIDTH]; - XSNPRINTF(buffer, sizeof(buffer), - "%s:%d - Error calling %s: ret = %p", file, line, funcName, - ret); - wolfprovider_log(WP_LOG_LEVEL_ERROR, component, buffer); - } + wolfprovider_msg(component, WP_LOG_LEVEL_ERROR, + "%s:%d - Error calling %s: ret = %p", file, line, funcName, ret); } /* Macro to control line length of WOLFPROV_BUFFER, for number of @@ -547,13 +405,12 @@ void WOLFPROV_BUFFER(int component, const unsigned char* buffer, int i, buflen = (int)length, bufidx; char line[(WOLFPROV_LINE_LEN * 4) + 3]; /* \t00..0F | chars...chars\0 */ - if (!loggingEnabled) { return; } if (!buffer) { - wolfprovider_log(WP_LOG_LEVEL_VERBOSE, component, "\tNULL"); + wolfprovider_msg(component, WP_LOG_LEVEL_VERBOSE, "\tNULL"); return; } @@ -584,7 +441,7 @@ void WOLFPROV_BUFFER(int component, const unsigned char* buffer, } } - wolfprovider_log(WP_LOG_LEVEL_VERBOSE, component, line); + wolfprovider_msg(WP_LOG_LEVEL_VERBOSE, component, line); buffer += WOLFPROV_LINE_LEN; buflen -= WOLFPROV_LINE_LEN; } diff --git a/test/test_logging.c b/test/test_logging.c index c9596b94..bc435096 100644 --- a/test/test_logging.c +++ b/test/test_logging.c @@ -106,6 +106,7 @@ int test_logging(void *data) PRINT_ERR_MSG("wolfProv_SetLoggingCb failed: %d", ret); return -1; } + /* Scenario A: ALL levels, provider component */ reset_env_and_init("WP_LOG_LEVEL_ALL", "WP_LOG_COMP_PROVIDER"); {