Revert "Revert "and added files""
[bcm963xx.git] / userapps / opensource / net-snmp / agent / mibgroup / agent / nsTransactionTable.c
1 #ifdef BRCM_SNMP_MIB_SUPPORT
2 /*
3  * Note: this file originally auto-generated by mib2c 
4  */
5
6 #include <net-snmp/net-snmp-config.h>
7 #include <net-snmp/net-snmp-includes.h>
8 #include <net-snmp/agent/net-snmp-agent-includes.h>
9
10 #include <net-snmp/agent/table.h>
11 #include <net-snmp/agent/table_iterator.h>
12 #include "nsTransactionTable.h"
13
14 /** Initialize the nsTransactionTable table by defining it's contents
15    and how it's structured */
16 void
17 initialize_table_nsTransactionTable(void)
18 {
19     static oid      nsTransactionTable_oid[] =
20         { 1, 3, 6, 1, 4, 1, 8072, 1, 8, 1 };
21     size_t          nsTransactionTable_oid_len =
22         OID_LENGTH(nsTransactionTable_oid);
23     netsnmp_table_registration_info *table_info;
24     netsnmp_handler_registration *my_handler;
25     netsnmp_iterator_info *iinfo;
26
27     /*
28      * create the table structure itself 
29      */
30     table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info);
31     iinfo = SNMP_MALLOC_TYPEDEF(netsnmp_iterator_info);
32
33     /*
34      * if your table is read only, it's easiest to change the
35      * HANDLER_CAN_RWRITE definition below to HANDLER_CAN_RONLY 
36      */
37     my_handler = netsnmp_create_handler_registration("nsTransactionTable",
38                                                      nsTransactionTable_handler,
39                                                      nsTransactionTable_oid,
40                                                      nsTransactionTable_oid_len,
41                                                      HANDLER_CAN_RONLY);
42
43     if (!my_handler || !table_info || !iinfo)
44         return;                 /* mallocs failed */
45
46     /***************************************************
47      * Setting up the table's definition
48      */
49     netsnmp_table_helper_add_index(table_info, ASN_INTEGER);    /* index:
50                                                                  * * nsTransactionID 
51                                                                  */
52
53     table_info->min_column = 2;
54     table_info->max_column = 2;
55     iinfo->get_first_data_point = nsTransactionTable_get_first_data_point;
56     iinfo->get_next_data_point = nsTransactionTable_get_next_data_point;
57     iinfo->table_reginfo = table_info;
58
59     /***************************************************
60      * registering the table with the master agent
61      */
62     DEBUGMSGTL(("initialize_table_nsTransactionTable",
63                 "Registering table nsTransactionTable as a table iterator\n"));
64     netsnmp_register_table_iterator(my_handler, iinfo);
65 }
66
67 /** Initialzies the nsTransactionTable module */
68 void
69 init_nsTransactionTable(void)
70 {
71
72     /*
73      * here we initialize all the tables we're planning on supporting 
74      */
75     initialize_table_nsTransactionTable();
76 }
77
78 /** returns the first data point within the nsTransactionTable table data.
79
80     Set the my_loop_context variable to the first data point structure
81     of your choice (from which you can find the next one).  This could
82     be anything from the first node in a linked list, to an integer
83     pointer containing the beginning of an array variable.
84
85     Set the my_data_context variable to something to be returned to
86     you later that will provide you with the data to return in a given
87     row.  This could be the same pointer as what my_loop_context is
88     set to, or something different.
89
90     The put_index_data variable contains a list of snmp variable
91     bindings, one for each index in your table.  Set the values of
92     each appropriately according to the data matching the first row
93     and return the put_index_data variable at the end of the function.
94 */
95 extern netsnmp_agent_session *agent_delegated_list;
96
97 netsnmp_variable_list *
98 nsTransactionTable_get_first_data_point(void **my_loop_context,
99                                         void **my_data_context,
100                                         netsnmp_variable_list
101                                         * put_index_data,
102                                         netsnmp_iterator_info *iinfo)
103 {
104
105     netsnmp_variable_list *vptr;
106
107     if (!agent_delegated_list)
108         return NULL;
109
110     *my_loop_context = (void *) agent_delegated_list;
111     *my_data_context = (void *) agent_delegated_list;
112
113     vptr = put_index_data;
114
115     snmp_set_var_value(vptr,
116                        (u_char *) & agent_delegated_list->pdu->transid,
117                        sizeof(agent_delegated_list->pdu->transid));
118     return put_index_data;
119 }
120
121 /** functionally the same as nsTransactionTable_get_first_data_point, but
122    my_loop_context has already been set to a previous value and should
123    be updated to the next in the list.  For example, if it was a
124    linked list, you might want to cast it and the return
125    my_loop_context->next.  The my_data_context pointer should be set
126    to something you need later and the indexes in put_index_data
127    updated again. */
128
129 netsnmp_variable_list *
130 nsTransactionTable_get_next_data_point(void **my_loop_context,
131                                        void **my_data_context,
132                                        netsnmp_variable_list
133                                        * put_index_data,
134                                        netsnmp_iterator_info *iinfo)
135 {
136
137     netsnmp_variable_list *vptr;
138     netsnmp_agent_session *alist = (netsnmp_agent_session *)
139         *my_loop_context;
140
141     if (!alist->next)
142         return NULL;
143
144     alist = alist->next;
145
146     *my_loop_context = (void *) alist;
147     *my_data_context = (void *) alist;
148
149     vptr = put_index_data;
150
151     snmp_set_var_value(vptr, (u_char *) & alist->pdu->transid,
152                        sizeof(alist->pdu->transid));
153     return put_index_data;
154 }
155
156 /** handles requests for the nsTransactionTable table, if anything
157    else needs to be done */
158 int
159 nsTransactionTable_handler(netsnmp_mib_handler *handler,
160                            netsnmp_handler_registration *reginfo,
161                            netsnmp_agent_request_info *reqinfo,
162                            netsnmp_request_info *requests)
163 {
164
165     netsnmp_table_request_info *table_info;
166     netsnmp_variable_list *var;
167     netsnmp_agent_session *asp;
168
169     while (requests) {
170         var = requests->requestvb;
171         if (requests->processed != 0)
172             continue;
173
174         /*
175          * perform anything here that you need to do.  The requests have
176          * already been processed by the master table_dataset handler, but
177          * this gives you chance to act on the request in some other way if 
178          * need be. 
179          */
180
181         /*
182          * the following extracts the my_data_context pointer set in the
183          * loop functions above.  You can then use the results to help
184          * return data for the columns of the nsTransactionTable table in
185          * question 
186          */
187         asp =
188             (netsnmp_agent_session *)
189             netsnmp_extract_iterator_context(requests);
190         if (asp == NULL) {
191             netsnmp_set_request_error(reqinfo, requests,
192                                       SNMP_NOSUCHINSTANCE);
193         }
194
195         /*
196          * extracts the information about the table from the request 
197          */
198         table_info = netsnmp_extract_table_info(requests);
199
200         /*
201          * table_info->colnum contains the column number requested 
202          */
203         /*
204          * table_info->indexes contains a linked list of snmp variable
205          * bindings for the indexes of the table.  Values in the list have 
206          * been set corresponding to the indexes of the request 
207          */
208         if (table_info == NULL) {
209             requests = requests->next;
210             continue;
211         }
212
213         switch (reqinfo->mode) {
214             /*
215              * the table_iterator helper should change all GETNEXTs into
216              * GETs for you automatically, so you don't have to worry
217              * about the GETNEXT case.  Only GETs and SETs need to be
218              * dealt with here 
219              */
220         case MODE_GET:
221             switch (table_info->colnum) {
222
223             case COLUMN_NSTRANSACTIONMODE:
224                 snmp_set_var_typed_value(var, ASN_INTEGER,
225                                          (u_char *) & asp->mode,
226                                          sizeof(asp->mode));
227                 break;
228
229             default:
230                 /*
231                  * We shouldn't get here 
232                  */
233                 snmp_log(LOG_ERR,
234                          "problem encountered in nsTransactionTable_handler: unknown column\n");
235             }
236             break;
237
238         default:
239             snmp_log(LOG_ERR,
240                      "problem encountered in nsTransactionTable_handler: unsupported mode\n");
241         }
242         requests = requests->next;
243     }
244     return SNMP_ERR_NOERROR;
245 }
246 #endif /* BRCM_SNMP_MIB_SUPPORT */