]> git.sur5r.net Git - freertos/blob - FreeRTOS-Plus/CyaSSL/ctaocrypt/src/logging.c
Commit 3 RX100 low power demos.
[freertos] / FreeRTOS-Plus / CyaSSL / ctaocrypt / src / logging.c
1 /* logging.c
2  *
3  * Copyright (C) 2006-2012 Sawtooth Consulting Ltd.
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
20  */
21
22 #ifdef HAVE_CONFIG_H
23     #include <config.h>
24 #endif
25
26 /* submitted by eof */
27
28 #include <cyassl/ctaocrypt/settings.h>
29 #include <cyassl/ctaocrypt/logging.h>
30 #include <cyassl/ctaocrypt/error.h>
31
32
33 #ifdef __cplusplus
34     extern "C" {
35 #endif
36     CYASSL_API int  CyaSSL_Debugging_ON(void);
37     CYASSL_API void CyaSSL_Debugging_OFF(void);
38 #ifdef __cplusplus
39     } 
40 #endif
41
42
43 #ifdef DEBUG_CYASSL
44
45 /* Set these to default values initially. */
46 static CyaSSL_Logging_cb log_function = 0;
47 static int loggingEnabled = 0;
48
49 #endif /* DEBUG_CYASSL */
50
51
52 int CyaSSL_SetLoggingCb(CyaSSL_Logging_cb f)
53 {
54 #ifdef DEBUG_CYASSL
55     int res = 0;
56
57     if (f)
58         log_function = f;
59     else
60         res = BAD_FUNC_ARG;
61
62     return res;
63 #else
64     (void)f;
65     return NOT_COMPILED_IN;
66 #endif
67 }
68
69
70 int CyaSSL_Debugging_ON(void)
71 {
72 #ifdef DEBUG_CYASSL
73     loggingEnabled = 1;
74     return 0;
75 #else
76     return NOT_COMPILED_IN;
77 #endif
78 }
79
80
81 void CyaSSL_Debugging_OFF(void)
82 {
83 #ifdef DEBUG_CYASSL
84     loggingEnabled = 0;
85 #endif
86 }
87
88
89 #ifdef DEBUG_CYASSL
90
91 #include <stdio.h>   /* for default printf stuff */
92
93 #ifdef THREADX
94     int dc_log_printf(char*, ...);
95 #endif
96
97 static void cyassl_log(const int logLevel, const char *const logMessage)
98 {
99     if (log_function)
100         log_function(logLevel, logMessage);
101     else {
102         if (loggingEnabled) {
103 #ifdef THREADX
104             dc_log_printf("%s\n", logMessage);
105 #elif defined(MICRIUM)
106         #if (NET_SECURE_MGR_CFG_EN == DEF_ENABLED)
107             NetSecure_TraceOut((CPU_CHAR *)logMessage);
108         #endif
109 #else
110             fprintf(stderr, "%s\n", logMessage);
111 #endif
112         }
113     }
114 }
115
116
117 void CYASSL_MSG(const char* msg)
118 {
119     if (loggingEnabled)
120         cyassl_log(INFO_LOG , msg);
121 }
122
123
124 void CYASSL_ENTER(const char* msg)
125 {
126     if (loggingEnabled) {
127         char buffer[80];
128         sprintf(buffer, "CyaSSL Entering %s", msg);
129         cyassl_log(ENTER_LOG , buffer);
130     }
131 }
132
133
134 void CYASSL_LEAVE(const char* msg, int ret)
135 {
136     if (loggingEnabled) {
137         char buffer[80];
138         sprintf(buffer, "CyaSSL Leaving %s, return %d", msg, ret);
139         cyassl_log(LEAVE_LOG , buffer);
140     }
141 }
142
143
144 void CYASSL_ERROR(int error)
145 {
146     if (loggingEnabled) {
147         char buffer[80];
148         sprintf(buffer, "CyaSSL error occured, error = %d", error);
149         cyassl_log(ERROR_LOG , buffer);
150     }
151 }
152
153 #endif  /* DEBUG_CYASSL */