xref: /titanic_52/usr/src/cmd/cmd-inet/usr.lib/mdnsd/mDNSDebug.h (revision 3f318a288186db82aae78875c429f248622cf19f)
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.26.2.1  2006/08/29 06:24:22  cheshire
21 Re-licensed mDNSResponder daemon source code under Apache License, Version 2.0
22 
23 Revision 1.26  2005/07/04 22:40:26  cheshire
24 Additional debugging code to help catch memory corruption
25 
26 Revision 1.25  2004/12/14 21:34:16  cheshire
27 Add "#define ANSWER_REMOTE_HOSTNAME_QUERIES 0" and comment
28 
29 Revision 1.24  2004/09/16 01:58:21  cheshire
30 Fix compiler warnings
31 
32 Revision 1.23  2004/05/18 23:51:25  cheshire
33 Tidy up all checkin comments to use consistent "<rdar://problem/xxxxxxx>" format for bug numbers
34 
35 Revision 1.22  2004/04/22 04:27:42  cheshire
36 Spacing tidyup
37 
38 Revision 1.21  2004/04/14 23:21:41  ksekar
39 Removed accidental checkin of MALLOC_DEBUGING flag in 1.20
40 
41 Revision 1.20  2004/04/14 23:09:28  ksekar
42 Support for TSIG signed dynamic updates.
43 
44 Revision 1.19  2004/03/15 18:57:59  cheshire
45 Undo last checkin that accidentally made verbose debugging the default for all targets
46 
47 Revision 1.18  2004/03/13 01:57:33  ksekar
48 <rdar://problem/3192546>: DynDNS: Dynamic update of service records
49 
50 Revision 1.17  2004/01/28 21:14:23  cheshire
51 Reconcile debug_mode and gDebugLogging into a single flag (mDNS_DebugMode)
52 
53 Revision 1.16  2003/12/09 01:30:06  rpantos
54 Fix usage of ARGS... macros to build properly on Windows.
55 
56 Revision 1.15  2003/12/08 20:55:26  rpantos
57 Move some definitions here from mDNSMacOSX.h.
58 
59 Revision 1.14  2003/08/12 19:56:24  cheshire
60 Update to APSL 2.0
61 
62 Revision 1.13  2003/07/02 21:19:46  cheshire
63 <rdar://problem/3313413> Update copyright notices, etc., in source code comments
64 
65 Revision 1.12  2003/05/26 03:01:27  cheshire
66 <rdar://problem/3268904> sprintf/vsprintf-style functions are unsafe; use snprintf/vsnprintf instead
67 
68 Revision 1.11  2003/05/21 17:48:10  cheshire
69 Add macro to enable GCC's printf format string checking
70 
71 Revision 1.10  2003/04/26 02:32:57  cheshire
72 Add extern void LogMsg(const char *format, ...);
73 
74 Revision 1.9  2002/09/21 20:44:49  zarzycki
75 Added APSL info
76 
77 Revision 1.8  2002/09/19 04:20:43  cheshire
78 Remove high-ascii characters that confuse some systems
79 
80 Revision 1.7  2002/09/16 18:41:42  cheshire
81 Merge in license terms from Quinn's copy, in preparation for Darwin release
82 
83 */
84 
85 #pragma ident	"%Z%%M%	%I%	%E% SMI"
86 
87 #ifndef __mDNSDebug_h
88 #define __mDNSDebug_h
89 
90 // Set MDNS_DEBUGMSGS to 0 to optimize debugf() calls out of the compiled code
91 // Set MDNS_DEBUGMSGS to 1 to generate normal debugging messages
92 // Set MDNS_DEBUGMSGS to 2 to generate verbose debugging messages
93 // MDNS_DEBUGMSGS is normally set in the project options (or makefile) but can also be set here if desired
94 // (If you edit the file here to turn on MDNS_DEBUGMSGS while you're debugging some code, be careful
95 // not to accidentally check-in that change by mistake when you check in your other changes.)
96 
97 //#undef MDNS_DEBUGMSGS
98 //#define MDNS_DEBUGMSGS 2
99 
100 // Set MDNS_CHECK_PRINTF_STYLE_FUNCTIONS to 1 to enable extra GCC compiler warnings
101 // Note: You don't normally want to do this, because it generates a bunch of
102 // spurious warnings for the following custom extensions implemented by mDNS_vsnprintf:
103 //    warning: `#' flag used with `%s' printf format    (for %#s              -- pascal string format)
104 //    warning: repeated `#' flag in format              (for %##s             -- DNS name string format)
105 //    warning: double format, pointer arg (arg 2)       (for %.4a, %.16a, %#a -- IP address formats)
106 #define MDNS_CHECK_PRINTF_STYLE_FUNCTIONS 0
107 #if MDNS_CHECK_PRINTF_STYLE_FUNCTIONS
108 #define IS_A_PRINTF_STYLE_FUNCTION(F,A) __attribute__ ((format(printf,F,A)))
109 #else
110 #define IS_A_PRINTF_STYLE_FUNCTION(F,A)
111 #endif
112 
113 #ifdef	__cplusplus
114 	extern "C" {
115 #endif
116 
117 #if MDNS_DEBUGMSGS
118 #define debugf debugf_
119 extern void debugf_(const char *format, ...) IS_A_PRINTF_STYLE_FUNCTION(1,2);
120 #else // If debug breaks are off, use a preprocessor trick to optimize those calls out of the code
121 	#if (defined(__GNUC__))
122 		#define	debugf( ARGS... ) ((void)0)
123 	#elif (defined(__MWERKS__))
124 		#define	debugf( ... )
125 	#else
126 		#define debugf 1 ? ((void)0) : (void)
127 	#endif
128 #endif
129 
130 #if MDNS_DEBUGMSGS > 1
131 #define verbosedebugf verbosedebugf_
132 extern void verbosedebugf_(const char *format, ...) IS_A_PRINTF_STYLE_FUNCTION(1,2);
133 #else
134 	#if (defined(__GNUC__))
135 		#define	verbosedebugf( ARGS... ) ((void)0)
136 	#elif (defined(__MWERKS__))
137 		#define	verbosedebugf( ... )
138 	#else
139 		#define verbosedebugf 1 ? ((void)0) : (void)
140 	#endif
141 #endif
142 
143 // LogMsg is used even in shipping code, to write truly serious error messages to syslog (or equivalent)
144 extern int	mDNS_DebugMode;	// If non-zero, LogMsg() writes to stderr instead of syslog
145 extern void LogMsg(const char *format, ...) IS_A_PRINTF_STYLE_FUNCTION(1,2);
146 extern void LogMsgIdent(const char *ident, const char *format, ...) IS_A_PRINTF_STYLE_FUNCTION(2,3);
147 extern void LogMsgNoIdent(const char *format, ...) IS_A_PRINTF_STYLE_FUNCTION(1,2);
148 
149 // Set this symbol to 1 to answer remote queries for our Address, reverse mapping PTR, and HINFO records
150 #define ANSWER_REMOTE_HOSTNAME_QUERIES 0
151 
152 // Set this symbol to 1 to do extra debug checks on malloc() and free()
153 // Set this symbol to 2 to write a log message for every malloc() and free()
154 #define MACOSX_MDNS_MALLOC_DEBUGGING 0
155 
156 #if MACOSX_MDNS_MALLOC_DEBUGGING >= 1
157 extern void *mallocL(char *msg, unsigned int size);
158 extern void freeL(char *msg, void *x);
159 extern void LogMemCorruption(const char *format, ...);
160 extern void uds_validatelists(void);
161 #else
162 #define mallocL(X,Y) malloc(Y)
163 #define freeL(X,Y) free(Y)
164 #endif
165 
166 #if MACOSX_MDNS_MALLOC_DEBUGGING >= 2
167 #define LogMalloc LogMsg
168 #else
169 	#if (defined( __GNUC__ ))
170 		#define	LogMalloc(ARGS...) ((void)0)
171 	#elif (defined( __MWERKS__ ))
172 		#define	LogMalloc( ... )
173 	#else
174 		#define LogMalloc 1 ? ((void)0) : (void)
175 	#endif
176 #endif
177 
178 #define LogAllOperations 0
179 
180 #if LogAllOperations
181 #define LogOperation LogMsg
182 #else
183 #define	LogOperation debugf
184 #endif
185 
186 #define ForceAlerts 0
187 
188 #ifdef	__cplusplus
189 	}
190 #endif
191 
192 #endif
193