snmp_debug.h

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

net-snmpに対してSat Sep 5 13:14:25 2009に生成されました。  doxygen 1.4.7