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

« back to all changes in this revision

Viewing changes to agent/mibgroup/mibII/vacm_context.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
#include <net-snmp/net-snmp-config.h>
 
2
 
 
3
#if HAVE_STRING_H
 
4
#include <string.h>
 
5
#else
 
6
#include <strings.h>
 
7
#endif
 
8
 
 
9
#include <net-snmp/net-snmp-includes.h>
 
10
#include <net-snmp/agent/net-snmp-agent-includes.h>
 
11
#include <net-snmp/agent/table.h>
 
12
#include <net-snmp/agent/table_iterator.h>
 
13
 
 
14
#include "vacm_context.h"
 
15
 
 
16
static oid      vacm_context_oid[] = { 1, 3, 6, 1, 6, 3, 16, 1, 1 };
 
17
 
 
18
#define CONTEXTNAME_COLUMN 1
 
19
 
 
20
/*
 
21
 * return the index data from the first node in the agent's
 
22
 * subtree_context_cache list.
 
23
 */
 
24
netsnmp_variable_list *
 
25
get_first_context(void **my_loop_context, void **my_data_context,
 
26
                  netsnmp_variable_list * put_data,
 
27
                  netsnmp_iterator_info *iinfo)
 
28
{
 
29
    subtree_context_cache *context_ptr;
 
30
    context_ptr = get_top_context_cache();
 
31
 
 
32
    if (!context_ptr)
 
33
        return NULL;
 
34
 
 
35
    *my_loop_context = context_ptr;
 
36
    *my_data_context = context_ptr;
 
37
 
 
38
    snmp_set_var_value(put_data, context_ptr->context_name,
 
39
                       strlen(context_ptr->context_name));
 
40
    return put_data;
 
41
}
 
42
 
 
43
/*
 
44
 * return the next index data from the first node in the agent's
 
45
 * subtree_context_cache list.
 
46
 */
 
47
netsnmp_variable_list *
 
48
get_next_context(void **my_loop_context,
 
49
                 void **my_data_context,
 
50
                 netsnmp_variable_list * put_data,
 
51
                 netsnmp_iterator_info *iinfo)
 
52
{
 
53
    subtree_context_cache *context_ptr;
 
54
 
 
55
    if (!my_loop_context || !*my_loop_context)
 
56
        return NULL;
 
57
 
 
58
    context_ptr = (subtree_context_cache *) (*my_loop_context);
 
59
    context_ptr = context_ptr->next;
 
60
    *my_loop_context = context_ptr;
 
61
    *my_data_context = context_ptr;
 
62
 
 
63
    if (!context_ptr)
 
64
        return NULL;
 
65
 
 
66
    snmp_set_var_value(put_data, context_ptr->context_name,
 
67
                       strlen(context_ptr->context_name));
 
68
    return put_data;
 
69
}
 
70
 
 
71
void
 
72
init_vacm_context(void)
 
73
{
 
74
    /*
 
75
     * table vacm_context
 
76
     */
 
77
    netsnmp_handler_registration *my_handler;
 
78
    netsnmp_table_registration_info *table_info;
 
79
    netsnmp_iterator_info *iinfo;
 
80
 
 
81
    my_handler = netsnmp_create_handler_registration("vacm_context",
 
82
                                                     vacm_context_handler,
 
83
                                                     vacm_context_oid,
 
84
                                                     sizeof
 
85
                                                     (vacm_context_oid) /
 
86
                                                     sizeof(oid),
 
87
                                                     HANDLER_CAN_RONLY);
 
88
 
 
89
    if (!my_handler)
 
90
        return;
 
91
 
 
92
    table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info);
 
93
    iinfo = SNMP_MALLOC_TYPEDEF(netsnmp_iterator_info);
 
94
 
 
95
    if (!table_info || !iinfo)
 
96
        return;
 
97
 
 
98
    netsnmp_table_helper_add_index(table_info, ASN_OCTET_STR)
 
99
        table_info->min_column = 1;
 
100
    table_info->max_column = 1;
 
101
    iinfo->get_first_data_point = get_first_context;
 
102
    iinfo->get_next_data_point = get_next_context;
 
103
    iinfo->table_reginfo = table_info;
 
104
    netsnmp_register_table_iterator(my_handler, iinfo);
 
105
}
 
106
 
 
107
/*
 
108
 * returns a list of known context names
 
109
 */
 
110
 
 
111
int
 
112
vacm_context_handler(netsnmp_mib_handler *handler,
 
113
                     netsnmp_handler_registration *reginfo,
 
114
                     netsnmp_agent_request_info *reqinfo,
 
115
                     netsnmp_request_info *requests)
 
116
{
 
117
    subtree_context_cache *context_ptr;
 
118
 
 
119
    for(; requests; requests = requests->next) {
 
120
        netsnmp_variable_list *var = requests->requestvb;
 
121
 
 
122
        if (requests->processed != 0)
 
123
            continue;
 
124
 
 
125
 
 
126
        context_ptr = (subtree_context_cache *)
 
127
            netsnmp_extract_iterator_context(requests);
 
128
 
 
129
        if (context_ptr == NULL) {
 
130
            snmp_log(LOG_ERR,
 
131
                     "vacm_context_handler called without data\n");
 
132
            continue;
 
133
        }
 
134
 
 
135
        switch (reqinfo->mode) {
 
136
        case MODE_GET:
 
137
            /*
 
138
             * if here we should have a context_ptr passed in already 
 
139
             */
 
140
            /*
 
141
             * only one column should ever reach us, so don't check it 
 
142
             */
 
143
            snmp_set_var_typed_value(var, ASN_OCTET_STR,
 
144
                                     context_ptr->context_name,
 
145
                                     strlen(context_ptr->context_name));
 
146
 
 
147
            break;
 
148
 
 
149
        default:
 
150
            /*
 
151
             * We should never get here, getnext already have been
 
152
             * handled by the table_iterator and we're read_only 
 
153
             */
 
154
            snmp_log(LOG_ERR,
 
155
                     "vacm_context table accessed as mode=%d.  We're improperly registered!",
 
156
                     reqinfo->mode);
 
157
            break;
 
158
 
 
159
 
 
160
        }
 
161
    }
 
162
 
 
163
    return SNMP_ERR_NOERROR;
 
164
}