net-snmp  5.4.1
debug_handler.c
00001 /* Portions of this file are subject to the following copyright(s).  See
00002  * the Net-SNMP's COPYING file for more details and other copyrights
00003  * that may apply:
00004  */
00005 /*
00006  * Portions of this file are copyrighted by:
00007  * Copyright © 2003 Sun Microsystems, Inc. All rights reserved.
00008  * Use is subject to license terms specified in the COPYING file
00009  * distributed with the Net-SNMP package.
00010  */
00011 #include <net-snmp/net-snmp-config.h>
00012 
00013 #if HAVE_STRING_H
00014 #include <string.h>
00015 #else
00016 #include <strings.h>
00017 #endif
00018 
00019 #include <net-snmp/net-snmp-includes.h>
00020 #include <net-snmp/agent/net-snmp-agent-includes.h>
00021 
00022 #include <net-snmp/agent/debug_handler.h>
00023 
00050 netsnmp_mib_handler *
00051 netsnmp_get_debug_handler(void)
00052 {
00053     return netsnmp_create_handler("debug", netsnmp_debug_helper);
00054 }
00055 
00057 void
00058 debug_print_requests(netsnmp_request_info *requests)
00059 {
00060     netsnmp_request_info *request;
00061 
00062     for (request = requests; request; request = request->next) {
00063         DEBUGMSGTL(("helper:debug", "      #%2d: ", request->index));
00064         DEBUGMSGVAR(("helper:debug", request->requestvb));
00065         DEBUGMSG(("helper:debug", "\n"));
00066 
00067         if (request->processed)
00068             DEBUGMSGTL(("helper:debug", "        [processed]\n"));
00069         if (request->delegated)
00070             DEBUGMSGTL(("helper:debug", "        [delegated]\n"));
00071         if (request->status)
00072             DEBUGMSGTL(("helper:debug", "        [status = %d]\n",
00073                         request->status));
00074         if (request->parent_data) {
00075             netsnmp_data_list *lst;
00076             DEBUGMSGTL(("helper:debug", "        [parent data ="));
00077             for (lst = request->parent_data; lst; lst = lst->next) {
00078                 DEBUGMSG(("helper:debug", " %s", lst->name));
00079             }
00080             DEBUGMSG(("helper:debug", "]\n"));
00081         }
00082     }
00083 }
00084 
00085 
00087 int
00088 netsnmp_debug_helper(netsnmp_mib_handler *handler,
00089                      netsnmp_handler_registration *reginfo,
00090                      netsnmp_agent_request_info *reqinfo,
00091                      netsnmp_request_info *requests)
00092 {
00093 
00094     netsnmp_mib_handler *hptr;
00095     int             i, ret, count;
00096     char           *cp;
00097 
00098     DEBUGMSGTL(("helper:debug", "Entering Debugging Helper:\n"));
00099     DEBUGMSGTL(("helper:debug", "  Handler Registration Info:\n"));
00100     DEBUGMSGTL(("helper:debug", "    Name:        %s\n",
00101                 reginfo->handlerName));
00102     DEBUGMSGTL(("helper:debug", "    Context:     %s\n",
00103                 SNMP_STRORNULL(reginfo->contextName)));
00104     DEBUGMSGTL(("helper:debug", "    Base OID:    "));
00105     DEBUGMSGOID(("helper:debug", reginfo->rootoid, reginfo->rootoid_len));
00106     DEBUGMSG(("helper:debug", "\n"));
00107 
00108     DEBUGMSGTL(("helper:debug", "    Modes:       0x%x = ",
00109                 reginfo->modes));
00110     for (count = 0, i = reginfo->modes; i; i = i >> 1, count++) {
00111         if (i & 0x01) {
00112             cp = se_find_label_in_slist("handler_can_mode",
00113                                              0x01 << count);
00114             DEBUGMSG(("helper:debug", "%s | ", SNMP_STRORNULL(cp)));
00115         }
00116     }
00117     DEBUGMSG(("helper:debug", "\n"));
00118 
00119     DEBUGMSGTL(("helper:debug", "    Priority:    %d\n",
00120                 reginfo->priority));
00121 
00122     DEBUGMSGTL(("helper:debug", "  Handler Calling Chain:\n"));
00123     DEBUGMSGTL(("helper:debug", "   "));
00124     for (hptr = reginfo->handler; hptr; hptr = hptr->next) {
00125         DEBUGMSG(("helper:debug", " -> %s", hptr->handler_name));
00126         if (hptr->myvoid)
00127             DEBUGMSG(("helper:debug", " [myvoid = %x]", hptr->myvoid));
00128     }
00129     DEBUGMSG(("helper:debug", "\n"));
00130 
00131     DEBUGMSGTL(("helper:debug", "  Request information:\n"));
00132     DEBUGMSGTL(("helper:debug", "    Mode:        %s (%d = 0x%x)\n",
00133                 se_find_label_in_slist("agent_mode", reqinfo->mode),
00134                 reqinfo->mode, reqinfo->mode));
00135     DEBUGMSGTL(("helper:debug", "    Request Variables:\n"));
00136     debug_print_requests(requests);
00137 
00138     DEBUGMSGTL(("helper:debug", "  --- calling next handler --- \n"));
00139     ret = netsnmp_call_next_handler(handler, reginfo, reqinfo, requests);
00140 
00141     DEBUGMSGTL(("helper:debug", "  Results:\n"));
00142     DEBUGMSGTL(("helper:debug", "    Returned code: %d\n", ret));
00143     DEBUGMSGTL(("helper:debug", "    Returned Variables:\n"));
00144     debug_print_requests(requests);
00145 
00146     DEBUGMSGTL(("helper:debug", "Exiting Debugging Helper:\n"));
00147     return ret;
00148 }
00149 
00154 void
00155 netsnmp_init_debug_helper(void)
00156 {
00157     netsnmp_register_handler_by_name("debug", netsnmp_get_debug_handler());
00158 }