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