logging.h
Go to the documentation of this file.
1 /* logging.h
2  *
3  * Copyright (C) 2006-2020 wolfSSL Inc.
4  *
5  * This file is part of wolfSSL.
6  *
7  * wolfSSL 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  * wolfSSL 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-1335, USA
20  */
21 
27 /* submitted by eof */
28 
29 
30 #ifndef WOLFSSL_LOGGING_H
31 #define WOLFSSL_LOGGING_H
32 
34 
35 #ifdef __cplusplus
36  extern "C" {
37 #endif
38 
39 
40 enum wc_LogLevels {
41  ERROR_LOG = 0,
42  INFO_LOG,
43  ENTER_LOG,
44  LEAVE_LOG,
45  OTHER_LOG
46 };
47 
48 #ifdef WOLFSSL_FUNC_TIME
49 /* WARNING: This code is only to be used for debugging performance.
50  * The code is not thread-safe.
51  * Do not use WOLFSSL_FUNC_TIME in production code.
52  */
53 enum wc_FuncNum {
54  WC_FUNC_HELLO_REQUEST_SEND = 0,
55  WC_FUNC_HELLO_REQUEST_DO,
56  WC_FUNC_CLIENT_HELLO_SEND,
57  WC_FUNC_CLIENT_HELLO_DO,
58  WC_FUNC_SERVER_HELLO_SEND,
59  WC_FUNC_SERVER_HELLO_DO,
60  WC_FUNC_ENCRYPTED_EXTENSIONS_SEND,
61  WC_FUNC_ENCRYPTED_EXTENSIONS_DO,
62  WC_FUNC_CERTIFICATE_REQUEST_SEND,
63  WC_FUNC_CERTIFICATE_REQUEST_DO,
64  WC_FUNC_CERTIFICATE_SEND,
65  WC_FUNC_CERTIFICATE_DO,
66  WC_FUNC_CERTIFICATE_VERIFY_SEND,
67  WC_FUNC_CERTIFICATE_VERIFY_DO,
68  WC_FUNC_FINISHED_SEND,
69  WC_FUNC_FINISHED_DO,
70  WC_FUNC_KEY_UPDATE_SEND,
71  WC_FUNC_KEY_UPDATE_DO,
72  WC_FUNC_EARLY_DATA_SEND,
73  WC_FUNC_EARLY_DATA_DO,
74  WC_FUNC_NEW_SESSION_TICKET_SEND,
75  WC_FUNC_NEW_SESSION_TICKET_DO,
76  WC_FUNC_SERVER_HELLO_DONE_SEND,
77  WC_FUNC_SERVER_HELLO_DONE_DO,
78  WC_FUNC_TICKET_SEND,
79  WC_FUNC_TICKET_DO,
80  WC_FUNC_CLIENT_KEY_EXCHANGE_SEND,
81  WC_FUNC_CLIENT_KEY_EXCHANGE_DO,
82  WC_FUNC_CERTIFICATE_STATUS_SEND,
83  WC_FUNC_CERTIFICATE_STATUS_DO,
84  WC_FUNC_SERVER_KEY_EXCHANGE_SEND,
85  WC_FUNC_SERVER_KEY_EXCHANGE_DO,
86  WC_FUNC_END_OF_EARLY_DATA_SEND,
87  WC_FUNC_END_OF_EARLY_DATA_DO,
88  WC_FUNC_COUNT
89 };
90 #endif
91 
92 typedef void (*wolfSSL_Logging_cb)(const int logLevel,
93  const char *const logMessage);
94 
95 WOLFSSL_API int wolfSSL_SetLoggingCb(wolfSSL_Logging_cb log_function);
96 WOLFSSL_API wolfSSL_Logging_cb wolfSSL_GetLoggingCb(void);
97 
98 /* turn logging on, only if compiled in */
99 WOLFSSL_API int wolfSSL_Debugging_ON(void);
100 /* turn logging off */
101 WOLFSSL_API void wolfSSL_Debugging_OFF(void);
102 
103 
104 #if defined(OPENSSL_EXTRA) || defined(DEBUG_WOLFSSL_VERBOSE)
105  WOLFSSL_LOCAL int wc_LoggingInit(void);
106  WOLFSSL_LOCAL int wc_LoggingCleanup(void);
107  WOLFSSL_LOCAL int wc_AddErrorNode(int error, int line, char* buf,
108  char* file);
109  WOLFSSL_LOCAL int wc_PeekErrorNode(int index, const char **file,
110  const char **reason, int *line);
111  WOLFSSL_LOCAL void wc_RemoveErrorNode(int index);
112  WOLFSSL_LOCAL void wc_ClearErrorNodes(void);
113  WOLFSSL_LOCAL int wc_PullErrorNode(const char **file, const char **reason,
114  int *line);
115  WOLFSSL_API int wc_SetLoggingHeap(void* h);
116  WOLFSSL_API int wc_ERR_remove_state(void);
117  #if !defined(NO_FILESYSTEM) && !defined(NO_STDIO_FILESYSTEM)
118  WOLFSSL_API void wc_ERR_print_errors_fp(XFILE fp);
119  WOLFSSL_API void wc_ERR_print_errors_cb(int (*cb)(const char *str,
120  size_t len, void *u), void *u);
121  #endif
122 #endif /* OPENSSL_EXTRA || DEBUG_WOLFSSL_VERBOSE */
123 
124 #ifdef WOLFSSL_FUNC_TIME
125  /* WARNING: This code is only to be used for debugging performance.
126  * The code is not thread-safe.
127  * Do not use WOLFSSL_FUNC_TIME in production code.
128  */
129  WOLFSSL_API void WOLFSSL_START(int funcNum);
130  WOLFSSL_API void WOLFSSL_END(int funcNum);
131  WOLFSSL_API void WOLFSSL_TIME(int count);
132 #else
133  #define WOLFSSL_START(n)
134  #define WOLFSSL_END(n)
135  #define WOLFSSL_TIME(n)
136 #endif
137 
138 #if defined(DEBUG_WOLFSSL) && !defined(WOLFSSL_DEBUG_ERRORS_ONLY)
139  #if defined(_WIN32)
140  #if defined(INTIME_RTOS)
141  #define __func__ NULL
142  #else
143  #define __func__ __FUNCTION__
144  #endif
145  #endif
146 
147  /* a is prepended to m and b is appended, creating a log msg a + m + b */
148  #define WOLFSSL_LOG_CAT(a, m, b) #a " " m " " #b
149 
150  WOLFSSL_API void WOLFSSL_ENTER(const char* msg);
151  WOLFSSL_API void WOLFSSL_LEAVE(const char* msg, int ret);
152  #define WOLFSSL_STUB(m) \
153  WOLFSSL_MSG(WOLFSSL_LOG_CAT(wolfSSL Stub, m, not implemented))
154  WOLFSSL_API int WOLFSSL_IS_DEBUG_ON(void);
155 
156  WOLFSSL_API void WOLFSSL_MSG(const char* msg);
157  WOLFSSL_API void WOLFSSL_BUFFER(const byte* buffer, word32 length);
158 
159 #else
160 
161  #define WOLFSSL_ENTER(m)
162  #define WOLFSSL_LEAVE(m, r)
163  #define WOLFSSL_STUB(m)
164  #define WOLFSSL_IS_DEBUG_ON() 0
165 
166  #define WOLFSSL_MSG(m)
167  #define WOLFSSL_BUFFER(b, l)
168 
169 #endif /* DEBUG_WOLFSSL && !WOLFSSL_DEBUG_ERRORS_ONLY */
170 
171 #if defined(DEBUG_WOLFSSL) || defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) ||\
172  defined(WOLFSSL_HAPROXY) || defined(OPENSSL_EXTRA)
173 
174  #if (!defined(NO_ERROR_QUEUE) && defined(OPENSSL_EXTRA) && !defined(_WIN32))\
175  || defined(DEBUG_WOLFSSL_VERBOSE)
176  WOLFSSL_API void WOLFSSL_ERROR_LINE(int err, const char* func, unsigned int line,
177  const char* file, void* ctx);
178  #define WOLFSSL_ERROR(x) \
179  WOLFSSL_ERROR_LINE((x), __func__, __LINE__, __FILE__, NULL)
180  #else
181  WOLFSSL_API void WOLFSSL_ERROR(int err);
182  #endif
183  WOLFSSL_API void WOLFSSL_ERROR_MSG(const char* msg);
184 
185 #else
186  #define WOLFSSL_ERROR(e)
187  #define WOLFSSL_ERROR_MSG(m)
188 #endif
189 
190 #ifdef __cplusplus
191 }
192 #endif
193 #endif /* WOLFSSL_LOGGING_H */
194 
WOLFSSL_API void wolfSSL_Debugging_OFF(void)
This function turns off runtime logging messages. If they’re already off, no action is taken...
Definition: logging.c:165
WOLFSSL_API int wolfSSL_Debugging_ON(void)
If logging has been enabled at build time this function turns on logging at runtime. To enable logging at build time use –enable-debug or define DEBUG_WOLFSSL.
Definition: logging.c:151
WOLFSSL_API int wolfSSL_SetLoggingCb(wolfSSL_Logging_cb log_function)
This function registers a logging callback that will be used to handle the wolfSSL log message...
Definition: logging.c:129