forked from wolfSSL/wolfssl
allow runtime setting of logging function, move to ctaocrypt for use by both, submitted by eof
This commit is contained in:
46
ctaocrypt/include/logging.h
Normal file
46
ctaocrypt/include/logging.h
Normal file
@ -0,0 +1,46 @@
|
||||
#ifndef CYASSL_LOGGING_H
|
||||
#define CYASSL_LOGGING_H
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
enum CYA_Log_Levels {
|
||||
ERROR_LOG = 0,
|
||||
INFO_LOG,
|
||||
ENTER_LOG,
|
||||
LEAVE_LOG,
|
||||
OTHER_LOG
|
||||
};
|
||||
|
||||
typedef void (*CyaSSL_Logging_cb)(const int logLevel,
|
||||
const char *const logMessage);
|
||||
|
||||
int CyaSSL_SetLoggingCb(CyaSSL_Logging_cb log_function);
|
||||
|
||||
|
||||
#ifdef DEBUG_CYASSL
|
||||
|
||||
void CYASSL_ENTER(const char* msg);
|
||||
void CYASSL_LEAVE(const char* msg, int ret);
|
||||
|
||||
void CYASSL_ERROR(int);
|
||||
void CYASSL_MSG(const char* msg);
|
||||
|
||||
#else /* DEBUG_CYASSL */
|
||||
|
||||
#define CYASSL_ENTER(m)
|
||||
#define CYASSL_LEAVE(m, r)
|
||||
|
||||
#define CYASSL_ERROR(e)
|
||||
#define CYASSL_MSG(m)
|
||||
|
||||
#endif /* DEBUG_CYASSL */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CYASSL_MEMORY_H */
|
107
ctaocrypt/src/logging.c
Normal file
107
ctaocrypt/src/logging.c
Normal file
@ -0,0 +1,107 @@
|
||||
#include "logging.h"
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
|
||||
/* Set these to default values initially. */
|
||||
static CyaSSL_Logging_cb log_function = 0;
|
||||
static int loggingEnabled = 0;
|
||||
|
||||
|
||||
int CyaSSL_SetLoggingCb(CyaSSL_Logging_cb f)
|
||||
{
|
||||
int res = 0;
|
||||
|
||||
if (f)
|
||||
log_function = f;
|
||||
else
|
||||
res = -1;
|
||||
|
||||
return res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
int CyaSSL_Debugging_ON(void)
|
||||
{
|
||||
#ifdef DEBUG_CYASSL
|
||||
loggingEnabled = 1;
|
||||
return 0;
|
||||
#else
|
||||
return -1; /* not compiled in */
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void CyaSSL_Debugging_OFF(void)
|
||||
{
|
||||
loggingEnabled = 0;
|
||||
}
|
||||
|
||||
|
||||
#ifdef DEBUG_CYASSL
|
||||
|
||||
#include <stdio.h> /* for default printf stuff */
|
||||
|
||||
#ifdef THREADX
|
||||
int dc_log_printf(char*, ...);
|
||||
#endif
|
||||
|
||||
static void log(const int logLevel, const char *const logMessage)
|
||||
{
|
||||
if (log_function)
|
||||
log_function(logLevel, logMessage);
|
||||
else {
|
||||
if (loggingEnabled) {
|
||||
#ifdef THREADX
|
||||
dc_log_printf("%s\n", logMessage);
|
||||
#elif defined(MICRIUM)
|
||||
#if (NET_SECURE_MGR_CFG_EN == DEF_ENABLED)
|
||||
NetSecure_TraceOut((CPU_CHAR *)logMessage);
|
||||
#endif
|
||||
#else
|
||||
fprintf(stderr, "%s\n", logMessage);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CYASSL_MSG(const char* msg)
|
||||
{
|
||||
log(INFO_LOG , msg);
|
||||
}
|
||||
|
||||
|
||||
void CYASSL_ENTER(const char* msg)
|
||||
{
|
||||
if (loggingEnabled) {
|
||||
char buffer[80];
|
||||
sprintf(buffer, "CyaSSL Entering %s", msg);
|
||||
log(ENTER_LOG , buffer);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CYASSL_LEAVE(const char* msg, int ret)
|
||||
{
|
||||
if (loggingEnabled) {
|
||||
char buffer[80];
|
||||
sprintf(buffer, "CyaSSL Leaving %s, return %d", msg, ret);
|
||||
log(LEAVE_LOG , buffer);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CYASSL_ERROR(int error)
|
||||
{
|
||||
if (loggingEnabled) {
|
||||
char buffer[80];
|
||||
sprintf(buffer, "CyaSSL error occured, error = %d", error);
|
||||
log(ERROR_LOG , buffer);
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* DEBUG_CYASSL */
|
@ -33,6 +33,7 @@
|
||||
#include "asn.h"
|
||||
#include "ctc_md5.h"
|
||||
#include "ctc_aes.h"
|
||||
#include "logging.h"
|
||||
#ifdef HAVE_ECC
|
||||
#include "ctc_ecc.h"
|
||||
#endif
|
||||
@ -1221,23 +1222,6 @@ int LockMutex(CyaSSL_Mutex*);
|
||||
int UnLockMutex(CyaSSL_Mutex*);
|
||||
|
||||
|
||||
#ifdef DEBUG_CYASSL
|
||||
|
||||
void CYASSL_ENTER(const char* msg);
|
||||
void CYASSL_LEAVE(const char* msg, int ret);
|
||||
|
||||
void CYASSL_ERROR(int);
|
||||
void CYASSL_MSG(const char* msg);
|
||||
|
||||
#else /* DEBUG_CYASSL */
|
||||
|
||||
#define CYASSL_ENTER(m)
|
||||
#define CYASSL_LEAVE(m, r)
|
||||
|
||||
#define CYASSL_ERROR(e)
|
||||
#define CYASSL_MSG(m)
|
||||
|
||||
#endif /* DEBUG_CYASSL */
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -8,7 +8,7 @@ libcyassl_la_SOURCES = \
|
||||
../ctaocrypt/src/random.c ../ctaocrypt/src/rsa.c ../ctaocrypt/src/sha.c \
|
||||
../ctaocrypt/src/aes.c ../ctaocrypt/src/sha256.c ../ctaocrypt/src/dh.c \
|
||||
../ctaocrypt/src/dsa.c ../ctaocrypt/src/arc4.c ../ctaocrypt/src/rabbit.c \
|
||||
../ctaocrypt/src/pwdbased.c
|
||||
../ctaocrypt/src/pwdbased.c ../ctaocrypt/src/logging.c
|
||||
libcyassl_la_LDFLAGS = -no-undefined -version-info 1:0:0
|
||||
EXTRA_DIST = ../include/*.h ../include/openssl/*.h ../include/*.rc
|
||||
|
||||
|
@ -5382,87 +5382,3 @@ int UnLockMutex(CyaSSL_Mutex* m)
|
||||
|
||||
#endif /* USE_WINDOWS_API */
|
||||
#endif /* SINGLE_THREADED */
|
||||
|
||||
|
||||
#ifdef DEBUG_CYASSL
|
||||
|
||||
static int logging = 0;
|
||||
|
||||
|
||||
int CyaSSL_Debugging_ON(void)
|
||||
{
|
||||
logging = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void CyaSSL_Debugging_OFF(void)
|
||||
{
|
||||
logging = 0;
|
||||
}
|
||||
|
||||
|
||||
#ifdef THREADX
|
||||
int dc_log_printf(char*, ...);
|
||||
#endif
|
||||
|
||||
void CYASSL_MSG(const char* msg)
|
||||
{
|
||||
if (logging) {
|
||||
#ifdef THREADX
|
||||
dc_log_printf("%s\n", msg);
|
||||
#elif defined(MICRIUM)
|
||||
#if (NET_SECURE_MGR_CFG_EN == DEF_ENABLED)
|
||||
NetSecure_TraceOut((CPU_CHAR *)msg);
|
||||
#endif
|
||||
#else
|
||||
fprintf(stderr, "%s\n", msg);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CYASSL_ENTER(const char* msg)
|
||||
{
|
||||
if (logging) {
|
||||
char buffer[80];
|
||||
sprintf(buffer, "CyaSSL Entering %s", msg);
|
||||
CYASSL_MSG(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CYASSL_LEAVE(const char* msg, int ret)
|
||||
{
|
||||
if (logging) {
|
||||
char buffer[80];
|
||||
sprintf(buffer, "CyaSSL Leaving %s, return %d", msg, ret);
|
||||
CYASSL_MSG(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CYASSL_ERROR(int error)
|
||||
{
|
||||
if (logging) {
|
||||
char buffer[80];
|
||||
sprintf(buffer, "CyaSSL error occured, error = %d", error);
|
||||
CYASSL_MSG(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#else /* DEBUG_CYASSL */
|
||||
|
||||
int CyaSSL_Debugging_ON(void)
|
||||
{
|
||||
return -1; /* not compiled in */
|
||||
}
|
||||
|
||||
|
||||
void CyaSSL_Debugging_OFF(void)
|
||||
{
|
||||
/* already off */
|
||||
}
|
||||
|
||||
#endif /* DEBUG_CYASSL */
|
||||
|
Reference in New Issue
Block a user