65e55a6397081f7d3d1126c861c31c37e0efc47c
[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 /** low-level encoding/decoding (ASN.1, X.509 etc.) */
52 DBG_ASN,
53 /** message encoding/decoding */
54 DBG_ENC,
55 /** trusted network connect */
56 DBG_TNC,
57 /** integrity measurement client */
58 DBG_IMC,
59 /** integrity measurement verifier */
60 DBG_IMV,
61 /** platform trust service */
62 DBG_PTS,
63 /** libtls */
64 DBG_TLS,
65 /** applications other than daemons */
66 DBG_APP,
67 /** libstrongswan */
68 DBG_LIB,
69 /** number of groups */
70 DBG_MAX,
71 /** pseudo group with all groups */
72 DBG_ANY = DBG_MAX,
73 };
74
75 /**
76 * short names of debug message group.
77 */
78 extern enum_name_t *debug_names;
79
80 /**
81 * short names of debug message group, lower case.
82 */
83 extern enum_name_t *debug_lower_names;
84
85 /**
86 * Debug levels used to control output verbosity.
87 */
88 enum level_t {
89 /** absolutely silent */
90 LEVEL_SILENT = -1,
91 /** most important auditing logs */
92 LEVEL_AUDIT = 0,
93 /** control flow */
94 LEVEL_CTRL = 1,
95 /** diagnose problems */
96 LEVEL_DIAG = 2,
97 /** raw binary blobs */
98 LEVEL_RAW = 3,
99 /** including sensitive data (private keys) */
100 LEVEL_PRIVATE = 4,
101 };
102
103 #ifndef DEBUG_LEVEL
104 # define DEBUG_LEVEL 4
105 #endif /* DEBUG_LEVEL */
106
107 /** debug macros, they call the dbg function hook */
108 #if DEBUG_LEVEL >= 0
109 # define DBG0(group, fmt, ...) dbg(group, 0, fmt, ##__VA_ARGS__)
110 #endif /* DEBUG_LEVEL */
111 #if DEBUG_LEVEL >= 1
112 # define DBG1(group, fmt, ...) dbg(group, 1, fmt, ##__VA_ARGS__)
113 #endif /* DEBUG_LEVEL */
114 #if DEBUG_LEVEL >= 2
115 # define DBG2(group, fmt, ...) dbg(group, 2, fmt, ##__VA_ARGS__)
116 #endif /* DEBUG_LEVEL */
117 #if DEBUG_LEVEL >= 3
118 # define DBG3(group, fmt, ...) dbg(group, 3, fmt, ##__VA_ARGS__)
119 #endif /* DEBUG_LEVEL */
120 #if DEBUG_LEVEL >= 4
121 # define DBG4(group, fmt, ...) dbg(group, 4, fmt, ##__VA_ARGS__)
122 #endif /* DEBUG_LEVEL */
123
124 #ifndef DBG0
125 # define DBG0(...) {}
126 #endif
127 #ifndef DBG1
128 # define DBG1(...) {}
129 #endif
130 #ifndef DBG2
131 # define DBG2(...) {}
132 #endif
133 #ifndef DBG3
134 # define DBG3(...) {}
135 #endif
136 #ifndef DBG4
137 # define DBG4(...) {}
138 #endif
139
140 /** dbg function hook, uses dbg_default() by default */
141 extern void (*dbg) (debug_t group, level_t level, char *fmt, ...);
142
143 /** default logging function */
144 void dbg_default(debug_t group, level_t level, char *fmt, ...);
145
146 /** set the level logged by dbg_default() */
147 void dbg_default_set_level(level_t level);
148
149 /** set the stream logged by dbg_default() to */
150 void dbg_default_set_stream(FILE *stream);
151
152 #endif /** DEBUG_H_ @}*/