OpenDNSSEC-enforcer
1.4.5
Main Page
Data Structures
Files
File List
Globals
enforcer
ksm
debug.c
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2008-2009 Nominet UK. All rights reserved.
3
*
4
* Redistribution and use in source and binary forms, with or without
5
* modification, are permitted provided that the following conditions
6
* are met:
7
* 1. Redistributions of source code must retain the above copyright
8
* notice, this list of conditions and the following disclaimer.
9
* 2. Redistributions in binary form must reproduce the above copyright
10
* notice, this list of conditions and the following disclaimer in the
11
* documentation and/or other materials provided with the distribution.
12
*
13
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
14
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
17
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
19
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
21
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
22
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
23
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24
*
25
*/
26
27
/*+
28
* debug.c - Debug Routines
29
*
30
* Description:
31
* Contains functions used to produce debug output.
32
*
33
* Debug information is controlled by the debug bitmask. Different items
34
* of debug information are controlled by the different bits, so setting or
35
* clearing those bits controls what information is output.
36
-*/
37
38
#include <stdarg.h>
39
#include <stdio.h>
40
41
#include "
ksm/debug.h
"
42
#include "
ksm/message.h
"
43
44
/* Bitmask of debug flags */
45
46
static
unsigned
int
m_debug = 0;
47
48
/*+
49
* DbgGet - Get Debug Bitmask
50
*
51
* Description:
52
* Returns the current value of the debug bitmask.
53
*
54
* Returns:
55
* unsigned int
56
* Current value of the debug bitmask.
57
-*/
58
59
unsigned
int
DbgGet
(
void
)
60
{
61
return
m_debug;
62
}
63
64
65
66
/*+
67
* DbgSet - Set Debug Bitmask
68
*
69
* Description:
70
* Sets the debug bitmask to the given value.
71
*
72
* Input:
73
* unsigned int mask
74
* New bitmask value.
75
*
76
* Returns:
77
* unsigned int
78
* Previous setting of the debug bitmask.
79
-*/
80
81
unsigned
int
DbgSet
(
unsigned
int
mask)
82
{
83
unsigned
int
oldmask;
84
85
oldmask = m_debug;
86
m_debug = mask;
87
return
oldmask;
88
}
89
90
91
/*+
92
* DbgIsSet - Is Debug Bit Set?
93
*
94
* Description:
95
* Checks if any of the bits in the passed bitmask are also set in the
96
* current debug bitmask.
97
*
98
* Arguments:
99
* unsigned int mask
100
* Bitmask to test.
101
*
102
* Returns:
103
* int
104
* 1 if any of the bits in the mask are set.
105
* 0 if none of them are set.
106
-*/
107
108
int
DbgIsSet
(
unsigned
int
flags)
109
{
110
return
(flags & m_debug);
111
}
112
113
114
115
/*+
116
* DbgOutput - Output Debug Message
117
*
118
* Description:
119
* Outputs a debug message to stdout if one or more of the bits in the
120
* given bitmask is also set in the debug bit mask. If no bits are set,
121
* the function is a no-op.
122
*
123
* Arguments:
124
* unsigned int mask
125
* Only output the text if one or more of the bits in this bitmask is
126
* also set in the debug bitmask.
127
*
128
* const char* format
129
* printf()-style format string for the message.
130
*
131
* ...
132
* Arguments for the format string
133
-*/
134
135
void
DbgOutput
(
unsigned
int
mask,
const
char
* format, ...)
136
{
137
va_list ap;
138
139
if
(
DbgIsSet
(mask)) {
140
va_start(ap, format);
141
printf(
"DEBUG: "
);
142
vprintf(format, ap);
143
va_end(ap);
144
}
145
146
return
;
147
}
148
149
150
/*+
151
* DbgLog - Output Debug Message
152
*
153
* Description:
154
* Outputs a debug message via MsgLog if one or more of the bits in the
155
* given bitmask is also set in the debug bit mask. If no bits are set,
156
* the function is a no-op.
157
*
158
* Arguments:
159
* unsigned int mask
160
* Only output the text if one or more of the bits in this bitmask is
161
* also set in the debug bitmask.
162
*
163
* int status
164
* Status code identifying the message to output.
165
*
166
* ...
167
* Arguments for the format string
168
-*/
169
170
void
DbgLog
(
unsigned
int
mask,
int
status, ...)
171
{
172
va_list ap;
/* variable arguments */
173
174
if
(
DbgIsSet
(mask)) {
175
176
/* Must output the message, so get the arguments as a va_list */
177
178
va_start(ap, status);
179
MsgLogAp
(status, ap);
180
va_end(ap);
181
}
182
183
return
;
184
}
185
186
187
188
/*+
189
* DbgPrint - Unconditionally Print Debug Message
190
*
191
* Description:
192
* Outputs a debug message on stdout.
193
*
194
* Arguments:
195
* const char* format
196
* printf()-style format string for the message.
197
*
198
* ...
199
* Arguments for the format string
200
-*/
201
202
void
DbgPrint
(
const
char
* format, ...)
203
{
204
va_list ap;
205
206
va_start(ap, format);
207
printf(
"DEBUG: "
);
208
vprintf(format, ap);
209
va_end(ap);
210
211
return
;
212
}
Generated on Tue Jul 22 2014 00:37:50 for OpenDNSSEC-enforcer by
1.8.1.2