openserSIPMethodSupportedTable.c

Go to the documentation of this file.
00001 /*
00002  * $Id: openserSIPMethodSupportedTable.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  * Originally Generated with mib2c using mib2c.array-user.conf
00030  *
00031  * The file implements the openserSIPMethodSupportedTable.  The table is
00032  * populated by looking to see which modules are loaded, and guessing what SIP
00033  * Methods they  provide.  It is quite possible that this initial implementation
00034  * is not very good at guessing.  This should be fixed in future releases as
00035  * more information becomes available.  
00036  *
00037  * For full details, please see the OPENSER-SIP-COMMON-MIB.
00038  *
00039  */
00040 
00041 #include "../../sr_module.h"
00042 #include "../../mem/mem.h"
00043 
00044 #include <net-snmp/net-snmp-config.h>
00045 #include <net-snmp/net-snmp-includes.h>
00046 #include <net-snmp/agent/net-snmp-agent-includes.h>
00047 
00048 #include <net-snmp/library/snmp_assert.h>
00049 
00050 #include "openserSIPMethodSupportedTable.h"
00051 
00052 static netsnmp_handler_registration *my_handler = NULL;
00053 static netsnmp_table_array_callbacks cb;
00054 
00055 oid    openserSIPMethodSupportedTable_oid[] = 
00056    { openserSIPMethodSupportedTable_TABLE_OID };
00057 
00058 size_t openserSIPMethodSupportedTable_oid_len = 
00059    OID_LENGTH(openserSIPMethodSupportedTable_oid);
00060 
00061 
00062 /* Create a row at the given index, containing stringToRegister, and insert it
00063  * into the table.  Note that stringToRegister will be copied, so it is not
00064  * necessary to pre-allocate this string anywhere. */
00065 void createRow(int index, char *stringToRegister) {
00066 
00067    openserSIPMethodSupportedTable_context *theRow;
00068 
00069    oid  *OIDIndex;
00070    char *copiedString;
00071    int  stringLength;
00072 
00073    theRow = SNMP_MALLOC_TYPEDEF(openserSIPMethodSupportedTable_context);
00074 
00075    if (theRow == NULL) {
00076       LM_ERR("failed to create a row for openserSIPMethodSupportedTable\n");
00077       return;
00078    }
00079 
00080    OIDIndex = pkg_malloc(sizeof(oid));
00081 
00082    if (OIDIndex == NULL) {
00083       free(theRow);
00084       LM_ERR("failed to create a row for openserSIPMethodSupportedTable\n");
00085       return;
00086    }
00087 
00088    stringLength = strlen(stringToRegister);
00089 
00090    copiedString = pkg_malloc((stringLength + 1) * sizeof(char));
00091 
00092    if (copiedString == NULL) {
00093       LM_ERR("failed to create a row for openserSIPMethodSupportedTable\n");
00094       return;
00095    }
00096 
00097    strcpy(copiedString, stringToRegister);
00098 
00099    OIDIndex[0] = index;
00100 
00101    theRow->index.len  = 1;
00102    theRow->index.oids = OIDIndex;
00103    theRow->openserSIPMethodSupportedIndex = index;
00104 
00105    theRow->openserSIPMethodName     = (unsigned char*) copiedString;
00106    theRow->openserSIPMethodName_len = stringLength;
00107 
00108    CONTAINER_INSERT(cb.container, theRow);
00109 }
00110 
00111 
00112 /* Initializes the openserSIPMethodSupportedTable, and populates the tables 
00113  * contents */
00114 void init_openserSIPMethodSupportedTable(void)
00115 {
00116    initialize_table_openserSIPMethodSupportedTable();
00117 
00118    /* Tables is defined as follows:
00119     *
00120     *    1)  METHOD_INVITE
00121     *    2)  METHOD_CANCEL
00122     * 3)  METHOD_ACK
00123     * 4)  METHOD_BYE
00124     * 5)  METHOD_INFO
00125     * 6)  METHOD_OPTIONS
00126     * 7)  METHOD_UPDATE
00127     * 8)  METHOD_REGISTER
00128     * 9)  METHOD_MESSAGE
00129     * 10) METHOD_SUBSCRIBE
00130     * 11) METHOD_NOTIFY
00131     * 12) METHOD_PRACK
00132     * 13) METHOD_REFER
00133     * 14) METHOD_PUBLISH
00134     *
00135     * We should keep these indices fixed.  For example if we don't support
00136     * METHOD_REGISTER but we do support METHOD_MESSAGE, then METHOD_MESSAGE
00137     * should still be at index 9.  
00138     *
00139     * NOTE: My way of checking what METHODS we support is probably wrong.
00140     * Please feel free to correct it! */
00141    
00142    if (module_loaded("sl")) {
00143       createRow(1, "METHOD_INVITE");
00144       createRow(2, "METHOD_CANCEL");
00145       createRow(3, "METHOD_ACK");
00146    }
00147 
00148    if (module_loaded("tm")) {
00149       createRow(4, "METHOD_BYE");
00150    }
00151 
00152    if (module_loaded("options")) {
00153       createRow(6, "METHOD_OPTIONS");
00154    }
00155 
00156    if (module_loaded("dialog")) {
00157       createRow(7, "METHOD_UPDATE");
00158    }
00159 
00160    if (module_loaded("registrar")) {
00161       createRow(8, "METHOD_REGISTER");
00162       createRow(10, "METHOD_SUBSCRIBE");
00163       createRow(11, "METHOD_NOTIFY");
00164    }
00165 
00166    createRow(5,  "METHOD_INFO");
00167    createRow(9,  "METHOD_MESSAGE");
00168 
00169    /* I'm not sure what these guys are, so saying we support them by
00170     * default.  */
00171    createRow(12, "METHOD_PRACK");
00172    createRow(13, "METHOD_REFER");
00173    createRow(14, "METHOD_PUBLISH");
00174 }
00175 
00176 
00177 /* Initialize the openserSIPMethodSupportedTable by defining its structure and
00178  * callback mechanisms */
00179 void initialize_table_openserSIPMethodSupportedTable(void)
00180 {
00181    netsnmp_table_registration_info *table_info;
00182 
00183    if(my_handler) {
00184       snmp_log(LOG_ERR, "initialize_table_openserSIPMethodSupported"
00185             "Table_handler called again\n");
00186       return;
00187    }
00188 
00189    memset(&cb, 0x00, sizeof(cb));
00190 
00191    /** create the table structure itself */
00192    table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info);
00193 
00194    my_handler = 
00195       netsnmp_create_handler_registration(
00196          "openserSIPMethodSupportedTable",
00197          netsnmp_table_array_helper_handler,
00198          openserSIPMethodSupportedTable_oid,
00199          openserSIPMethodSupportedTable_oid_len,
00200          HANDLER_CAN_RONLY);
00201          
00202    if (!my_handler || !table_info) {
00203       snmp_log(LOG_ERR, "malloc failed in initialize_table_openser"
00204             "SIPMethodSupportedTable_handler\n");
00205       return; 
00206    }
00207 
00208    netsnmp_table_helper_add_index(table_info, ASN_UNSIGNED);
00209 
00210    table_info->min_column = openserSIPMethodSupportedTable_COL_MIN;
00211    table_info->max_column = openserSIPMethodSupportedTable_COL_MAX;
00212 
00213    /***************************************************
00214     * registering the table with the master agent
00215     */
00216    cb.get_value = openserSIPMethodSupportedTable_get_value;
00217    cb.container = 
00218       netsnmp_container_find("openserSIPMethodSupportedTable_primary:"
00219          "openserSIPMethodSupportedTable:" "table_container");
00220    
00221    DEBUGMSGTL(("initialize_table_openserSIPMethodSupportedTable", 
00222             "Registering table openserSIPMethodSupportedTable"
00223             "as a table array\n"));
00224 
00225    netsnmp_table_container_register(my_handler, table_info, &cb,
00226          cb.container, 1);
00227 
00228 }
00229 
00230 /* 
00231  * This routine is called to process get requests for elements of the table.
00232  *
00233  * The function is pretty much left as is from the auto-generated code. 
00234  */
00235 int openserSIPMethodSupportedTable_get_value(
00236          netsnmp_request_info *request,
00237          netsnmp_index *item,
00238          netsnmp_table_request_info *table_info )
00239 {
00240    netsnmp_variable_list *var = request->requestvb;
00241 
00242    openserSIPMethodSupportedTable_context *context = 
00243       (openserSIPMethodSupportedTable_context *)item;
00244 
00245    switch(table_info->colnum) 
00246    {
00247       case COLUMN_OPENSERSIPMETHODNAME:
00248 
00249          /** SnmpAdminString = ASN_OCTET_STR */
00250          snmp_set_var_typed_value(var, ASN_OCTET_STR,
00251                (unsigned char*)
00252                context->openserSIPMethodName,
00253                context->openserSIPMethodName_len );
00254          break;
00255    
00256       default: /** We shouldn't get here */
00257          snmp_log(LOG_ERR, "unknown column in openserSIPMethod"
00258                "SupportedTable_get_value\n");
00259          return SNMP_ERR_GENERR;
00260    }
00261 
00262    return SNMP_ERR_NOERROR;
00263 }
00264 
00265 /*
00266  * openserSIPMethodSupportedTable_get_by_idx is an auto-generated function.
00267  */
00268 const openserSIPMethodSupportedTable_context *
00269    openserSIPMethodSupportedTable_get_by_idx(netsnmp_index * hdr)
00270 {
00271    return (const openserSIPMethodSupportedTable_context *)
00272       CONTAINER_FIND(cb.container, hdr );
00273 }
00274 
00275 

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