1 | /* logging.h
|
---|
2 | *
|
---|
3 | * Copyright (C) 2006-2017 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 |
|
---|
22 | /*!
|
---|
23 | \file wolfssl/wolfcrypt/logging.h
|
---|
24 | */
|
---|
25 |
|
---|
26 |
|
---|
27 | /* submitted by eof */
|
---|
28 |
|
---|
29 |
|
---|
30 | #ifndef WOLFSSL_LOGGING_H
|
---|
31 | #define WOLFSSL_LOGGING_H
|
---|
32 |
|
---|
33 | #include <wolfssl/wolfcrypt/types.h>
|
---|
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 |
|
---|
97 | /* turn logging on, only if compiled in */
|
---|
98 | WOLFSSL_API int wolfSSL_Debugging_ON(void);
|
---|
99 | /* turn logging off */
|
---|
100 | WOLFSSL_API void wolfSSL_Debugging_OFF(void);
|
---|
101 |
|
---|
102 |
|
---|
103 | #if defined(OPENSSL_EXTRA) || defined(DEBUG_WOLFSSL_VERBOSE)
|
---|
104 | WOLFSSL_LOCAL int wc_LoggingInit(void);
|
---|
105 | WOLFSSL_LOCAL int wc_LoggingCleanup(void);
|
---|
106 | WOLFSSL_LOCAL int wc_AddErrorNode(int error, int line, char* buf,
|
---|
107 | char* file);
|
---|
108 | WOLFSSL_LOCAL int wc_PeekErrorNode(int index, const char **file,
|
---|
109 | const char **reason, int *line);
|
---|
110 | WOLFSSL_LOCAL void wc_RemoveErrorNode(int index);
|
---|
111 | WOLFSSL_LOCAL void wc_ClearErrorNodes(void);
|
---|
112 | WOLFSSL_LOCAL int wc_PullErrorNode(const char **file, const char **reason,
|
---|
113 | int *line);
|
---|
114 | WOLFSSL_API int wc_SetLoggingHeap(void* h);
|
---|
115 | WOLFSSL_API int wc_ERR_remove_state(void);
|
---|
116 | #if !defined(NO_FILESYSTEM) && !defined(NO_STDIO_FILESYSTEM)
|
---|
117 | WOLFSSL_API void wc_ERR_print_errors_fp(XFILE fp);
|
---|
118 | #endif
|
---|
119 | #endif /* OPENSSL_EXTRA || DEBUG_WOLFSSL_VERBOSE */
|
---|
120 |
|
---|
121 | #ifdef WOLFSSL_FUNC_TIME
|
---|
122 | /* WARNING: This code is only to be used for debugging performance.
|
---|
123 | * The code is not thread-safe.
|
---|
124 | * Do not use WOLFSSL_FUNC_TIME in production code.
|
---|
125 | */
|
---|
126 | WOLFSSL_API void WOLFSSL_START(int funcNum);
|
---|
127 | WOLFSSL_API void WOLFSSL_END(int funcNum);
|
---|
128 | WOLFSSL_API void WOLFSSL_TIME(int count);
|
---|
129 | #else
|
---|
130 | #define WOLFSSL_START(n)
|
---|
131 | #define WOLFSSL_END(n)
|
---|
132 | #define WOLFSSL_TIME(n)
|
---|
133 | #endif
|
---|
134 |
|
---|
135 | #if defined(DEBUG_WOLFSSL) && !defined(WOLFSSL_DEBUG_ERRORS_ONLY)
|
---|
136 | #if defined(_WIN32)
|
---|
137 | #if defined(INTIME_RTOS)
|
---|
138 | #define __func__ NULL
|
---|
139 | #else
|
---|
140 | #define __func__ __FUNCTION__
|
---|
141 | #endif
|
---|
142 | #endif
|
---|
143 |
|
---|
144 | /* a is prepended to m and b is appended, creating a log msg a + m + b */
|
---|
145 | #define WOLFSSL_LOG_CAT(a, m, b) #a " " m " " #b
|
---|
146 |
|
---|
147 | WOLFSSL_API void WOLFSSL_ENTER(const char* msg);
|
---|
148 | WOLFSSL_API void WOLFSSL_LEAVE(const char* msg, int ret);
|
---|
149 | #define WOLFSSL_STUB(m) \
|
---|
150 | WOLFSSL_MSG(WOLFSSL_LOG_CAT(wolfSSL Stub, m, not implemented))
|
---|
151 |
|
---|
152 | WOLFSSL_API void WOLFSSL_MSG(const char* msg);
|
---|
153 | WOLFSSL_API void WOLFSSL_BUFFER(const byte* buffer, word32 length);
|
---|
154 |
|
---|
155 | #else
|
---|
156 |
|
---|
157 | #define WOLFSSL_ENTER(m)
|
---|
158 | #define WOLFSSL_LEAVE(m, r)
|
---|
159 | #define WOLFSSL_STUB(m)
|
---|
160 |
|
---|
161 | #define WOLFSSL_MSG(m)
|
---|
162 | #define WOLFSSL_BUFFER(b, l)
|
---|
163 |
|
---|
164 | #endif /* DEBUG_WOLFSSL && !WOLFSSL_DEBUG_ERRORS_ONLY */
|
---|
165 |
|
---|
166 | #if defined(DEBUG_WOLFSSL) || defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) || defined(WOLFSSL_HAPROXY)
|
---|
167 |
|
---|
168 | #if defined(OPENSSL_EXTRA) || defined(DEBUG_WOLFSSL_VERBOSE)
|
---|
169 | WOLFSSL_API void WOLFSSL_ERROR_LINE(int err, const char* func, unsigned int line,
|
---|
170 | const char* file, void* ctx);
|
---|
171 | #define WOLFSSL_ERROR(x) \
|
---|
172 | WOLFSSL_ERROR_LINE((x), __func__, __LINE__, __FILE__, NULL)
|
---|
173 | #else
|
---|
174 | WOLFSSL_API void WOLFSSL_ERROR(int err);
|
---|
175 | #endif
|
---|
176 | WOLFSSL_API void WOLFSSL_ERROR_MSG(const char* msg);
|
---|
177 |
|
---|
178 | #else
|
---|
179 | #define WOLFSSL_ERROR(e)
|
---|
180 | #define WOLFSSL_ERROR_MSG(m)
|
---|
181 | #endif
|
---|
182 |
|
---|
183 | #ifdef __cplusplus
|
---|
184 | }
|
---|
185 | #endif
|
---|
186 | #endif /* WOLFSSL_LOGGING_H */
|
---|
187 |
|
---|