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