Home | History | Annotate | Download | only in mDNSShared
      1 /* -*- Mode: C; tab-width: 4 -*-
      2  *
      3  * Copyright (c) 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  	File:		mDNSDebug.c
     18 
     19  	Contains:	Implementation of debugging utilities. Requires a POSIX environment.
     20 
     21  	Version:	1.0
     22 
     23  */
     24 
     25 #include "mDNSDebug.h"
     26 
     27 #include <stdio.h>
     28 
     29 #if defined(WIN32) || defined(EFI32) || defined(EFI64) || defined(EFIX64)
     30 // Need to add Windows/EFI syslog support here
     31 #define LOG_PID 0x01
     32 #define LOG_CONS 0x02
     33 #define LOG_PERROR 0x20
     34 #else
     35 #include <syslog.h>
     36 #endif
     37 
     38 #include "mDNSEmbeddedAPI.h"
     39 
     40 // TODO - turn off debugging
     41 mDNSexport int mDNS_LoggingEnabled = 1;
     42 mDNSexport int mDNS_PacketLoggingEnabled = 0;
     43 
     44 #if MDNS_DEBUGMSGS && !defined(__ANDROID__)
     45 mDNSexport int mDNS_DebugMode = mDNStrue;
     46 #else
     47 mDNSexport int mDNS_DebugMode = mDNSfalse;
     48 #endif
     49 
     50 // Note, this uses mDNS_vsnprintf instead of standard "vsnprintf", because mDNS_vsnprintf knows
     51 // how to print special data types like IP addresses and length-prefixed domain names
     52 #if MDNS_DEBUGMSGS > 1
     53 mDNSexport void verbosedebugf_(const char *format, ...)
     54 	{
     55 	char buffer[512];
     56 	va_list ptr;
     57 	va_start(ptr,format);
     58 	buffer[mDNS_vsnprintf(buffer, sizeof(buffer), format, ptr)] = 0;
     59 	va_end(ptr);
     60 	mDNSPlatformWriteDebugMsg(buffer);
     61 	}
     62 #endif
     63 
     64 // Log message with default "mDNSResponder" ident string at the start
     65 mDNSlocal void LogMsgWithLevelv(mDNSLogLevel_t logLevel, const char *format, va_list ptr)
     66 	{
     67 	char buffer[512];
     68 	buffer[mDNS_vsnprintf((char *)buffer, sizeof(buffer), format, ptr)] = 0;
     69 	mDNSPlatformWriteLogMsg(ProgramName, buffer, logLevel);
     70 	}
     71 
     72 #define LOG_HELPER_BODY(L) \
     73 	{ \
     74 	va_list ptr; \
     75 	va_start(ptr,format); \
     76 	LogMsgWithLevelv(L, format, ptr); \
     77 	va_end(ptr); \
     78 	}
     79 
     80 // see mDNSDebug.h
     81 #if !MDNS_HAS_VA_ARG_MACROS
     82 void LogMsg_(const char *format, ...)       LOG_HELPER_BODY(MDNS_LOG_MSG)
     83 void LogOperation_(const char *format, ...) LOG_HELPER_BODY(MDNS_LOG_OPERATION)
     84 void LogSPS_(const char *format, ...)       LOG_HELPER_BODY(MDNS_LOG_SPS)
     85 void LogInfo_(const char *format, ...)      LOG_HELPER_BODY(MDNS_LOG_INFO)
     86 #endif
     87 
     88 #if MDNS_DEBUGMSGS
     89 void debugf_(const char *format, ...)       LOG_HELPER_BODY(MDNS_LOG_DEBUG)
     90 #endif
     91 
     92 // Log message with default "mDNSResponder" ident string at the start
     93 mDNSexport void LogMsgWithLevel(mDNSLogLevel_t logLevel, const char *format, ...)
     94 	LOG_HELPER_BODY(logLevel)
     95