Annotation of embedaddon/strongswan/src/libstrongswan/utils/debug.h, revision 1.1.1.1

1.1       misho       1: /*
                      2:  * Copyright (C) 2006 Martin Willi
                      3:  * HSR 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 utils
                     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 <utils/printf_hook/printf_hook.h>
                     28: #include <utils/utils.h>
                     29: #include <stdio.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:        /** libipsec */
                     68:        DBG_ESP,
                     69:        /** libstrongswan */
                     70:        DBG_LIB,
                     71:        /** number of groups */
                     72:        DBG_MAX,
                     73:        /** pseudo group with all groups */
                     74:        DBG_ANY = DBG_MAX,
                     75: };
                     76: 
                     77: /**
                     78:  * short names of debug message group.
                     79:  */
                     80: extern enum_name_t *debug_names;
                     81: 
                     82: /**
                     83:  * short names of debug message group, lower case.
                     84:  */
                     85: extern enum_name_t *debug_lower_names;
                     86: 
                     87: /**
                     88:  * Debug levels used to control output verbosity.
                     89:  */
                     90: enum level_t {
                     91:        /** absolutely silent */
                     92:        LEVEL_SILENT = -1,
                     93:        /** most important auditing logs */
                     94:        LEVEL_AUDIT =   0,
                     95:        /** control flow */
                     96:        LEVEL_CTRL =    1,
                     97:        /** diagnose problems */
                     98:        LEVEL_DIAG =    2,
                     99:        /** raw binary blobs */
                    100:        LEVEL_RAW =     3,
                    101:        /** including sensitive data (private keys) */
                    102:        LEVEL_PRIVATE = 4,
                    103: };
                    104: 
                    105: #ifndef DEBUG_LEVEL
                    106: # define DEBUG_LEVEL 4
                    107: #endif /* DEBUG_LEVEL */
                    108: 
                    109: /** debug macros, they call the dbg function hook */
                    110: #if DEBUG_LEVEL >= 0
                    111: # define DBG0(group, fmt, ...) dbg(group, 0, fmt, ##__VA_ARGS__)
                    112: #endif /* DEBUG_LEVEL */
                    113: #if DEBUG_LEVEL >= 1
                    114: # define DBG1(group, fmt, ...) dbg(group, 1, fmt, ##__VA_ARGS__)
                    115: #endif /* DEBUG_LEVEL */
                    116: #if DEBUG_LEVEL >= 2
                    117: # define DBG2(group, fmt, ...) dbg(group, 2, fmt, ##__VA_ARGS__)
                    118: #endif /* DEBUG_LEVEL */
                    119: #if DEBUG_LEVEL >= 3
                    120: # define DBG3(group, fmt, ...) dbg(group, 3, fmt, ##__VA_ARGS__)
                    121: #endif /* DEBUG_LEVEL */
                    122: #if DEBUG_LEVEL >= 4
                    123: # define DBG4(group, fmt, ...) dbg(group, 4, fmt, ##__VA_ARGS__)
                    124: #endif /* DEBUG_LEVEL */
                    125: 
                    126: #ifndef DBG0
                    127: # define DBG0(...) {}
                    128: #endif
                    129: #ifndef DBG1
                    130: # define DBG1(...) {}
                    131: #endif
                    132: #ifndef DBG2
                    133: # define DBG2(...) {}
                    134: #endif
                    135: #ifndef DBG3
                    136: # define DBG3(...) {}
                    137: #endif
                    138: #ifndef DBG4
                    139: # define DBG4(...) {}
                    140: #endif
                    141: 
                    142: /** dbg function hook, uses dbg_default() by default */
                    143: extern void (*dbg) (debug_t group, level_t level, char *fmt, ...);
                    144: 
                    145: /** default logging function */
                    146: void dbg_default(debug_t group, level_t level, char *fmt, ...);
                    147: 
                    148: /** set the level logged by dbg_default() */
                    149: void dbg_default_set_level(level_t level);
                    150: 
                    151: /** set the stream logged by dbg_default() to */
                    152: void dbg_default_set_stream(FILE *stream);
                    153: 
                    154: #endif /** DEBUG_H_ @}*/

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>