snmpSIPRegUserTable.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 originally auto-generated by mib2c using
00032  * mib2c.array-user.conf
00033  *
00034  * This file defines the prototypes that implement the openserSIPRegUserTable.
00035  * For a full description of the table, please see the OPENSER-SIP-SERVER-MIB.
00036  *
00037  * Understanding this code will be much simpler with the following information:
00038  *
00039  * 1) All rows are indexed by an integer user index.  This is different from the
00040  *    usrloc module, which indexes by strings.  This less natural indexing
00041  *    scheme was required due to SNMP String index limitations.  (for example,
00042  *    SNMP has maximum index lengths.)
00043  *
00044  * 2) We need a quick way of mapping usrloc indices to our integer indices.  For
00045  *    this reason a string indexed Hash Table was created, with each entry mapping
00046  *    to an integer user index. 
00047  *
00048  *    This hash table is used by the openserSIPContactTable (the hash table also
00049  *    maps a user to its contacts), as well as the openserSIPRegUserLookupTable.
00050  *    The hash table is also used for quick lookups when a user expires. (i.e, it
00051  *    gives us a more direct reference, instead of having to search the whole
00052  *    table).
00053  *
00054  * 3) We are informed about new/expired users via a callback mechanism from the
00055  *    usrloc module.  Because of NetSNMP inefficiencies, we had to abstract this
00056  *    process.  Specifically:
00057  *
00058  *    - It can take a long time for the NetSNMP code base to populate a table with
00059  *      a large number of records. 
00060  *
00061  *    - We rely on callbacks for updated user information. 
00062  *
00063  *    Clearly, using the SNMPStats module in this situation could lead to some
00064  *    big performance loses if we don't find another way to deal with this.  The
00065  *    solution was to use an interprocess communications buffer.  
00066  *
00067  *    Instead of adding the record directly to the table, the callback functions
00068  *    now adds either an add/delete command to the interprocessBuffer.  When an
00069  *    snmp request is recieved by the SNMPStats sub-process, it will consume
00070  *    this interprocess buffer, adding and deleting users.  When it is finished,
00071  *    it can service the SNMP request.  
00072  *
00073  *    This doesn't remove the NetSNMP inefficiency, but instead moves it to a
00074  *    non-critical path.  Such an approach allows SNMP support with almost no
00075  *    overhead to the rest of OpenSER.
00076  */
00077 
00078 #ifndef OPENSERSIPREGUSERTABLE_H
00079 #define OPENSERSIPREGUSERTABLE_H
00080 
00081 #ifdef __cplusplus
00082 extern "C" {
00083 #endif
00084 
00085 #include <net-snmp/net-snmp-config.h>
00086 #include <net-snmp/library/container.h>
00087 #include <net-snmp/agent/table_array.h>
00088 
00089 #include "../../config.h"
00090 
00091 /* Defines what each SNMP Row is made of. */
00092 typedef struct openserSIPRegUserTable_context_s 
00093 {
00094         netsnmp_index index; 
00095 
00096         unsigned long openserSIPUserIndex;
00097 
00098         /* There are potentially a lot of these of varying sizes, so lets
00099          * allocate only the amount of memory we need when the row is
00100          * created. */
00101         unsigned char *openserSIPUserUri;
00102 
00103         long openserSIPUserUri_len;
00104 
00105         unsigned long openserSIPUserAuthenticationFailures;
00106 
00107         void * data;
00108 
00109 } openserSIPRegUserTable_context;
00110 
00111 /*******************************/
00112 /*    Customized Prototypes    */
00113 /*******************************/
00114 
00115 /* If the usrloc module is loaded, this function will grab hooks into its
00116  * callback registration function, and add handleContactCallbacks() as the
00117  * callback for UL_CONTACT_INSERT and UL_CONTACT_EXPIRE. 
00118  *
00119  * Returns 1 on success, and zero otherwise */
00120 int registerForUSRLOCCallbacks(void);
00121 
00122 /*
00123  * Creates a row and inserts it.  
00124  *
00125  * Returns: The rows userIndex on success, and 0 otherwise. 
00126  */
00127 int  createRegUserRow(char *stringToRegister);
00128 
00129 
00130 /* Removes an SNMP row indexed by userIndex, and frees the string and index it
00131  * pointed to. */
00132 void  deleteRegUserRow(int userIndex);
00133 
00134 /* Creates an 'aor to userindex' record from stringName and userIndex, and pushes
00135  * them onto the hash table. */
00136 void  pushUserIntoHashTable(int userIndex, char *stringName);
00137 
00138 /*
00139  * Adds or updates a user:
00140  *
00141  *   - If a user with the name userName exists, its 'number of contacts' count
00142  *     will be incremented.  
00143  *   - If the user doesn't exist, the user will be added to the table, and its
00144  *     number of contacts' count set to 1. 
00145  */
00146 void updateUser(char *userName);
00147 
00148 /*******************************/
00149 /* Normal Function Prototypes  */
00150 /*******************************/
00151 
00152 /* Initializes the openserSIPRegUserTable module.  */
00153 void  init_openserSIPRegUserTable(void);
00154 
00155 /*
00156  * Initialize the openserSIPRegUserTable table by defining its contents and how
00157  * it's structured
00158  */
00159 void  initialize_table_openserSIPRegUserTable(void);
00160 
00161 const openserSIPRegUserTable_context * openserSIPRegUserTable_get_by_idx(
00162                 netsnmp_index *);
00163 
00164 const openserSIPRegUserTable_context * openserSIPRegUserTable_get_by_idx_rs(
00165                 netsnmp_index *, int row_status);
00166 
00167 /* Handles SNMP GET requests. */
00168 int   openserSIPRegUserTable_get_value(
00169                 netsnmp_request_info *, 
00170                 netsnmp_index *, 
00171                 netsnmp_table_request_info *);
00172 
00173 /* OID Declarations. */
00174 extern oid openserSIPRegUserTable_oid[];
00175 extern size_t openserSIPRegUserTable_oid_len;
00176 
00177 #define openserSIPRegUserTable_TABLE_OID OPENSER_OID,3,1,2,1,5,6
00178     
00179 /* Column Definitions */
00180 #define COLUMN_OPENSERSIPUSERINDEX                  1
00181 #define COLUMN_OPENSERSIPUSERURI                    2
00182 #define COLUMN_OPENSERSIPUSERAUTHENTICATIONFAILURES 3
00183 
00184 #define openserSIPRegUserTable_COL_MIN 2
00185 #define openserSIPRegUserTable_COL_MAX 3
00186 
00187 #ifdef __cplusplus
00188 }
00189 #endif
00190 
00191 #endif