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-features.h> 00013 00014 #include <net-snmp/net-snmp-includes.h> 00015 #include <net-snmp/agent/net-snmp-agent-includes.h> 00016 00017 #include <net-snmp/agent/mode_end_call.h> 00018 00019 netsnmp_feature_provide(mode_end_call) 00020 netsnmp_feature_child_of(mode_end_call, mib_helpers) 00021 00022 #ifndef NETSNMP_FEATURE_REMOVE_MODE_END_CALL 00023 00049 netsnmp_mib_handler * 00050 netsnmp_get_mode_end_call_handler(netsnmp_mode_handler_list *endlist) 00051 { 00052 netsnmp_mib_handler *me = 00053 netsnmp_create_handler("mode_end_call", 00054 netsnmp_mode_end_call_helper); 00055 00056 if (!me) 00057 return NULL; 00058 00059 me->myvoid = endlist; 00060 return me; 00061 } 00062 00069 netsnmp_mode_handler_list * 00070 netsnmp_mode_end_call_add_mode_callback(netsnmp_mode_handler_list *endlist, 00071 int mode, 00072 netsnmp_mib_handler *callbackh) { 00073 netsnmp_mode_handler_list *ptr, *ptr2; 00074 ptr = SNMP_MALLOC_TYPEDEF(netsnmp_mode_handler_list); 00075 if (!ptr) 00076 return NULL; 00077 00078 ptr->mode = mode; 00079 ptr->callback_handler = callbackh; 00080 ptr->next = NULL; 00081 00082 if (!endlist) 00083 return ptr; 00084 00085 /* get to end */ 00086 for(ptr2 = endlist; ptr2->next != NULL; ptr2 = ptr2->next); 00087 00088 ptr2->next = ptr; 00089 return endlist; 00090 } 00091 00093 int 00094 netsnmp_mode_end_call_helper(netsnmp_mib_handler *handler, 00095 netsnmp_handler_registration *reginfo, 00096 netsnmp_agent_request_info *reqinfo, 00097 netsnmp_request_info *requests) 00098 { 00099 00100 int ret; 00101 int ret2 = SNMP_ERR_NOERROR; 00102 netsnmp_mode_handler_list *ptr; 00103 00104 /* always call the real handlers first */ 00105 ret = netsnmp_call_next_handler(handler, reginfo, reqinfo, 00106 requests); 00107 00108 /* then call the callback handlers */ 00109 for (ptr = (netsnmp_mode_handler_list*)handler->myvoid; ptr; ptr = ptr->next) { 00110 if (ptr->mode == NETSNMP_MODE_END_ALL_MODES || 00111 reqinfo->mode == ptr->mode) { 00112 ret2 = netsnmp_call_handler(ptr->callback_handler, reginfo, 00113 reqinfo, requests); 00114 if (ret != SNMP_ERR_NOERROR) 00115 ret = ret2; 00116 } 00117 } 00118 00119 return ret2; 00120 } 00121 #else 00122 netsnmp_feature_unused(mode_end_call); 00123 #endif /* NETSNMP_FEATURE_REMOVE_MODE_END_CALL */ 00124 00125