]>
Commit | Line | Data |
---|---|---|
67c8f8a1 A |
1 | /* -*- Mode: C; tab-width: 4 -*- |
2 | * | |
9f221bca | 3 | * Copyright (c) 2002-2015 Apple Inc. All rights reserved. |
c9b9ae52 | 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 | |
83fb1e36 | 8 | * |
67c8f8a1 | 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
83fb1e36 | 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 | |
39 | typedef enum | |
83fb1e36 A |
40 | { |
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 |
83fb1e36 | 67 | extern "C" { |
6528fe3e A |
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__)) | |
83fb1e36 A |
73 | #if ((__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 2))) |
74 | #define MDNS_C99_VA_ARGS 1 | |
75 | #define MDNS_GNU_VA_ARGS 0 | |
76 | #else | |
77 | #define MDNS_C99_VA_ARGS 0 | |
78 | #define MDNS_GNU_VA_ARGS 1 | |
79 | #endif | |
80 | #define MDNS_HAS_VA_ARG_MACROS 1 | |
030b743d | 81 | #elif (_MSC_VER >= 1400) // Visual Studio 2005 and later |
83fb1e36 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__)) |
83fb1e36 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 |
83fb1e36 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) |
83fb1e36 A |
96 | #if (MDNS_C99_VA_ARGS) |
97 | #define debug_noop(... ) ((void)0) | |
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) | |
102 | #elif (MDNS_GNU_VA_ARGS) | |
103 | #define debug_noop( ARGS... ) ((void)0) | |
104 | #define LogMsg( ARGS... ) LogMsgWithLevel(MDNS_LOG_MSG, ARGS) | |
105 | #define LogOperation( ARGS... ) do { if (mDNS_LoggingEnabled) LogMsgWithLevel(MDNS_LOG_OPERATION, ARGS);} while (0) | |
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) | |
108 | #else | |
109 | #error Unknown variadic macros | |
110 | #endif | |
32bb7e43 | 111 | #else |
83fb1e36 A |
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 | |
114 | #define debug_noop 1 ? (void)0 : (void) | |
115 | #define LogMsg LogMsg_ | |
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); | |
120 | extern void LogOperation_(const char *format, ...) IS_A_PRINTF_STYLE_FUNCTION(1,2); | |
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_ | |
127 | extern 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_ | |
134 | extern 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 | ||
83fb1e36 A |
139 | extern int mDNS_LoggingEnabled; |
140 | extern int mDNS_PacketLoggingEnabled; | |
51601d48 A |
141 | extern int mDNS_McastLoggingEnabled; |
142 | extern int mDNS_McastTracingEnabled; | |
83fb1e36 | 143 | extern int mDNS_DebugMode; // If non-zero, LogMsg() writes to stderr instead of syslog |
32bb7e43 | 144 | extern const char ProgramName[]; |
67c8f8a1 | 145 | |
32bb7e43 | 146 | extern void LogMsgWithLevel(mDNSLogLevel_t logLevel, const char *format, ...) IS_A_PRINTF_STYLE_FUNCTION(2,3); |
263eeeab A |
147 | // LogMsgNoIdent needs to be fixed so that it logs without the ident prefix like it used to |
148 | // (or completely overhauled to use the new "log to a separate file" facility) | |
32bb7e43 | 149 | #define LogMsgNoIdent LogMsg |
8e92c31c | 150 | |
9f221bca A |
151 | #if APPLE_OSX_mDNSResponder |
152 | extern void LogFatalError(const char *format, ...); | |
153 | #else | |
154 | #define LogFatalError LogMsg | |
155 | #endif | |
156 | ||
67c8f8a1 | 157 | #if APPLE_OSX_mDNSResponder && MACOSX_MDNS_MALLOC_DEBUGGING >= 1 |
8e92c31c A |
158 | extern void *mallocL(char *msg, unsigned int size); |
159 | extern void freeL(char *msg, void *x); | |
67c8f8a1 A |
160 | extern void uds_validatelists(void); |
161 | extern void udns_validatelists(void *const v); | |
9f221bca | 162 | extern void LogMemCorruption(const char *format, ...); |
8e92c31c A |
163 | #else |
164 | #define mallocL(X,Y) malloc(Y) | |
165 | #define freeL(X,Y) free(Y) | |
166 | #endif | |
167 | ||
32bb7e43 | 168 | #ifdef __cplusplus |
83fb1e36 | 169 | } |
6528fe3e | 170 | #endif |
c9b9ae52 A |
171 | |
172 | #endif |