wolf SSL / CyaSSL-2.9.4

Dependents:  

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers logging.c Source File

logging.c

00001 /* logging.c
00002  *
00003  * Copyright (C) 2006-2013 wolfSSL Inc.
00004  *
00005  * This file is part of CyaSSL.
00006  *
00007  * CyaSSL is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 2 of the License, or
00010  * (at your option) any later version.
00011  *
00012  * CyaSSL is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
00020  */
00021 
00022 #ifdef HAVE_CONFIG_H
00023     #include <config.h>
00024 #endif
00025 
00026 #include <cyassl/ctaocrypt/settings.h>
00027 
00028 /* submitted by eof */
00029 
00030 #include <cyassl/ctaocrypt/logging.h>
00031 #include <cyassl/ctaocrypt/error-crypt.h>
00032 
00033 
00034 #ifdef __cplusplus
00035     extern "C" {
00036 #endif
00037     CYASSL_API int  CyaSSL_Debugging_ON(void);
00038     CYASSL_API void CyaSSL_Debugging_OFF(void);
00039 #ifdef __cplusplus
00040     } 
00041 #endif
00042 
00043 
00044 #ifdef DEBUG_CYASSL
00045 
00046 /* Set these to default values initially. */
00047 static CyaSSL_Logging_cb log_function = 0;
00048 static int loggingEnabled = 0;
00049 
00050 #endif /* DEBUG_CYASSL */
00051 
00052 
00053 int CyaSSL_SetLoggingCb(CyaSSL_Logging_cb f)
00054 {
00055 #ifdef DEBUG_CYASSL
00056     int res = 0;
00057 
00058     if (f)
00059         log_function = f;
00060     else
00061         res = BAD_FUNC_ARG;
00062 
00063     return res;
00064 #else
00065     (void)f;
00066     return NOT_COMPILED_IN;
00067 #endif
00068 }
00069 
00070 
00071 int CyaSSL_Debugging_ON(void)
00072 {
00073 #ifdef DEBUG_CYASSL
00074     loggingEnabled = 1;
00075     return 0;
00076 #else
00077     return NOT_COMPILED_IN;
00078 #endif
00079 }
00080 
00081 
00082 void CyaSSL_Debugging_OFF(void)
00083 {
00084 #ifdef DEBUG_CYASSL
00085     loggingEnabled = 0;
00086 #endif
00087 }
00088 
00089 
00090 #ifdef DEBUG_CYASSL
00091 
00092 #ifdef FREESCALE_MQX
00093     #include <fio.h>
00094 #else
00095     #include <stdio.h>   /* for default printf stuff */
00096 #endif
00097 
00098 #ifdef THREADX
00099     int dc_log_printf(char*, ...);
00100 #endif
00101 
00102 static void cyassl_log(const int logLevel, const char *const logMessage)
00103 {
00104     if (log_function)
00105         log_function(logLevel, logMessage);
00106     else {
00107         if (loggingEnabled) {
00108 #ifdef THREADX
00109             dc_log_printf("%s\n", logMessage);
00110 #elif defined(MICRIUM)
00111         #if (NET_SECURE_MGR_CFG_EN == DEF_ENABLED)
00112             NetSecure_TraceOut((CPU_CHAR *)logMessage);
00113         #endif
00114 #elif defined(CYASSL_MDK_ARM)
00115             fflush(stdout) ;
00116             printf("%s\n", logMessage);
00117             fflush(stdout) ;
00118 #else
00119             fprintf(stderr, "%s\n", logMessage);
00120 #endif
00121         }
00122     }
00123 }
00124 
00125 
00126 void CYASSL_MSG(const char* msg)
00127 {
00128     if (loggingEnabled)
00129         cyassl_log(INFO_LOG , msg);
00130 }
00131 
00132 
00133 void CYASSL_ENTER(const char* msg)
00134 {
00135     if (loggingEnabled) {
00136         char buffer[80];
00137         sprintf(buffer, "CyaSSL Entering %s", msg);
00138         cyassl_log(ENTER_LOG , buffer);
00139     }
00140 }
00141 
00142 
00143 void CYASSL_LEAVE(const char* msg, int ret)
00144 {
00145     if (loggingEnabled) {
00146         char buffer[80];
00147         sprintf(buffer, "CyaSSL Leaving %s, return %d", msg, ret);
00148         cyassl_log(LEAVE_LOG , buffer);
00149     }
00150 }
00151 
00152 
00153 void CYASSL_ERROR(int error)
00154 {
00155     if (loggingEnabled) {
00156         char buffer[80];
00157         sprintf(buffer, "CyaSSL error occured, error = %d", error);
00158         cyassl_log(ERROR_LOG , buffer);
00159     }
00160 }
00161 
00162 #endif  /* DEBUG_CYASSL */