net-snmp  5.4.1
mode_end_call.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 #include <net-snmp/net-snmp-includes.h>
00014 #include <net-snmp/agent/net-snmp-agent-includes.h>
00015 
00016 #include <net-snmp/agent/mode_end_call.h>
00017 
00044 netsnmp_mib_handler *
00045 netsnmp_get_mode_end_call_handler(netsnmp_mode_handler_list *endlist)
00046 {
00047     netsnmp_mib_handler *me =
00048         netsnmp_create_handler("mode_end_call",
00049                                netsnmp_mode_end_call_helper);
00050 
00051     if (!me)
00052         return NULL;
00053 
00054     me->myvoid = endlist;
00055     return me;
00056 }
00057 
00064 netsnmp_mode_handler_list *
00065 netsnmp_mode_end_call_add_mode_callback(netsnmp_mode_handler_list *endlist,
00066                                         int mode,
00067                                         netsnmp_mib_handler *callbackh) {
00068     netsnmp_mode_handler_list *ptr, *ptr2;
00069     ptr = SNMP_MALLOC_TYPEDEF(netsnmp_mode_handler_list);
00070     if (!ptr)
00071         return NULL;
00072     
00073     ptr->mode = mode;
00074     ptr->callback_handler = callbackh;
00075     ptr->next = NULL;
00076 
00077     if (!endlist)
00078         return ptr;
00079 
00080     /* get to end */
00081     for(ptr2 = endlist; ptr2->next != NULL; ptr2 = ptr2->next);
00082 
00083     ptr2->next = ptr;
00084     return endlist;
00085 }
00086     
00088 int
00089 netsnmp_mode_end_call_helper(netsnmp_mib_handler *handler,
00090                             netsnmp_handler_registration *reginfo,
00091                             netsnmp_agent_request_info *reqinfo,
00092                             netsnmp_request_info *requests)
00093 {
00094 
00095     int             ret;
00096     int             ret2 = SNMP_ERR_NOERROR;
00097     netsnmp_mode_handler_list *ptr;
00098 
00099     /* always call the real handlers first */
00100     ret = netsnmp_call_next_handler(handler, reginfo, reqinfo,
00101                                     requests);
00102 
00103     /* then call the callback handlers */
00104     for(ptr = handler->myvoid; ptr; ptr = ptr->next) {
00105         if (ptr->mode == NETSNMP_MODE_END_ALL_MODES ||
00106             reqinfo->mode == ptr->mode) {
00107             ret2 = netsnmp_call_handler(ptr->callback_handler, reginfo,
00108                                              reqinfo, requests);
00109             if (ret != SNMP_ERR_NOERROR)
00110                 ret = ret2;
00111         }
00112     }
00113     
00114     return ret2;
00115 }