openserSIPStatusCodesTable.c

Go to the documentation of this file.
00001 /*
00002  * $Id: openserSIPStatusCodesTable.c 4518 2008-07-28 15:39:28Z henningw $
00003  *
00004  * SNMPStats Module 
00005  * Copyright (C) 2006 SOMA Networks, INC.
00006  * Written by: Jeffrey Magder (jmagder@somanetworks.com)
00007  *
00008  * This file is part of Kamailio, a free SIP server.
00009  *
00010  * Kamailio is free software; you can redistribute it and/or modify it
00011  * under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version
00014  *
00015  * Kamailio is distributed in the hope that it will be useful, but
00016  * WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  * General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License
00021  * along with this program; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023  * USA
00024  *
00025  * History:
00026  * --------
00027  * 2006-11-23 initial version (jmagder)
00028  *
00029  * Note: this file originally auto-generated by mib2c using
00030  * mib2c.array-user.conf
00031  *
00032  * The file implements the openserSIPStatusCodesTable.  For a full description
00033  * of the table, please see the OPENSER-SIP-COMMON-MIB.
00034  * 
00035  * This file is much larger and more complicated than the files for other
00036  * tables.  This is because the table is settable, bringing a lot of SNMP
00037  * overhead.  Most of the file consists of the original auto-generated
00038  * code (aside from white space and comment changes).
00039  *
00040  * The functions that have been modified to implement this table are the
00041  * following:
00042  *
00043  * 1) openserSIPStatusCodesTable_create_row()
00044  *
00045  *    - The row structure has been modified from its default to store the
00046  *      number of messages that have been recieved and sent with a certain
00047  *      status code, at the time this row was created.  This function 
00048  *      populates that data. 
00049  *
00050  * 2) openserSIPStatusCodesTable_extract_index() 
00051  *
00052  *    - Modified to fail if the index is invalid.  The index is invalid if it
00053  *      does not match up with the global userLookupCounter.
00054  *
00055  * 3) openserSIPStatusCodesTable_can_[activate|deactivate|delete]()
00056  *   
00057  *    - Simplified to always allow activation/deactivation/deletion. 
00058  *
00059  * 4) openserSIPStatusCodesTable_set_reserve1()
00060  *
00061  *    - The reserve1 phase passes if the row is new, and the rowStatus column
00062  *      is being set to 'createAndGo'
00063  *
00064  *    - The reserve1 phase passes if the row is not new, and the rowStatus
00065  *      column is being set to 'destroy'
00066  *
00067  * 5) openserSIPStatusCodesTable_get_value()
00068  *
00069  *    - Instead of returning a variable binding to either
00070  *      openserSIPStatusCodeIns or openserSIPStatusCodeOuts, the function 
00071  *      returns a variable binding equal to the current value as per the 
00072  *      statistics framework, minus either openserSIPStatusCodeIns or
00073  *      openserSIPStatusCodeOuts
00074  *
00075  * You can safely ignore the other functions.  
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  * Initializes the openserSIPStatusCodesTable module.  This step is easier
00100  * than in the other tables because there is no table population.  All table
00101  * population takes place during run time. 
00102  */
00103 void init_openserSIPStatusCodesTable(void)
00104 {
00105    initialize_table_openserSIPStatusCodesTable();
00106 }
00107 
00108 
00109 /* the *_row_copy routine */
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    /* copy index, if provided */
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    /* copy components into the context structure */
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  * the *_extract_index routine (Mostly auto-generated)
00146  *
00147  * This routine is called when a set request is received for an index that 
00148  * was not found in the table container. Here, we parse the oid in the
00149  * individual index components and copy those indexes to the context. Then 
00150  * we make sure the indexes for the new row are valid.
00151  *
00152  * It has been modified from its original form in that the indexes aren't
00153  * returned if they are invalid.  An index is invalid if it is not between 
00154  * 100 and 699 (Inclusive).
00155  */
00156 int openserSIPStatusCodesTable_extract_index( 
00157       openserSIPStatusCodesTable_context * ctx, netsnmp_index * hdr)
00158 {
00159 
00160    /*
00161     * temporary local storage for extracting oid index
00162     *
00163     * extract index uses varbinds (netsnmp_variable_list) to parse
00164     * the index OID into the individual components for each index part.
00165     */
00166    netsnmp_variable_list var_openserSIPStatusCodeMethod;
00167    netsnmp_variable_list var_openserSIPStatusCodeValue;
00168    int err;
00169 
00170    /*
00171     * copy index, if provided
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    /* Initialize the two variables responsible for holding our two indices.
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    /* parse the oid into the individual index components */
00204    err = parse_oid_indexes( hdr->oids, hdr->len, 
00205          &var_openserSIPStatusCodeMethod );
00206 
00207    if (err == SNMP_ERR_NOERROR) {
00208 
00209       /* copy index components into the context structure */
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    /* parsing may have allocated memory. free it. */
00230    snmp_reset_var_buffers( &var_openserSIPStatusCodeMethod );
00231 
00232    return err;
00233 }
00234 
00235 
00236 /*
00237  * This is an auto-generated function.  In general the *_can_activate routine 
00238  * is called when a row is changed to determine if all the values set are
00239  * consistent with the row's rules for a row status of ACTIVE.  If not, then 0
00240  * can be returned to prevent the row status from becomming final. 
00241  *
00242  * For our purposes, we have no need for this check, so we always return 1.
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  * This is an auto-generated function.  In general the *_can_deactivate routine
00255  * is called when a row that is currently ACTIVE is set to a state other than
00256  * ACTIVE. If there are conditions in which a row should not be allowed to
00257  * transition out of the ACTIVE state (such as the row being referred to by
00258  * another row or table), check for them here.
00259  *
00260  * Since this table has no reason why this shouldn't be allowed, we always
00261  * return 1;
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  * This is an auto-generated function.  In general the *_can_delete routine is
00274  * called to determine if a row can be deleted.  This usually involved checking
00275  * if it can be deactivated, and if it can be, then checking for other
00276  * conditions.  
00277  *
00278  * Since this table ha no reason why row deletion shouldn't be allowed, we
00279  * always return 1, unless we can't deactivate.  
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  * (Mostly auto-generated function) 
00294  *
00295  * The *_create_row routine is called by the table handler to create a new row
00296  * for a given index. This is the first stage of the row creation process.  The
00297  * *_set_reserve_* functions can be used to prevent the row from being inserted
00298  * into the table even if the row passes any preliminary checks set here. 
00299  *
00300  * Returns a newly allocated openserSIPRegUserLookupTable_context structure (a
00301  * row in the table) if the indexes are legal.  NULL will be returned otherwise.
00302  *
00303  * The function has been modified from its original form, in that it will store
00304  * the number of messages 'in' to the system, and the number of messages 'out'
00305  * of the system, that had a status code matching this rows status code, at the
00306  * time this row was created.  
00307  *
00308  * This value will be used in the future to calculate the delta between now and
00309  * the time this row has been read.  
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    /* The *_extract_index funtion already validates the indices, so we
00323     * don't need to do any further evaluations here.  */
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    /* The indices were already set up in the extract_index function
00333     * above. */
00334    ctx->openserSIPStatusCodeIns       = 0;
00335    ctx->openserSIPStatusCodeOuts      = 0;
00336    ctx->openserSIPStatusCodeRowStatus = 0;
00337 
00338    /* Retrieve the index for the status code, and then assign the starting
00339     * values.  The starting values will be used to calculate deltas during
00340     * the next snmpget/snmpwalk/snmptable/etc. */
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  * Auto-generated function.  The *_duplicate row routine
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  * The *_delete_row method is auto-generated, and is called to delete a row.
00390  *
00391  * This will not be called if earlier checks said that this row can't be
00392  * deleted.  However, in our implementation there is never a reason why this
00393  * function can't be called. 
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  * Large parts of this function have been auto-generated.  The functions purpose
00409  * is to check to make sure all SNMP set values for the given row, have been
00410  * valid.  If not, then the process is supposed to be aborted.  Otherwise, we
00411  * pass on to the *_reserve2 function.  
00412  *
00413  * For our purposes, our only check is to make sure that either of the following
00414  * conditions are true: 
00415  *
00416  * 1) If this row already exists, then the SET request is setting the rowStatus
00417  *    column to 'destroy'.
00418  *
00419  * 2) If this row does not already exist, then the SET request is setting the 
00420  *    rowStatus to 'createAndGo'. 
00421  *
00422  * Since the MIB specified there are to be no other modifications to the row,
00423  * any other condition is considered illegal, and will result in an SNMP error
00424  * being returned. 
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    /* Loop through the specified columns, and make sure that all values are
00437     * valid. */
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             /** RowStatus = ASN_INTEGER */
00448             rc = netsnmp_check_vb_type_and_size(var, 
00449                   ASN_INTEGER,
00450                   sizeof(
00451                   row_ctx->openserSIPStatusCodeRowStatus));
00452          
00453             /* Want to make sure that if it already exists that it
00454              * is setting it to 'destroy', or if it doesn't exist,
00455              * that it is setting it to 'createAndGo' */
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: /** We shouldn't get here */
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  * Auto-generated function.  The function is supposed to check for any
00492  * last-minute conditions not being met.  However, we don't have any such
00493  * conditions, so we leave the default function as is.
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             /** RowStatus = ASN_INTEGER */
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: /** We shouldn't get here */
00525             netsnmp_assert(0); /** why wasn't this caught in reserve1? */
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  * This function is called only when all the *_reserve[1|2] functions were
00539  * succeful.  Its purpose is to make any changes to the row before it is
00540  * inserted into the table.  
00541  *
00542  * In our case, we don't require any changes.  So we leave the original
00543  * auto-generated code as is.   
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    /* Depending on what the snmpset was, set the row to be created or
00560     * deleted.   */
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             /** RowStatus = ASN_INTEGER */
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                /* We should never be here, because the RESERVE
00583                 * functions should have taken care of all other
00584                 * values. */
00585             LM_ERR("Invalid RowStatus in openserSIPStatusCodesTable\n");
00586             }
00587 
00588             break;
00589 
00590          default: /** We shouldn't get here */
00591             netsnmp_assert(0); /** why wasn't this caught in reserve1? */
00592       }
00593    }
00594 
00595    /*
00596     * done with all the columns. Could check row related
00597     * requirements here.
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     * check activation/deactivation
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  * The COMMIT phase is used to do any extra processing after the ACTION phase.
00626  * In our table, there is nothing to do, so the function body is empty.
00627  */
00628 void openserSIPStatusCodesTable_set_commit( netsnmp_request_group *rg )
00629 {
00630 
00631 }
00632 
00633 
00634 /*
00635  * This function is called if the *_reserve[1|2] calls failed.  Its supposed to
00636  * free up any resources allocated earlier.  However, we already take care of
00637  * all these resources in earlier functions.  So for our purposes, the function
00638  * body is empty. 
00639  */
00640 void openserSIPStatusCodesTable_set_free( netsnmp_request_group *rg )
00641 {
00642 
00643 }
00644 
00645 
00646 /* 
00647  * This function is called if an ACTION phase fails, to do extra clean-up work.
00648  * We don't have anything complicated enough to warrant putting anything in this
00649  * function.  Therefore, its just left with an empty function body. 
00650  */
00651 void openserSIPStatusCodesTable_set_undo( netsnmp_request_group *rg )
00652 {
00653 
00654 }
00655 
00656 
00657 
00658 /*
00659  * Initialize the openserSIPStatusCodesTable table by defining how it is
00660  * structured. 
00661  *
00662  * This function is mostly auto-generated.
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    /** create the table structure itself */
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; /** mallocs failed */
00690    }
00691 
00692    /** index: openserSIPStatusCodeMethod */
00693    netsnmp_table_helper_add_index(table_info, ASN_UNSIGNED);
00694    /** index: openserSIPStatusCodeValue */
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     * registering the table with the master agent
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  * This function is called to handle SNMP GET requests.  
00761  *
00762  * The row which this function is called with, will store a message code.  The
00763  * function will retrieve the 'number of messages in' and 'number of messages
00764  * out' statistic for this particular message code from the statistics
00765  * framework.  
00766  *
00767  * The function will then subtract from this value the value it was initialized
00768  * with when the row was first created.  In this sense, the row shows how many
00769  * ins and how many outs have been received (With respect to the message code)
00770  * since this row was created. 
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    /* Retrieve the statusCodeIdx so we can calculate deltas between current
00785     * values and previous values. */
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             /* Calculate the Delta */
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             /* Calculate the Delta */
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          /** RowStatus = ASN_INTEGER */
00831          snmp_set_var_typed_value(var, ASN_INTEGER,
00832                 (unsigned char*)
00833                 &context->openserSIPStatusCodeRowStatus,
00834                 sizeof(context->openserSIPStatusCodeRowStatus) );
00835       break;
00836    
00837    default: /** We shouldn't get here */
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  * openserSIPRegUserLookupTable_get_by_idx
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 

Generated on Thu May 24 00:00:28 2012 for Kamailio - The Open Source SIP Server by  doxygen 1.5.6