make IMC/IMV pairs independent of libcharon
[strongswan.git] / src / libstrongswan / debug.h
1 /*
2 * Copyright (C) 2006 Martin Willi
3 * Hochschule fuer Technik Rapperswil
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16 /**
17 * @defgroup debug debug
18 * @{ @ingroup libstrongswan
19 */
20
21 #ifndef DEBUG_H_
22 #define DEBUG_H_
23
24 typedef enum debug_t debug_t;
25 typedef enum level_t level_t;
26
27 #include <stdio.h>
28
29 #include "enum.h"
30
31 /**
32 * Debug message group.
33 */
34 enum debug_t {
35 /** daemon specific */
36 DBG_DMN,
37 /** IKE_SA_MANAGER */
38 DBG_MGR,
39 /** IKE_SA */
40 DBG_IKE,
41 /** CHILD_SA */
42 DBG_CHD,
43 /** job processing */
44 DBG_JOB,
45 /** configuration backends */
46 DBG_CFG,
47 /** kernel interface */
48 DBG_KNL,
49 /** networking/sockets */
50 DBG_NET,
51 /** message encoding/decoding */
52 DBG_ENC,
53 /** trusted network connect */
54 DBG_TNC,
55 /** integrity measurement client */
56 DBG_IMC,
57 /** integrity measurement verifier */
58 DBG_IMV,
59 /** libtls */
60 DBG_TLS,
61 /** libstrongswan */
62 DBG_LIB,
63 /** number of groups */
64 DBG_MAX,
65 /** pseudo group with all groups */
66 DBG_ANY = DBG_MAX,
67 };
68
69 /**
70 * short names of debug message group.
71 */
72 extern enum_name_t *debug_names;
73
74 /**
75 * short names of debug message group, lower case.
76 */
77 extern enum_name_t *debug_lower_names;
78
79 /**
80 * Debug levels used to control output verbosity.
81 */
82 enum level_t {
83 /** absolutely silent */
84 LEVEL_SILENT = -1,
85 /** most important auditing logs */
86 LEVEL_AUDIT = 0,
87 /** control flow */
88 LEVEL_CTRL = 1,
89 /** diagnose problems */
90 LEVEL_DIAG = 2,
91 /** raw binary blobs */
92 LEVEL_RAW = 3,
93 /** including sensitive data (private keys) */
94 LEVEL_PRIVATE = 4,
95 };
96
97 #ifndef DEBUG_LEVEL
98 # define DEBUG_LEVEL 4
99 #endif /* DEBUG_LEVEL */
100
101 /** debug macros, they call the dbg function hook */
102 #if DEBUG_LEVEL >= 0
103 # define DBG0(group, fmt, ...) dbg(group, 0, fmt, ##__VA_ARGS__)
104 #endif /* DEBUG_LEVEL */
105 #if DEBUG_LEVEL >= 1
106 # define DBG1(group, fmt, ...) dbg(group, 1, fmt, ##__VA_ARGS__)
107 #endif /* DEBUG_LEVEL */
108 #if DEBUG_LEVEL >= 2
109 # define DBG2(group, fmt, ...) dbg(group, 2, fmt, ##__VA_ARGS__)
110 #endif /* DEBUG_LEVEL */
111 #if DEBUG_LEVEL >= 3
112 # define DBG3(group, fmt, ...) dbg(group, 3, fmt, ##__VA_ARGS__)
113 #endif /* DEBUG_LEVEL */
114 #if DEBUG_LEVEL >= 4
115 # define DBG4(group, fmt, ...) dbg(group, 4, fmt, ##__VA_ARGS__)
116 #endif /* DEBUG_LEVEL */
117
118 #ifndef DBG0
119 # define DBG0(...) {}
120 #endif
121 #ifndef DBG1
122 # define DBG1(...) {}
123 #endif
124 #ifndef DBG2
125 # define DBG2(...) {}
126 #endif
127 #ifndef DBG3
128 # define DBG3(...) {}
129 #endif
130 #ifndef DBG4
131 # define DBG4(...) {}
132 #endif
133
134 /** dbg function hook, uses dbg_default() by default */
135 extern void (*dbg) (debug_t group, level_t level, char *fmt, ...);
136
137 /** default logging function */
138 void dbg_default(debug_t group, level_t level, char *fmt, ...);
139
140 /** set the level logged by dbg_default() */
141 void dbg_default_set_level(level_t level);
142
143 /** set the stream logged by dbg_default() to */
144 void dbg_default_set_stream(FILE *stream);
145
146 #endif /** DEBUG_H_ @}*/