|
1 /* |
|
2 * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved. |
|
3 * |
|
4 * U.S. Government Rights - Commercial software. Government users are subject |
|
5 * to the Sun Microsystems, Inc. standard license agreement and applicable |
|
6 * provisions of the FAR and its supplements. |
|
7 * |
|
8 * |
|
9 * This distribution may include materials developed by third parties. Sun, |
|
10 * Sun Microsystems, the Sun logo and Solaris are trademarks or registered |
|
11 * trademarks of Sun Microsystems, Inc. in the U.S. and other countries. |
|
12 * |
|
13 */ |
|
14 /* |
|
15 * Note: this file originally auto-generated by mib2c using |
|
16 * : mib2c.iterate.conf,v 5.5 2002/12/16 22:50:18 hardaker Exp $ |
|
17 */ |
|
18 |
|
19 #include <net-snmp/net-snmp-config.h> |
|
20 #include <net-snmp/net-snmp-includes.h> |
|
21 #include <net-snmp/agent/net-snmp-agent-includes.h> |
|
22 #include "stdhdr.h" |
|
23 #include "entLogicalTable.h" |
|
24 #include "entAliasMappingTable.h" |
|
25 #include "entLastChangeTime.h" |
|
26 #include "entLPMappingTable.h" |
|
27 |
|
28 static int AddToLogicalTable(entLogicalEntry_t *); |
|
29 static int FreeLogicalEntry(entLogicalEntry_t *); |
|
30 |
|
31 entLogicalEntry_t *gLogicalTableHead, *gLogicalTableTail; |
|
32 int gLogicalTableSize; |
|
33 |
|
34 |
|
35 /** Initialize the entLogicalTable table by defining its contents and how it's structured */ |
|
36 void |
|
37 initialize_table_entLogicalTable(void) |
|
38 { |
|
39 static oid entLogicalTable_oid[] = {1,3,6,1,2,1,47,1,2,1}; |
|
40 netsnmp_table_registration_info *table_info; |
|
41 netsnmp_handler_registration *my_handler; |
|
42 netsnmp_iterator_info *iinfo; |
|
43 |
|
44 /* create the table structure itself */ |
|
45 table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info); |
|
46 iinfo = SNMP_MALLOC_TYPEDEF(netsnmp_iterator_info); |
|
47 |
|
48 /* if your table is read only, it's easiest to change the |
|
49 HANDLER_CAN_RWRITE definition below to HANDLER_CAN_RONLY */ |
|
50 /* Fix for 4910624 - changing HANDLER_CAN_RWRITE to HANDLER_CAN_RONLY */ |
|
51 my_handler = netsnmp_create_handler_registration("entLogicalTable", |
|
52 entLogicalTable_handler, |
|
53 entLogicalTable_oid, |
|
54 OID_LENGTH(entLogicalTable_oid), |
|
55 HANDLER_CAN_RONLY); |
|
56 /* End of Fix for 4910624 */ |
|
57 |
|
58 if (!my_handler || !table_info || !iinfo) |
|
59 return; /* mallocs failed */ |
|
60 |
|
61 /*************************************************** |
|
62 * Setting up the table's definition |
|
63 */ |
|
64 netsnmp_table_helper_add_indexes(table_info, |
|
65 ASN_INTEGER, /* index: entLogicalIndex */ |
|
66 0); |
|
67 |
|
68 table_info->min_column = 2; |
|
69 table_info->max_column = 8; |
|
70 |
|
71 /* iterator access routines */ |
|
72 iinfo->get_first_data_point = entLogicalTable_get_first_data_point; |
|
73 iinfo->get_next_data_point = entLogicalTable_get_next_data_point; |
|
74 |
|
75 iinfo->table_reginfo = table_info; |
|
76 |
|
77 /*************************************************** |
|
78 * registering the table with the master agent |
|
79 */ |
|
80 DEBUGMSGTL(("initialize_table_entLogicalTable", |
|
81 "Registering table entLogicalTable as a table iterator\n")); |
|
82 netsnmp_register_table_iterator(my_handler, iinfo); |
|
83 } |
|
84 |
|
85 /** Initializes the entLogicalTable module */ |
|
86 void |
|
87 init_entLogicalTable(void) |
|
88 { |
|
89 |
|
90 /* here we initialize all the tables we're planning on supporting */ |
|
91 initialize_table_entLogicalTable(); |
|
92 gLogicalTableHead = NULL; |
|
93 gLogicalTableSize = 0; |
|
94 gLogicalTableTail = NULL; |
|
95 } |
|
96 |
|
97 /** returns the first data point within the entLogicalTable table data. |
|
98 |
|
99 Set the my_loop_context variable to the first data point structure |
|
100 of your choice (from which you can find the next one). This could |
|
101 be anything from the first node in a linked list, to an integer |
|
102 pointer containing the beginning of an array variable. |
|
103 |
|
104 Set the my_data_context variable to something to be returned to |
|
105 you later that will provide you with the data to return in a given |
|
106 row. This could be the same pointer as what my_loop_context is |
|
107 set to, or something different. |
|
108 |
|
109 The put_index_data variable contains a list of snmp variable |
|
110 bindings, one for each index in your table. Set the values of |
|
111 each appropriately according to the data matching the first row |
|
112 and return the put_index_data variable at the end of the function. |
|
113 */ |
|
114 netsnmp_variable_list * |
|
115 entLogicalTable_get_first_data_point(void **my_loop_context, void **my_data_context, |
|
116 netsnmp_variable_list *put_index_data, |
|
117 netsnmp_iterator_info *mydata) |
|
118 { |
|
119 |
|
120 netsnmp_variable_list *vptr; |
|
121 entLogicalEntry_t *zRunner; |
|
122 zRunner = gLogicalTableHead; |
|
123 |
|
124 while (zRunner) { |
|
125 if (zRunner->entLogicalIndex > 0) |
|
126 break; |
|
127 zRunner = zRunner->pNextEntry; |
|
128 } |
|
129 |
|
130 if (zRunner == NULL) return NULL; |
|
131 |
|
132 *my_loop_context = (void *)zRunner; |
|
133 *my_data_context = (void *)zRunner; |
|
134 |
|
135 vptr = put_index_data; |
|
136 |
|
137 snmp_set_var_value(vptr, (u_char *)&zRunner->entLogicalIndex, sizeof(zRunner->entLogicalIndex)); |
|
138 vptr = vptr->next_variable; |
|
139 |
|
140 return put_index_data; |
|
141 |
|
142 } |
|
143 |
|
144 /** functionally the same as entLogicalTable_get_first_data_point, but |
|
145 my_loop_context has already been set to a previous value and should |
|
146 be updated to the next in the list. For example, if it was a |
|
147 linked list, you might want to cast it and the return |
|
148 my_loop_context->next. The my_data_context pointer should be set |
|
149 to something you need later and the indexes in put_index_data |
|
150 updated again. */ |
|
151 |
|
152 netsnmp_variable_list * |
|
153 entLogicalTable_get_next_data_point(void **my_loop_context, void **my_data_context, |
|
154 netsnmp_variable_list *put_index_data, |
|
155 netsnmp_iterator_info *mydata) |
|
156 { |
|
157 |
|
158 entLogicalEntry_t *zRunner; |
|
159 netsnmp_variable_list *vptr; |
|
160 |
|
161 zRunner = (entLogicalEntry_t *) *my_loop_context; |
|
162 |
|
163 while (zRunner) { |
|
164 zRunner = zRunner->pNextEntry; |
|
165 if (zRunner && zRunner->entLogicalIndex > 0) |
|
166 break; |
|
167 } |
|
168 |
|
169 if (zRunner == NULL) return NULL; |
|
170 |
|
171 *my_loop_context = (void *)zRunner; |
|
172 *my_data_context = (void *)zRunner; |
|
173 |
|
174 vptr = put_index_data; |
|
175 |
|
176 snmp_set_var_value(vptr, (u_char *)&zRunner->entLogicalIndex, sizeof(zRunner->entLogicalIndex)); |
|
177 vptr = vptr->next_variable; |
|
178 |
|
179 return put_index_data; |
|
180 |
|
181 } |
|
182 |
|
183 /** handles requests for the entLogicalTable table, if anything else needs to be done */ |
|
184 int |
|
185 entLogicalTable_handler( |
|
186 netsnmp_mib_handler *handler, |
|
187 netsnmp_handler_registration *reginfo, |
|
188 netsnmp_agent_request_info *reqinfo, |
|
189 netsnmp_request_info *requests) { |
|
190 |
|
191 netsnmp_request_info *request; |
|
192 netsnmp_table_request_info *table_info; |
|
193 netsnmp_variable_list *var; |
|
194 entLogicalEntry_t *zLogicalEntry; |
|
195 |
|
196 for(request = requests; request; request = request->next) { |
|
197 var = request->requestvb; |
|
198 if (request->processed != 0) |
|
199 continue; |
|
200 |
|
201 /* perform anything here that you need to do before each |
|
202 request is processed. */ |
|
203 |
|
204 /* the following extracts the my_data_context pointer set in |
|
205 the loop functions above. You can then use the results to |
|
206 help return data for the columns of the entLogicalTable table in question */ |
|
207 zLogicalEntry = (entLogicalEntry_t *) netsnmp_extract_iterator_context(request); |
|
208 |
|
209 if ((zLogicalEntry == NULL) || (zLogicalEntry->entLogicalIndex <= 0) ) { |
|
210 if (reqinfo->mode == MODE_GET) { |
|
211 netsnmp_set_request_error(reqinfo, request, SNMP_NOSUCHINSTANCE); |
|
212 continue; |
|
213 } |
|
214 /* XXX: no row existed, if you support creation and this is a |
|
215 set, start dealing with it here, else continue */ |
|
216 } |
|
217 |
|
218 /* extracts the information about the table from the request */ |
|
219 table_info = netsnmp_extract_table_info(request); |
|
220 /* table_info->colnum contains the column number requested */ |
|
221 /* table_info->indexes contains a linked list of snmp variable |
|
222 bindings for the indexes of the table. Values in the list |
|
223 have been set corresponding to the indexes of the |
|
224 request */ |
|
225 if (table_info==NULL) { |
|
226 continue; |
|
227 } |
|
228 |
|
229 switch(reqinfo->mode) { |
|
230 /* the table_iterator helper should change all GETNEXTs |
|
231 into GETs for you automatically, so you don't have to |
|
232 worry about the GETNEXT case. Only GETs and SETs need |
|
233 to be dealt with here */ |
|
234 case MODE_GET: |
|
235 switch(table_info->colnum) { |
|
236 case COLUMN_ENTLOGICALDESCR: |
|
237 snmp_set_var_typed_value(var, ASN_OCTET_STR, (u_char *) zLogicalEntry->entLogicalDescr, strlen(zLogicalEntry->entLogicalDescr)); |
|
238 break; |
|
239 |
|
240 case COLUMN_ENTLOGICALTYPE: |
|
241 snmp_set_var_typed_value(var, ASN_OBJECT_ID, (u_char *) zLogicalEntry->entLogicalType, zLogicalEntry->entLogicalTypeSize); |
|
242 break; |
|
243 |
|
244 case COLUMN_ENTLOGICALCOMMUNITY: |
|
245 snmp_set_var_typed_value(var, ASN_OCTET_STR, (u_char *) zLogicalEntry->entLogicalCommunity, strlen(zLogicalEntry->entLogicalCommunity)); |
|
246 break; |
|
247 |
|
248 case COLUMN_ENTLOGICALTADDRESS: |
|
249 snmp_set_var_typed_value(var, ASN_OCTET_STR, (u_char *) zLogicalEntry->entLogicalTAddress, strlen(zLogicalEntry->entLogicalTAddress)); |
|
250 break; |
|
251 |
|
252 case COLUMN_ENTLOGICALTDOMAIN: |
|
253 snmp_set_var_typed_value(var, ASN_OBJECT_ID, (u_char *) zLogicalEntry->entLogicalTDomain, zLogicalEntry->entLogicalTDomainSize); |
|
254 break; |
|
255 |
|
256 case COLUMN_ENTLOGICALCONTEXTENGINEID: |
|
257 snmp_set_var_typed_value(var, ASN_OCTET_STR, (u_char *) zLogicalEntry->entLogicalContextEngineId, strlen(zLogicalEntry->entLogicalContextEngineId)); |
|
258 break; |
|
259 |
|
260 case COLUMN_ENTLOGICALCONTEXTNAME: |
|
261 snmp_set_var_typed_value(var, ASN_OCTET_STR, (u_char *) zLogicalEntry->entLogicalContextName, strlen(zLogicalEntry->entLogicalContextName)); |
|
262 break; |
|
263 |
|
264 default: |
|
265 /* We shouldn't get here */ |
|
266 snmp_log(LOG_ERR, "problem encountered in entLogicalTable_handler: unknown column\n"); |
|
267 } |
|
268 break; |
|
269 |
|
270 case MODE_SET_RESERVE1: |
|
271 /* set handling... */ |
|
272 |
|
273 default: |
|
274 snmp_log(LOG_ERR, "problem encountered in entLogicalTable_handler: unsupported mode\n"); |
|
275 } |
|
276 } |
|
277 return SNMP_ERR_NOERROR; |
|
278 } |
|
279 |
|
280 void populate_entLogicalEntry(entLogicalEntry_t *xLogicalStatic, |
|
281 char *entLogicalDescr, |
|
282 oid *entLogicalType, |
|
283 int entLogicalTypeSize, |
|
284 char *entLogicalCommunity, |
|
285 char *entLogicalTAddress, |
|
286 oid *entLogicalTDomain, |
|
287 int entLogicalTDomainSize, |
|
288 char *entLogicalContextEngineId, |
|
289 char *entLogicalContextName) |
|
290 { |
|
291 xLogicalStatic->entLogicalDescr = entLogicalDescr; |
|
292 xLogicalStatic->entLogicalType = entLogicalType; |
|
293 xLogicalStatic->entLogicalTypeSize = entLogicalTypeSize; |
|
294 xLogicalStatic->entLogicalCommunity = entLogicalCommunity; |
|
295 xLogicalStatic->entLogicalTAddress = entLogicalTAddress; |
|
296 xLogicalStatic->entLogicalTDomain = entLogicalTDomain; |
|
297 xLogicalStatic->entLogicalTDomainSize = entLogicalTDomainSize; |
|
298 xLogicalStatic->entLogicalContextEngineId = entLogicalContextEngineId; |
|
299 xLogicalStatic->entLogicalContextName = entLogicalContextName; |
|
300 } |
|
301 |
|
302 |
|
303 /* |
|
304 * Allocates a Logical entry. if logicidx >0 attempts to reuse an |
|
305 * existing entry |
|
306 */ |
|
307 |
|
308 int |
|
309 allocLogicalEntry(int xLogicalIdx, entLogicalEntry_t * xnewLogicalEntry) |
|
310 { |
|
311 entLogicalEntry_t *logicent; |
|
312 int index; |
|
313 /* Fix for 4893101 */ |
|
314 static oid mib2oid[] = { 1,3,6,1,2,1 }; |
|
315 /* End of Fix for 4893101 */ |
|
316 /* Fix for 4927412 */ |
|
317 char emptystring[1] = ""; |
|
318 /* End of Fix for 4927412 */ |
|
319 |
|
320 /* Fix for 4927412: according to RFC 2737, entLogicalDescr has to be */ |
|
321 /* unique - NULL should be rejected. */ |
|
322 /* entLogicalTAddress should not accept NULL or "". */ |
|
323 /* entLogicalTDomain should not accept NULL */ |
|
324 /* entLogicalType will default to mib-2 for */ |
|
325 /* NULL. For the rest, we will force NULL = "" */ |
|
326 /* (zero-length string) */ |
|
327 if (xnewLogicalEntry->entLogicalDescr == NULL) |
|
328 return -1; |
|
329 /* Fix for 4893101: We have to check for NULL so that it does not */ |
|
330 /* crash. Also we need to have mib-2 as the default, */ |
|
331 /* as outlined in the RFC */ |
|
332 if (xnewLogicalEntry->entLogicalType == NULL) { |
|
333 xnewLogicalEntry->entLogicalType = mib2oid; |
|
334 xnewLogicalEntry->entLogicalTypeSize = sizeof(mib2oid); |
|
335 } |
|
336 /* End of Fix for 4893101 */ |
|
337 if (xnewLogicalEntry->entLogicalCommunity == NULL) |
|
338 xnewLogicalEntry->entLogicalCommunity = emptystring; |
|
339 if (xnewLogicalEntry->entLogicalTAddress == NULL) |
|
340 return -1; |
|
341 else if (strcmp((const char *)xnewLogicalEntry->entLogicalTAddress, "") == 0) |
|
342 return -1; |
|
343 if (xnewLogicalEntry->entLogicalTDomain == NULL) |
|
344 return -1; |
|
345 if (xnewLogicalEntry->entLogicalContextEngineId == NULL) |
|
346 xnewLogicalEntry->entLogicalContextEngineId = emptystring; |
|
347 if (xnewLogicalEntry->entLogicalContextName == NULL) |
|
348 xnewLogicalEntry->entLogicalContextName = emptystring; |
|
349 /* End of Fix for 4927412 */ |
|
350 |
|
351 /* Fix for 4921309 */ |
|
352 if (xLogicalIdx < 0 || xLogicalIdx > MAX_ENTITY_INDEX) |
|
353 return NULL; |
|
354 /* End of Fix for 4921309 */ |
|
355 |
|
356 /* Fix for 4911817: Check for size and boundary limits */ |
|
357 /* entLogicalDescr 0..255 */ |
|
358 if (strlen(xnewLogicalEntry->entLogicalDescr) > 255) |
|
359 return -1; |
|
360 |
|
361 /* entLogicalCommunity 0..255 (deprecated) */ |
|
362 if (strlen(xnewLogicalEntry->entLogicalCommunity) > 255) |
|
363 return -1; |
|
364 |
|
365 /* entLogicalTAddress 1..255 */ |
|
366 if (strlen(xnewLogicalEntry->entLogicalTAddress) < 1 || strlen(xnewLogicalEntry->entLogicalTAddress) > 255) |
|
367 return -1; |
|
368 |
|
369 /* entLogicalContextEngineId 0..32 */ |
|
370 if (strlen(xnewLogicalEntry->entLogicalContextEngineId) > 32) |
|
371 return -1; |
|
372 |
|
373 /* entLogicalContextName 0..255 */ |
|
374 if (strlen(xnewLogicalEntry->entLogicalContextName) > 255) |
|
375 return -1; |
|
376 /* End of Fix for 4911817 */ |
|
377 |
|
378 logicent = malloc(sizeof (entLogicalEntry_t)); |
|
379 if (logicent == NULL) { |
|
380 return (-1); |
|
381 } |
|
382 |
|
383 logicent->entLogicalIndex = xLogicalIdx; |
|
384 |
|
385 logicent->entLogicalDescr = strdup(xnewLogicalEntry->entLogicalDescr); |
|
386 /* Fix for 4884526 */ |
|
387 if (logicent->entLogicalDescr == NULL) { |
|
388 free (logicent); |
|
389 return (-1); |
|
390 } |
|
391 /* End of Fix for 4884526 */ |
|
392 |
|
393 logicent->entLogicalType = malloc(xnewLogicalEntry->entLogicalTypeSize); |
|
394 /* Fix for 4884526 */ |
|
395 if (logicent->entLogicalType == NULL) { |
|
396 free(logicent->entLogicalDescr); |
|
397 free (logicent); |
|
398 return (-1); |
|
399 } |
|
400 /* End of Fix for 4884526 */ |
|
401 |
|
402 memcpy(logicent->entLogicalType, xnewLogicalEntry->entLogicalType, |
|
403 xnewLogicalEntry->entLogicalTypeSize); |
|
404 logicent->entLogicalTypeSize = xnewLogicalEntry->entLogicalTypeSize; |
|
405 |
|
406 logicent->entLogicalCommunity = |
|
407 strdup(xnewLogicalEntry->entLogicalCommunity); |
|
408 /* Fix for 4884526 */ |
|
409 if (logicent->entLogicalCommunity == NULL) { |
|
410 free(logicent->entLogicalType); |
|
411 free(logicent->entLogicalDescr); |
|
412 free (logicent); |
|
413 return (-1); |
|
414 } |
|
415 /* End of Fix for 4884526 */ |
|
416 logicent->entLogicalTAddress = |
|
417 strdup(xnewLogicalEntry->entLogicalTAddress); |
|
418 /* Fix for 4884526 */ |
|
419 if (logicent->entLogicalTAddress == NULL) { |
|
420 free(logicent->entLogicalCommunity); |
|
421 free(logicent->entLogicalType); |
|
422 free(logicent->entLogicalDescr); |
|
423 free (logicent); |
|
424 return (-1); |
|
425 } |
|
426 /* End of Fix for 4884526 */ |
|
427 |
|
428 /* Fix for 4926767: We do not want NULL TDomain */ |
|
429 if (xnewLogicalEntry->entLogicalTDomain == NULL) { |
|
430 logicent->entLogicalTDomain = NULL; |
|
431 } else { |
|
432 logicent->entLogicalTDomain = |
|
433 malloc(xnewLogicalEntry->entLogicalTDomainSize); |
|
434 } |
|
435 /* End of Fix for 4926767 */ |
|
436 |
|
437 /* Fix for 4884526 */ |
|
438 if (logicent->entLogicalTDomain == NULL) { |
|
439 free(logicent->entLogicalTAddress); |
|
440 free(logicent->entLogicalCommunity); |
|
441 free(logicent->entLogicalType); |
|
442 free(logicent->entLogicalDescr); |
|
443 free (logicent); |
|
444 return (-1); |
|
445 } |
|
446 /* End of Fix for 4884526 */ |
|
447 |
|
448 memcpy(logicent->entLogicalTDomain, xnewLogicalEntry->entLogicalTDomain, |
|
449 xnewLogicalEntry->entLogicalTDomainSize); |
|
450 logicent->entLogicalTDomainSize = xnewLogicalEntry->entLogicalTDomainSize; |
|
451 |
|
452 logicent->entLogicalContextEngineId = |
|
453 strdup(xnewLogicalEntry->entLogicalContextEngineId); |
|
454 /* Fix for 4884526 */ |
|
455 if (logicent->entLogicalContextEngineId == NULL) { |
|
456 free(logicent->entLogicalTDomain); |
|
457 free(logicent->entLogicalTAddress); |
|
458 free(logicent->entLogicalCommunity); |
|
459 free(logicent->entLogicalType); |
|
460 free(logicent->entLogicalDescr); |
|
461 free (logicent); |
|
462 return (-1); |
|
463 } |
|
464 /* End of Fix for 4884526 */ |
|
465 logicent->entLogicalContextName = |
|
466 strdup(xnewLogicalEntry->entLogicalContextName); |
|
467 /* Fix for 4884526 */ |
|
468 if (logicent->entLogicalContextName == NULL) { |
|
469 free(logicent->entLogicalContextEngineId); |
|
470 free(logicent->entLogicalTDomain); |
|
471 free(logicent->entLogicalTAddress); |
|
472 free(logicent->entLogicalCommunity); |
|
473 free(logicent->entLogicalType); |
|
474 free(logicent->entLogicalDescr); |
|
475 free (logicent); |
|
476 return (-1); |
|
477 } |
|
478 /* End of Fix for 4884526 */ |
|
479 |
|
480 logicent->pNextEntry = NULL; |
|
481 |
|
482 index = AddToLogicalTable(logicent); |
|
483 return (index); |
|
484 } |
|
485 |
|
486 static int |
|
487 AddToLogicalTable(entLogicalEntry_t * xnewLogicalEntry) |
|
488 { |
|
489 entLogicalEntry_t *zRunner, *temp; |
|
490 int placeFound; /* Fix for 4921309 */ |
|
491 int zIndex; |
|
492 zRunner = gLogicalTableHead; |
|
493 |
|
494 if (xnewLogicalEntry == NULL) return (-1); |
|
495 xnewLogicalEntry->pNextEntry = NULL; |
|
496 |
|
497 /* Fix for 4921309 */ |
|
498 /* If index > 0, attempt to insert in appropriate place. */ |
|
499 if (xnewLogicalEntry->entLogicalIndex > 0) { |
|
500 placeFound = 0; |
|
501 temp = zRunner; |
|
502 while (zRunner != NULL) { |
|
503 if (xnewLogicalEntry->entLogicalIndex > |
|
504 abs(zRunner->entLogicalIndex)) { |
|
505 temp = zRunner; |
|
506 zRunner = zRunner->pNextEntry; |
|
507 } else { |
|
508 break; |
|
509 } |
|
510 } |
|
511 |
|
512 /* If the indexes don't match, we can use the specified index */ |
|
513 if (temp == NULL) { |
|
514 /* List is empty, make this the first/last entry */ |
|
515 gLogicalTableHead = xnewLogicalEntry; |
|
516 gLogicalTableTail = xnewLogicalEntry; |
|
517 placeFound = 1; |
|
518 } else if (zRunner == NULL) { |
|
519 /* Index > last value, make this the last entry */ |
|
520 temp->pNextEntry = xnewLogicalEntry; |
|
521 gLogicalTableTail = xnewLogicalEntry; |
|
522 placeFound = 1; |
|
523 } else if (xnewLogicalEntry->entLogicalIndex != |
|
524 abs(zRunner->entLogicalIndex)) { |
|
525 /* Index < zRunner, insert entry before it */ |
|
526 xnewLogicalEntry->pNextEntry = zRunner; |
|
527 if (zRunner == gLogicalTableHead) { |
|
528 /* Index fits before list head, insert entry */ |
|
529 gLogicalTableHead = xnewLogicalEntry; |
|
530 } else { |
|
531 /* Index fits between two entries, insert entry */ |
|
532 temp->pNextEntry = xnewLogicalEntry; |
|
533 } |
|
534 placeFound = 1; |
|
535 } |
|
536 |
|
537 if (placeFound) { |
|
538 gLogicalTableSize++; |
|
539 configChanged(); |
|
540 return (xnewLogicalEntry->entLogicalIndex); |
|
541 } else { |
|
542 /* Re-initialize for code that follows */ |
|
543 zRunner = gLogicalTableHead; |
|
544 } |
|
545 } |
|
546 |
|
547 /* Either index was zero or specified index is already taken */ |
|
548 /* End of Fix for 4921309 */ |
|
549 |
|
550 if (gLogicalTableSize > LARGE_TABLE) { |
|
551 gLogicalTableTail->pNextEntry = xnewLogicalEntry; |
|
552 zIndex = abs(gLogicalTableTail->entLogicalIndex) + 1; |
|
553 xnewLogicalEntry->entLogicalIndex = zIndex; |
|
554 gLogicalTableTail = xnewLogicalEntry; |
|
555 gLogicalTableSize++; |
|
556 configChanged(); |
|
557 return (zIndex); |
|
558 } |
|
559 |
|
560 if (gLogicalTableHead) { /* A slightly slower way to add into the list */ |
|
561 while (zRunner->pNextEntry != NULL) { |
|
562 if ((abs(zRunner->pNextEntry->entLogicalIndex) |
|
563 - abs(zRunner->entLogicalIndex)) > 1) { |
|
564 temp = zRunner->pNextEntry; |
|
565 zRunner->pNextEntry = xnewLogicalEntry; |
|
566 zIndex = abs(zRunner->entLogicalIndex) + 1; |
|
567 xnewLogicalEntry->entLogicalIndex = zIndex; |
|
568 xnewLogicalEntry->pNextEntry = temp; |
|
569 gLogicalTableSize++; |
|
570 configChanged(); |
|
571 return (zIndex); |
|
572 } |
|
573 zRunner = zRunner->pNextEntry; |
|
574 } |
|
575 zIndex = abs(zRunner->entLogicalIndex) + 1; |
|
576 xnewLogicalEntry->entLogicalIndex = zIndex; |
|
577 zRunner->pNextEntry = xnewLogicalEntry; |
|
578 } else { |
|
579 zIndex = xnewLogicalEntry->entLogicalIndex = 1; |
|
580 gLogicalTableHead = xnewLogicalEntry; |
|
581 } |
|
582 gLogicalTableTail = xnewLogicalEntry; |
|
583 gLogicalTableSize++; |
|
584 configChanged(); |
|
585 return (zIndex); |
|
586 } |
|
587 |
|
588 int |
|
589 makeLogicalTableEntryStale(int xLogicalIndex) |
|
590 { |
|
591 |
|
592 entLogicalEntry_t *zRunner; |
|
593 int zLogicalIndex; |
|
594 |
|
595 /* Fix for 4888088 */ |
|
596 if (xLogicalIndex <= 0 || xLogicalIndex > MAX_ENTITY_INDEX) |
|
597 return (-1); |
|
598 /* End of Fix for 4888088 */ |
|
599 |
|
600 zRunner = gLogicalTableHead; |
|
601 |
|
602 while (zRunner) { |
|
603 zLogicalIndex = zRunner->entLogicalIndex; |
|
604 if (zLogicalIndex < 0) { |
|
605 if (zLogicalIndex == -(xLogicalIndex)) |
|
606 return (-2); /* Entry is already stale */ |
|
607 } |
|
608 if (zLogicalIndex == xLogicalIndex) { |
|
609 /* Fix for 4918876: We need to delete the related entries first */ |
|
610 |
|
611 /* |
|
612 Delete all instances of this logical index in all other |
|
613 tables to maintain table integrity. Should we roll-back if a |
|
614 deletion fails, perhaps not |
|
615 */ |
|
616 deleteAliasMappingLogicalIndex( xLogicalIndex); /*Alias mapping*/ |
|
617 deleteLPMappingLogicalIndex( xLogicalIndex); /* LPTable */ |
|
618 /* End of Fix for 4918876 */ |
|
619 |
|
620 zRunner->entLogicalIndex = -zLogicalIndex; |
|
621 |
|
622 configChanged(); |
|
623 |
|
624 return (0); |
|
625 } |
|
626 zRunner = zRunner->pNextEntry; |
|
627 } |
|
628 return (-1); |
|
629 } |
|
630 |
|
631 int |
|
632 makeLogicalTableEntryLive(int xLogicalIndex) |
|
633 { |
|
634 entLogicalEntry_t *zRunner; |
|
635 int zLogicalIndex; |
|
636 |
|
637 /* Fix for 4888088 */ |
|
638 if (xLogicalIndex <= 0 || xLogicalIndex > MAX_ENTITY_INDEX) |
|
639 return (-1); |
|
640 /* End of Fix for 4888088 */ |
|
641 |
|
642 zRunner = gLogicalTableHead; |
|
643 |
|
644 while (zRunner) { |
|
645 zLogicalIndex = zRunner->entLogicalIndex; |
|
646 if (zLogicalIndex > 0) { |
|
647 if (zLogicalIndex == xLogicalIndex) |
|
648 return (-2); /* Entry is already live */ |
|
649 } |
|
650 if (zLogicalIndex == -(xLogicalIndex)) { |
|
651 zRunner->entLogicalIndex = xLogicalIndex; |
|
652 configChanged(); |
|
653 return (0); |
|
654 } |
|
655 zRunner = zRunner->pNextEntry; |
|
656 } |
|
657 return (-1); |
|
658 } |
|
659 |
|
660 entLogicalEntry_t* |
|
661 getLogicalTableEntry(int xLogicalIndex) |
|
662 { |
|
663 entLogicalEntry_t *zRunner; |
|
664 int zLogicalIndex; |
|
665 |
|
666 /* Fix for 4888088 */ |
|
667 if (xLogicalIndex <= 0 || xLogicalIndex > MAX_ENTITY_INDEX) |
|
668 return NULL; |
|
669 /* End of Fix for 4888088 */ |
|
670 |
|
671 zRunner = gLogicalTableHead; |
|
672 while (zRunner) { |
|
673 zLogicalIndex = zRunner->entLogicalIndex; |
|
674 if (zLogicalIndex > 0) { |
|
675 if (zLogicalIndex == xLogicalIndex) |
|
676 return zRunner; |
|
677 } |
|
678 if (zLogicalIndex == -(xLogicalIndex)) { |
|
679 return NULL; /* The stale entry exist, we can stop the search*/ |
|
680 } |
|
681 zRunner = zRunner->pNextEntry; |
|
682 } |
|
683 return NULL; |
|
684 } |
|
685 |
|
686 entLogicalEntry_t* |
|
687 getLogicalTableStaleEntry(int xLogicalIndex) |
|
688 { |
|
689 entLogicalEntry_t *zRunner; |
|
690 int zLogicalIndex; |
|
691 |
|
692 /* Fix for 4888088 */ |
|
693 if (xLogicalIndex <= 0 || xLogicalIndex > MAX_ENTITY_INDEX) |
|
694 return NULL; |
|
695 /* End of Fix for 4888088 */ |
|
696 |
|
697 zRunner = gLogicalTableHead; |
|
698 while (zRunner) { |
|
699 zLogicalIndex = zRunner->entLogicalIndex; |
|
700 if (zLogicalIndex < 0) { |
|
701 if (zLogicalIndex == -(xLogicalIndex)) |
|
702 return zRunner; |
|
703 } |
|
704 if (zLogicalIndex == xLogicalIndex) { |
|
705 return NULL; /* The live entry exist, we can stop the search*/ |
|
706 } |
|
707 zRunner = zRunner->pNextEntry; |
|
708 } |
|
709 return NULL; |
|
710 } |
|
711 |
|
712 |
|
713 int |
|
714 deleteLogicalTableEntry(int xLogicalIndex) |
|
715 { |
|
716 entLogicalEntry_t *zRunner, *temp, *prevEntry; |
|
717 int zLogicalIndex; |
|
718 |
|
719 /* Fix for 4888088 */ |
|
720 if (xLogicalIndex <= 0 || xLogicalIndex > MAX_ENTITY_INDEX) |
|
721 return -1; |
|
722 /* End of Fix for 4888088 */ |
|
723 |
|
724 zRunner = gLogicalTableHead; |
|
725 prevEntry = NULL; |
|
726 while (zRunner) { |
|
727 zLogicalIndex = zRunner->entLogicalIndex; |
|
728 if (zLogicalIndex > 0) { |
|
729 if (zLogicalIndex == xLogicalIndex) { |
|
730 /* Fix for 4918876: We need to delete the related entries */ |
|
731 /* first */ |
|
732 /* |
|
733 Delete all instances of this logical index in all other |
|
734 tables to maintain table integrity. Should we roll-back if a |
|
735 deletion fails, perhaps not |
|
736 */ |
|
737 deleteAliasMappingLogicalIndex( xLogicalIndex); /*Alias mapping*/ |
|
738 deleteLPMappingLogicalIndex( xLogicalIndex); /* LPTable */ |
|
739 /* End of Fix for 4918876 */ |
|
740 |
|
741 temp = zRunner->pNextEntry; |
|
742 zRunner->pNextEntry = NULL; |
|
743 if (prevEntry) |
|
744 prevEntry->pNextEntry = temp; |
|
745 else |
|
746 gLogicalTableHead = temp;; |
|
747 FreeLogicalEntry(zRunner); |
|
748 |
|
749 configChanged(); |
|
750 |
|
751 gLogicalTableSize--; |
|
752 return (0); |
|
753 } |
|
754 } |
|
755 if (zLogicalIndex == -(xLogicalIndex)) { |
|
756 return (-2); /* The stale entry exist, we can stop the search*/ |
|
757 } |
|
758 prevEntry = zRunner; |
|
759 zRunner = zRunner->pNextEntry; |
|
760 } |
|
761 return (-1); |
|
762 } |
|
763 |
|
764 int |
|
765 FreeLogicalEntry(entLogicalEntry_t *xEntry) |
|
766 { |
|
767 if (xEntry == NULL) return (-1); |
|
768 free(xEntry->entLogicalDescr); |
|
769 free(xEntry->entLogicalType); |
|
770 free(xEntry->entLogicalCommunity); |
|
771 free(xEntry->entLogicalTAddress); |
|
772 free(xEntry->entLogicalTDomain); |
|
773 free(xEntry->entLogicalContextEngineId); |
|
774 free(xEntry->entLogicalContextName); |
|
775 free(xEntry); |
|
776 xEntry = NULL; |
|
777 return (1); |
|
778 } |