]> git.sur5r.net Git - freertos/blob - FreeRTOS-Plus/Source/CyaSSL/ctaocrypt/src/logging.c
Final commit before tagging - cosmetic changes only.
[freertos] / FreeRTOS-Plus / Source / CyaSSL / ctaocrypt / src / logging.c
1 /* logging.c
2  *
3  * Copyright (C) 2006-2014 wolfSSL Inc.
4  *
5  * This file is part of CyaSSL.
6  *
7  * CyaSSL is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * CyaSSL is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
20  */
21
22 #ifdef HAVE_CONFIG_H
23     #include <config.h>
24 #endif
25
26 #include <cyassl/ctaocrypt/settings.h>
27
28 /* submitted by eof */
29
30 #include <cyassl/ctaocrypt/logging.h>
31 #include <cyassl/ctaocrypt/error-crypt.h>
32
33
34 #ifdef __cplusplus
35     extern "C" {
36 #endif
37     CYASSL_API int  CyaSSL_Debugging_ON(void);
38     CYASSL_API void CyaSSL_Debugging_OFF(void);
39 #ifdef __cplusplus
40     } 
41 #endif
42
43
44 #ifdef DEBUG_CYASSL
45
46 /* Set these to default values initially. */
47 static CyaSSL_Logging_cb log_function = 0;
48 static int loggingEnabled = 0;
49
50 #endif /* DEBUG_CYASSL */
51
52
53 int CyaSSL_SetLoggingCb(CyaSSL_Logging_cb f)
54 {
55 #ifdef DEBUG_CYASSL
56     int res = 0;
57
58     if (f)
59         log_function = f;
60     else
61         res = BAD_FUNC_ARG;
62
63     return res;
64 #else
65     (void)f;
66     return NOT_COMPILED_IN;
67 #endif
68 }
69
70
71 int CyaSSL_Debugging_ON(void)
72 {
73 #ifdef DEBUG_CYASSL
74     loggingEnabled = 1;
75     return 0;
76 #else
77     return NOT_COMPILED_IN;
78 #endif
79 }
80
81
82 void CyaSSL_Debugging_OFF(void)
83 {
84 #ifdef DEBUG_CYASSL
85     loggingEnabled = 0;
86 #endif
87 }
88
89
90 #ifdef DEBUG_CYASSL
91
92 #ifdef FREESCALE_MQX
93     #include <fio.h>
94 #else
95     #include <stdio.h>   /* for default printf stuff */
96 #endif
97
98 #ifdef THREADX
99     int dc_log_printf(char*, ...);
100 #endif
101
102 static void cyassl_log(const int logLevel, const char *const logMessage)
103 {
104     if (log_function)
105         log_function(logLevel, logMessage);
106     else {
107         if (loggingEnabled) {
108 #ifdef THREADX
109             dc_log_printf("%s\n", logMessage);
110 #elif defined(MICRIUM)
111         #if (NET_SECURE_MGR_CFG_EN == DEF_ENABLED)
112             NetSecure_TraceOut((CPU_CHAR *)logMessage);
113         #endif
114 #elif defined(CYASSL_MDK_ARM)
115             fflush(stdout) ;
116             printf("%s\n", logMessage);
117             fflush(stdout) ;
118 #else
119             fprintf(stderr, "%s\n", logMessage);
120 #endif
121         }
122     }
123 }
124
125
126 void CYASSL_MSG(const char* msg)
127 {
128     if (loggingEnabled)
129         cyassl_log(INFO_LOG , msg);
130 }
131
132
133 void CYASSL_ENTER(const char* msg)
134 {
135     if (loggingEnabled) {
136         char buffer[80];
137         sprintf(buffer, "CyaSSL Entering %s", msg);
138         cyassl_log(ENTER_LOG , buffer);
139     }
140 }
141
142
143 void CYASSL_LEAVE(const char* msg, int ret)
144 {
145     if (loggingEnabled) {
146         char buffer[80];
147         sprintf(buffer, "CyaSSL Leaving %s, return %d", msg, ret);
148         cyassl_log(LEAVE_LOG , buffer);
149     }
150 }
151
152
153 void CYASSL_ERROR(int error)
154 {
155     if (loggingEnabled) {
156         char buffer[80];
157         sprintf(buffer, "CyaSSL error occured, error = %d", error);
158         cyassl_log(ERROR_LOG , buffer);
159     }
160 }
161
162 #endif  /* DEBUG_CYASSL */