]> git.saurik.com Git - apple/security.git/blob - SecureTransport/privateInc/sslDebug.h
f6912cf44407ad1cd8af343ecf406608e394bc23
[apple/security.git] / SecureTransport / privateInc / sslDebug.h
1 /*
2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
3 *
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
8 * using this file.
9 *
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
16 */
17
18
19 /*
20 File: sslDebug.h
21
22 Contains: Debugging macros.
23
24 Written by: Doug Mitchell
25
26 Copyright: (c) 1998, 1999 by Apple Computer, Inc., all rights reserved.
27
28 Change History (most recent first):
29
30 03/10/98 dpm Created.
31
32 */
33
34 #ifndef _SSL_DEBUG_H_
35 #define _SSL_DEBUG_H_
36
37 #include "sslBuildFlags.h"
38
39 #if SSL_DEBUG || ERROR_LOG_ENABLE
40
41 /* any other way? */
42 #define LOG_VIA_PRINTF 1
43
44 #include <stdio.h>
45 #include <stdlib.h>
46
47 #if !LOG_VIA_PRINTF
48
49 #error Hey, figure out a debug mechanism
50
51 #include <string.h>
52 #include <CoreServices/../Frameworks/CarbonCore.framework/Headers/MacTypes.h>
53 #include <TextUtils.h>
54
55 /* common log macros */
56
57 /* remaining ones can take constant strings */
58
59 #ifdef __cplusplus
60 extern "C" {
61 #endif
62
63 extern void dblog0(char *str);
64 extern void dblog1(char *str, void * arg1);
65 extern void dblog2(char *str, void * arg1, void * arg2);
66 extern void dblog3(char *str, void * arg1, void * arg2, void * arg3);
67 extern void dblog4(char *str, void * arg1, void * arg2, void * arg3, void * arg4);
68
69 #ifdef __cplusplus
70 }
71 #endif
72
73
74 #else /* LOG_VIA_PRINTF */
75
76 #define dblog0(str) printf(str)
77 #define dblog1(str, arg1) printf(str, arg1)
78 #define dblog2(str, arg1, arg2) printf(str, arg1, arg2)
79 #define dblog3(str, arg1, arg2, arg3) printf(str, arg1, arg2, arg3)
80 #define dblog4(str, arg1, arg2, arg3, arg4) printf(str, arg1, arg2, arg3, arg4)
81
82 #endif /* LOG_VIA_PRINTF */
83
84 #else /* log macros disabled */
85
86 #define dblog0(str)
87 #define dblog1(str, arg1)
88 #define dblog2(str, arg1, arg2)
89 #define dblog3(str, arg1, arg2, arg3)
90 #define dblog4(str, arg1, arg2, arg3, arg4)
91
92 #endif /* SSL_DEBUG || ERROR_LOG_ENABLE */
93
94 #if SSL_DEBUG
95
96 #define dprintf0(str) dblog0(str)
97 #define dprintf1(str, arg1) dblog1(str, arg1)
98 #define dprintf2(str, arg1, arg2) dblog2(str, arg1, arg2)
99 #define dprintf3(str, arg1, arg2, arg3) dblog3(str, arg1, arg2, arg3)
100 #define dprintf4(str, arg1, arg2, arg3, arg4) dblog4(str, arg1, arg2, arg3, arg4)
101
102 #ifdef __cplusplus
103 extern "C" {
104 #endif
105
106 static inline volatile void sslPanic(const char *str)
107 {
108 printf(str);
109 exit(1);
110 }
111
112 #ifdef __cplusplus
113 }
114 #endif
115
116 #define CASSERT(expression) \
117 ((expression) ? (void)0 : \
118 (dprintf1 ("Assertion failed: " #expression \
119 ", file " __FILE__ ", line %d.\n", __LINE__), \
120 sslPanic("Assertion Failure")))
121
122 #else /* SSL_DEBUG */
123
124 #define dprintf0(str)
125 #define dprintf1(str, arg1)
126 #define dprintf2(str, arg1, arg2)
127 #define dprintf3(str, arg1, arg2, arg3)
128 #define dprintf4(str, arg1, arg2, arg3, arg4)
129
130 #define CASSERT(expression)
131 #define sslPanic(s)
132 #endif /* SSL_DEBUG */
133
134 /*
135 * Error logging. This may well be platform dependent.
136 */
137 #if ERROR_LOG_ENABLE
138 #define errorLog0(str) dblog0(str);
139 #define errorLog1(str, arg1) dblog1(str, arg1)
140 #define errorLog2(str, arg1, arg2) dblog2(str, arg1, arg2)
141 #define errorLog3(str, arg1, arg2, arg3) dblog3(str, arg1, arg2, arg3)
142 #define errorLog4(str, arg1, arg2, arg3, arg4) dblog4(str, arg1, arg2, arg3, arg4)
143
144 #else /* ERROR_LOG_ENABLE */
145
146 #define errorLog0(str)
147 #define errorLog1(str, arg1)
148 #define errorLog2(str, arg1, arg2)
149 #define errorLog3(str, arg1, arg2, arg3)
150 #define errorLog4(str, arg1, arg2, arg3, arg4)
151
152 #endif /* ERROR_LOG_ENABLE */
153
154 /*
155 * Override SSLRef macros
156 */
157 #define ERR(x) (x)
158 #define DUMP_BUFFER_NAME(name, buf)
159 #define DUMP_DATA_NAME(name, p, len)
160 #define ASSERTMSG(m) sslPanic(m)
161 #define DEBUGVAL1(str, arg) errorLog1(str, arg)
162
163 /*** SSL-Specific debugging ***/
164
165 #ifndef _SSLCTX_H_
166 #include "sslctx.h"
167 #endif
168
169 /* Logging Enable Flags */
170
171 #if SSL_DEBUG
172
173 /* log changes in handshake state */
174 #define LOG_HDSK_STATE 0
175
176 /* log handshake messages */
177 #define LOG_HDSK_MSG 0
178
179 /* log negotiated handshake parameters */
180 #define LOG_NEGOTIATE 0
181
182 /* log received protocol messsages */
183 #define LOG_RX_PROTOCOL 0
184
185 /* log resumable session info */
186 #define LOG_RESUM_SESSION 0
187
188 #else /* !SSL_DEBUG - normal build - all flags disabled */
189 #define LOG_HDSK_STATE 0
190 #define LOG_HDSK_MSG 0
191 #define LOG_NEGOTIATE 0
192 #define LOG_RX_PROTOCOL 0
193 #define LOG_RESUM_SESSION 0
194 #endif /* SSL_DEBUG */
195
196 #if LOG_HDSK_STATE
197 extern void SSLChangeHdskState(SSLContext *ctx, SSLHandshakeState newState);
198 #else /* LOG_HDSK_STATE */
199 #define SSLChangeHdskState(ctx, newState) { ctx->state=newState; }
200 #endif /* LOG_HDSK_STATE */
201
202 #if LOG_HDSK_MSG
203 extern void SSLLogHdskMsg(SSLHandshakeType msg, char sent);
204 extern char *hdskStateToStr(SSLHandshakeState state);
205 #else /* LOG_HDSK_STATE */
206 #define SSLLogHdskMsg(msg, sent)
207 #endif /* LOG_HDSK_STATE */
208
209 #if LOG_RESUM_SESSION
210 #define SSLLogResumSess(m) printf(m)
211 #else
212 #define SSLLogResumSess(m)
213 #endif /* LOG_RESUM_SESSION */
214
215 /*
216 * A crufty little routine to write cert blobs to disk.
217 * Implemented in appleCdsa.c.
218 */
219 #if SSL_DEBUG
220 extern void writeBufBlob(const SSLBuffer *blob,
221 const char *fileName);
222 #endif
223
224 #endif /* _SSL_DEBUG_H_ */