2011-04-16 03:43:00 +04:00
|
|
|
/* logging.c
|
|
|
|
*
|
2013-02-06 00:44:17 +04:00
|
|
|
* Copyright (C) 2006-2013 wolfSSL Inc.
|
2011-04-16 03:43:00 +04:00
|
|
|
*
|
|
|
|
* This file is part of CyaSSL.
|
|
|
|
*
|
|
|
|
* CyaSSL is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* CyaSSL is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
|
|
|
*/
|
|
|
|
|
2011-08-25 03:37:16 +04:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
2011-08-05 02:42:55 +04:00
|
|
|
|
2011-04-16 03:48:13 +04:00
|
|
|
/* submitted by eof */
|
|
|
|
|
2011-08-25 23:41:19 +04:00
|
|
|
#include <cyassl/ctaocrypt/settings.h>
|
|
|
|
#include <cyassl/ctaocrypt/logging.h>
|
|
|
|
#include <cyassl/ctaocrypt/error.h>
|
2011-04-16 01:55:07 +04:00
|
|
|
|
|
|
|
|
2012-03-23 23:20:26 +04:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
CYASSL_API int CyaSSL_Debugging_ON(void);
|
|
|
|
CYASSL_API void CyaSSL_Debugging_OFF(void);
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-04-28 04:31:08 +04:00
|
|
|
|
2011-07-13 23:25:08 +04:00
|
|
|
#ifdef DEBUG_CYASSL
|
|
|
|
|
2011-04-16 01:55:07 +04:00
|
|
|
/* Set these to default values initially. */
|
|
|
|
static CyaSSL_Logging_cb log_function = 0;
|
|
|
|
static int loggingEnabled = 0;
|
|
|
|
|
2011-07-13 23:25:08 +04:00
|
|
|
#endif /* DEBUG_CYASSL */
|
|
|
|
|
2011-04-16 01:55:07 +04:00
|
|
|
|
|
|
|
int CyaSSL_SetLoggingCb(CyaSSL_Logging_cb f)
|
|
|
|
{
|
2011-07-13 23:25:08 +04:00
|
|
|
#ifdef DEBUG_CYASSL
|
2011-04-16 03:43:00 +04:00
|
|
|
int res = 0;
|
2011-04-16 01:55:07 +04:00
|
|
|
|
2011-04-16 03:43:00 +04:00
|
|
|
if (f)
|
|
|
|
log_function = f;
|
|
|
|
else
|
2011-04-21 03:29:19 +04:00
|
|
|
res = BAD_FUNC_ARG;
|
2011-04-16 01:55:07 +04:00
|
|
|
|
2011-04-16 03:43:00 +04:00
|
|
|
return res;
|
2011-07-13 23:25:08 +04:00
|
|
|
#else
|
|
|
|
(void)f;
|
|
|
|
return NOT_COMPILED_IN;
|
|
|
|
#endif
|
2011-04-16 01:55:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int CyaSSL_Debugging_ON(void)
|
|
|
|
{
|
|
|
|
#ifdef DEBUG_CYASSL
|
|
|
|
loggingEnabled = 1;
|
|
|
|
return 0;
|
|
|
|
#else
|
2011-04-21 03:29:19 +04:00
|
|
|
return NOT_COMPILED_IN;
|
2011-04-16 01:55:07 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CyaSSL_Debugging_OFF(void)
|
|
|
|
{
|
2011-07-13 23:25:08 +04:00
|
|
|
#ifdef DEBUG_CYASSL
|
2011-04-16 01:55:07 +04:00
|
|
|
loggingEnabled = 0;
|
2011-07-13 23:25:08 +04:00
|
|
|
#endif
|
2011-04-16 01:55:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef DEBUG_CYASSL
|
|
|
|
|
2012-11-01 21:23:42 +04:00
|
|
|
#ifdef FREESCALE_MQX
|
|
|
|
#include <fio.h>
|
|
|
|
#else
|
|
|
|
#include <stdio.h> /* for default printf stuff */
|
|
|
|
#endif
|
2011-04-16 01:55:07 +04:00
|
|
|
|
|
|
|
#ifdef THREADX
|
|
|
|
int dc_log_printf(char*, ...);
|
|
|
|
#endif
|
|
|
|
|
2011-05-16 21:12:20 +04:00
|
|
|
static void cyassl_log(const int logLevel, const char *const logMessage)
|
2011-04-16 01:55:07 +04:00
|
|
|
{
|
2011-04-16 03:43:00 +04:00
|
|
|
if (log_function)
|
|
|
|
log_function(logLevel, logMessage);
|
|
|
|
else {
|
2011-04-16 01:55:07 +04:00
|
|
|
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
|
2011-04-16 03:43:00 +04:00
|
|
|
}
|
|
|
|
}
|
2011-04-16 01:55:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CYASSL_MSG(const char* msg)
|
|
|
|
{
|
2011-08-17 04:18:12 +04:00
|
|
|
if (loggingEnabled)
|
|
|
|
cyassl_log(INFO_LOG , msg);
|
2011-04-16 01:55:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CYASSL_ENTER(const char* msg)
|
|
|
|
{
|
2011-04-16 03:43:00 +04:00
|
|
|
if (loggingEnabled) {
|
|
|
|
char buffer[80];
|
|
|
|
sprintf(buffer, "CyaSSL Entering %s", msg);
|
2011-05-16 21:12:20 +04:00
|
|
|
cyassl_log(ENTER_LOG , buffer);
|
2011-04-16 03:43:00 +04:00
|
|
|
}
|
2011-04-16 01:55:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CYASSL_LEAVE(const char* msg, int ret)
|
|
|
|
{
|
2011-04-16 03:43:00 +04:00
|
|
|
if (loggingEnabled) {
|
|
|
|
char buffer[80];
|
|
|
|
sprintf(buffer, "CyaSSL Leaving %s, return %d", msg, ret);
|
2011-05-16 21:12:20 +04:00
|
|
|
cyassl_log(LEAVE_LOG , buffer);
|
2011-04-16 03:43:00 +04:00
|
|
|
}
|
2011-04-16 01:55:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CYASSL_ERROR(int error)
|
|
|
|
{
|
2011-04-16 03:43:00 +04:00
|
|
|
if (loggingEnabled) {
|
|
|
|
char buffer[80];
|
|
|
|
sprintf(buffer, "CyaSSL error occured, error = %d", error);
|
2011-05-16 21:12:20 +04:00
|
|
|
cyassl_log(ERROR_LOG , buffer);
|
2011-04-16 03:43:00 +04:00
|
|
|
}
|
2011-04-16 01:55:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* DEBUG_CYASSL */
|