openserSIPRegUserLookupTable.c

Go to the documentation of this file.
00001 /*
00002  * $Id: openserSIPRegUserLookupTable.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  * This file implements the openserSIPRegUserLookupTable.  For a full
00033  * description of the table, please see the OPENSER-SIP-SERVER-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) openserSIPRegUserLookupTable_extract_index() 
00044  *
00045  *    - Modified to fail if the index is invalid.  The index is invalid if it
00046  *      does not match up with the global userLookupCounter.
00047  *
00048  * 2) openserSIPRegUserLookupTable_can_[activate|deactivate|delete]()
00049  *   
00050  *    - Simplified to always allow activation/deactivation/deletion. 
00051  *
00052  * 3) openserSIPRegUserLookupTable_set_reserve1()
00053  *
00054  *    - The reserve1 phase passes if the row is new, and the rowStatus column
00055  *      is being set to 'createAndGo'
00056  *    - The reserve1 phase passes if the row is not new, and the rowStatus
00057  *      column is being set to 'destroy'
00058  *
00059  * 4) openserSIPRegUserLookupTable_set_action()
00060  *
00061  *    - The function was modified to populate the row with the userIndex of the
00062  *      supplied URI if that URI was found on the system, and set the rowStatus
00063  *      to 'active'.  If the URI was not found, the rowStatus is set to
00064  *      'notInService' 
00065  *
00066  * You can safely ignore the other functions.  
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  * Initializes the openserSIPRegUserLookupTable table.  This step is easier
00092  * than in the other tables because there is no table population.  All table
00093  * population takes place during run time. 
00094  */
00095 void init_openserSIPRegUserLookupTable(void)
00096 {
00097    initialize_table_openserSIPRegUserLookupTable();
00098 }
00099 
00100 /* the *_row_copy routine */
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    /* copy index, if provided */
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    /* Copy out almost all components of the structure.  We don't copy out
00126     * the openserSIPRegUSerLookupURI (or its length).  */
00127    dst->openserSIPRegUserLookupIndex     = src->openserSIPRegUserLookupIndex;
00128    dst->openserSIPRegUserIndex           = src->openserSIPRegUserIndex;
00129    dst->openserSIPRegUserLookupRowStatus = 
00130       src->openserSIPRegUserLookupRowStatus;
00131 
00132    return 0;
00133 }
00134 
00135 /*
00136  * the *_extract_index routine. (Mostly auto-generated) 
00137  *
00138  * This routine is called when a set request is received for an index
00139  * that was not found in the table container. Here, we parse the oid
00140  * in the individual index components and copy those indexes to the
00141  * context. Then we make sure the indexes for the new row are valid.
00142  *
00143  * It has been modified from its original form in that if the indexes are
00144  * invalid, then they aren't returned.  An index is invalid if:
00145  *
00146  *   1) It is < 1
00147  *   2) It doesn't match the global userLookupIndex. (As per MIB specs)
00148  *
00149  */
00150 int openserSIPRegUserLookupTable_extract_index(
00151       openserSIPRegUserLookupTable_context * ctx, 
00152       netsnmp_index * hdr)
00153 {
00154    /*
00155     * temporary local storage for extracting oid index
00156     *
00157     * extract index uses varbinds (netsnmp_variable_list) to parse
00158     * the index OID into the individual components for each index part.
00159     */
00160    netsnmp_variable_list var_openserSIPRegUserLookupIndex;
00161    int err;
00162 
00163    /* copy index, if provided */
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    /* Set up the index */
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    /* parse the oid into the individual index components */
00183    err = parse_oid_indexes( hdr->oids, hdr->len, 
00184          &var_openserSIPRegUserLookupIndex );
00185 
00186    if (err == SNMP_ERR_NOERROR) {
00187       
00188       /* copy index components into the context structure */
00189       ctx->openserSIPRegUserLookupIndex = 
00190          *var_openserSIPRegUserLookupIndex.val.integer;
00191 
00192       /* 
00193        * Check to make sure that the index corresponds to the
00194        * global_userLookupCounter, as per the MIB specifications. 
00195        */
00196       if (*var_openserSIPRegUserLookupIndex.val.integer != 
00197             global_UserLookupCounter || 
00198           *var_openserSIPRegUserLookupIndex.val.integer < 1) {
00199          err = -1;
00200       }
00201 
00202    }
00203 
00204    /* parsing may have allocated memory. free it. */
00205    snmp_reset_var_buffers( &var_openserSIPRegUserLookupIndex );
00206 
00207    return err;
00208 }
00209 
00210 /*
00211  * This is an auto-generated function.  In general the *_can_activate routine 
00212  * is called when a row is changed to determine if all the values set are
00213  * consistent with the row's rules for a row status of ACTIVE.  If not, then 0
00214  * can be returned to prevent the row status from becomming final. 
00215  *
00216  * For our purposes, we have no need for this check, so we always return 1.
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  * This is an auto-generated function.  In general the *_can_deactivate routine
00228  * is called when a row that is currently ACTIVE is set to a state other than
00229  * ACTIVE. If there are conditions in which a row should not be allowed to
00230  * transition out of the ACTIVE state (such as the row being referred to by
00231  * another row or table), check for them here.
00232  *
00233  * Since this table has no reason why this shouldn't be allowed, we always
00234  * return 1;
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  * This is an auto-generated function.  In general the *_can_delete routine is
00246  * called to determine if a row can be deleted.  This usually involved checking
00247  * if it can be deactivated, and if it can be, then checking for other
00248  * conditions.  
00249  *
00250  * Since this table ha no reason why row deletion shouldn't be allowed, we
00251  * always return 1, unless we can't deactivate.  
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  * This is an auto-generated function.  
00266  *
00267  * The *_create_row routine is called by the table handler to create a new row
00268  * for a given index. This is the first stage of the row creation process.  The
00269  * *_set_reserve_* functions can be used to prevent the row from being inserted
00270  * into the table even if the row passes any preliminary checks set here. 
00271  *
00272  * Returns a newly allocated openserSIPRegUserLookupTable_context structure (a
00273  * row in the table) if the indexes are legal.  NULL will be returned otherwise. 
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     * Extract the index.  The function has been modified from its original
00288     * auto-generated version in that the function will fail if index is
00289     * somehow invalid. 
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  * Auto-generated function.  The *_duplicate row routine
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  * The *_delete_row method is auto-generated, and is called to delete a row.
00338  *
00339  * This will not be called if earlier checks said that this row can't be
00340  * deleted.  However, in our implementation there is never a reason why this
00341  * function can't be called. 
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  * Large parts of this function have been auto-generated.  The functions purpose
00365  * is to check to make sure all SNMP set values for the given row, have been
00366  * valid.  If not, then the process is supposed to be aborted.  Otherwise, we
00367  * pass on to the *_reserve2 function.  
00368  *
00369  * For our purposes, our only check is to make sure that either of the following
00370  * conditions are true: 
00371  *
00372  * 1) If this row already exists, then the SET request is setting the rowStatus
00373  *    column to 'destroy'.
00374  *
00375  * 2) If this row does not already exist, then the SET request is setting the 
00376  *    rowStatus to 'createAndGo'. 
00377  *
00378  * Since the MIB specified there are to be no other modifications to the row,
00379  * any other condition is considered illegal, and will result in an SNMP error
00380  * being returned. 
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             /** RowStatus = ASN_INTEGER */
00416             rc = netsnmp_check_vb_type_and_size(var, ASN_INTEGER,
00417                   sizeof(
00418                   row_ctx->openserSIPRegUserLookupRowStatus));
00419           
00420             /* Want to make sure that if it already exists that it
00421              * is setting it to 'destroy', or if it doesn't exist,
00422              * that it is setting it to 'createAndGo' */
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: /** We shouldn't get here */
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  * Auto-generated function.  The function is supposed to check for any
00458  * last-minute conditions not being met.  However, we don't have any such
00459  * conditions, so we leave the default function as is.
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             /** RowStatus = ASN_INTEGER */
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: /** We shouldn't get here */
00496             netsnmp_assert(0); /** why wasn't this caught in reserve1? */
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  * This function is called only when all the *_reserve[1|2] functions were
00509  * succeful.  Its purpose is to make any changes to the row before it is
00510  * inserted into the table.  
00511  *
00512  * In the case of this table, this involves looking up the index of the
00513  * requested user in the URI to userIndex mapping hash table.  If the result is
00514  * found, the index will be copied to the row, and the rowStatus set to
00515  * 'active'.  Otherwise, the row status will be set to 'notInService'
00516  *
00517  * All other handling is auto-generated.
00518  */
00519 void openserSIPRegUserLookupTable_set_action( netsnmp_request_group *rg )
00520 {  
00521    /* First things first, we need to consume the interprocess buffer, in
00522     * case something has changed. We want to return the freshest data. */
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    /* Copy the actual data to the row. */
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             /* Usually NetSNMP won't terminate strings with '\0'.
00557              * The hash function expect them to be terminated
00558              * though, so we have to add this on to the end.  The +1
00559              * in the malloc makes sure of the extra space for us.
00560              */   
00561             row_ctx->openserSIPRegUserLookupURI[var->val_len] = '\0';
00562 
00563             row_ctx->openserSIPRegUserLookupURI_len = var->val_len;
00564       
00565             /* Do the lookup.  If we could find the record, then set
00566              * the index and the row status to active.  Otherwise,
00567              * set the row to notInService */
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                /* Set to NOT READY until the lookup URI has
00599                 * been supplied. */
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                /* We should never be here, because the RESERVE
00610                 * functions should have taken care of all other
00611                 * values. */
00612             LM_ERR("invalid RowStatus in openserSIPStatusCodesTable\n");
00613             }
00614 
00615             break;
00616 
00617          default: /** We shouldn't get here */
00618             netsnmp_assert(0); /** why wasn't this caught in reserve1? */
00619       }
00620    }
00621 
00622    /*
00623     * done with all the columns. Could check row related
00624     * requirements here.
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     * check activation/deactivation
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  * The COMMIT phase is used to do any extra processing after the ACTION phase.
00650  * In our table, there is nothing to do, so the function body is empty.
00651  */
00652 void openserSIPRegUserLookupTable_set_commit( netsnmp_request_group *rg )
00653 {
00654 
00655 }
00656 
00657 
00658 /*
00659  * This function is called if the *_reserve[1|2] calls failed.  Its supposed to
00660  * free up any resources allocated earlier.  However, we already take care of
00661  * all these resources in earlier functions.  So for our purposes, the function
00662  * body is empty. 
00663  */
00664 void openserSIPRegUserLookupTable_set_free( netsnmp_request_group *rg )
00665 {
00666 
00667 }
00668 
00669 
00670 /* 
00671  * This function is called if an ACTION phase fails, to do extra clean-up work.
00672  * We don't have anything complicated enough to warrant putting anything in this
00673  * function.  Therefore, its just left with an empty function body. 
00674  */
00675 void openserSIPRegUserLookupTable_set_undo( netsnmp_request_group *rg )
00676 {
00677 
00678 }
00679 
00680 
00681 /*
00682  * Initialize the openserSIPRegUserLookupTable table by defining how it is
00683  * structured. 
00684  *
00685  * This function is mostly auto-generated.
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    /** create the table structure itself */
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; /** mallocs failed */
00714    }
00715 
00716    /*
00717     * Setting up the table's definition
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     * registering the table with the master agent
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  * This function was auto-generated and didn't need modifications from its
00769  * auto-generation.  It is called to handle an SNMP GET request. 
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          /** SnmpAdminString = ASN_OCTET_STR */
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          /** UNSIGNED32 = ASN_UNSIGNED */
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          /** RowStatus = ASN_INTEGER */
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: /** We shouldn't get here */
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  * openserSIPRegUserLookupTable_get_by_idx
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 

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