Revert "Revert "and added files""
[bcm963xx.git] / userapps / opensource / net-snmp / agent / mibgroup / disman / mteEventTable.c
1 /*
2  * Note: this file originally auto-generated by mib2c using
3  *        : mib2c.create-dataset.conf,v 5.2 2002/07/17 14:41:53 dts12 Exp $
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 #include "mteTriggerTable.h"
10 #include "mteEventTable.h"
11 #include "mteEventNotificationTable.h"
12 #include "mteObjectsTable.h"
13
14 netsnmp_table_data_set *table_set = NULL;
15
16 /** Initialize the mteEventTable table by defining its contents and how it's structured */
17 void
18 initialize_table_mteEventTable(void)
19 {
20     static oid      mteEventTable_oid[] =
21         { 1, 3, 6, 1, 2, 1, 88, 1, 4, 2 };
22     size_t          mteEventTable_oid_len = OID_LENGTH(mteEventTable_oid);
23
24     /*
25      * create the table structure itself 
26      */
27     table_set = netsnmp_create_table_data_set("mteEventTable");
28
29     /*
30      * comment this out or delete if you don't support creation of new rows 
31      */
32     table_set->allow_creation = 1;
33     /* mark the row status column */
34     table_set->rowstatus_column = COLUMN_MTEEVENTENTRYSTATUS;
35
36     /***************************************************
37      * Adding indexes
38      */
39     DEBUGMSGTL(("initialize_table_mteEventTable",
40                 "adding indexes to table mteEventTable\n"));
41     netsnmp_table_set_add_indexes(table_set,
42                                   ASN_OCTET_STR,   /* index: mteOwner */
43                                   ASN_PRIV_IMPLIED_OCTET_STR, /* index: mteEventName */
44                                   0);
45
46     DEBUGMSGTL(("initialize_table_mteEventTable",
47                 "adding column types to table mteEventTable\n"));
48     netsnmp_table_set_multi_add_default_row(table_set,
49                                             COLUMN_MTEEVENTNAME,
50                                             ASN_OCTET_STR, 0, NULL, 0,
51                                             COLUMN_MTEEVENTCOMMENT,
52                                             ASN_OCTET_STR, 1, NULL, 0,
53                                             COLUMN_MTEEVENTACTIONS,
54                                             ASN_OCTET_STR, 1, NULL, 0,
55                                             COLUMN_MTEEVENTENABLED,
56                                             ASN_INTEGER, 1, NULL, 0,
57                                             COLUMN_MTEEVENTENTRYSTATUS,
58                                             ASN_INTEGER, 1, NULL, 0, 0);
59
60     /* keep index values around for comparisons later */
61     table_set->table->store_indexes = 1;
62     /*
63      * registering the table with the master agent 
64      */
65     /*
66      * note: if you don't need a subhandler to deal with any aspects
67      * of the request, change mteEventTable_handler to "NULL" 
68      */
69     netsnmp_register_table_data_set(netsnmp_create_handler_registration
70                                     ("mteEventTable",
71                                      mteEventTable_handler,
72                                      mteEventTable_oid,
73                                      mteEventTable_oid_len,
74                                      HANDLER_CAN_RWRITE), table_set, NULL);
75 }
76
77 /** Initializes the mteEventTable module */
78 void
79 init_mteEventTable(void)
80 {
81
82     /*
83      * here we initialize all the tables we're planning on supporting 
84      */
85     initialize_table_mteEventTable();
86 }
87
88 /** handles requests for the mteEventTable table, if anything else needs to be done */
89 int
90 mteEventTable_handler(netsnmp_mib_handler *handler,
91                       netsnmp_handler_registration *reginfo,
92                       netsnmp_agent_request_info *reqinfo,
93                       netsnmp_request_info *requests)
94 {
95     /*
96      * perform anything here that you need to do.  The requests have
97      * already been processed by the master table_dataset handler, but
98      * this gives you chance to act on the request in some other way
99      * if need be. 
100      */
101
102     /* XXX: on rowstatus = destroy, remove the corresponding rows from the
103        other tables: snmpEventNotificationTable and the set table */
104     return SNMP_ERR_NOERROR;
105 }
106
107 /*
108  * send trap 
109  */
110 void
111 run_mte_events(struct mteTriggerTable_data *item,
112                oid * name_oid, size_t name_oid_len,
113                const char *eventobjowner, const char *eventobjname)
114 {
115     static oid      objid_snmptrap[] = { 1, 3, 6, 1, 6, 3, 1, 1, 4, 1, 0 };     /* snmpTrapIOD.0 */
116
117     netsnmp_variable_list *var_list = NULL;
118
119     netsnmp_table_row *row, *notif_row;
120     netsnmp_table_data_set_storage *col1, *tc, *no, *noo;
121
122     for(row = table_set->table->first_row; row; row = row->next) {
123         if (strcmp(row->indexes->val.string, eventobjowner) == 0 &&
124             strcmp(row->indexes->next_variable->val.string,
125                    eventobjname) == 0) {
126             /* run this event */
127             col1 = (netsnmp_table_data_set_storage *) row->data;
128             
129             tc = netsnmp_table_data_set_find_column(col1,
130                                                     COLUMN_MTEEVENTACTIONS);
131             if (!tc->data.bitstring[0] & 0x80) {
132                 /* not a notification.  next! (XXX: do sets) */
133                 continue;
134             }
135
136             tc = netsnmp_table_data_set_find_column(col1,
137                                                     COLUMN_MTEEVENTENABLED);
138             if (*(tc->data.integer) != 1) {
139                 /* not enabled.  next! */
140                 continue;
141             }
142
143             if (!mteEventNotif_table_set) {
144                 /* no notification info */
145                 continue;
146             }
147
148             /* send the notification */
149             var_list = NULL;
150
151             /* XXX: get notif information */
152             for(notif_row = mteEventNotif_table_set->table->first_row;
153                 notif_row; notif_row = notif_row->next) {
154                 if (strcmp(notif_row->indexes->val.string,
155                            eventobjowner) == 0 &&
156                     strcmp(notif_row->indexes->next_variable->val.string,
157                            eventobjname) == 0) {
158
159                     /* run this event */
160                     col1 = (netsnmp_table_data_set_storage *) notif_row->data;
161             
162                     tc = netsnmp_table_data_set_find_column(col1, COLUMN_MTEEVENTNOTIFICATION);
163                     no = netsnmp_table_data_set_find_column(col1, COLUMN_MTEEVENTNOTIFICATIONOBJECTS);
164                     noo = netsnmp_table_data_set_find_column(col1, COLUMN_MTEEVENTNOTIFICATIONOBJECTSOWNER);
165                     if (!tc)
166                         continue; /* no notification to be had. XXX: return? */
167                     
168                     /*
169                      * snmpTrap oid 
170                      */
171                     snmp_varlist_add_variable(&var_list, objid_snmptrap,
172                                               sizeof(objid_snmptrap) /
173                                               sizeof(oid),
174                                               ASN_OBJECT_ID,
175                                               (u_char *) tc->data.objid,
176                                               tc->data_len);
177
178                     /* XXX: add objects from the mteObjectsTable */
179                     if (no && no->data.string &&
180                         noo && noo->data.string && name_oid) {
181                         mte_add_objects(var_list, item,
182                                         noo->data.string,
183                                         no->data.string,
184                                         name_oid + item->mteTriggerValueIDLen,
185                                         name_oid_len - item->mteTriggerValueIDLen);
186                     }
187
188                     DEBUGMSGTL(("mteEventTable:send_events", "sending an event "));
189                     DEBUGMSGOID(("mteEventTable:send_events", tc->data.objid, tc->data_len / sizeof(oid)));
190                     DEBUGMSG(("mteEventTable:send_events", "\n"));
191                     
192                     send_v2trap(var_list);
193                     snmp_free_varbind(var_list);
194                 }
195             }
196         }
197     }
198 }