1 /* -*- Mode: C; tab-width: 4 -*- 2 * 3 * Copyright (c) 2002-2015 Apple 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 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 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.) 27 28 //#undef MDNS_DEBUGMSGS 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 #ifndef MDNS_CHECK_PRINTF_STYLE_FUNCTIONS 38 #define MDNS_CHECK_PRINTF_STYLE_FUNCTIONS 0 39 #endif 40 41 typedef enum 42 { 43 MDNS_LOG_MSG, 44 MDNS_LOG_OPERATION, 45 MDNS_LOG_SPS, 46 MDNS_LOG_INFO, 47 MDNS_LOG_DEBUG, 48 } mDNSLogLevel_t; 49 50 // Set this symbol to 1 to answer remote queries for our Address, reverse mapping PTR, and HINFO records 51 #define ANSWER_REMOTE_HOSTNAME_QUERIES 0 52 53 // Set this symbol to 1 to do extra debug checks on malloc() and free() 54 // Set this symbol to 2 to write a log message for every malloc() and free() 55 //#define MACOSX_MDNS_MALLOC_DEBUGGING 1 56 57 //#define ForceAlerts 1 58 //#define LogTimeStamps 1 59 60 // Developer-settings section ends here 61 62 #if MDNS_CHECK_PRINTF_STYLE_FUNCTIONS 63 #define IS_A_PRINTF_STYLE_FUNCTION(F,A) __attribute__ ((format(printf,F,A))) 64 #else 65 #define IS_A_PRINTF_STYLE_FUNCTION(F,A) 66 #endif 67 68 #ifdef __cplusplus 69 extern "C" { 70 #endif 71 72 // Variable argument macro support. Use ANSI C99 __VA_ARGS__ where possible. Otherwise, use the next best thing. 73 74 #if (defined(__GNUC__)) 75 #if ((__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 2))) 76 #define MDNS_C99_VA_ARGS 1 77 #define MDNS_GNU_VA_ARGS 0 78 #else 79 #define MDNS_C99_VA_ARGS 0 80 #define MDNS_GNU_VA_ARGS 1 81 #endif 82 #define MDNS_HAS_VA_ARG_MACROS 1 83 #elif (_MSC_VER >= 1400) // Visual Studio 2005 and later 84 #define MDNS_C99_VA_ARGS 1 85 #define MDNS_GNU_VA_ARGS 0 86 #define MDNS_HAS_VA_ARG_MACROS 1 87 #elif (defined(__MWERKS__)) 88 #define MDNS_C99_VA_ARGS 1 89 #define MDNS_GNU_VA_ARGS 0 90 #define MDNS_HAS_VA_ARG_MACROS 1 91 #else 92 #define MDNS_C99_VA_ARGS 0 93 #define MDNS_GNU_VA_ARGS 0 94 #define MDNS_HAS_VA_ARG_MACROS 0 95 #endif 96 97 #if (MDNS_HAS_VA_ARG_MACROS) 98 #if (MDNS_C99_VA_ARGS) 99 #define debug_noop(... ) ((void)0) 100 #define LogMsg(... ) LogMsgWithLevel(MDNS_LOG_MSG, __VA_ARGS__) 101 #define LogOperation(... ) do { if (mDNS_LoggingEnabled) LogMsgWithLevel(MDNS_LOG_OPERATION, __VA_ARGS__);} while (0) 102 #define LogSPS(... ) do { if (mDNS_LoggingEnabled) LogMsgWithLevel(MDNS_LOG_SPS, __VA_ARGS__);} while (0) 103 #define LogInfo(... ) do { if (mDNS_LoggingEnabled) LogMsgWithLevel(MDNS_LOG_INFO, __VA_ARGS__);} while (0) 104 #elif (MDNS_GNU_VA_ARGS) 105 #define debug_noop( ARGS... ) ((void)0) 106 #define LogMsg( ARGS... ) LogMsgWithLevel(MDNS_LOG_MSG, ARGS) 107 #define LogOperation( ARGS... ) do { if (mDNS_LoggingEnabled) LogMsgWithLevel(MDNS_LOG_OPERATION, ARGS);} while (0) 108 #define LogSPS( ARGS... ) do { if (mDNS_LoggingEnabled) LogMsgWithLevel(MDNS_LOG_SPS, ARGS);} while (0) 109 #define LogInfo( ARGS... ) do { if (mDNS_LoggingEnabled) LogMsgWithLevel(MDNS_LOG_INFO, ARGS);} while (0) 110 #else 111 #error Unknown variadic macros 112 #endif 113 #else 114 // If your platform does not support variadic macros, you need to define the following variadic functions. 115 // See mDNSShared/mDNSDebug.c for sample implementation 116 #define debug_noop 1 ? (void)0 : (void) 117 #define LogMsg LogMsg_ 118 #define LogOperation (mDNS_LoggingEnabled == 0) ? ((void)0) : LogOperation_ 119 #define LogSPS (mDNS_LoggingEnabled == 0) ? ((void)0) : LogSPS_ 120 #define LogInfo (mDNS_LoggingEnabled == 0) ? ((void)0) : LogInfo_ 121 extern void LogMsg_(const char *format, ...) IS_A_PRINTF_STYLE_FUNCTION(1,2); 122 extern void LogOperation_(const char *format, ...) IS_A_PRINTF_STYLE_FUNCTION(1,2); 123 extern void LogSPS_(const char *format, ...) IS_A_PRINTF_STYLE_FUNCTION(1,2); 124 extern void LogInfo_(const char *format, ...) IS_A_PRINTF_STYLE_FUNCTION(1,2); 125 #endif 126 127 #if MDNS_DEBUGMSGS 128 #define debugf debugf_ 129 extern void debugf_(const char *format, ...) IS_A_PRINTF_STYLE_FUNCTION(1,2); 130 #else 131 #define debugf debug_noop 132 #endif 133 134 #if MDNS_DEBUGMSGS > 1 135 #define verbosedebugf verbosedebugf_ 136 extern void verbosedebugf_(const char *format, ...) IS_A_PRINTF_STYLE_FUNCTION(1,2); 137 #else 138 #define verbosedebugf debug_noop 139 #endif 140 141 extern int mDNS_LoggingEnabled; 142 extern int mDNS_PacketLoggingEnabled; 143 extern int mDNS_McastLoggingEnabled; 144 extern int mDNS_McastTracingEnabled; 145 extern int mDNS_DebugMode; // If non-zero, LogMsg() writes to stderr instead of syslog 146 extern const char ProgramName[]; 147 148 extern void LogMsgWithLevel(mDNSLogLevel_t logLevel, const char *format, ...) IS_A_PRINTF_STYLE_FUNCTION(2,3); 149 // LogMsgNoIdent needs to be fixed so that it logs without the ident prefix like it used to 150 // (or completely overhauled to use the new "log to a separate file" facility) 151 #define LogMsgNoIdent LogMsg 152 153 #if APPLE_OSX_mDNSResponder 154 extern void LogFatalError(const char *format, ...); 155 #else 156 #define LogFatalError LogMsg 157 #endif 158 159 #if APPLE_OSX_mDNSResponder && MACOSX_MDNS_MALLOC_DEBUGGING >= 1 160 extern void *mallocL(char *msg, unsigned int size); 161 extern void freeL(char *msg, void *x); 162 extern void uds_validatelists(void); 163 extern void udns_validatelists(void *const v); 164 extern void LogMemCorruption(const char *format, ...); 165 #else 166 #define mallocL(X,Y) malloc(Y) 167 #define freeL(X,Y) free(Y) 168 #endif 169 170 #ifdef __cplusplus 171 } 172 #endif 173 174 #endif 175