1 /*
2  * SNMPStats Module
3  * Copyright (C) 2006 SOMA Networks, INC.
4  * Written by: Jeffrey Magder (jmagder@somanetworks.com)
5  *
6  * This file is part of Kamailio, a free SIP server.
7  *
8  * Kamailio is free software; you can redistribute it and/or modify it
9  * under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version
12  *
13  * Kamailio is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
21  * USA
22  *
23  * Note: this file originally auto-generated by mib2c using
24  * mib2c.array-user.conf
25  *
26  * This file implements the kamailioSIPRegUserLookupTable.  For a full
27  * description of the table, please see the KAMAILIO-SIP-SERVER-MIB.
28  *
29  * This file is much larger and more complicated than the files for other
30  * tables.  This is because the table is settable, bringing a lot of SNMP
31  * overhead.  Most of the file consists of the original auto-generated
32  * code (aside from white space and comment changes).
33  *
34  * The functions that have been modified to implement this table are the
35  * following:
36  *
37  * 1) kamailioSIPRegUserLookupTable_extract_index()
38  *
39  *    - Modified to fail if the index is invalid.  The index is invalid if it
40  *      does not match up with the global userLookupCounter.
41  *
42  * 2) kamailioSIPRegUserLookupTable_can_[activate|deactivate|delete]()
43  *
44  *    - Simplified to always allow activation/deactivation/deletion.
45  *
46  * 3) kamailioSIPRegUserLookupTable_set_reserve1()
47  *
48  *    - The reserve1 phase passes if the row is new, and the rowStatus column
49  *      is being set to 'createAndGo'
50  *    - The reserve1 phase passes if the row is not new, and the rowStatus
51  *      column is being set to 'destroy'
52  *
53  * 4) kamailioSIPRegUserLookupTable_set_action()
54  *
55  *    - The function was modified to populate the row with the userIndex of the
56  *      supplied URI if that URI was found on the system, and set the rowStatus
57  *      to 'active'.  If the URI was not found, the rowStatus is set to
58  *      'notInService'
59  *
60  * You can safely ignore the other functions.
61  */
62 
63 #include <net-snmp/net-snmp-config.h>
64 #include <net-snmp/net-snmp-includes.h>
65 #include <net-snmp/agent/net-snmp-agent-includes.h>
66 
67 #include <net-snmp/library/snmp_assert.h>
68 
69 #include "snmpSIPRegUserLookupTable.h"
70 #include "snmpstats_globals.h"
71 #include "hashTable.h"
72 #include "interprocess_buffer.h"
73 
74 static netsnmp_handler_registration *my_handler = NULL;
75 static netsnmp_table_array_callbacks cb;
76 
77 oid kamailioSIPRegUserLookupTable_oid[] = {
78 		kamailioSIPRegUserLookupTable_TABLE_OID};
79 
80 size_t kamailioSIPRegUserLookupTable_oid_len =
81 		OID_LENGTH(kamailioSIPRegUserLookupTable_oid);
82 
83 
84 /*
85  * Initializes the kamailioSIPRegUserLookupTable table.  This step is easier
86  * than in the other tables because there is no table population.  All table
87  * population takes place during run time.
88  */
init_kamailioSIPRegUserLookupTable(void)89 void init_kamailioSIPRegUserLookupTable(void)
90 {
91 	initialize_table_kamailioSIPRegUserLookupTable();
92 }
93 
94 /* the *_row_copy routine */
kamailioSIPRegUserLookupTable_row_copy(kamailioSIPRegUserLookupTable_context * dst,kamailioSIPRegUserLookupTable_context * src)95 static int kamailioSIPRegUserLookupTable_row_copy(
96 		kamailioSIPRegUserLookupTable_context *dst,
97 		kamailioSIPRegUserLookupTable_context *src)
98 {
99 	if(!dst || !src) {
100 		return 1;
101 	}
102 
103 
104 	/* copy index, if provided */
105 	if(dst->index.oids) {
106 		free(dst->index.oids);
107 	}
108 
109 	if(snmp_clone_mem((void *)&dst->index.oids, src->index.oids,
110 			   src->index.len * sizeof(oid))) {
111 		dst->index.oids = NULL;
112 		return 1;
113 	}
114 
115 	dst->index.len = src->index.len;
116 
117 	/* Copy out almost all components of the structure.  We don't copy out
118 	 * the kamailioSIPRegUSerLookupURI (or its length).  */
119 	dst->kamailioSIPRegUserLookupIndex = src->kamailioSIPRegUserLookupIndex;
120 	dst->kamailioSIPRegUserIndex = src->kamailioSIPRegUserIndex;
121 	dst->kamailioSIPRegUserLookupRowStatus =
122 			src->kamailioSIPRegUserLookupRowStatus;
123 
124 	return 0;
125 }
126 
127 /*
128  * the *_extract_index routine. (Mostly auto-generated)
129  *
130  * This routine is called when a set request is received for an index
131  * that was not found in the table container. Here, we parse the oid
132  * in the individual index components and copy those indexes to the
133  * context. Then we make sure the indexes for the new row are valid.
134  *
135  * It has been modified from its original form in that if the indexes are
136  * invalid, then they aren't returned.  An index is invalid if:
137  *
138  *   1) It is < 1
139  *   2) It doesn't match the global userLookupIndex. (As per MIB specs)
140  *
141  */
kamailioSIPRegUserLookupTable_extract_index(kamailioSIPRegUserLookupTable_context * ctx,netsnmp_index * hdr)142 int kamailioSIPRegUserLookupTable_extract_index(
143 		kamailioSIPRegUserLookupTable_context *ctx, netsnmp_index *hdr)
144 {
145 	/*
146 	 * temporary local storage for extracting oid index
147 	 *
148 	 * extract index uses varbinds (netsnmp_variable_list) to parse
149 	 * the index OID into the individual components for each index part.
150 	 */
151 	netsnmp_variable_list var_kamailioSIPRegUserLookupIndex;
152 	int err;
153 
154 	/* copy index, if provided */
155 	if(hdr) {
156 		netsnmp_assert(ctx->index.oids == NULL);
157 		if((hdr->len > MAX_OID_LEN)
158 				|| snmp_clone_mem((void *)&ctx->index.oids, hdr->oids,
159 						   hdr->len * sizeof(oid))) {
160 			return -1;
161 		}
162 		ctx->index.len = hdr->len;
163 	}
164 
165 	/* Set up the index */
166 	memset(&var_kamailioSIPRegUserLookupIndex, 0x00,
167 			sizeof(var_kamailioSIPRegUserLookupIndex));
168 
169 	var_kamailioSIPRegUserLookupIndex.type = ASN_UNSIGNED;
170 	var_kamailioSIPRegUserLookupIndex.next_variable = NULL;
171 
172 	if(hdr) {
173 		/* parse the oid into the individual index components */
174 		err = parse_oid_indexes(
175 				hdr->oids, hdr->len, &var_kamailioSIPRegUserLookupIndex);
176 
177 		if(err == SNMP_ERR_NOERROR) {
178 
179 			/* copy index components into the context structure */
180 			ctx->kamailioSIPRegUserLookupIndex =
181 					*var_kamailioSIPRegUserLookupIndex.val.integer;
182 
183 			/*
184 		 * Check to make sure that the index corresponds to the
185 		 * global_userLookupCounter, as per the MIB specifications.
186 		 */
187 			if(*var_kamailioSIPRegUserLookupIndex.val.integer
188 							!= global_UserLookupCounter
189 					|| *var_kamailioSIPRegUserLookupIndex.val.integer < 1) {
190 				err = -1;
191 			}
192 		}
193 
194 		/* parsing may have allocated memory. free it. */
195 		snmp_reset_var_buffers(&var_kamailioSIPRegUserLookupIndex);
196 
197 		return err;
198 	}
199 
200 	return -1;
201 }
202 
203 /*
204  * This is an auto-generated function.  In general the *_can_activate routine
205  * is called when a row is changed to determine if all the values set are
206  * consistent with the row's rules for a row status of ACTIVE.  If not, then 0
207  * can be returned to prevent the row status from becomming final.
208  *
209  * For our purposes, we have no need for this check, so we always return 1.
210  */
kamailioSIPRegUserLookupTable_can_activate(kamailioSIPRegUserLookupTable_context * undo_ctx,kamailioSIPRegUserLookupTable_context * row_ctx,netsnmp_request_group * rg)211 int kamailioSIPRegUserLookupTable_can_activate(
212 		kamailioSIPRegUserLookupTable_context *undo_ctx,
213 		kamailioSIPRegUserLookupTable_context *row_ctx,
214 		netsnmp_request_group *rg)
215 {
216 	return 1;
217 }
218 
219 /*
220  * This is an auto-generated function.  In general the *_can_deactivate routine
221  * is called when a row that is currently ACTIVE is set to a state other than
222  * ACTIVE. If there are conditions in which a row should not be allowed to
223  * transition out of the ACTIVE state (such as the row being referred to by
224  * another row or table), check for them here.
225  *
226  * Since this table has no reason why this shouldn't be allowed, we always
227  * return 1;
228  */
kamailioSIPRegUserLookupTable_can_deactivate(kamailioSIPRegUserLookupTable_context * undo_ctx,kamailioSIPRegUserLookupTable_context * row_ctx,netsnmp_request_group * rg)229 int kamailioSIPRegUserLookupTable_can_deactivate(
230 		kamailioSIPRegUserLookupTable_context *undo_ctx,
231 		kamailioSIPRegUserLookupTable_context *row_ctx,
232 		netsnmp_request_group *rg)
233 {
234 	return 1;
235 }
236 
237 /*
238  * This is an auto-generated function.  In general the *_can_delete routine is
239  * called to determine if a row can be deleted.  This usually involved checking
240  * if it can be deactivated, and if it can be, then checking for other
241  * conditions.
242  *
243  * Since this table ha no reason why row deletion shouldn't be allowed, we
244  * always return 1, unless we can't deactivate.
245  */
kamailioSIPRegUserLookupTable_can_delete(kamailioSIPRegUserLookupTable_context * undo_ctx,kamailioSIPRegUserLookupTable_context * row_ctx,netsnmp_request_group * rg)246 int kamailioSIPRegUserLookupTable_can_delete(
247 		kamailioSIPRegUserLookupTable_context *undo_ctx,
248 		kamailioSIPRegUserLookupTable_context *row_ctx,
249 		netsnmp_request_group *rg)
250 {
251 	if(kamailioSIPRegUserLookupTable_can_deactivate(undo_ctx, row_ctx, rg) != 1)
252 		return 0;
253 
254 	return 1;
255 }
256 
257 /*
258  * This is an auto-generated function.
259  *
260  * The *_create_row routine is called by the table handler to create a new row
261  * for a given index. This is the first stage of the row creation process.  The
262  * *_set_reserve_* functions can be used to prevent the row from being inserted
263  * into the table even if the row passes any preliminary checks set here.
264  *
265  * Returns a newly allocated kamailioSIPRegUserLookupTable_context structure (a
266  * row in the table) if the indexes are legal.  NULL will be returned otherwise.
267  */
kamailioSIPRegUserLookupTable_create_row(netsnmp_index * hdr)268 kamailioSIPRegUserLookupTable_context *kamailioSIPRegUserLookupTable_create_row(
269 		netsnmp_index *hdr)
270 {
271 	kamailioSIPRegUserLookupTable_context *ctx =
272 			SNMP_MALLOC_TYPEDEF(kamailioSIPRegUserLookupTable_context);
273 
274 	if(!ctx) {
275 		return NULL;
276 	}
277 
278 	/*
279 	 * Extract the index.  The function has been modified from its original
280 	 * auto-generated version in that the function will fail if index is
281 	 * somehow invalid.
282 	 */
283 	if(kamailioSIPRegUserLookupTable_extract_index(ctx, hdr)) {
284 
285 		if(NULL != ctx->index.oids) {
286 			free(ctx->index.oids);
287 		}
288 
289 		free(ctx);
290 
291 		return NULL;
292 	}
293 
294 	ctx->kamailioSIPRegUserLookupURI = NULL;
295 	ctx->kamailioSIPRegUserLookupURI_len = 0;
296 	ctx->kamailioSIPRegUserIndex = 0;
297 	ctx->kamailioSIPRegUserLookupRowStatus = 0;
298 
299 	return ctx;
300 }
301 
302 /*
303  * Auto-generated function.  The *_duplicate row routine
304  */
305 kamailioSIPRegUserLookupTable_context *
kamailioSIPRegUserLookupTable_duplicate_row(kamailioSIPRegUserLookupTable_context * row_ctx)306 kamailioSIPRegUserLookupTable_duplicate_row(
307 		kamailioSIPRegUserLookupTable_context *row_ctx)
308 {
309 	kamailioSIPRegUserLookupTable_context *dup;
310 
311 	if(!row_ctx)
312 		return NULL;
313 
314 	dup = SNMP_MALLOC_TYPEDEF(kamailioSIPRegUserLookupTable_context);
315 	if(!dup)
316 		return NULL;
317 
318 	if(kamailioSIPRegUserLookupTable_row_copy(dup, row_ctx)) {
319 		free(dup);
320 		dup = NULL;
321 	}
322 
323 	return dup;
324 }
325 
326 /*
327  * The *_delete_row method is auto-generated, and is called to delete a row.
328  *
329  * This will not be called if earlier checks said that this row can't be
330  * deleted.  However, in our implementation there is never a reason why this
331  * function can't be called.
332  */
kamailioSIPRegUserLookupTable_delete_row(kamailioSIPRegUserLookupTable_context * ctx)333 netsnmp_index *kamailioSIPRegUserLookupTable_delete_row(
334 		kamailioSIPRegUserLookupTable_context *ctx)
335 {
336 	if(ctx->index.oids) {
337 		free(ctx->index.oids);
338 	}
339 
340 
341 	if(ctx->kamailioSIPRegUserLookupURI != NULL) {
342 		pkg_free(ctx->kamailioSIPRegUserLookupURI);
343 	}
344 
345 	free(ctx);
346 
347 	return NULL;
348 }
349 
350 
351 /*
352  * Large parts of this function have been auto-generated.  The functions purpose
353  * is to check to make sure all SNMP set values for the given row, have been
354  * valid.  If not, then the process is supposed to be aborted.  Otherwise, we
355  * pass on to the *_reserve2 function.
356  *
357  * For our purposes, our only check is to make sure that either of the following
358  * conditions are true:
359  *
360  * 1) If this row already exists, then the SET request is setting the rowStatus
361  *    column to 'destroy'.
362  *
363  * 2) If this row does not already exist, then the SET request is setting the
364  *    rowStatus to 'createAndGo'.
365  *
366  * Since the MIB specified there are to be no other modifications to the row,
367  * any other condition is considered illegal, and will result in an SNMP error
368  * being returned.
369  */
kamailioSIPRegUserLookupTable_set_reserve1(netsnmp_request_group * rg)370 void kamailioSIPRegUserLookupTable_set_reserve1(netsnmp_request_group *rg)
371 {
372 	kamailioSIPRegUserLookupTable_context *row_ctx =
373 			(kamailioSIPRegUserLookupTable_context *)rg->existing_row;
374 
375 	netsnmp_variable_list *var;
376 
377 	netsnmp_request_group_item *current;
378 
379 	int rc;
380 
381 	for(current = rg->list; current; current = current->next) {
382 
383 		var = current->ri->requestvb;
384 		rc = SNMP_ERR_NOERROR;
385 
386 		switch(current->tri->colnum) {
387 
388 			case COLUMN_KAMAILIOSIPREGUSERLOOKUPURI:
389 
390 				if(row_ctx->kamailioSIPRegUserLookupRowStatus == 0
391 						|| row_ctx->kamailioSIPRegUserLookupRowStatus
392 								   == TC_ROWSTATUS_NOTREADY) {
393 
394 				} else {
395 					rc = SNMP_ERR_BADVALUE;
396 				}
397 
398 				break;
399 
400 			case COLUMN_KAMAILIOSIPREGUSERLOOKUPROWSTATUS:
401 
402 				/** RowStatus = ASN_INTEGER */
403 				rc = netsnmp_check_vb_type_and_size(var, ASN_INTEGER,
404 						sizeof(row_ctx->kamailioSIPRegUserLookupRowStatus));
405 
406 				/* Want to make sure that if it already exists that it
407 				 * is setting it to 'destroy', or if it doesn't exist,
408 				 * that it is setting it to 'createAndGo' */
409 				if(row_ctx->kamailioSIPRegUserLookupRowStatus == 0
410 						&& *var->val.integer != TC_ROWSTATUS_CREATEANDGO) {
411 					rc = SNMP_ERR_BADVALUE;
412 				}
413 
414 				else if(row_ctx->kamailioSIPRegUserLookupRowStatus
415 								== TC_ROWSTATUS_ACTIVE
416 						&& *var->val.integer != TC_ROWSTATUS_DESTROY) {
417 					rc = SNMP_ERR_BADVALUE;
418 				}
419 
420 				break;
421 
422 			default: /** We shouldn't get here */
423 				rc = SNMP_ERR_GENERR;
424 				snmp_log(LOG_ERR, "unknown column in kamailioSIPReg"
425 								  "UserLookupTable_set_reserve1\n");
426 		}
427 
428 		if(rc) {
429 			netsnmp_set_mode_request_error(MODE_SET_BEGIN, current->ri, rc);
430 		}
431 
432 		rg->status = SNMP_MAX(rg->status, current->ri->status);
433 	}
434 }
435 
436 /*
437  * Auto-generated function.  The function is supposed to check for any
438  * last-minute conditions not being met.  However, we don't have any such
439  * conditions, so we leave the default function as is.
440  */
kamailioSIPRegUserLookupTable_set_reserve2(netsnmp_request_group * rg)441 void kamailioSIPRegUserLookupTable_set_reserve2(netsnmp_request_group *rg)
442 {
443 	kamailioSIPRegUserLookupTable_context *undo_ctx =
444 			(kamailioSIPRegUserLookupTable_context *)rg->undo_info;
445 
446 	netsnmp_request_group_item *current;
447 
448 	int rc;
449 
450 	rg->rg_void = rg->list->ri;
451 
452 	for(current = rg->list; current; current = current->next) {
453 
454 		rc = SNMP_ERR_NOERROR;
455 
456 		switch(current->tri->colnum) {
457 			case COLUMN_KAMAILIOSIPREGUSERLOOKUPURI:
458 				break;
459 
460 			case COLUMN_KAMAILIOSIPREGUSERLOOKUPROWSTATUS:
461 
462 				/** RowStatus = ASN_INTEGER */
463 				rc = netsnmp_check_vb_rowstatus(current->ri->requestvb,
464 						undo_ctx ? undo_ctx->kamailioSIPRegUserLookupRowStatus
465 								 : 0);
466 
467 				rg->rg_void = current->ri;
468 
469 				break;
470 
471 			default:			   /** We shouldn't get here */
472 				netsnmp_assert(0); /** why wasn't this caught in reserve1? */
473 		}
474 
475 		if(rc) {
476 			netsnmp_set_mode_request_error(MODE_SET_BEGIN, current->ri, rc);
477 		}
478 	}
479 }
480 
481 /*
482  * This function is called only when all the *_reserve[1|2] functions were
483  * succeful.  Its purpose is to make any changes to the row before it is
484  * inserted into the table.
485  *
486  * In the case of this table, this involves looking up the index of the
487  * requested user in the URI to userIndex mapping hash table.  If the result is
488  * found, the index will be copied to the row, and the rowStatus set to
489  * 'active'.  Otherwise, the row status will be set to 'notInService'
490  *
491  * All other handling is auto-generated.
492  */
kamailioSIPRegUserLookupTable_set_action(netsnmp_request_group * rg)493 void kamailioSIPRegUserLookupTable_set_action(netsnmp_request_group *rg)
494 {
495 	/* First things first, we need to consume the interprocess buffer, in
496 	 * case something has changed. We want to return the freshest data. */
497 	consumeInterprocessBuffer();
498 
499 	aorToIndexStruct_t *hashRecord;
500 
501 	netsnmp_variable_list *var;
502 
503 	kamailioSIPRegUserLookupTable_context *row_ctx =
504 			(kamailioSIPRegUserLookupTable_context *)rg->existing_row;
505 
506 	kamailioSIPRegUserLookupTable_context *undo_ctx =
507 			(kamailioSIPRegUserLookupTable_context *)rg->undo_info;
508 
509 	netsnmp_request_group_item *current;
510 
511 	int row_err = 0;
512 
513 	/* Copy the actual data to the row. */
514 	for(current = rg->list; current; current = current->next) {
515 
516 		var = current->ri->requestvb;
517 
518 		switch(current->tri->colnum) {
519 
520 			case COLUMN_KAMAILIOSIPREGUSERLOOKUPURI:
521 
522 				row_ctx->kamailioSIPRegUserLookupURI =
523 						pkg_malloc(sizeof(char) * (var->val_len + 1));
524 
525 				memcpy(row_ctx->kamailioSIPRegUserLookupURI, var->val.string,
526 						var->val_len);
527 
528 				/* Usually NetSNMP won't terminate strings with '\0'.
529 				 * The hash function expect them to be terminated
530 				 * though, so we have to add this on to the end.  The +1
531 				 * in the malloc makes sure of the extra space for us.
532 				 */
533 				row_ctx->kamailioSIPRegUserLookupURI[var->val_len] = '\0';
534 
535 				row_ctx->kamailioSIPRegUserLookupURI_len = var->val_len;
536 
537 				/* Do the lookup.  If we could find the record, then set
538 				 * the index and the row status to active.  Otherwise,
539 				 * set the row to notInService */
540 				hashRecord = findHashRecord(hashTable,
541 						(char *)row_ctx->kamailioSIPRegUserLookupURI,
542 						HASH_SIZE);
543 
544 				if(hashRecord == NULL) {
545 					row_ctx->kamailioSIPRegUserIndex = 0;
546 					row_ctx->kamailioSIPRegUserLookupRowStatus =
547 							TC_ROWSTATUS_NOTINSERVICE;
548 				} else {
549 					row_ctx->kamailioSIPRegUserIndex = hashRecord->userIndex;
550 					row_ctx->kamailioSIPRegUserLookupRowStatus =
551 							TC_ROWSTATUS_ACTIVE;
552 				}
553 
554 				break;
555 
556 			case COLUMN_KAMAILIOSIPREGUSERLOOKUPROWSTATUS:
557 
558 				row_ctx->kamailioSIPRegUserLookupRowStatus = *var->val.integer;
559 
560 				if(*var->val.integer == TC_ROWSTATUS_CREATEANDGO) {
561 					rg->row_created = 1;
562 					/* Set to NOT READY until the lookup URI has
563 					 * been supplied. */
564 					row_ctx->kamailioSIPRegUserLookupRowStatus =
565 							TC_ROWSTATUS_NOTREADY;
566 				} else if(*var->val.integer == TC_ROWSTATUS_DESTROY) {
567 					rg->row_deleted = 1;
568 				} else {
569 					/* We should never be here, because the RESERVE
570 					 * functions should have taken care of all other
571 					 * values. */
572 					LM_ERR("invalid RowStatus in "
573 						   "kamailioSIPStatusCodesTable\n");
574 				}
575 
576 				break;
577 
578 			default:			   /** We shouldn't get here */
579 				netsnmp_assert(0); /** why wasn't this caught in reserve1? */
580 		}
581 	}
582 
583 /*
584 	 * done with all the columns. Could check row related
585 	 * requirements here.
586 	 */
587 #ifndef kamailioSIPRegUserLookupTable_CAN_MODIFY_ACTIVE_ROW
588 	if(undo_ctx && RS_IS_ACTIVE(undo_ctx->kamailioSIPRegUserLookupRowStatus)
589 			&& row_ctx
590 			&& RS_IS_ACTIVE(row_ctx->kamailioSIPRegUserLookupRowStatus)) {
591 		row_err = 1;
592 	}
593 #endif
594 
595 	LM_DBG("stage row_err = %d\n", row_err);
596 
597 	/*
598 	 * check activation/deactivation
599 	 */
600 	row_err = netsnmp_table_array_check_row_status(&cb, rg,
601 			row_ctx ? &row_ctx->kamailioSIPRegUserLookupRowStatus : NULL,
602 			undo_ctx ? &undo_ctx->kamailioSIPRegUserLookupRowStatus : NULL);
603 
604 	if(row_err) {
605 		netsnmp_set_mode_request_error(
606 				MODE_SET_BEGIN, (netsnmp_request_info *)rg->rg_void, row_err);
607 		return;
608 	}
609 }
610 
611 /*
612  * The COMMIT phase is used to do any extra processing after the ACTION phase.
613  * In our table, there is nothing to do, so the function body is empty.
614  */
kamailioSIPRegUserLookupTable_set_commit(netsnmp_request_group * rg)615 void kamailioSIPRegUserLookupTable_set_commit(netsnmp_request_group *rg)
616 {
617 }
618 
619 
620 /*
621  * This function is called if the *_reserve[1|2] calls failed.  Its supposed to
622  * free up any resources allocated earlier.  However, we already take care of
623  * all these resources in earlier functions.  So for our purposes, the function
624  * body is empty.
625  */
kamailioSIPRegUserLookupTable_set_free(netsnmp_request_group * rg)626 void kamailioSIPRegUserLookupTable_set_free(netsnmp_request_group *rg)
627 {
628 }
629 
630 
631 /*
632  * This function is called if an ACTION phase fails, to do extra clean-up work.
633  * We don't have anything complicated enough to warrant putting anything in this
634  * function.  Therefore, its just left with an empty function body.
635  */
kamailioSIPRegUserLookupTable_set_undo(netsnmp_request_group * rg)636 void kamailioSIPRegUserLookupTable_set_undo(netsnmp_request_group *rg)
637 {
638 }
639 
640 
641 /*
642  * Initialize the kamailioSIPRegUserLookupTable table by defining how it is
643  * structured.
644  *
645  * This function is mostly auto-generated.
646  */
initialize_table_kamailioSIPRegUserLookupTable(void)647 void initialize_table_kamailioSIPRegUserLookupTable(void)
648 {
649 	netsnmp_table_registration_info *table_info;
650 
651 	if(my_handler) {
652 		snmp_log(LOG_ERR, "initialize_table_kamailioSIPRegUserLookup"
653 						  "Table_handler called again\n");
654 		return;
655 	}
656 
657 	memset(&cb, 0x00, sizeof(cb));
658 
659 	/** create the table structure itself */
660 	table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info);
661 	if(table_info==NULL) {
662 		snmp_log(LOG_ERR, "failed to allocate table_info\n");
663 		return;
664 	}
665 
666 	my_handler = netsnmp_create_handler_registration(
667 			"kamailioSIPRegUserLookupTable", netsnmp_table_array_helper_handler,
668 			kamailioSIPRegUserLookupTable_oid,
669 			kamailioSIPRegUserLookupTable_oid_len, HANDLER_CAN_RWRITE);
670 
671 	if(!my_handler) {
672 		SNMP_FREE(table_info);
673 		snmp_log(LOG_ERR, "malloc failed in "
674 						  "initialize_table_kamailioSIPRegUserLookup"
675 						  "Table_handler\n");
676 		return; /** mallocs failed */
677 	}
678 
679 	/*
680 	 * Setting up the table's definition
681 	 */
682 
683 	netsnmp_table_helper_add_index(table_info, ASN_UNSIGNED);
684 
685 	table_info->min_column = kamailioSIPRegUserLookupTable_COL_MIN;
686 	table_info->max_column = kamailioSIPRegUserLookupTable_COL_MAX;
687 
688 	/*
689 	 * registering the table with the master agent
690 	 */
691 	cb.get_value = kamailioSIPRegUserLookupTable_get_value;
692 	cb.container =
693 			netsnmp_container_find("kamailioSIPRegUserLookupTable_primary:"
694 								   "kamailioSIPRegUserLookupTable:"
695 								   "table_container");
696 
697 	cb.can_set = 1;
698 	cb.create_row = (UserRowMethod *)kamailioSIPRegUserLookupTable_create_row;
699 	cb.duplicate_row =
700 			(UserRowMethod *)kamailioSIPRegUserLookupTable_duplicate_row;
701 	cb.delete_row = (UserRowMethod *)kamailioSIPRegUserLookupTable_delete_row;
702 	cb.row_copy = (Netsnmp_User_Row_Operation *)
703 			kamailioSIPRegUserLookupTable_row_copy;
704 
705 	cb.can_activate = (Netsnmp_User_Row_Action *)
706 			kamailioSIPRegUserLookupTable_can_activate;
707 	cb.can_deactivate = (Netsnmp_User_Row_Action *)
708 			kamailioSIPRegUserLookupTable_can_deactivate;
709 	cb.can_delete =
710 			(Netsnmp_User_Row_Action *)kamailioSIPRegUserLookupTable_can_delete;
711 
712 	cb.set_reserve1 = kamailioSIPRegUserLookupTable_set_reserve1;
713 	cb.set_reserve2 = kamailioSIPRegUserLookupTable_set_reserve2;
714 	cb.set_action = kamailioSIPRegUserLookupTable_set_action;
715 	cb.set_commit = kamailioSIPRegUserLookupTable_set_commit;
716 	cb.set_free = kamailioSIPRegUserLookupTable_set_free;
717 	cb.set_undo = kamailioSIPRegUserLookupTable_set_undo;
718 
719 	DEBUGMSGTL(("initialize_table_kamailioSIPRegUserLookupTable",
720 			"Registering table kamailioSIPRegUserLookupTable "
721 			"as a table array\n"));
722 
723 	netsnmp_table_container_register(
724 			my_handler, table_info, &cb, cb.container, 1);
725 }
726 
727 /*
728  * This function was auto-generated and didn't need modifications from its
729  * auto-generation.  It is called to handle an SNMP GET request.
730  */
kamailioSIPRegUserLookupTable_get_value(netsnmp_request_info * request,netsnmp_index * item,netsnmp_table_request_info * table_info)731 int kamailioSIPRegUserLookupTable_get_value(netsnmp_request_info *request,
732 		netsnmp_index *item, netsnmp_table_request_info *table_info)
733 {
734 	netsnmp_variable_list *var = request->requestvb;
735 
736 	kamailioSIPRegUserLookupTable_context *context =
737 			(kamailioSIPRegUserLookupTable_context *)item;
738 
739 	switch(table_info->colnum) {
740 		case COLUMN_KAMAILIOSIPREGUSERLOOKUPURI:
741 			/** SnmpAdminString = ASN_OCTET_STR */
742 			snmp_set_var_typed_value(var, ASN_OCTET_STR,
743 					(unsigned char *)context->kamailioSIPRegUserLookupURI,
744 					context->kamailioSIPRegUserLookupURI_len);
745 			break;
746 
747 		case COLUMN_KAMAILIOSIPREGUSERINDEX:
748 			/** UNSIGNED32 = ASN_UNSIGNED */
749 			snmp_set_var_typed_value(var, ASN_UNSIGNED,
750 					(unsigned char *)&context->kamailioSIPRegUserIndex,
751 					sizeof(context->kamailioSIPRegUserIndex));
752 			break;
753 
754 		case COLUMN_KAMAILIOSIPREGUSERLOOKUPROWSTATUS:
755 			/** RowStatus = ASN_INTEGER */
756 			snmp_set_var_typed_value(var, ASN_INTEGER,
757 					(unsigned char *)&context
758 							->kamailioSIPRegUserLookupRowStatus,
759 					sizeof(context->kamailioSIPRegUserLookupRowStatus));
760 			break;
761 
762 		default: /** We shouldn't get here */
763 			snmp_log(LOG_ERR, "unknown column in "
764 							  "kamailioSIPRegUserLookupTable_get_value\n");
765 			return SNMP_ERR_GENERR;
766 	}
767 
768 	return SNMP_ERR_NOERROR;
769 }
770 
771 /*
772  * kamailioSIPRegUserLookupTable_get_by_idx
773  */
774 const kamailioSIPRegUserLookupTable_context *
kamailioSIPRegUserLookupTable_get_by_idx(netsnmp_index * hdr)775 kamailioSIPRegUserLookupTable_get_by_idx(netsnmp_index *hdr)
776 {
777 	return (const kamailioSIPRegUserLookupTable_context *)CONTAINER_FIND(
778 			cb.container, hdr);
779 }