00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069 #include <net-snmp/net-snmp-config.h>
00070 #include <net-snmp/net-snmp-includes.h>
00071 #include <net-snmp/agent/net-snmp-agent-includes.h>
00072
00073 #include <net-snmp/library/snmp_assert.h>
00074
00075 #include "openserSIPRegUserLookupTable.h"
00076 #include "snmpstats_globals.h"
00077 #include "hashTable.h"
00078 #include "interprocess_buffer.h"
00079
00080 static netsnmp_handler_registration *my_handler = NULL;
00081 static netsnmp_table_array_callbacks cb;
00082
00083 oid openserSIPRegUserLookupTable_oid[] = {
00084 openserSIPRegUserLookupTable_TABLE_OID };
00085
00086 size_t openserSIPRegUserLookupTable_oid_len =
00087 OID_LENGTH(openserSIPRegUserLookupTable_oid);
00088
00089
00090
00091
00092
00093
00094
00095 void init_openserSIPRegUserLookupTable(void)
00096 {
00097 initialize_table_openserSIPRegUserLookupTable();
00098 }
00099
00100
00101 static int openserSIPRegUserLookupTable_row_copy(
00102 openserSIPRegUserLookupTable_context * dst,
00103 openserSIPRegUserLookupTable_context * src)
00104 {
00105 if(!dst||!src)
00106 {
00107 return 1;
00108 }
00109
00110
00111
00112 if(dst->index.oids)
00113 {
00114 free(dst->index.oids);
00115 }
00116
00117 if(snmp_clone_mem( (void*)&dst->index.oids, src->index.oids,
00118 src->index.len * sizeof(oid) )) {
00119 dst->index.oids = NULL;
00120 return 1;
00121 }
00122
00123 dst->index.len = src->index.len;
00124
00125
00126
00127 dst->openserSIPRegUserLookupIndex = src->openserSIPRegUserLookupIndex;
00128 dst->openserSIPRegUserIndex = src->openserSIPRegUserIndex;
00129 dst->openserSIPRegUserLookupRowStatus =
00130 src->openserSIPRegUserLookupRowStatus;
00131
00132 return 0;
00133 }
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150 int openserSIPRegUserLookupTable_extract_index(
00151 openserSIPRegUserLookupTable_context * ctx,
00152 netsnmp_index * hdr)
00153 {
00154
00155
00156
00157
00158
00159
00160 netsnmp_variable_list var_openserSIPRegUserLookupIndex;
00161 int err;
00162
00163
00164 if(hdr) {
00165 netsnmp_assert(ctx->index.oids == NULL);
00166 if((hdr->len > MAX_OID_LEN) ||
00167 snmp_clone_mem( (void*)&ctx->index.oids, hdr->oids,
00168 hdr->len * sizeof(oid) )) {
00169 return -1;
00170 }
00171 ctx->index.len = hdr->len;
00172 }
00173
00174
00175 memset(&var_openserSIPRegUserLookupIndex, 0x00,
00176 sizeof(var_openserSIPRegUserLookupIndex));
00177
00178 var_openserSIPRegUserLookupIndex.type = ASN_UNSIGNED;
00179 var_openserSIPRegUserLookupIndex.next_variable = NULL;
00180
00181
00182
00183 err = parse_oid_indexes( hdr->oids, hdr->len,
00184 &var_openserSIPRegUserLookupIndex );
00185
00186 if (err == SNMP_ERR_NOERROR) {
00187
00188
00189 ctx->openserSIPRegUserLookupIndex =
00190 *var_openserSIPRegUserLookupIndex.val.integer;
00191
00192
00193
00194
00195
00196 if (*var_openserSIPRegUserLookupIndex.val.integer !=
00197 global_UserLookupCounter ||
00198 *var_openserSIPRegUserLookupIndex.val.integer < 1) {
00199 err = -1;
00200 }
00201
00202 }
00203
00204
00205 snmp_reset_var_buffers( &var_openserSIPRegUserLookupIndex );
00206
00207 return err;
00208 }
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218 int openserSIPRegUserLookupTable_can_activate(
00219 openserSIPRegUserLookupTable_context *undo_ctx,
00220 openserSIPRegUserLookupTable_context *row_ctx,
00221 netsnmp_request_group * rg)
00222 {
00223 return 1;
00224 }
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236 int openserSIPRegUserLookupTable_can_deactivate(
00237 openserSIPRegUserLookupTable_context *undo_ctx,
00238 openserSIPRegUserLookupTable_context *row_ctx,
00239 netsnmp_request_group * rg)
00240 {
00241 return 1;
00242 }
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253 int openserSIPRegUserLookupTable_can_delete(
00254 openserSIPRegUserLookupTable_context *undo_ctx,
00255 openserSIPRegUserLookupTable_context *row_ctx,
00256 netsnmp_request_group * rg)
00257 {
00258 if(openserSIPRegUserLookupTable_can_deactivate(undo_ctx,row_ctx,rg) != 1)
00259 return 0;
00260
00261 return 1;
00262 }
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275 openserSIPRegUserLookupTable_context *
00276 openserSIPRegUserLookupTable_create_row( netsnmp_index* hdr)
00277 {
00278 openserSIPRegUserLookupTable_context * ctx =
00279 SNMP_MALLOC_TYPEDEF(openserSIPRegUserLookupTable_context);
00280
00281 if (!ctx)
00282 {
00283 return NULL;
00284 }
00285
00286
00287
00288
00289
00290
00291 if(openserSIPRegUserLookupTable_extract_index( ctx, hdr ))
00292 {
00293
00294 if (NULL != ctx->index.oids)
00295 {
00296 free(ctx->index.oids);
00297 }
00298
00299 free(ctx);
00300
00301 return NULL;
00302 }
00303
00304 ctx->openserSIPRegUserLookupURI = NULL;
00305 ctx->openserSIPRegUserLookupURI_len = 0;
00306 ctx->openserSIPRegUserIndex = 0;
00307 ctx->openserSIPRegUserLookupRowStatus = 0;
00308
00309 return ctx;
00310 }
00311
00312
00313
00314
00315 openserSIPRegUserLookupTable_context *
00316 openserSIPRegUserLookupTable_duplicate_row(
00317 openserSIPRegUserLookupTable_context * row_ctx)
00318 {
00319 openserSIPRegUserLookupTable_context * dup;
00320
00321 if(!row_ctx)
00322 return NULL;
00323
00324 dup = SNMP_MALLOC_TYPEDEF(openserSIPRegUserLookupTable_context);
00325 if(!dup)
00326 return NULL;
00327
00328 if(openserSIPRegUserLookupTable_row_copy(dup,row_ctx)) {
00329 free(dup);
00330 dup = NULL;
00331 }
00332
00333 return dup;
00334 }
00335
00336
00337
00338
00339
00340
00341
00342
00343 netsnmp_index * openserSIPRegUserLookupTable_delete_row(
00344 openserSIPRegUserLookupTable_context * ctx )
00345 {
00346 if(ctx->index.oids)
00347 {
00348 free(ctx->index.oids);
00349 }
00350
00351
00352 if (ctx->openserSIPRegUserLookupURI != NULL)
00353 {
00354 pkg_free(ctx->openserSIPRegUserLookupURI);
00355 }
00356
00357 free( ctx );
00358
00359 return NULL;
00360 }
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382 void openserSIPRegUserLookupTable_set_reserve1( netsnmp_request_group *rg )
00383 {
00384 openserSIPRegUserLookupTable_context *row_ctx =
00385 (openserSIPRegUserLookupTable_context *)rg->existing_row;
00386
00387 netsnmp_variable_list *var;
00388
00389 netsnmp_request_group_item *current;
00390
00391 int rc;
00392
00393 for( current = rg->list; current; current = current->next ) {
00394
00395 var = current->ri->requestvb;
00396 rc = SNMP_ERR_NOERROR;
00397
00398 switch(current->tri->colnum)
00399 {
00400
00401 case COLUMN_OPENSERSIPREGUSERLOOKUPURI:
00402
00403 if (row_ctx->openserSIPRegUserLookupRowStatus == 0 ||
00404 row_ctx->openserSIPRegUserLookupRowStatus ==
00405 TC_ROWSTATUS_NOTREADY) {
00406
00407 } else {
00408 rc = SNMP_ERR_BADVALUE;
00409 }
00410
00411 break;
00412
00413 case COLUMN_OPENSERSIPREGUSERLOOKUPROWSTATUS:
00414
00415
00416 rc = netsnmp_check_vb_type_and_size(var, ASN_INTEGER,
00417 sizeof(
00418 row_ctx->openserSIPRegUserLookupRowStatus));
00419
00420
00421
00422
00423 if (row_ctx->openserSIPRegUserLookupRowStatus == 0 &&
00424 *var->val.integer != TC_ROWSTATUS_CREATEANDGO)
00425 {
00426 rc = SNMP_ERR_BADVALUE;
00427 }
00428
00429 else if (row_ctx->openserSIPRegUserLookupRowStatus ==
00430 TC_ROWSTATUS_ACTIVE &&
00431 *var->val.integer !=
00432 TC_ROWSTATUS_DESTROY)
00433 {
00434 rc = SNMP_ERR_BADVALUE;
00435 }
00436
00437 break;
00438
00439 default:
00440 rc = SNMP_ERR_GENERR;
00441 snmp_log(LOG_ERR, "unknown column in openserSIPReg"
00442 "UserLookupTable_set_reserve1\n");
00443 }
00444
00445 if (rc)
00446 {
00447 netsnmp_set_mode_request_error(
00448 MODE_SET_BEGIN, current->ri, rc );
00449 }
00450
00451 rg->status = SNMP_MAX( rg->status, current->ri->status );
00452 }
00453
00454 }
00455
00456
00457
00458
00459
00460
00461 void openserSIPRegUserLookupTable_set_reserve2( netsnmp_request_group *rg )
00462 {
00463 openserSIPRegUserLookupTable_context *undo_ctx =
00464 (openserSIPRegUserLookupTable_context *)rg->undo_info;
00465
00466 netsnmp_request_group_item *current;
00467
00468 netsnmp_variable_list *var;
00469
00470 int rc;
00471
00472 rg->rg_void = rg->list->ri;
00473
00474 for( current = rg->list; current; current = current->next ) {
00475
00476 var = current->ri->requestvb;
00477 rc = SNMP_ERR_NOERROR;
00478
00479 switch(current->tri->colnum)
00480 {
00481 case COLUMN_OPENSERSIPREGUSERLOOKUPURI:
00482 break;
00483
00484 case COLUMN_OPENSERSIPREGUSERLOOKUPROWSTATUS:
00485
00486
00487 rc = netsnmp_check_vb_rowstatus(current->ri->requestvb,
00488 undo_ctx ?
00489 undo_ctx->openserSIPRegUserLookupRowStatus:0);
00490
00491 rg->rg_void = current->ri;
00492
00493 break;
00494
00495 default:
00496 netsnmp_assert(0);
00497 }
00498
00499 if (rc)
00500 {
00501 netsnmp_set_mode_request_error(MODE_SET_BEGIN, current->ri, rc);
00502 }
00503 }
00504
00505 }
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519 void openserSIPRegUserLookupTable_set_action( netsnmp_request_group *rg )
00520 {
00521
00522
00523 consumeInterprocessBuffer();
00524
00525 aorToIndexStruct_t *hashRecord;
00526
00527 netsnmp_variable_list *var;
00528
00529 openserSIPRegUserLookupTable_context *row_ctx =
00530 (openserSIPRegUserLookupTable_context *)rg->existing_row;
00531
00532 openserSIPRegUserLookupTable_context *undo_ctx =
00533 (openserSIPRegUserLookupTable_context *)rg->undo_info;
00534
00535 netsnmp_request_group_item *current;
00536
00537 int row_err = 0;
00538
00539
00540 for( current = rg->list; current; current = current->next ) {
00541
00542 var = current->ri->requestvb;
00543
00544 switch(current->tri->colnum)
00545 {
00546
00547 case COLUMN_OPENSERSIPREGUSERLOOKUPURI:
00548
00549 row_ctx->openserSIPRegUserLookupURI =
00550 pkg_malloc(sizeof(char)*(var->val_len + 1));
00551
00552 memcpy(row_ctx->openserSIPRegUserLookupURI,
00553 var->val.string,
00554 var->val_len);
00555
00556
00557
00558
00559
00560
00561 row_ctx->openserSIPRegUserLookupURI[var->val_len] = '\0';
00562
00563 row_ctx->openserSIPRegUserLookupURI_len = var->val_len;
00564
00565
00566
00567
00568 hashRecord =
00569 findHashRecord(hashTable,
00570 (char *)
00571 row_ctx->openserSIPRegUserLookupURI,
00572 HASH_SIZE);
00573
00574 if (hashRecord == NULL)
00575 {
00576 row_ctx->openserSIPRegUserIndex = 0;
00577 row_ctx->openserSIPRegUserLookupRowStatus =
00578 TC_ROWSTATUS_NOTINSERVICE;
00579 }
00580 else
00581 {
00582 row_ctx->openserSIPRegUserIndex =
00583 hashRecord->userIndex;
00584 row_ctx->openserSIPRegUserLookupRowStatus =
00585 TC_ROWSTATUS_ACTIVE;
00586 }
00587
00588 break;
00589
00590 case COLUMN_OPENSERSIPREGUSERLOOKUPROWSTATUS:
00591
00592 row_ctx->openserSIPRegUserLookupRowStatus =
00593 *var->val.integer;
00594
00595 if (*var->val.integer == TC_ROWSTATUS_CREATEANDGO)
00596 {
00597 rg->row_created = 1;
00598
00599
00600 row_ctx->openserSIPRegUserLookupRowStatus =
00601 TC_ROWSTATUS_NOTREADY;
00602 }
00603 else if (*var->val.integer == TC_ROWSTATUS_DESTROY)
00604 {
00605 rg->row_deleted = 1;
00606 }
00607 else
00608 {
00609
00610
00611
00612 LM_ERR("invalid RowStatus in openserSIPStatusCodesTable\n");
00613 }
00614
00615 break;
00616
00617 default:
00618 netsnmp_assert(0);
00619 }
00620 }
00621
00622
00623
00624
00625
00626 #ifndef openserSIPRegUserLookupTable_CAN_MODIFY_ACTIVE_ROW
00627 if( undo_ctx && RS_IS_ACTIVE(undo_ctx->openserSIPRegUserLookupRowStatus) &&
00628 row_ctx && RS_IS_ACTIVE(row_ctx->openserSIPRegUserLookupRowStatus) ) {
00629 row_err = 1;
00630 }
00631 #endif
00632
00633
00634
00635
00636 row_err = netsnmp_table_array_check_row_status(&cb, rg,
00637 row_ctx ? &row_ctx->openserSIPRegUserLookupRowStatus : NULL,
00638 undo_ctx ? &undo_ctx->openserSIPRegUserLookupRowStatus : NULL);
00639
00640 if(row_err) {
00641 netsnmp_set_mode_request_error(MODE_SET_BEGIN,
00642 (netsnmp_request_info*)rg->rg_void, row_err);
00643 return;
00644 }
00645
00646 }
00647
00648
00649
00650
00651
00652 void openserSIPRegUserLookupTable_set_commit( netsnmp_request_group *rg )
00653 {
00654
00655 }
00656
00657
00658
00659
00660
00661
00662
00663
00664 void openserSIPRegUserLookupTable_set_free( netsnmp_request_group *rg )
00665 {
00666
00667 }
00668
00669
00670
00671
00672
00673
00674
00675 void openserSIPRegUserLookupTable_set_undo( netsnmp_request_group *rg )
00676 {
00677
00678 }
00679
00680
00681
00682
00683
00684
00685
00686
00687 void initialize_table_openserSIPRegUserLookupTable(void)
00688 {
00689 netsnmp_table_registration_info *table_info;
00690
00691 if(my_handler) {
00692 snmp_log(LOG_ERR, "initialize_table_openserSIPRegUserLookup"
00693 "Table_handler called again\n");
00694 return;
00695 }
00696
00697 memset(&cb, 0x00, sizeof(cb));
00698
00699
00700 table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info);
00701
00702 my_handler = netsnmp_create_handler_registration(
00703 "openserSIPRegUserLookupTable",
00704 netsnmp_table_array_helper_handler,
00705 openserSIPRegUserLookupTable_oid,
00706 openserSIPRegUserLookupTable_oid_len,
00707 HANDLER_CAN_RWRITE);
00708
00709 if (!my_handler || !table_info) {
00710 snmp_log(LOG_ERR, "malloc failed in "
00711 "initialize_table_openserSIPRegUserLookup"
00712 "Table_handler\n");
00713 return;
00714 }
00715
00716
00717
00718
00719
00720 netsnmp_table_helper_add_index(table_info, ASN_UNSIGNED);
00721
00722 table_info->min_column = openserSIPRegUserLookupTable_COL_MIN;
00723 table_info->max_column = openserSIPRegUserLookupTable_COL_MAX;
00724
00725
00726
00727
00728 cb.get_value = openserSIPRegUserLookupTable_get_value;
00729 cb.container = netsnmp_container_find(
00730 "openserSIPRegUserLookupTable_primary:"
00731 "openserSIPRegUserLookupTable:"
00732 "table_container");
00733
00734 cb.can_set = 1;
00735 cb.create_row =
00736 (UserRowMethod*)openserSIPRegUserLookupTable_create_row;
00737 cb.duplicate_row =
00738 (UserRowMethod*)openserSIPRegUserLookupTable_duplicate_row;
00739 cb.delete_row =
00740 (UserRowMethod*)openserSIPRegUserLookupTable_delete_row;
00741 cb.row_copy =
00742 (Netsnmp_User_Row_Operation *)
00743 openserSIPRegUserLookupTable_row_copy;
00744
00745 cb.can_activate = (Netsnmp_User_Row_Action *)
00746 openserSIPRegUserLookupTable_can_activate;
00747 cb.can_deactivate = (Netsnmp_User_Row_Action *)
00748 openserSIPRegUserLookupTable_can_deactivate;
00749 cb.can_delete = (Netsnmp_User_Row_Action *)
00750 openserSIPRegUserLookupTable_can_delete;
00751
00752 cb.set_reserve1 = openserSIPRegUserLookupTable_set_reserve1;
00753 cb.set_reserve2 = openserSIPRegUserLookupTable_set_reserve2;
00754 cb.set_action = openserSIPRegUserLookupTable_set_action;
00755 cb.set_commit = openserSIPRegUserLookupTable_set_commit;
00756 cb.set_free = openserSIPRegUserLookupTable_set_free;
00757 cb.set_undo = openserSIPRegUserLookupTable_set_undo;
00758
00759 DEBUGMSGTL(("initialize_table_openserSIPRegUserLookupTable",
00760 "Registering table openserSIPRegUserLookupTable "
00761 "as a table array\n"));
00762
00763 netsnmp_table_container_register(my_handler, table_info, &cb,
00764 cb.container, 1);
00765 }
00766
00767
00768
00769
00770
00771 int openserSIPRegUserLookupTable_get_value(
00772 netsnmp_request_info *request,
00773 netsnmp_index *item,
00774 netsnmp_table_request_info *table_info )
00775 {
00776 netsnmp_variable_list *var = request->requestvb;
00777
00778 openserSIPRegUserLookupTable_context *context =
00779 (openserSIPRegUserLookupTable_context *)item;
00780
00781 switch(table_info->colnum)
00782 {
00783 case COLUMN_OPENSERSIPREGUSERLOOKUPURI:
00784
00785 snmp_set_var_typed_value(var, ASN_OCTET_STR,
00786 (unsigned char*)
00787 context->openserSIPRegUserLookupURI,
00788 context->openserSIPRegUserLookupURI_len);
00789 break;
00790
00791 case COLUMN_OPENSERSIPREGUSERINDEX:
00792
00793 snmp_set_var_typed_value(var, ASN_UNSIGNED,
00794 (unsigned char*)
00795 &context->openserSIPRegUserIndex,
00796 sizeof(context->openserSIPRegUserIndex));
00797 break;
00798
00799 case COLUMN_OPENSERSIPREGUSERLOOKUPROWSTATUS:
00800
00801 snmp_set_var_typed_value(var, ASN_INTEGER,
00802 (unsigned char*)
00803 &context->openserSIPRegUserLookupRowStatus,
00804 sizeof(
00805 context->openserSIPRegUserLookupRowStatus));
00806 break;
00807
00808 default:
00809 snmp_log(LOG_ERR, "unknown column in "
00810 "openserSIPRegUserLookupTable_get_value\n");
00811 return SNMP_ERR_GENERR;
00812 }
00813
00814 return SNMP_ERR_NOERROR;
00815 }
00816
00817
00818
00819
00820 const openserSIPRegUserLookupTable_context *
00821 openserSIPRegUserLookupTable_get_by_idx(netsnmp_index * hdr)
00822 {
00823 return (const openserSIPRegUserLookupTable_context *)
00824 CONTAINER_FIND(cb.container, hdr );
00825 }
00826
00827