snmpSIPContactTable.h

00001 /*
00002  * $Id$
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  * 2007-02-16 Moved all OID registrations from the experimental branch to 
00029  *            OpenSER's IANA assigned enterprise branch. (jmagder)
00030  * 
00031  * Note: this file was originally auto-generated by mib2c using
00032  * mib2c.array-user.conf
00033  *
00034  * This file contains the implementation of the openserSIPContact Table.  For a
00035  * full description of this structure, please see the OPENSER-SIP-SERVER-MIB.
00036  *
00037  * Some important notes on implementation follow:
00038  *
00039  * We require OpenSERs usrloc module to inform us when a contact is
00040  * added/removed.  The general callback process works as follows:
00041  *
00042  * 1) On startup, we register handleContactCallbacks() for USRLOC callbacks, so 
00043  *    we can be informed whenever a contact is added/removed from the system.  
00044  *    This registration happens with a call to registerForUSRLOCCallbacks().  
00045  *    (This is actually called when the SNMPStats module is initialized)
00046  *
00047  * 2) Whenever we receive a contact callback, handleContactCallbacks() will 
00048  *    quickly add the contact information and operation type to the
00049  *    interprocess buffer.  
00050  *
00051  * 3) When we receive an SNMP request for user/contact information, we consume
00052  *    the interprocess buffer with consumeInterprocessBuffer().  The function
00053  *    will add/delete rows to the tables, and then service the SNMP request.
00054  *
00055  * Notes: 
00056  *
00057  * - The interprocess buffer was necessary, because NetSNMP's containers can be
00058  *   very inefficient at adding large amounts of data at a time, such as when
00059  *   OpenSER first starts up.  It was decided its better to make an SNMP manager
00060  *   wait for data, instead of slowing down the rest of OpenSER while the
00061  *   sub-agent processes the data. 
00062  *
00063  * - It is important to send periodic SNMP requests to this table (or the user
00064  *   table), to make sure the process buffer doesn't get too large.  
00065  */
00066 
00067 #ifndef OPENSERSIPCONTACTTABLE_H
00068 #define OPENSERSIPCONTACTTABLE_H
00069 
00070 #ifdef __cplusplus
00071 extern "C" {
00072 #endif
00073 
00074     
00075 #include <net-snmp/net-snmp-config.h>
00076 #include <net-snmp/library/container.h>
00077 #include <net-snmp/agent/table_array.h>
00078 
00079 #include "interprocess_buffer.h"
00080 
00081 #include "../usrloc/ucontact.h"
00082 #include "../../config.h"
00083 
00084 /* This strucutre is actually quite different from what was generated by mib2c.
00085  * Specifically, the scalars openserSIPContactURI, openserSIPContactExpiry, and
00086  * openserSIPContactPreference have been removed from the rows definition.  This
00087  * was done because the values change over time.  Therefore we retrieve the data
00088  * only when it is requested for, instead of storing stale data.
00089  */
00090 typedef struct openserSIPContactTable_context_s 
00091 {
00092         netsnmp_index index; 
00094         unsigned long openserSIPContactIndex;
00095 
00096         unsigned char *openserSIPContactURI;
00097         long           openserSIPContactURI_len;
00098 
00099         /* A pointer to the rest of the contact structure, giving us access to
00100          * openserSIPContactURI, openserSIPContactExpirty, and
00101          * openserSIPContactPreference. */
00102         ucontact_t *contactInfo;
00103 
00104         void * data;
00105 
00106 } openserSIPContactTable_context;
00107 
00108 /******************************/
00109 /* Customized SNMP Prototypes */
00110 /******************************/
00111 
00112 /* 
00113  * Creates an SNMP row and inserts it into the contact table. This function
00114  * should only be called when the interprocess buffer is being consumed.
00115  *
00116  * Returns: 1 on success, and 0 otherwise. 
00117  */
00118 int  createContactRow(int userIndex, int contactIndex, char *contactName,
00119                 ucontact_t *contactInfo);
00120 
00121 /* 
00122  * Removes the row indexed by userIndex and contactIndex, and free's up the
00123  * memory allocated to it.  If the row could not be found, then nothing is done.
00124  */
00125 void deleteContactRow(int userIndex, int contactIndex);
00126 
00127 
00128 /* 
00129  * This function adds a new contactToIndexStruct_t record to the front of
00130  * 'contactRecord'.  
00131  *
00132  * The structure is used to map a contact name to the SNMPStats modules integer
00133  * indexing scheme.  It will be used later when a delete command comes in, and
00134  * we need to find out which SNMP row the information is stored under.
00135  */
00136 int  insertContactRecord(contactToIndexStruct_t **contactRecord, int index, 
00137                 char *name);
00138 
00139 /*
00140  * This function will remove the contactToIndexStruct_T record matching
00141  * 'contactName' from the users contactToIndexStruct_t linked-list, and return
00142  * the records index.  In the event that the record could not be found, 0 will
00143  * be returned. 
00144  */
00145 int  deleteContactRecord(contactToIndexStruct_t **contactRecord, 
00146                 char *contactName);
00147 
00148 
00149 /********************************/
00150 /* Normal SNMP Table Prototypes */
00151 /********************************/
00152 
00153 /*
00154  * Initializes the openserSIPContactTable module.  This involves:
00155  *
00156  *  1) Registering the tables OID with the master agent
00157  *
00158  *  2) Creating a default row, so that there is a row to query to trigger the
00159  *     consumption of the interprocess buffer.
00160  */
00161 void  init_openserSIPContactTable(void);
00162 
00163 
00164 /*
00165  * Initialize the openserSIPContactTable table by defining its contents and how
00166  * it's structured.
00167  *
00168  * This function is mostly auto-generated.
00169  */
00170 void  initialize_table_openserSIPContactTable(void);
00171 
00172 const openserSIPContactTable_context * openserSIPContactTable_get_by_idx(
00173                 netsnmp_index *);
00174 
00175 const openserSIPContactTable_context * openserSIPContactTable_get_by_idx_rs(
00176                 netsnmp_index *, int row_status);
00177 
00178 /* This routine is called to process get requests for elements of the table. */
00179 int   openserSIPContactTable_get_value(netsnmp_request_info *, netsnmp_index *,
00180                 netsnmp_table_request_info *);
00181 
00182 
00183 /* oid declarations */
00184 extern oid    openserSIPContactTable_oid[];
00185 extern size_t openserSIPContactTable_oid_len;
00186 
00187 #define openserSIPContactTable_TABLE_OID OPENSER_OID,3,1,2,1,5,7
00188     
00189 /*************************************************************
00190  * column number definitions for table openserSIPContactTable
00191  */
00192 #define COLUMN_OPENSERSIPCONTACTINDEX       1
00193 #define COLUMN_OPENSERSIPCONTACTDISPLAYNAME 2
00194 #define COLUMN_OPENSERSIPCONTACTURI         3
00195 #define COLUMN_OPENSERSIPCONTACTLASTUPDATED 4
00196 #define COLUMN_OPENSERSIPCONTACTEXPIRY      5
00197 #define COLUMN_OPENSERSIPCONTACTPREFERENCE  6
00198 
00199 #define openserSIPContactTable_COL_MIN 2
00200 #define openserSIPContactTable_COL_MAX 6
00201 
00202 #ifdef __cplusplus
00203 }
00204 #endif
00205 
00206 #endif