]> git.saurik.com Git - apple/mdnsresponder.git/blame - mDNSCore/mDNSDebug.h
mDNSResponder-320.18.tar.gz
[apple/mdnsresponder.git] / mDNSCore / mDNSDebug.h
CommitLineData
67c8f8a1
A
1/* -*- Mode: C; tab-width: 4 -*-
2 *
c9b9ae52
A
3 * Copyright (c) 2002-2003 Apple Computer, Inc. All rights reserved.
4 *
67c8f8a1
A
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
c9b9ae52 8 *
67c8f8a1 9 * http://www.apache.org/licenses/LICENSE-2.0
c9b9ae52 10 *
67c8f8a1
A
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
c9b9ae52 15 * limitations under the License.
263eeeab 16 */
c9b9ae52
A
17
18#ifndef __mDNSDebug_h
19#define __mDNSDebug_h
20
21// Set MDNS_DEBUGMSGS to 0 to optimize debugf() calls out of the compiled code
22// Set MDNS_DEBUGMSGS to 1 to generate normal debugging messages
23// Set MDNS_DEBUGMSGS to 2 to generate verbose debugging messages
24// MDNS_DEBUGMSGS is normally set in the project options (or makefile) but can also be set here if desired
8e92c31c
A
25// (If you edit the file here to turn on MDNS_DEBUGMSGS while you're debugging some code, be careful
26// not to accidentally check-in that change by mistake when you check in your other changes.)
c9b9ae52 27
7f0064bd 28//#undef MDNS_DEBUGMSGS
c9b9ae52
A
29//#define MDNS_DEBUGMSGS 2
30
31// Set MDNS_CHECK_PRINTF_STYLE_FUNCTIONS to 1 to enable extra GCC compiler warnings
32// Note: You don't normally want to do this, because it generates a bunch of
33// spurious warnings for the following custom extensions implemented by mDNS_vsnprintf:
34// warning: `#' flag used with `%s' printf format (for %#s -- pascal string format)
35// warning: repeated `#' flag in format (for %##s -- DNS name string format)
36// warning: double format, pointer arg (arg 2) (for %.4a, %.16a, %#a -- IP address formats)
37#define MDNS_CHECK_PRINTF_STYLE_FUNCTIONS 0
5e65c77f
A
38
39typedef enum
40 {
32bb7e43
A
41 MDNS_LOG_MSG,
42 MDNS_LOG_OPERATION,
43 MDNS_LOG_SPS,
44 MDNS_LOG_INFO,
45 MDNS_LOG_DEBUG,
46 } mDNSLogLevel_t;
5e65c77f
A
47
48// Set this symbol to 1 to answer remote queries for our Address, reverse mapping PTR, and HINFO records
49#define ANSWER_REMOTE_HOSTNAME_QUERIES 0
50
51// Set this symbol to 1 to do extra debug checks on malloc() and free()
52// Set this symbol to 2 to write a log message for every malloc() and free()
32bb7e43
A
53//#define MACOSX_MDNS_MALLOC_DEBUGGING 1
54
55//#define ForceAlerts 1
56//#define LogTimeStamps 1
5e65c77f 57
5e65c77f
A
58// Developer-settings section ends here
59
c9b9ae52
A
60#if MDNS_CHECK_PRINTF_STYLE_FUNCTIONS
61#define IS_A_PRINTF_STYLE_FUNCTION(F,A) __attribute__ ((format(printf,F,A)))
62#else
63#define IS_A_PRINTF_STYLE_FUNCTION(F,A)
64#endif
6528fe3e 65
32bb7e43 66#ifdef __cplusplus
6528fe3e
A
67 extern "C" {
68#endif
69
030b743d
A
70// Variable argument macro support. Use ANSI C99 __VA_ARGS__ where possible. Otherwise, use the next best thing.
71
72#if (defined(__GNUC__))
73 #if ((__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 2)))
32bb7e43
A
74 #define MDNS_C99_VA_ARGS 1
75 #define MDNS_GNU_VA_ARGS 0
030b743d 76 #else
32bb7e43
A
77 #define MDNS_C99_VA_ARGS 0
78 #define MDNS_GNU_VA_ARGS 1
030b743d 79 #endif
32bb7e43 80 #define MDNS_HAS_VA_ARG_MACROS 1
030b743d 81#elif (_MSC_VER >= 1400) // Visual Studio 2005 and later
32bb7e43
A
82 #define MDNS_C99_VA_ARGS 1
83 #define MDNS_GNU_VA_ARGS 0
84 #define MDNS_HAS_VA_ARG_MACROS 1
030b743d 85#elif (defined(__MWERKS__))
32bb7e43
A
86 #define MDNS_C99_VA_ARGS 1
87 #define MDNS_GNU_VA_ARGS 0
88 #define MDNS_HAS_VA_ARG_MACROS 1
030b743d 89#else
32bb7e43
A
90 #define MDNS_C99_VA_ARGS 0
91 #define MDNS_GNU_VA_ARGS 0
92 #define MDNS_HAS_VA_ARG_MACROS 0
030b743d
A
93#endif
94
32bb7e43 95#if (MDNS_HAS_VA_ARG_MACROS)
030b743d 96 #if (MDNS_C99_VA_ARGS)
32bb7e43 97 #define debug_noop( ... ) ((void)0)
263eeeab
A
98 #define LogMsg( ... ) LogMsgWithLevel(MDNS_LOG_MSG, __VA_ARGS__)
99 #define LogOperation( ... ) do { if (mDNS_LoggingEnabled) LogMsgWithLevel(MDNS_LOG_OPERATION, __VA_ARGS__); } while (0)
100 #define LogSPS( ... ) do { if (mDNS_LoggingEnabled) LogMsgWithLevel(MDNS_LOG_SPS, __VA_ARGS__); } while (0)
101 #define LogInfo( ... ) do { if (mDNS_LoggingEnabled) LogMsgWithLevel(MDNS_LOG_INFO, __VA_ARGS__); } while (0)
030b743d 102 #elif (MDNS_GNU_VA_ARGS)
32bb7e43 103 #define debug_noop( ARGS... ) ((void)0)
263eeeab 104 #define LogMsg( ARGS... ) LogMsgWithLevel(MDNS_LOG_MSG, ARGS)
32bb7e43 105 #define LogOperation( ARGS... ) do { if (mDNS_LoggingEnabled) LogMsgWithLevel(MDNS_LOG_OPERATION, ARGS); } while (0)
263eeeab
A
106 #define LogSPS( ARGS... ) do { if (mDNS_LoggingEnabled) LogMsgWithLevel(MDNS_LOG_SPS, ARGS); } while (0)
107 #define LogInfo( ARGS... ) do { if (mDNS_LoggingEnabled) LogMsgWithLevel(MDNS_LOG_INFO, ARGS); } while (0)
6528fe3e 108 #else
32bb7e43 109 #error Unknown variadic macros
6528fe3e 110 #endif
32bb7e43
A
111#else
112 // If your platform does not support variadic macros, you need to define the following variadic functions.
113 // See mDNSShared/mDNSDebug.c for sample implementation
263eeeab 114 #define debug_noop 1 ? (void)0 : (void)
32bb7e43 115 #define LogMsg LogMsg_
263eeeab
A
116 #define LogOperation (mDNS_LoggingEnabled == 0) ? ((void)0) : LogOperation_
117 #define LogSPS (mDNS_LoggingEnabled == 0) ? ((void)0) : LogSPS_
118 #define LogInfo (mDNS_LoggingEnabled == 0) ? ((void)0) : LogInfo_
119 extern void LogMsg_(const char *format, ...) IS_A_PRINTF_STYLE_FUNCTION(1,2);
32bb7e43 120 extern void LogOperation_(const char *format, ...) IS_A_PRINTF_STYLE_FUNCTION(1,2);
263eeeab
A
121 extern void LogSPS_(const char *format, ...) IS_A_PRINTF_STYLE_FUNCTION(1,2);
122 extern void LogInfo_(const char *format, ...) IS_A_PRINTF_STYLE_FUNCTION(1,2);
32bb7e43
A
123#endif
124
125#if MDNS_DEBUGMSGS
126#define debugf debugf_
127extern void debugf_(const char *format, ...) IS_A_PRINTF_STYLE_FUNCTION(1,2);
128#else
129#define debugf debug_noop
6528fe3e
A
130#endif
131
c9b9ae52
A
132#if MDNS_DEBUGMSGS > 1
133#define verbosedebugf verbosedebugf_
134extern void verbosedebugf_(const char *format, ...) IS_A_PRINTF_STYLE_FUNCTION(1,2);
6528fe3e 135#else
32bb7e43 136#define verbosedebugf debug_noop
6528fe3e
A
137#endif
138
32bb7e43
A
139extern int mDNS_LoggingEnabled;
140extern int mDNS_PacketLoggingEnabled;
67c8f8a1 141extern int mDNS_DebugMode; // If non-zero, LogMsg() writes to stderr instead of syslog
32bb7e43 142extern const char ProgramName[];
67c8f8a1 143
32bb7e43 144extern void LogMsgWithLevel(mDNSLogLevel_t logLevel, const char *format, ...) IS_A_PRINTF_STYLE_FUNCTION(2,3);
263eeeab
A
145// LogMsgNoIdent needs to be fixed so that it logs without the ident prefix like it used to
146// (or completely overhauled to use the new "log to a separate file" facility)
32bb7e43 147#define LogMsgNoIdent LogMsg
8e92c31c 148
67c8f8a1 149#if APPLE_OSX_mDNSResponder && MACOSX_MDNS_MALLOC_DEBUGGING >= 1
8e92c31c
A
150extern void *mallocL(char *msg, unsigned int size);
151extern void freeL(char *msg, void *x);
67c8f8a1
A
152extern void LogMemCorruption(const char *format, ...);
153extern void uds_validatelists(void);
154extern void udns_validatelists(void *const v);
8e92c31c
A
155#else
156#define mallocL(X,Y) malloc(Y)
157#define freeL(X,Y) free(Y)
158#endif
159
32bb7e43 160#ifdef __cplusplus
6528fe3e
A
161 }
162#endif
c9b9ae52
A
163
164#endif