]> git.saurik.com Git - apple/security.git/blob - SecureTransport/privateInc/sslDebug.h
Security-29.tar.gz
[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
46 #if !LOG_VIA_PRINTF
47
48 #error Hey, figure out a debug mechanism
49
50 #include <string.h>
51 #include <CoreServices/../Frameworks/CarbonCore.framework/Headers/MacTypes.h>
52 #include <TextUtils.h>
53
54 /* common log macros */
55
56 /* remaining ones can take constant strings */
57
58 #ifdef __cplusplus
59 extern "C" {
60 #endif
61
62 extern void dblog0(char *str);
63 extern void dblog1(char *str, void * arg1);
64 extern void dblog2(char *str, void * arg1, void * arg2);
65 extern void dblog3(char *str, void * arg1, void * arg2, void * arg3);
66 extern void dblog4(char *str, void * arg1, void * arg2, void * arg3, void * arg4);
67
68 #ifdef __cplusplus
69 }
70 #endif
71
72
73 #else /* LOG_VIA_PRINTF */
74
75 #define dblog0(str) printf(str)
76 #define dblog1(str, arg1) printf(str, arg1)
77 #define dblog2(str, arg1, arg2) printf(str, arg1, arg2)
78 #define dblog3(str, arg1, arg2, arg3) printf(str, arg1, arg2, arg3)
79 #define dblog4(str, arg1, arg2, arg3, arg4) printf(str, arg1, arg2, arg3, arg4)
80
81 #endif /* LOG_VIA_PRINTF */
82
83 #else /* log macros disabled */
84
85 #define dblog0(str)
86 #define dblog1(str, arg1)
87 #define dblog2(str, arg1, arg2)
88 #define dblog3(str, arg1, arg2, arg3)
89 #define dblog4(str, arg1, arg2, arg3, arg4)
90
91 #endif /* SSL_DEBUG || ERROR_LOG_ENABLE */
92
93 #if SSL_DEBUG
94
95 #define dprintf0(str) dblog0(str)
96 #define dprintf1(str, arg1) dblog1(str, arg1)
97 #define dprintf2(str, arg1, arg2) dblog2(str, arg1, arg2)
98 #define dprintf3(str, arg1, arg2, arg3) dblog3(str, arg1, arg2, arg3)
99 #define dprintf4(str, arg1, arg2, arg3, arg4) dblog4(str, arg1, arg2, arg3, arg4)
100
101 #ifdef __cplusplus
102 extern "C" {
103 #endif
104
105 static inline volatile void sslPanic(const char *str)
106 {
107 printf(str);
108 exit(1);
109 }
110
111 #ifdef __cplusplus
112 }
113 #endif
114
115 #define CASSERT(expression) \
116 ((expression) ? (void)0 : \
117 (dprintf1 ("Assertion failed: " #expression \
118 ", file " __FILE__ ", line %d.\n", __LINE__), \
119 sslPanic("Assertion Failure")))
120
121 #else /* SSL_DEBUG */
122
123 #define dprintf0(str)
124 #define dprintf1(str, arg1)
125 #define dprintf2(str, arg1, arg2)
126 #define dprintf3(str, arg1, arg2, arg3)
127 #define dprintf4(str, arg1, arg2, arg3, arg4)
128
129 #define CASSERT(expression)
130 #define sslPanic(s)
131 #endif /* SSL_DEBUG */
132
133 /*
134 * Error logging. This may well be platform dependent.
135 */
136 #if ERROR_LOG_ENABLE
137 #define errorLog0(str) dblog0(str);
138 #define errorLog1(str, arg1) dblog1(str, arg1)
139 #define errorLog2(str, arg1, arg2) dblog2(str, arg1, arg2)
140 #define errorLog3(str, arg1, arg2, arg3) dblog3(str, arg1, arg2, arg3)
141 #define errorLog4(str, arg1, arg2, arg3, arg4) dblog4(str, arg1, arg2, arg3, arg4)
142
143 #else /* ERROR_LOG_ENABLE */
144
145 #define errorLog0(str)
146 #define errorLog1(str, arg1)
147 #define errorLog2(str, arg1, arg2)
148 #define errorLog3(str, arg1, arg2, arg3)
149 #define errorLog4(str, arg1, arg2, arg3, arg4)
150
151 #endif /* ERROR_LOG_ENABLE */
152
153 /*
154 * Override SSLRef macros
155 */
156 #define ERR(x) (x)
157 #define DUMP_BUFFER_NAME(name, buf)
158 #define DUMP_DATA_NAME(name, p, len)
159 #define ASSERTMSG(m) sslPanic(m)
160 #define DEBUGVAL1(str, arg) errorLog1(str, arg)
161
162 /*** SSL-Specific debugging ***/
163
164 #ifndef _SSLCTX_H_
165 #include "sslctx.h"
166 #endif
167
168 /* Logging Enable Flags */
169
170 #if SSL_DEBUG
171
172 /* log changes in handshake state */
173 #define LOG_HDSK_STATE 0
174
175 /* log handshake messages */
176 #define LOG_HDSK_MSG 0
177
178 /* log negotiated handshake paramters */
179 #define LOG_NEGOTIATE 0
180
181 /* log received protocol messsages */
182 #define LOG_RX_PROTOCOL 0
183
184 #else /* !SSL_DEBUG - normal build - all flags disabled */
185 #define LOG_HDSK_STATE 0
186 #define LOG_HDSK_MSG 0
187 #define LOG_NEGOTIATE 0
188 #endif /* SSL_DEBUG */
189
190 #if LOG_HDSK_STATE
191 extern void SSLChangeHdskState(SSLContext *ctx, SSLHandshakeState newState);
192 #else /* LOG_HDSK_STATE */
193 #define SSLChangeHdskState(ctx, newState) { ctx->state=newState; }
194 #endif /* LOG_HDSK_STATE */
195
196 #if LOG_HDSK_MSG
197 extern void SSLLogHdskMsg(SSLHandshakeType msg, char sent);
198 extern char *hdskStateToStr(SSLHandshakeState state);
199 #else /* LOG_HDSK_STATE */
200 #define SSLLogHdskMsg(msg, sent)
201 #endif /* LOG_HDSK_STATE */
202
203 /*
204 * A crufty little routine to write cert blobs to disk.
205 * Implemented in appleCdsa.c.
206 */
207 #if SSL_DEBUG
208 extern void writeBufBlob(const SSLBuffer *blob,
209 const char *fileName);
210 #endif
211
212 #endif /* _SSL_DEBUG_H_ */