00001 #ifndef SNMP_DEBUG_H 00002 #define SNMP_DEBUG_H 00003 00004 #ifdef __cplusplus 00005 extern "C" { 00006 #endif 00007 00008 /* 00009 * snmp_debug.h: 00010 * 00011 * - prototypes for snmp debugging routines. 00012 * - easy to use macros to wrap around the functions. This also provides 00013 * the ability to remove debugging code easily from the applications at 00014 * compile time. 00015 */ 00016 00017 00018 /* 00019 * These functions should not be used, if at all possible. Instead, use 00020 * the macros below. 00021 */ 00022 #if !defined(__GNUC__) || __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8) 00023 void debugmsg(const char *token, const char *format, ...); 00024 void debugmsgtoken(const char *token, const char *format, 00025 ...); 00026 void debug_combo_nc(const char *token, const char *format, 00027 ...); 00028 #else 00029 void debugmsg(const char *token, const char *format, ...) 00030 __attribute__ ((__format__ (__printf__, 2, 3))); 00031 void debugmsgtoken(const char *token, const char *format, 00032 ...) 00033 __attribute__ ((__format__ (__printf__, 2, 3))); 00034 void debug_combo_nc(const char *token, const char *format, 00035 ...) 00036 __attribute__ ((__format__ (__printf__, 2, 3))); 00037 #endif 00038 void debugmsg_oid(const char *token, const oid * theoid, 00039 size_t len); 00040 void debugmsg_suboid(const char *token, const oid * theoid, 00041 size_t len); 00042 void debugmsg_var(const char *token, 00043 netsnmp_variable_list * var); 00044 void debugmsg_oidrange(const char *token, 00045 const oid * theoid, size_t len, 00046 size_t var_subid, oid range_ubound); 00047 void debugmsg_hex(const char *token, u_char * thedata, 00048 size_t len); 00049 void debugmsg_hextli(const char *token, u_char * thedata, 00050 size_t len); 00051 void debug_indent_add(int amount); 00052 int debug_indent_get(void); 00053 /* 00054 * What is said above is true for this function as well. Further this 00055 * function is deprecated and only provided for backwards compatibility. 00056 * Please use "%*s", debug_indent_get(), "" if you used this one before. 00057 */ 00058 const char *debug_indent(void); 00059 00060 /* 00061 * Use these macros instead of the functions above to allow them to be 00062 * re-defined at compile time to NOP for speed optimization. 00063 * 00064 * They need to be called enclosing all the arguments in a single set of ()s. 00065 * Example: 00066 * DEBUGMSGTL(("token", "debugging of something %s related\n", "snmp")); 00067 * 00068 * Usage: 00069 * All of the functions take a "token" argument that helps determine when 00070 * the output in question should be printed. See the snmpcmd.1 manual page 00071 * on the -D flag to turn on/off output for a given token on the command line. 00072 * 00073 * DEBUGMSG((token, format, ...)): equivalent to printf(format, ...) 00074 * (if "token" debugging output 00075 * is requested by the user) 00076 * 00077 * DEBUGMSGT((token, format, ...)): equivalent to DEBUGMSG, but prints 00078 * "token: " at the beginning of the 00079 * line for you. 00080 * 00081 * DEBUGTRACE Insert this token anywhere you want 00082 * tracing output displayed when the 00083 * "trace" debugging token is selected. 00084 * 00085 * DEBUGMSGL((token, format, ...)): equivalent to DEBUGMSG, but includes 00086 * DEBUGTRACE debugging line just before 00087 * yours. 00088 * 00089 * DEBUGMSGTL((token, format, ...)): Same as DEBUGMSGL and DEBUGMSGT 00090 * combined. 00091 * 00092 * Important: 00093 * It is considered best if you use DEBUGMSGTL() everywhere possible, as it 00094 * gives the nicest format output and provides tracing support just before 00095 * every debugging statement output. 00096 * 00097 * To print multiple pieces to a single line in one call, use: 00098 * 00099 * DEBUGMSGTL(("token", "line part 1")); 00100 * DEBUGMSG (("token", " and part 2\n")); 00101 * 00102 * to get: 00103 * 00104 * token: line part 1 and part 2 00105 * 00106 * as debugging output. 00107 * 00108 * 00109 * Each of these macros also have a version with a suffix of '_NC'. The 00110 * NC suffix stands for 'No Check', which means that no check will be 00111 * performed to see if debug is enabled or if the token has been turned 00112 * on. These NC versions are intended for use within a DEBUG_IF {} block, 00113 * where the debug/token check has already been performed. 00114 */ 00115 00116 #ifndef NETSNMP_NO_DEBUGGING /* make sure we're wanted */ 00117 00118 /* 00119 * define two macros : one macro with, one without, 00120 * a test if debugging is enabled. 00121 * 00122 * Generally, use the macro with _DBG_IF_ 00123 */ 00124 00125 /******************* Start private macros ************************/ 00126 #define _DBG_IF_ snmp_get_do_debugging() 00127 #define DEBUGIF(x) if (_DBG_IF_ && debug_is_token_registered(x) == SNMPERR_SUCCESS) 00128 00129 #define __DBGMSGT(x) debugmsgtoken x, debugmsg x 00130 #define __DBGMSG_NC(x) debugmsg x 00131 #define __DBGMSGT_NC(x) debug_combo_nc x 00132 #define __DBGMSGL_NC(x) __DBGTRACE; debugmsg x 00133 #define __DBGMSGTL_NC(x) __DBGTRACE; debug_combo_nc x 00134 00135 #ifdef NETSNMP_FUNCTION 00136 #define __DBGTRACE __DBGMSGT(("trace","%s(): %s, %d:\n",\ 00137 NETSNMP_FUNCTION,__FILE__,__LINE__)) 00138 #else 00139 #define __DBGTRACE __DBGMSGT(("trace"," %s, %d:\n", __FILE__,__LINE__)) 00140 #endif 00141 00142 #define __DBGMSGL(x) __DBGTRACE, debugmsg x 00143 #define __DBGMSGTL(x) __DBGTRACE, debugmsgtoken x, debugmsg x 00144 #define __DBGMSGOID(x) debugmsg_oid x 00145 #define __DBGMSGSUBOID(x) debugmsg_suboid x 00146 #define __DBGMSGVAR(x) debugmsg_var x 00147 #define __DBGMSGOIDRANGE(x) debugmsg_oidrange x 00148 #define __DBGMSGHEX(x) debugmsg_hex x 00149 #define __DBGMSGHEXTLI(x) debugmsg_hextli x 00150 #define __DBGINDENT() debug_indent_get() 00151 #define __DBGINDENTADD(x) debug_indent_add(x) 00152 #define __DBGINDENTMORE() debug_indent_add(2) 00153 #define __DBGINDENTLESS() debug_indent_add(-2) 00154 #define __DBGPRINTINDENT(token) __DBGMSGTL((token, "%*s", __DBGINDENT(), "")) 00155 00156 #define __DBGDUMPHEADER(token,x) \ 00157 __DBGPRINTINDENT("dumph_" token); \ 00158 debugmsg("dumph_" token,x); \ 00159 if (debug_is_token_registered("dumpx" token) == SNMPERR_SUCCESS || \ 00160 debug_is_token_registered("dumpv" token) == SNMPERR_SUCCESS || \ 00161 (debug_is_token_registered("dumpx_" token) != SNMPERR_SUCCESS && \ 00162 debug_is_token_registered("dumpv_" token) != SNMPERR_SUCCESS)) { \ 00163 debugmsg("dumph_" token,"\n"); \ 00164 } else { \ 00165 debugmsg("dumph_" token," "); \ 00166 } \ 00167 __DBGINDENTMORE() 00168 00169 #define __DBGDUMPSECTION(token,x) \ 00170 __DBGPRINTINDENT("dumph_" token); \ 00171 debugmsg("dumph_" token,"%s\n",x);\ 00172 __DBGINDENTMORE() 00173 00174 #define __DBGDUMPSETUP(token,buf,len) \ 00175 debugmsg("dumpx" token, "dumpx_%s:%*s", token, __DBGINDENT(), ""); \ 00176 __DBGMSGHEX(("dumpx_" token,buf,len)); \ 00177 if (debug_is_token_registered("dumpv" token) == SNMPERR_SUCCESS || \ 00178 debug_is_token_registered("dumpv_" token) != SNMPERR_SUCCESS) { \ 00179 debugmsg("dumpx_" token,"\n"); \ 00180 } else { \ 00181 debugmsg("dumpx_" token," "); \ 00182 } \ 00183 debugmsg("dumpv" token, "dumpv_%s:%*s", token, __DBGINDENT(), ""); 00184 00185 /******************* End private macros ************************/ 00186 /*****************************************************************/ 00187 00188 /*****************************************************************/ 00189 /********************Start public macros ************************/ 00190 00191 #define DEBUGMSG(x) do {if (_DBG_IF_) {debugmsg x;} }while(0) 00192 #define DEBUGMSGT(x) do {if (_DBG_IF_) {__DBGMSGT(x);} }while(0) 00193 #define DEBUGTRACE do {if (_DBG_IF_) {__DBGTRACE;} }while(0) 00194 #define DEBUGMSGL(x) do {if (_DBG_IF_) {__DBGMSGL(x);} }while(0) 00195 #define DEBUGMSGTL(x) do {if (_DBG_IF_) {__DBGMSGTL(x);} }while(0) 00196 #define DEBUGMSGOID(x) do {if (_DBG_IF_) {__DBGMSGOID(x);} }while(0) 00197 #define DEBUGMSGSUBOID(x) do {if (_DBG_IF_) {__DBGMSGSUBOID(x);} }while(0) 00198 #define DEBUGMSGVAR(x) do {if (_DBG_IF_) {__DBGMSGVAR(x);} }while(0) 00199 #define DEBUGMSGOIDRANGE(x) do {if (_DBG_IF_) {__DBGMSGOIDRANGE(x);} }while(0) 00200 #define DEBUGMSGHEX(x) do {if (_DBG_IF_) {__DBGMSGHEX(x);} }while(0) 00201 #define DEBUGMSGHEXTLI(x) do {if (_DBG_IF_) {__DBGMSGHEXTLI(x);} }while(0) 00202 #define DEBUGINDENTADD(x) do {if (_DBG_IF_) {__DBGINDENTADD(x);} }while(0) 00203 #define DEBUGINDENTMORE() do {if (_DBG_IF_) {__DBGINDENTMORE();} }while(0) 00204 #define DEBUGINDENTLESS() do {if (_DBG_IF_) {__DBGINDENTLESS();} }while(0) 00205 #define DEBUGPRINTINDENT(token) \ 00206 do {if (_DBG_IF_) {__DBGPRINTINDENT(token);} }while(0) 00207 00208 00209 #define DEBUGDUMPHEADER(token,x) \ 00210 do {if (_DBG_IF_) {__DBGDUMPHEADER(token,x);} }while(0) 00211 00212 #define DEBUGDUMPSECTION(token,x) \ 00213 do {if (_DBG_IF_) {__DBGDUMPSECTION(token,x);} }while(0) 00214 00215 #define DEBUGDUMPSETUP(token,buf,len) \ 00216 do {if (_DBG_IF_) {__DBGDUMPSETUP(token,buf,len);} }while(0) 00217 00218 #define DEBUGMSG_NC(x) do { __DBGMSG_NC(x); }while(0) 00219 #define DEBUGMSGT_NC(x) do { __DBGMSGT_NC(x); }while(0) 00220 00221 #else /* NETSNMP_NO_DEBUGGING := enable streamlining of the code */ 00222 00223 #define DEBUGMSG(x) 00224 #define DEBUGMSGT(x) 00225 #define DEBUGTRACE 00226 #define DEBUGMSGL(x) 00227 #define DEBUGMSGTL(x) 00228 #define DEBUGMSGOID(x) 00229 #define DEBUGMSGSUBOID(x) 00230 #define DEBUGMSGVAR(x) 00231 #define DEBUGMSGOIDRANGE(x) 00232 #define DEBUGMSGHEX(x) 00233 #define DEBUGIF(x) if(0) 00234 #define DEBUGDUMP(t,b,l,p) 00235 #define DEBUGINDENTMORE() 00236 #define DEBUGINDENTLESS() 00237 #define DEBUGINDENTADD(x) 00238 #define DEBUGMSGHEXTLI(x) 00239 #define DEBUGPRINTINDENT(token) 00240 #define DEBUGDUMPHEADER(token,x) 00241 #define DEBUGDUMPSECTION(token,x) 00242 #define DEBUGDUMPSETUP(token, buf, len) 00243 00244 #define DEBUGMSG_NC(x) 00245 #define DEBUGMSGT_NC(x) 00246 00247 #endif 00248 00249 #define MAX_DEBUG_TOKENS 256 00250 #define MAX_DEBUG_TOKEN_LEN 128 00251 #define DEBUG_TOKEN_DELIMITER "," 00252 #define DEBUG_ALWAYS_TOKEN "all" 00253 00254 /* 00255 * setup routines: 00256 * 00257 * debug_register_tokens(char *): registers a list of tokens to 00258 * print debugging output for. 00259 * 00260 * debug_is_token_registered(char *): returns SNMPERR_SUCCESS or SNMPERR_GENERR 00261 * if a token has been registered or 00262 * not (and debugging output is "on"). 00263 * snmp_debug_init(void): registers .conf handlers. 00264 */ 00265 void debug_register_tokens(char *tokens); 00266 int debug_is_token_registered(const char *token); 00267 void snmp_debug_init(void); 00268 void snmp_set_do_debugging(int); 00269 int snmp_get_do_debugging(void); 00270 00271 /* 00272 * internal: 00273 * You probably shouldn't be using this information unless the word 00274 * "expert" applies to you. I know it looks tempting. 00275 */ 00276 typedef struct netsnmp_token_descr_s { 00277 char *token_name; 00278 char enabled; 00279 } netsnmp_token_descr; 00280 00281 NETSNMP_IMPORT int debug_num_tokens; 00282 NETSNMP_IMPORT netsnmp_token_descr dbg_tokens[MAX_DEBUG_TOKENS]; 00283 00284 #ifdef __cplusplus 00285 } 00286 #endif 00287 #endif /* SNMP_DEBUG_H */
Last modified: Wednesday, 01-Aug-2018 04:41:28 UTC
For questions regarding web content and site functionality, please write to the net-snmp-users mail list.