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