net-snmp 5.7
|
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 #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 00049 #ifdef NETSNMP_NO_DEBUGGING 00050 00051 #define debug_print_requests(x) 00052 00053 #else /* NETSNMP_NO_DEBUGGING */ 00054 00056 static void 00057 debug_print_requests(netsnmp_request_info *requests) 00058 { 00059 netsnmp_request_info *request; 00060 00061 for (request = requests; request; request = request->next) { 00062 DEBUGMSGTL(("helper:debug", " #%2d: ", request->index)); 00063 DEBUGMSGVAR(("helper:debug", request->requestvb)); 00064 DEBUGMSG(("helper:debug", "\n")); 00065 00066 if (request->processed) 00067 DEBUGMSGTL(("helper:debug", " [processed]\n")); 00068 if (request->delegated) 00069 DEBUGMSGTL(("helper:debug", " [delegated]\n")); 00070 if (request->status) 00071 DEBUGMSGTL(("helper:debug", " [status = %d]\n", 00072 request->status)); 00073 if (request->parent_data) { 00074 netsnmp_data_list *lst; 00075 DEBUGMSGTL(("helper:debug", " [parent data =")); 00076 for (lst = request->parent_data; lst; lst = lst->next) { 00077 DEBUGMSG(("helper:debug", " %s", lst->name)); 00078 } 00079 DEBUGMSG(("helper:debug", "]\n")); 00080 } 00081 } 00082 } 00083 00084 #endif /* NETSNMP_NO_DEBUGGING */ 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 int ret; 00094 00095 DEBUGIF("helper:debug") { 00096 netsnmp_mib_handler *hptr; 00097 char *cp; 00098 int i, count; 00099 00100 DEBUGMSGTL(("helper:debug", "Entering Debugging Helper:\n")); 00101 DEBUGMSGTL(("helper:debug", " Handler Registration Info:\n")); 00102 DEBUGMSGTL(("helper:debug", " Name: %s\n", 00103 reginfo->handlerName)); 00104 DEBUGMSGTL(("helper:debug", " Context: %s\n", 00105 SNMP_STRORNULL(reginfo->contextName))); 00106 DEBUGMSGTL(("helper:debug", " Base OID: ")); 00107 DEBUGMSGOID(("helper:debug", reginfo->rootoid, reginfo->rootoid_len)); 00108 DEBUGMSG(("helper:debug", "\n")); 00109 00110 DEBUGMSGTL(("helper:debug", " Modes: 0x%x = ", 00111 reginfo->modes)); 00112 for (count = 0, i = reginfo->modes; i; i = i >> 1, count++) { 00113 if (i & 0x01) { 00114 cp = se_find_label_in_slist("handler_can_mode", 00115 0x01 << count); 00116 DEBUGMSG(("helper:debug", "%s | ", SNMP_STRORNULL(cp))); 00117 } 00118 } 00119 DEBUGMSG(("helper:debug", "\n")); 00120 00121 DEBUGMSGTL(("helper:debug", " Priority: %d\n", 00122 reginfo->priority)); 00123 00124 DEBUGMSGTL(("helper:debug", " Handler Calling Chain:\n")); 00125 DEBUGMSGTL(("helper:debug", " ")); 00126 for (hptr = reginfo->handler; hptr; hptr = hptr->next) { 00127 DEBUGMSG(("helper:debug", " -> %s", hptr->handler_name)); 00128 if (hptr->myvoid) 00129 DEBUGMSG(("helper:debug", " [myvoid = %p]", hptr->myvoid)); 00130 } 00131 DEBUGMSG(("helper:debug", "\n")); 00132 00133 DEBUGMSGTL(("helper:debug", " Request information:\n")); 00134 DEBUGMSGTL(("helper:debug", " Mode: %s (%d = 0x%x)\n", 00135 se_find_label_in_slist("agent_mode", reqinfo->mode), 00136 reqinfo->mode, reqinfo->mode)); 00137 DEBUGMSGTL(("helper:debug", " Request Variables:\n")); 00138 debug_print_requests(requests); 00139 00140 DEBUGMSGTL(("helper:debug", " --- calling next handler --- \n")); 00141 } 00142 00143 ret = netsnmp_call_next_handler(handler, reginfo, reqinfo, requests); 00144 00145 DEBUGIF("helper:debug") { 00146 DEBUGMSGTL(("helper:debug", " Results:\n")); 00147 DEBUGMSGTL(("helper:debug", " Returned code: %d\n", ret)); 00148 DEBUGMSGTL(("helper:debug", " Returned Variables:\n")); 00149 debug_print_requests(requests); 00150 00151 DEBUGMSGTL(("helper:debug", "Exiting Debugging Helper:\n")); 00152 } 00153 00154 return ret; 00155 } 00156 00161 void 00162 netsnmp_init_debug_helper(void) 00163 { 00164 netsnmp_register_handler_by_name("debug", netsnmp_get_debug_handler()); 00165 }