~ubuntu-branches/ubuntu/trusty/net-snmp/trusty

« back to all changes in this revision

Viewing changes to agent/helpers/mode_end_call.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2004-09-13 12:06:21 UTC
  • Revision ID: james.westby@ubuntu.com-20040913120621-g952ntonlleihcvm
Tags: upstream-5.1.1
Import upstream version 5.1.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Portions of this file are subject to the following copyright(s).  See
 
2
 * the Net-SNMP's COPYING file for more details and other copyrights
 
3
 * that may apply:
 
4
 */
 
5
/*
 
6
 * Portions of this file are copyrighted by:
 
7
 * Copyright � 2003 Sun Microsystems, Inc. All rights reserved.
 
8
 * Use is subject to license terms specified in the COPYING file
 
9
 * distributed with the Net-SNMP package.
 
10
 */
 
11
#include <net-snmp/net-snmp-config.h>
 
12
 
 
13
#include <net-snmp/net-snmp-includes.h>
 
14
#include <net-snmp/agent/net-snmp-agent-includes.h>
 
15
 
 
16
#include <net-snmp/agent/mode_end_call.h>
 
17
 
 
18
#if HAVE_DMALLOC_H
 
19
#include <dmalloc.h>
 
20
#endif
 
21
 
 
22
/** @defgroup mode_end_call mode_end_call: at the end of a series of requests, call another handler hook.
 
23
 *  Handlers that want to loop through a series of requests and then
 
24
 *  receive a callback at the end of a particular MODE can use this
 
25
 *  helper to make this possible.  For most modules, this is not
 
26
 *  needed as the handler itself could perform a for() loop around the
 
27
 *  request list and then perform its actions afterwards.  However, if
 
28
 *  something like the serialize helper is in use this isn't possible
 
29
 *  because not all the requests for a given handler are being passed
 
30
 *  downward in a single group.  Thus, this helper *must* be added
 
31
 *  above other helpers like the serialize helper to be useful.
 
32
 *
 
33
 *  Multiple mode specific handlers can be registered and will be
 
34
 *  called in the order they were regestered in.  Callbacks regesterd
 
35
 *  with a mode of NETSNMP_MODE_END_ALL_MODES will be called for all
 
36
 *  modes.
 
37
 * 
 
38
 *  @ingroup utilities
 
39
 *  @{
 
40
 */
 
41
 
 
42
/** returns a mode_end_call handler that can be injected into a given
 
43
 *  handler chain.
 
44
 * @param endlist The callback list for the handler to make use of.
 
45
 * @return An injectable Net-SNMP handler.
 
46
 */
 
47
netsnmp_mib_handler *
 
48
netsnmp_get_mode_end_call_handler(netsnmp_mode_handler_list *endlist)
 
49
{
 
50
    netsnmp_mib_handler *me =
 
51
        netsnmp_create_handler("mode_end_call",
 
52
                               netsnmp_mode_end_call_helper);
 
53
 
 
54
    if (!me)
 
55
        return NULL;
 
56
 
 
57
    me->myvoid = endlist;
 
58
    return me;
 
59
}
 
60
 
 
61
/** adds a mode specific callback to the callback list.
 
62
 * @param endinfo the information structure for the mode_end_call helper.  Can be NULL to create a new list.
 
63
 * @param mode the mode to be called upon.  A mode of NETSNMP_MODE_END_ALL_MODES = all modes.
 
64
 * @param callbackh the netsnmp_mib_handler callback to call.
 
65
 * @return the new registration information list upon success.
 
66
 */
 
67
netsnmp_mode_handler_list *
 
68
netsnmp_mode_end_call_add_mode_callback(netsnmp_mode_handler_list *endlist,
 
69
                                        int mode,
 
70
                                        netsnmp_mib_handler *callbackh) {
 
71
    netsnmp_mode_handler_list *ptr, *ptr2;
 
72
    ptr = SNMP_MALLOC_TYPEDEF(netsnmp_mode_handler_list);
 
73
    if (!ptr)
 
74
        return NULL;
 
75
    
 
76
    ptr->mode = mode;
 
77
    ptr->callback_handler = callbackh;
 
78
    ptr->next = NULL;
 
79
 
 
80
    if (!endlist)
 
81
        return ptr;
 
82
 
 
83
    /* get to end */
 
84
    for(ptr2 = endlist; ptr2->next != NULL; ptr2 = ptr2->next);
 
85
 
 
86
    ptr2->next = ptr;
 
87
    return endlist;
 
88
}
 
89
    
 
90
/** @internal Implements the mode_end_call handler */
 
91
int
 
92
netsnmp_mode_end_call_helper(netsnmp_mib_handler *handler,
 
93
                            netsnmp_handler_registration *reginfo,
 
94
                            netsnmp_agent_request_info *reqinfo,
 
95
                            netsnmp_request_info *requests)
 
96
{
 
97
 
 
98
    int             ret;
 
99
    int             ret2 = SNMP_ERR_NOERROR;
 
100
    netsnmp_mode_handler_list *ptr;
 
101
 
 
102
    /* always call the real handlers first */
 
103
    ret = netsnmp_call_next_handler(handler, reginfo, reqinfo,
 
104
                                    requests);
 
105
 
 
106
    /* then call the callback handlers */
 
107
    for(ptr = handler->myvoid; ptr; ptr = ptr->next) {
 
108
        if (ptr->mode == NETSNMP_MODE_END_ALL_MODES ||
 
109
            reqinfo->mode == ptr->mode) {
 
110
            ret2 = netsnmp_call_handler(ptr->callback_handler, reginfo,
 
111
                                             reqinfo, requests);
 
112
            if (ret != SNMP_ERR_NOERROR)
 
113
                ret = ret2;
 
114
        }
 
115
    }
 
116
    
 
117
    return ret2;
 
118
}