Debian Codegraph @

agent/mibgroup/disman/ping/pingProbeHistoryTable.c

raw
1 /*
2 *Copyright(c)2004,Cisco URP imburses and Network Information Center in Beijing University of Posts and Telecommunications researches.
3 *
4 *All right reserved
5 *
6 *File Name:pingProbeHistoryTable.c
7 *File Description:Rows of pingProbeHistoryTable MIB read.
8 *
9 *
10 *Current Version:1.0
11 *Author:ChenJing
12 *Date:2004.8.20
13 */
14
15
16 /*
17 * This should always be included first before anything else
18 */
19 #ifdef HAVE_STDLIB_H
20 #include <stdlib.h>
21 #endif
22 #ifdef HAVE_STRING_H
23 #include <string.h>
24 #else
25 #include <strings.h>
26 #endif
27 #ifdef HAVE_LIMITS_H
28 #include <limits.h>
29 #endif
30
31
32
33
34 #include <net-snmp/net-snmp-config.h>
35 #include <net-snmp/net-snmp-includes.h>
36 #include <net-snmp/agent/net-snmp-agent-includes.h>
37
38 #include "pingCtlTable.h"
39 #include "pingResultsTable.h"
40 #include "pingProbeHistoryTable.h"
41 #include "header_complex.h"
42
43
44 /*
45 *pingProbeHistoryTable_variables_oid:
46 *
47 */
48
49 oid pingProbeHistoryTable_variables_oid[] =
50 { 1, 3, 6, 1, 2, 1, 80, 1, 4 };
51
52 struct variable2 pingProbeHistoryTable_variables[] = {
53 {COLUMN_PINGPROBEHISTORYRESPONSE, ASN_UNSIGNED, NETSNMP_OLDAPI_RONLY,
54 var_pingProbeHistoryTable, 2, {1, 2}},
55 {COLUMN_PINGPROBEHISTORYSTATUS, ASN_INTEGER, NETSNMP_OLDAPI_RONLY,
56 var_pingProbeHistoryTable, 2, {1, 3}},
57 {COLUMN_PINGPROBEHISTORYLASTRC, ASN_INTEGER, NETSNMP_OLDAPI_RONLY,
58 var_pingProbeHistoryTable, 2, {1, 4}},
59 {COLUMN_PINGPROBEHISTORYTIME, ASN_OCTET_STR, NETSNMP_OLDAPI_RONLY,
60 var_pingProbeHistoryTable, 2, {1, 5}}
61 };
62
63
64 int
65 pingProbeHistoryTable_inadd(struct pingProbeHistoryTable_data *thedata);
66
67 #if 0
68 void
69 pingProbeHistoryTable_cleaner(struct header_complex_index *thestuff)
70 {
71 struct header_complex_index *hciptr, *nhciptr;
72
73 DEBUGMSGTL(("pingProbeHistoryTable", "cleanerout "));
74 for (hciptr = thestuff; hciptr; hciptr = nhciptr) {
75 nhciptr = hciptr->next;
76 header_complex_extract_entry(&pingProbeHistoryTableStorage, hciptr);
77 DEBUGMSGTL(("pingProbeHistoryTable", "cleaner "));
78 }
79 }
80 #endif
81
82 void
83 init_pingProbeHistoryTable(void)
84 {
85
86 DEBUGMSGTL(("pingProbeHistoryTable", "initializing... "));
87
88
89 /*
90 * register ourselves with the agent to handle our mib tree
91 */
92 REGISTER_MIB("pingProbeHistoryTable", pingProbeHistoryTable_variables,
93 variable2, pingProbeHistoryTable_variables_oid);
94
95
96 /*
97 * register our config handler(s) to deal with registrations
98 */
99 snmpd_register_config_handler("pingProbeHistoryTable",
100 parse_pingProbeHistoryTable, NULL, NULL);
101
102 /*
103 * we need to be called back later to store our data
104 */
105 snmp_register_callback(SNMP_CALLBACK_LIBRARY, SNMP_CALLBACK_STORE_DATA,
106 store_pingProbeHistoryTable, NULL);
107
108 DEBUGMSGTL(("pingProbeHistoryTable", "done.\n"));
109 }
110
111 /*
112 * parse_mteObjectsTable():
113 * parses .conf file entries needed to configure the mib.
114 */
115
116 void
117 parse_pingProbeHistoryTable(const char *token, char *line)
118 {
119 size_t tmpint;
120 struct pingProbeHistoryTable_data *StorageTmp =
121 SNMP_MALLOC_STRUCT(pingProbeHistoryTable_data);
122
123 DEBUGMSGTL(("pingProbeHistoryTable", "parsing config... "));
124
125
126 if (StorageTmp == NULL) {
127 config_perror("malloc failure");
128 return;
129 }
130
131 line =
132 read_config_read_data(ASN_OCTET_STR, line,
133 &StorageTmp->pingCtlOwnerIndex,
134 &StorageTmp->pingCtlOwnerIndexLen);
135 if (StorageTmp->pingCtlOwnerIndex == NULL) {
136 config_perror("invalid specification for pingCtlOwnerIndex");
137 free(StorageTmp);
138 return;
139 }
140
141 line =
142 read_config_read_data(ASN_OCTET_STR, line,
143 &StorageTmp->pingCtlTestName,
144 &StorageTmp->pingCtlTestNameLen);
145 if (StorageTmp->pingCtlTestName == NULL) {
146 config_perror("invalid specification for pingCtlTestName");
147 free(StorageTmp);
148 return;
149 }
150
151 line =
152 read_config_read_data(ASN_UNSIGNED, line,
153 &StorageTmp->pingProbeHistoryIndex, &tmpint);
154 line =
155 read_config_read_data(ASN_UNSIGNED, line,
156 &StorageTmp->pingProbeHistoryResponse,
157 &tmpint);
158 line =
159 read_config_read_data(ASN_INTEGER, line,
160 &StorageTmp->pingProbeHistoryStatus,
161 &tmpint);
162 line =
163 read_config_read_data(ASN_INTEGER, line,
164 &StorageTmp->pingProbeHistoryLastRC,
165 &tmpint);
166
167 line =
168 read_config_read_data(ASN_OCTET_STR, line,
169 &StorageTmp->pingProbeHistoryTime,
170 &StorageTmp->pingProbeHistoryTimeLen);
171 if (StorageTmp->pingProbeHistoryTime == NULL) {
172 config_perror("invalid specification for pingProbeHistoryTime");
173 free(StorageTmp);
174 return;
175 }
176
177
178 pingProbeHistoryTable_inadd(StorageTmp);
179
180 /* pingProbeHistoryTable_cleaner(pingProbeHistoryTableStorage); */
181
182 DEBUGMSGTL(("pingProbeHistoryTable", "done.\n"));
183 }
184
185
186
187
188
189 /*
190 * store_pingProbeHistoryTable():
191 * stores .conf file entries needed to configure the mib.
192 */
193
194 int
195 store_pingProbeHistoryTable(int majorID, int minorID, void *serverarg,
196 void *clientarg)
197 {
198 char line[SNMP_MAXBUF];
199 char *cptr;
200 size_t tmpint;
201 struct pingProbeHistoryTable_data *StorageTmp;
202 struct header_complex_index *hcindex;
203
204
205 DEBUGMSGTL(("pingProbeHistoryTable", "storing data... "));
206
207
208 for (hcindex = pingProbeHistoryTableStorage; hcindex != NULL;
209 hcindex = hcindex->next) {
210 StorageTmp = (struct pingProbeHistoryTable_data *) hcindex->data;
211
212 if (StorageTmp->storageType != ST_READONLY) {
213 memset(line, 0, sizeof(line));
214 strcat(line, "pingProbeHistoryTable ");
215 cptr = line + strlen(line);
216
217 cptr =
218 read_config_store_data(ASN_OCTET_STR, cptr,
219 &StorageTmp->pingCtlOwnerIndex,
220 &StorageTmp->pingCtlOwnerIndexLen);
221 cptr =
222 read_config_store_data(ASN_OCTET_STR, cptr,
223 &StorageTmp->pingCtlTestName,
224 &StorageTmp->pingCtlTestNameLen);
225 cptr =
226 read_config_store_data(ASN_UNSIGNED, cptr,
227 &StorageTmp->pingProbeHistoryIndex,
228 &tmpint);
229 cptr =
230 read_config_store_data(ASN_UNSIGNED, cptr,
231 &StorageTmp->
232 pingProbeHistoryResponse, &tmpint);
233 cptr =
234 read_config_store_data(ASN_INTEGER, cptr,
235 &StorageTmp->pingProbeHistoryStatus,
236 &tmpint);
237 cptr =
238 read_config_store_data(ASN_INTEGER, cptr,
239 &StorageTmp->pingProbeHistoryLastRC,
240 &tmpint);
241 cptr =
242 read_config_store_data(ASN_OCTET_STR, cptr,
243 &StorageTmp->pingProbeHistoryTime,
244 &StorageTmp->
245 pingProbeHistoryTimeLen);
246
247 snmpd_store_config(line);
248 }
249 }
250 DEBUGMSGTL(("pingProbeHistoryTable", "done.\n"));
251 return SNMPERR_SUCCESS;
252 }
253
254
255 int
256 pingProbeHistoryTable_inadd(struct pingProbeHistoryTable_data *thedata)
257 {
258 netsnmp_variable_list *vars_list;
259 vars_list = NULL;
260
261
262 snmp_varlist_add_variable(&vars_list, NULL, 0, ASN_OCTET_STR, (char *) thedata->pingCtlOwnerIndex, thedata->pingCtlOwnerIndexLen); /* pingCtlOwnerIndex */
263 snmp_varlist_add_variable(&vars_list, NULL, 0, ASN_OCTET_STR, (char *) thedata->pingCtlTestName, thedata->pingCtlTestNameLen); /* pingCtlTestName */
264 snmp_varlist_add_variable(&vars_list, NULL, 0, ASN_UNSIGNED, (char *) &thedata->pingProbeHistoryIndex, sizeof(thedata->pingProbeHistoryIndex)); /* pingProbeHistoryIndex */
265
266 /*
267 * XXX: fill in default row values here into StorageNew
268 *
269 */
270
271
272 DEBUGMSGTL(("pingProbeHistoryTable", "adding data... "));
273 /*
274 * add the index variables to the varbind list, which is
275 * used by header_complex to index the data
276 */
277
278 header_complex_add_data(&pingProbeHistoryTableStorage, vars_list,
279 thedata);
280 DEBUGMSGTL(("pingProbeHistoryTable", "registered an entry\n"));
281
282
283 DEBUGMSGTL(("pingProbeHistoryTable", "done.\n"));
284 return SNMPERR_SUCCESS;
285 }
286
287
288 /*
289 * var_pingProbeHistoryTable():
290 * Handle this table separately from the scalar value case.
291 * The workings of this are basically the same as for var_pingProbeHistoryTable above.
292 */
293 unsigned char *
294 var_pingProbeHistoryTable(struct variable *vp,
295 oid * name,
296 size_t *length,
297 int exact,
298 size_t *var_len, WriteMethod ** write_method)
299 {
300
301
302 struct pingProbeHistoryTable_data *StorageTmp = NULL;
303
304 *write_method = NULL;
305 /*
306 * this assumes you have registered all your data properly
307 */
308 if ((StorageTmp =
309 header_complex(pingProbeHistoryTableStorage, vp, name, length,
310 exact, var_len, write_method)) == NULL) {
311
312 return NULL;
313 }
314
315 /*
316 * this is where we do the value assignments for the mib results.
317 */
318
319 switch (vp->magic) {
320
321 case COLUMN_PINGPROBEHISTORYRESPONSE:
322 *var_len = sizeof(StorageTmp->pingProbeHistoryResponse);
323 return (u_char *) & StorageTmp->pingProbeHistoryResponse;
324
325 case COLUMN_PINGPROBEHISTORYSTATUS:
326 *var_len = sizeof(StorageTmp->pingProbeHistoryStatus);
327 return (u_char *) & StorageTmp->pingProbeHistoryStatus;
328
329 case COLUMN_PINGPROBEHISTORYLASTRC:
330 *var_len = sizeof(StorageTmp->pingProbeHistoryLastRC);
331 return (u_char *) & StorageTmp->pingProbeHistoryLastRC;
332
333 case COLUMN_PINGPROBEHISTORYTIME:
334 *var_len = (StorageTmp->pingProbeHistoryTimeLen);
335 return (u_char *) StorageTmp->pingProbeHistoryTime;
336
337 default:
338 ERROR_MSG("");
339 }
340
341 return NULL;
342 }