00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include <net-snmp/net-snmp-config.h>
00012 #include <net-snmp/net-snmp-includes.h>
00013 #include <net-snmp/agent/net-snmp-agent-includes.h>
00014
00015 #include <net-snmp/agent/debug_handler.h>
00016
00043 netsnmp_mib_handler *
00044 netsnmp_get_debug_handler(void)
00045 {
00046 return netsnmp_create_handler("debug", netsnmp_debug_helper);
00047 }
00048
00050 void
00051 debug_print_requests(netsnmp_request_info *requests)
00052 {
00053 netsnmp_request_info *request;
00054
00055 for (request = requests; request; request = request->next) {
00056 DEBUGMSGTL(("helper:debug", " #%2d: ", request->index));
00057 DEBUGMSGVAR(("helper:debug", request->requestvb));
00058 DEBUGMSG(("helper:debug", "\n"));
00059
00060 if (request->processed)
00061 DEBUGMSGTL(("helper:debug", " [processed]\n"));
00062 if (request->delegated)
00063 DEBUGMSGTL(("helper:debug", " [delegated]\n"));
00064 if (request->status)
00065 DEBUGMSGTL(("helper:debug", " [status = %d]\n",
00066 request->status));
00067 if (request->parent_data) {
00068 netsnmp_data_list *lst;
00069 DEBUGMSGTL(("helper:debug", " [parent data ="));
00070 for (lst = request->parent_data; lst; lst = lst->next) {
00071 DEBUGMSG(("helper:debug", " %s", lst->name));
00072 }
00073 DEBUGMSG(("helper:debug", "]\n"));
00074 }
00075 }
00076 }
00077
00078
00080 int
00081 netsnmp_debug_helper(netsnmp_mib_handler *handler,
00082 netsnmp_handler_registration *reginfo,
00083 netsnmp_agent_request_info *reqinfo,
00084 netsnmp_request_info *requests)
00085 {
00086
00087 netsnmp_mib_handler *hptr;
00088 int i, ret, count;
00089 char *cp;
00090
00091 DEBUGMSGTL(("helper:debug", "Entering Debugging Helper:\n"));
00092 DEBUGMSGTL(("helper:debug", " Handler Registration Info:\n"));
00093 DEBUGMSGTL(("helper:debug", " Name: %s\n",
00094 reginfo->handlerName));
00095 DEBUGMSGTL(("helper:debug", " Context: %s\n",
00096 SNMP_STRORNULL(reginfo->contextName)));
00097 DEBUGMSGTL(("helper:debug", " Base OID: "));
00098 DEBUGMSGOID(("helper:debug", reginfo->rootoid, reginfo->rootoid_len));
00099 DEBUGMSG(("helper:debug", "\n"));
00100
00101 DEBUGMSGTL(("helper:debug", " Modes: 0x%x = ",
00102 reginfo->modes));
00103 for (count = 0, i = reginfo->modes; i; i = i >> 1, count++) {
00104 if (i & 0x01) {
00105 cp = se_find_label_in_slist("handler_can_mode",
00106 0x01 << count);
00107 DEBUGMSG(("helper:debug", "%s | ", SNMP_STRORNULL(cp)));
00108 }
00109 }
00110 DEBUGMSG(("helper:debug", "\n"));
00111
00112 DEBUGMSGTL(("helper:debug", " Priority: %d\n",
00113 reginfo->priority));
00114
00115 DEBUGMSGTL(("helper:debug", " Handler Calling Chain:\n"));
00116 DEBUGMSGTL(("helper:debug", " "));
00117 for (hptr = reginfo->handler; hptr; hptr = hptr->next) {
00118 DEBUGMSG(("helper:debug", " -> %s", hptr->handler_name));
00119 if (hptr->myvoid)
00120 DEBUGMSG(("helper:debug", " [myvoid = %p]", hptr->myvoid));
00121 }
00122 DEBUGMSG(("helper:debug", "\n"));
00123
00124 DEBUGMSGTL(("helper:debug", " Request information:\n"));
00125 DEBUGMSGTL(("helper:debug", " Mode: %s (%d = 0x%x)\n",
00126 se_find_label_in_slist("agent_mode", reqinfo->mode),
00127 reqinfo->mode, reqinfo->mode));
00128 DEBUGMSGTL(("helper:debug", " Request Variables:\n"));
00129 debug_print_requests(requests);
00130
00131 DEBUGMSGTL(("helper:debug", " --- calling next handler --- \n"));
00132 ret = netsnmp_call_next_handler(handler, reginfo, reqinfo, requests);
00133
00134 DEBUGMSGTL(("helper:debug", " Results:\n"));
00135 DEBUGMSGTL(("helper:debug", " Returned code: %d\n", ret));
00136 DEBUGMSGTL(("helper:debug", " Returned Variables:\n"));
00137 debug_print_requests(requests);
00138
00139 DEBUGMSGTL(("helper:debug", "Exiting Debugging Helper:\n"));
00140 return ret;
00141 }
00142
00147 void
00148 netsnmp_init_debug_helper(void)
00149 {
00150 netsnmp_register_handler_by_name("debug", netsnmp_get_debug_handler());
00151 }