]> git.saurik.com Git - apple/mdnsresponder.git/blob - mDNSCore/mDNSDebug.h
mDNSResponder-170.tar.gz
[apple/mdnsresponder.git] / mDNSCore / mDNSDebug.h
1 /* -*- Mode: C; tab-width: 4 -*-
2 *
3 * Copyright (c) 2002-2003 Apple Computer, Inc. All rights reserved.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16
17 Change History (most recent first):
18
19 $Log: mDNSDebug.h,v $
20 Revision 1.38 2007/12/13 20:27:07 cheshire
21 Remove unused VerifySameNameAssumptions symbol
22
23 Revision 1.37 2007/12/01 00:33:17 cheshire
24 Fixes from Bob Bradley for building on EFI
25
26 Revision 1.36 2007/10/01 19:06:19 cheshire
27 Defined symbolic constant MDNS_LOG_INITIAL_LEVEL to set the logging level we start out at
28
29 Revision 1.35 2007/07/27 20:19:56 cheshire
30 For now, comment out unused log levels MDNS_LOG_ERROR, MDNS_LOG_WARN, MDNS_LOG_INFO, MDNS_LOG_DEBUG
31
32 Revision 1.34 2007/07/24 17:23:33 cheshire
33 <rdar://problem/5357133> Add list validation checks for debugging
34
35 Revision 1.33 2007/06/15 21:54:50 cheshire
36 <rdar://problem/4883206> Add packet logging to help debugging private browsing over TLS
37
38 Revision 1.32 2007/05/25 16:03:03 cheshire
39 Remove unused LogMalloc
40
41 Revision 1.31 2007/04/06 19:50:05 cheshire
42 Add ProgramName declaration
43
44 Revision 1.30 2007/03/24 01:22:44 cheshire
45 Add validator for uDNS data structures
46
47 Revision 1.29 2006/08/14 23:24:23 cheshire
48 Re-licensed mDNSResponder daemon source code under Apache License, Version 2.0
49
50 Revision 1.28 2006/07/07 01:09:09 cheshire
51 <rdar://problem/4472013> Add Private DNS server functionality to dnsextd
52 Only use mallocL/freeL debugging routines when building mDNSResponder, not dnsextd
53
54 Revision 1.27 2006/06/29 07:42:14 cheshire
55 <rdar://problem/3922989> Performance: Remove unnecessary SameDomainName() checks
56
57 Revision 1.26 2005/07/04 22:40:26 cheshire
58 Additional debugging code to help catch memory corruption
59
60 Revision 1.25 2004/12/14 21:34:16 cheshire
61 Add "#define ANSWER_REMOTE_HOSTNAME_QUERIES 0" and comment
62
63 Revision 1.24 2004/09/16 01:58:21 cheshire
64 Fix compiler warnings
65
66 Revision 1.23 2004/05/18 23:51:25 cheshire
67 Tidy up all checkin comments to use consistent "<rdar://problem/xxxxxxx>" format for bug numbers
68
69 Revision 1.22 2004/04/22 04:27:42 cheshire
70 Spacing tidyup
71
72 Revision 1.21 2004/04/14 23:21:41 ksekar
73 Removed accidental checkin of MALLOC_DEBUGING flag in 1.20
74
75 Revision 1.20 2004/04/14 23:09:28 ksekar
76 Support for TSIG signed dynamic updates.
77
78 Revision 1.19 2004/03/15 18:57:59 cheshire
79 Undo last checkin that accidentally made verbose debugging the default for all targets
80
81 Revision 1.18 2004/03/13 01:57:33 ksekar
82 <rdar://problem/3192546>: DynDNS: Dynamic update of service records
83
84 Revision 1.17 2004/01/28 21:14:23 cheshire
85 Reconcile debug_mode and gDebugLogging into a single flag (mDNS_DebugMode)
86
87 Revision 1.16 2003/12/09 01:30:06 rpantos
88 Fix usage of ARGS... macros to build properly on Windows.
89
90 Revision 1.15 2003/12/08 20:55:26 rpantos
91 Move some definitions here from mDNSMacOSX.h.
92
93 Revision 1.14 2003/08/12 19:56:24 cheshire
94 Update to APSL 2.0
95
96 Revision 1.13 2003/07/02 21:19:46 cheshire
97 <rdar://problem/3313413> Update copyright notices, etc., in source code comments
98
99 Revision 1.12 2003/05/26 03:01:27 cheshire
100 <rdar://problem/3268904> sprintf/vsprintf-style functions are unsafe; use snprintf/vsnprintf instead
101
102 Revision 1.11 2003/05/21 17:48:10 cheshire
103 Add macro to enable GCC's printf format string checking
104
105 Revision 1.10 2003/04/26 02:32:57 cheshire
106 Add extern void LogMsg(const char *format, ...);
107
108 Revision 1.9 2002/09/21 20:44:49 zarzycki
109 Added APSL info
110
111 Revision 1.8 2002/09/19 04:20:43 cheshire
112 Remove high-ascii characters that confuse some systems
113
114 Revision 1.7 2002/09/16 18:41:42 cheshire
115 Merge in license terms from Quinn's copy, in preparation for Darwin release
116
117 */
118
119 #ifndef __mDNSDebug_h
120 #define __mDNSDebug_h
121
122 // Set MDNS_DEBUGMSGS to 0 to optimize debugf() calls out of the compiled code
123 // Set MDNS_DEBUGMSGS to 1 to generate normal debugging messages
124 // Set MDNS_DEBUGMSGS to 2 to generate verbose debugging messages
125 // MDNS_DEBUGMSGS is normally set in the project options (or makefile) but can also be set here if desired
126 // (If you edit the file here to turn on MDNS_DEBUGMSGS while you're debugging some code, be careful
127 // not to accidentally check-in that change by mistake when you check in your other changes.)
128
129 //#undef MDNS_DEBUGMSGS
130 //#define MDNS_DEBUGMSGS 2
131
132 // Set MDNS_CHECK_PRINTF_STYLE_FUNCTIONS to 1 to enable extra GCC compiler warnings
133 // Note: You don't normally want to do this, because it generates a bunch of
134 // spurious warnings for the following custom extensions implemented by mDNS_vsnprintf:
135 // warning: `#' flag used with `%s' printf format (for %#s -- pascal string format)
136 // warning: repeated `#' flag in format (for %##s -- DNS name string format)
137 // warning: double format, pointer arg (arg 2) (for %.4a, %.16a, %#a -- IP address formats)
138 #define MDNS_CHECK_PRINTF_STYLE_FUNCTIONS 0
139 #if MDNS_CHECK_PRINTF_STYLE_FUNCTIONS
140 #define IS_A_PRINTF_STYLE_FUNCTION(F,A) __attribute__ ((format(printf,F,A)))
141 #else
142 #define IS_A_PRINTF_STYLE_FUNCTION(F,A)
143 #endif
144
145 #ifdef __cplusplus
146 extern "C" {
147 #endif
148
149 // Variable argument macro support. Use ANSI C99 __VA_ARGS__ where possible. Otherwise, use the next best thing.
150
151 #if (defined(__GNUC__))
152 #if ((__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 2)))
153 #define MDNS_C99_VA_ARGS 1
154 #define MDNS_GNU_VA_ARGS 0
155 #else
156 #define MDNS_C99_VA_ARGS 0
157 #define MDNS_GNU_VA_ARGS 1
158 #endif
159 #define MDNS_HAS_VA_ARG_MACROS 1
160 #elif (_MSC_VER >= 1400) // Visual Studio 2005 and later
161 #define MDNS_C99_VA_ARGS 1
162 #define MDNS_GNU_VA_ARGS 0
163 #define MDNS_HAS_VA_ARG_MACROS 1
164 #elif (defined(__MWERKS__))
165 #define MDNS_C99_VA_ARGS 1
166 #define MDNS_GNU_VA_ARGS 0
167 #define MDNS_HAS_VA_ARG_MACROS 1
168 #else
169 #define MDNS_C99_VA_ARGS 0
170 #define MDNS_GNU_VA_ARGS 0
171 #define MDNS_HAS_VA_ARG_MACROS 0
172 #endif
173
174 #if MDNS_DEBUGMSGS
175 #define debugf debugf_
176 extern void debugf_(const char *format, ...) IS_A_PRINTF_STYLE_FUNCTION(1,2);
177 #else // If debug breaks are off, use a preprocessor trick to optimize those calls out of the code
178 #if (MDNS_C99_VA_ARGS)
179 #define debugf( ... ) ((void)0)
180 #elif (MDNS_GNU_VA_ARGS)
181 #define debugf( ARGS... ) ((void)0)
182 #else
183 #define debugf 1 ? ((void)0) : (void)
184 #endif
185 #endif
186
187 #if MDNS_DEBUGMSGS > 1
188 #define verbosedebugf verbosedebugf_
189 extern void verbosedebugf_(const char *format, ...) IS_A_PRINTF_STYLE_FUNCTION(1,2);
190 #else
191 #if (MDNS_C99_VA_ARGS)
192 #define verbosedebugf( ... ) ((void)0)
193 #elif (MDNS_GNU_VA_ARGS)
194 #define verbosedebugf( ARGS... ) ((void)0)
195 #else
196 #define verbosedebugf 1 ? ((void)0) : (void)
197 #endif
198 #endif
199
200 // LogMsg is used even in shipping code, to write truly serious error messages to syslog (or equivalent)
201 typedef enum
202 {
203 MDNS_LOG_NONE,
204 // MDNS_LOG_ERROR,
205 // MDNS_LOG_WARN,
206 // MDNS_LOG_INFO,
207 // MDNS_LOG_DEBUG,
208 MDNS_LOG_VERBOSE_DEBUG
209 } LogLevel_t;
210
211 #define MDNS_LOG_INITIAL_LEVEL MDNS_LOG_NONE
212
213 extern LogLevel_t mDNS_LogLevel;
214 extern int mDNS_DebugMode; // If non-zero, LogMsg() writes to stderr instead of syslog
215 extern const char ProgramName[]; // Program Name for use with LogMsgIdent
216
217 extern void LogMsg(const char *format, ...) IS_A_PRINTF_STYLE_FUNCTION(1,2);
218 extern void LogMsgIdent(const char *ident, const char *format, ...) IS_A_PRINTF_STYLE_FUNCTION(2,3);
219 extern void LogMsgNoIdent(const char *format, ...) IS_A_PRINTF_STYLE_FUNCTION(1,2);
220 extern void SigLogLevel(void);
221
222 // Set this symbol to 1 to answer remote queries for our Address, reverse mapping PTR, and HINFO records
223 #define ANSWER_REMOTE_HOSTNAME_QUERIES 0
224
225 // Set this symbol to 1 to do extra debug checks on malloc() and free()
226 // Set this symbol to 2 to write a log message for every malloc() and free()
227 #define MACOSX_MDNS_MALLOC_DEBUGGING 0
228
229 #if APPLE_OSX_mDNSResponder && MACOSX_MDNS_MALLOC_DEBUGGING >= 1
230 extern void *mallocL(char *msg, unsigned int size);
231 extern void freeL(char *msg, void *x);
232 extern void LogMemCorruption(const char *format, ...);
233 extern void uds_validatelists(void);
234 extern void udns_validatelists(void *const v);
235 #else
236 #define mallocL(X,Y) malloc(Y)
237 #define freeL(X,Y) free(Y)
238 #endif
239
240 #define LogAllOperations 0
241
242 #if LogAllOperations
243 #define LogOperation LogMsg
244 #else
245 #define LogOperation debugf
246 #endif
247
248 #define ForceAlerts 0
249
250 #ifdef __cplusplus
251 }
252 #endif
253
254 #endif