1 /*- 2 * Copyright (c) 2009 Internet Initiative Japan Inc. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 #ifndef DEBUG_UTIL_H 27 #define DEBUG_UTIL_H 1 28 29 #include <stdio.h> /* for FILE * */ 30 #include "debugmacro.h" 31 32 #define DEBUG_LEVEL_1 ( 1 << 24) 33 #define DEBUG_LEVEL_2 ( 2 << 24) 34 #define DEBUG_LEVEL_3 ( 3 << 24) 35 #define DEBUG_LEVEL_4 ( 4 << 24) 36 #define DEBUG_LEVEL_5 ( 5 << 24) 37 #define DEBUG_LEVEL_6 ( 6 << 24) 38 #define DEBUG_LEVEL_7 ( 7 << 24) 39 #define DEBUG_LEVEL_8 ( 8 << 24) 40 #define DEBUG_LEVEL_9 ( 9 << 24) 41 #define DEBUG_LEVEL_10 (10 << 24) 42 #define DEBUG_LEVEL_11 (11 << 24) 43 #define DEBUG_LEVEL_12 (12 << 24) 44 #define DEBUG_LEVEL_13 (13 << 24) 45 #define DEBUG_LEVEL_14 (14 << 24) 46 #define DEBUG_LEVEL_15 (15 << 24) 47 48 extern int debuglevel; 49 50 /* adapted from FreeBSD:/usr/include/sys/cdefs */ 51 #ifndef __printflike 52 #if __GNUC__ < 2 || __GNUC__ == 2 && __GNUC_MINOR__ < 7 53 #define __printflike(fmtarg, firstvararg) 54 #else 55 #define __printflike(fmtarg, firstvararg) \ 56 __attribute__((__format__ (__printf__, fmtarg, firstvararg))) 57 #endif 58 #endif 59 60 #ifdef __cplusplus 61 extern "C" { 62 #endif 63 64 #include <stdarg.h> 65 66 void debug_set_debugfp (FILE *); 67 FILE *debug_get_debugfp (void); 68 int vlog_printf (uint32_t, const char *, va_list); 69 int log_printf (int, const char *, ...) __printflike(2, 3); 70 void show_hd (FILE *, const u_char *, int); 71 void debug_use_syslog (int); 72 void debug_set_syslog_level_adjust (int); 73 int debug_get_syslog_level_adjust (void); 74 void debug_set_no_debuglog (int); 75 76 #ifdef __cplusplus 77 } 78 #endif 79 80 81 #endif 82