⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sipcommonmib.c

📁 非常不错的网管开发包
💻 C
📖 第 1 页 / 共 3 页
字号:
/* ==================================================================== * The Vovida Software License, Version 1.0  *  * Copyright (c) 2000 Vovida Networks, Inc.  All rights reserved. *  * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: *  * 1. Redistributions of source code must retain the above copyright *    notice, this list of conditions and the following disclaimer. *  * 2. Redistributions in binary form must reproduce the above copyright *    notice, this list of conditions and the following disclaimer in *    the documentation and/or other materials provided with the *    distribution. *  * 3. The names "VOCAL", "Vovida Open Communication Application Library", *    and "Vovida Open Communication Application Library (VOCAL)" must *    not be used to endorse or promote products derived from this *    software without prior written permission. For written *    permission, please contact vocal\@vovida.org. * * 4. Products derived from this software may not be called "VOCAL", nor *    may "VOCAL" appear in their name, without prior written *    permission of Vovida Networks, Inc. *  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * DAMAGE. *  * ==================================================================== *  * This software consists of voluntary contributions made by Vovida * Networks, Inc. and many individuals on behalf of Vovida Networks, * Inc.  For more information on Vovida Networks, Inc., please see * <http://www.vovida.org/>. * *//* This should always be included first before anything else */#include <config.h>/* minimal include directives */#include "mibincl.h"#include "util_funcs.h"#include <time.h>#include <AgentApi.hxx>#include "VovidaSnmpUtil.h"#include "sipCommonMIB.h"#include "TrapAgentC.hxx"#include "TrapAgent.hxx"#include "Common.h"#define TABLE_SIZE 1/*  * sipCommonMIB_variables_oid: *   this is the top level oid that we want to register under.  This *   is essentially a prefix, with the suffix appearing in the *   variable below. */oid sipCommonMIB_variables_oid[] = { 1,3,6,1,4,1,5738,3,1,2 };struct timeval sysStartTime;/*  * variable7 sipCommonMIB_variables: *   this variable defines function callbacks and type return information  *   for the sipCommonMIB mib section  */struct variable7 sipCommonMIB_variables[] = {/*  magic number        , variable type , ro/rw , callback fn  , L, oidsuffix */// i removed the #defines that were generated by mib2c and replaced them with the enum// defined in AgentApiMibVars.  This will allow the same number to be used throuh// the entire system including the network manager, snmpd, SipAgent  {sipProtocolVersion   , ASN_OCTET_STR , RONLY , var_sipCommonCfgTable, 4, { 1,1,1,1 } },  {sipServiceOperStatus , ASN_INTEGER   , RONLY , var_sipCommonCfgTable, 4, { 1,1,1,2 } },// todo:  {sipServiceAdminStatus , ASN_INTEGER   , RWRITE, var_sipCommonCfgTable, 4, { 1,1,1,3 } },  {sipServiceStartTime  , ASN_TIMETICKS , RONLY , var_sipCommonCfgTable, 4, { 1,1,1,4 } },  {sipServiceLastChange , ASN_TIMETICKS , RONLY , var_sipCommonCfgTable, 4, { 1,1,1,5 } },// todo:  { sipOrganization     , ASN_OCTET_STR , RWRITE, var_sipCommonCfgTable, 4, { 1,1,1,6 } },  {sipMaxTransactions   , ASN_GAUGE     , RONLY , var_sipCommonCfgTable, 4, { 1,1,1,7 } },// new this version  { SIPINVITETIMEOUT    , ASN_GAUGE     , RWRITE, var_sipCommonCfgTable, 4, { 1,1,1,8 } }, // todo:  { sipHideOperation    , ASN_INTEGER   , RWRITE, var_sipCommonCfgTable, 4, { 1,1,1,9 } },// todo:  {sipUserLocationServerAddr , ASN_OCTET_STR , RWRITE, var_sipCommonCfgTable, 4, { 1,1,1,10 } }, // new this version  { SIPCANUSECOMPACT    , ASN_INTEGER   , RONLY , var_sipCommonCfgTable, 4, { 1,1,1,11 } },  // new this version  { SIPREQUESTURIHOSTMATCHING, ASN_INTEGER   , RWRITE, var_sipCommonCfgTable, 4, { 1,1,1,12 } },// todo:  {sipTransport         , ASN_INTEGER   , RWRITE, var_sipPortTable, 4, { 1,2,1,2 } },// todo:  { sipPortStatus       , ASN_INTEGER   , RWRITE, var_sipPortTable, 4, { 1,2,1,3 } },// todo:  {sipUriSupported      , ASN_OCTET_STR , RONLY , var_sipUriSupportedTable, 4, { 1,3,1,2 } },// todo:  {sipFtrSupported      , ASN_OCTET_STR , RONLY , var_sipFtrSupportedTable, 4, { 1,4,1,2 } },  {sipSummaryInRequests , ASN_COUNTER   , RONLY , var_sipSummaryStatsTable, 5, { 2,1,1,1,1 } },  {sipSummaryOutRequests , ASN_COUNTER   , RONLY , var_sipSummaryStatsTable, 5, { 2,1,1,1,2 } },  {sipSummaryInResponses , ASN_COUNTER   , RONLY , var_sipSummaryStatsTable, 5, { 2,1,1,1,3 } },  {sipSummaryOutResponses, ASN_COUNTER   , RONLY , var_sipSummaryStatsTable, 5, { 2,1,1,1,4 } },  {sipSummaryTotalTransactions , ASN_COUNTER   , RONLY , var_sipSummaryStatsTable, 5, { 2,1,1,1,5 } },  { sipStatsInviteIns   , ASN_COUNTER   , RONLY , var_sipMethodStatsTable, 5, { 2,2,1,1,1 } },  { sipStatsInviteOuts  , ASN_COUNTER   , RONLY , var_sipMethodStatsTable, 5, { 2,2,1,1,2 } },  { sipStatsAckIns      , ASN_COUNTER   , RONLY , var_sipMethodStatsTable, 5, { 2,2,1,1,3 } },  {  sipStatsAckOuts    , ASN_COUNTER   , RONLY , var_sipMethodStatsTable, 5, { 2,2,1,1,4 } },  { sipStatsByeIns      , ASN_COUNTER   , RONLY , var_sipMethodStatsTable, 5, { 2,2,1,1,5 } },  {   sipStatsByeOuts   , ASN_COUNTER   , RONLY , var_sipMethodStatsTable, 5, { 2,2,1,1,6 } },  {sipStatsCancelIns    , ASN_COUNTER   , RONLY , var_sipMethodStatsTable, 5, { 2,2,1,1,7 } },  {sipStatsCancelOuts   , ASN_COUNTER   , RONLY , var_sipMethodStatsTable, 5, { 2,2,1,1,8 } },  {sipStatsOptionsIns   , ASN_COUNTER   , RONLY , var_sipMethodStatsTable, 5, { 2,2,1,1,9 } },  {sipStatsOptionsOuts  , ASN_COUNTER   , RONLY , var_sipMethodStatsTable, 5, { 2,2,1,1,10 } },  {sipStatsRegisterIns  , ASN_COUNTER   , RONLY , var_sipMethodStatsTable, 5, { 2,2,1,1,11 } },  {sipStatsRegisterOuts , ASN_COUNTER   , RONLY , var_sipMethodStatsTable, 5, { 2,2,1,1,12 } },// todo:  // new this version  { SIPSTATSEXTMETHODNAME, ASN_OCTET_STR , RWRITE, var_sipStatsExtMethodTable, 5, { 2,2,2,1,2 } }, // new this version  { SIPSTATSEXTMETHODINS, ASN_COUNTER   , RONLY , var_sipStatsExtMethodTable, 5, { 2,2,2,1,3 } }, // new this version  { SIPSTATSEXTMETHODOUTS, ASN_COUNTER   , RONLY , var_sipStatsExtMethodTable, 5, { 2,2,2,1,4 } }, // new this version  { SIPSTATSEXTMETHODSTATUS, ASN_INTEGER   , RWRITE, var_sipStatsExtMethodTable, 5, { 2,2,2,1,5 } },   { sipStatsInfoClassIns, ASN_COUNTER   , RONLY , var_sipStatusCodesTable, 5, { 2,3,1,1,1 } }, // sum of 1xx msgs  { sipStatsInfoClassOuts, ASN_COUNTER   , RONLY , var_sipStatusCodesTable, 5, { 2,3,1,1,2 } }, // sum of 1xx msgs  { sipStatsSuccessClassIns, ASN_COUNTER   , RONLY , var_sipStatusCodesTable, 5, { 2,3,1,1,3 } }, // sum of 2xx msgs  { sipStatsSuccessClassOuts, ASN_COUNTER   , RONLY , var_sipStatusCodesTable, 5, { 2,3,1,1,4 } }, // sum of 2xx msgs  { sipStatsRedirClassIns, ASN_COUNTER   , RONLY , var_sipStatusCodesTable, 5, { 2,3,1,1,5 } }, // sum of 3xx msgs  { sipStatsRedirClassOuts, ASN_COUNTER   , RONLY , var_sipStatusCodesTable, 5, { 2,3,1,1,6 } }, // sum of 3xx msgs  { sipStatsReqFailClassIns, ASN_COUNTER   , RONLY , var_sipStatusCodesTable, 5, { 2,3,1,1,7 } }, // sum of 4xx msgs  { sipStatsReqFailClassOuts, ASN_COUNTER   , RONLY , var_sipStatusCodesTable, 5, { 2,3,1,1,8 } }, // sum of 4xx msgs  { sipStatsServerFailClassIns, ASN_COUNTER   , RONLY , var_sipStatusCodesTable, 5, { 2,3,1,1,9 } }, // sum of 5xx msgs  { sipStatsServerFailClassOuts, ASN_COUNTER   , RONLY , var_sipStatusCodesTable, 5, { 2,3,1,1,10 } }, // sum of 5xx msgs  { sipStatsGlobalFailClassIns, ASN_COUNTER   , RONLY , var_sipStatusCodesTable, 5, { 2,3,1,1,11 } }, // sum of 6xx msgs  { sipStatsGlobalFailClassOuts, ASN_COUNTER   , RONLY , var_sipStatusCodesTable, 5, { 2,3,1,1,12 } }, // sum of 6xx msgs// todo:  // new this version  { SIPCOMMONSTATUSCODEINS, ASN_COUNTER   , RONLY , var_sipCommonStatusCodeTable, 5, { 2,3,2,1,2 } },// new this version  { SIPCOMMONSTATUSCODEOUTS, ASN_COUNTER   , RONLY , var_sipCommonStatusCodeTable, 5, { 2,3,2,1,3 } },// new this version  { SIPCOMMONSTATUSCODESENDNOTIF, ASN_INTEGER   , RWRITE, var_sipCommonStatusCodeTable, 5, { 2,3,2,1,4 } },// new this version  { SIPCOMMONSTATUSCODESTATUS, ASN_INTEGER   , RWRITE, var_sipCommonStatusCodeTable, 5, { 2,3,2,1,5 } },//todo:  {sipCurrentTransactions , ASN_GAUGE     , RONLY , var_sipCurrentTransTable, 5, { 2,4,1,1,1 } },//todo:  {sipTransTo           , ASN_OCTET_STR , RONLY , var_sipTransactionTable, 5, { 2,4,2,1,2 } },//todo:  {sipTransFrom         , ASN_OCTET_STR , RONLY , var_sipTransactionTable, 5, { 2,4,2,1,3 } },//todo:  {sipTransCallId       , ASN_OCTET_STR , RONLY , var_sipTransactionTable, 5, { 2,4,2,1,4 } },//todo:  {sipTransCSeq         , ASN_GAUGE     , RONLY , var_sipTransactionTable, 5, { 2,4,2,1,5 } },//todo:  {sipTransState        , ASN_INTEGER   , RONLY , var_sipTransactionTable, 5, { 2,4,2,1,6 } },//todo:  {sipTransOutstandingBranches , ASN_INTEGER   , RONLY , var_sipTransactionTable, 5, { 2,4,2,1,7 } },//todo:  {sipTransExpiry       , ASN_OCTET_STR , RONLY , var_sipTransactionTable, 5, { 2,4,2,1,8 } },//todo:  {sipTransCallingPartyContentType , ASN_OCTET_STR , RONLY , var_sipTransactionTable, 5, { 2,4,2,1,9 } },//todo:  {sipTransCalledPartyContentType , ASN_OCTET_STR , RONLY , var_sipTransactionTable, 5, { 2,4,2,1,10 } },//todo:  {sipNumUnsupportedUris , ASN_COUNTER   , RONLY , var_sipOtherStatsTable, 4, { 2,5,1,5 } },};/*    (L = length of the oidsuffix) *//* * init_sipCommonMIB(): *   Initialization routine.  This is called when the agent starts up. *   At a minimum, registration of your variables should take place here. */void init_sipCommonMIB(void) {    struct timezone tz;  /* register ourselves with the agent to handle our mib tree */  REGISTER_MIB("sipCommonMIB", sipCommonMIB_variables, variable7,               sipCommonMIB_variables_oid);    timerclear(&sysStartTime);    tz.tz_minuteswest = 0;    tz.tz_dsttime = 0;    timerclear(&sysStartTime);    if (gettimeofday(&sysStartTime,&tz) > 0 ) {	perror("sipCommonMIB:gettimeofday failed:");	timerclear(&sysStartTime);    }  /* place any other initialization junk you need here */}// this function will set the counterVal to the correct// value and return proper error status based on the// input mib object reqObject (AgentApiMibT)enum voReturnStatusrequestSipCounter(int reqObject, ulong *counterVal, int port){    ipcMessage message;    enum voReturnStatus retVal;        retVal = ipcRequest((actionT)Get,		  (AgentApiMibVarT) reqObject,		  port,		  &message);    if (retVal == voSuccess) {	memcpy(counterVal,  message.parm2, sizeof (ulong));    } else {	*counterVal = (ulong) VO_NA_INT;    }    return retVal;}// this function will return the value of a string// IN reqObject,  the object to get defined in AgentApiMibT// IN/OUT outBuff  the buffer to write the string into.// IN  the size of the buffer in bytesenum voReturnStatusrequestSipString(int reqObject, char *outBuff, int strLen, int port){    ipcMessage message;    enum voReturnStatus retVal;        memset(outBuff, 0, strLen/4);    retVal = ipcRequest((actionT)Get,		  (AgentApiMibVarT) reqObject,		  port,		  &message);    if (retVal == voSuccess) {	strncpy(outBuff, message.parm2, min(strLen, PARM2SIZE));    } else {	strncpy(outBuff, VO_NA_STRING, min(strLen, strlen(VO_NA_STRING)));    }    return retVal;}/* * var_sipCommonMIB(): *   This function is called every time the agent gets a request for *   a scalar variable that might be found within your mib section *   registered above.  It is up to you to do the right thing and *   return the correct value. *     You should also correct the value of "var_len" if necessary. * *   Please see the documentation for more information about writing *   module extensions, and check out the examples in the examples *   and mibII directories. */unsigned char *var_sipCommonMIB(struct variable *vp,                 oid     *name,                 size_t  *length,                 int     exact,                 size_t  *var_len,                 WriteMethod **write_method){  /* variables we may use later */  static long long_ret;  static unsigned char string[SPRINT_MAX_LEN];  static oid objid[MAX_OID_LEN];  static struct counter64 c64;  if (header_generic(vp,name,length,exact,var_len,write_method)                                  == MATCH_FAILED )    return 0;  /*    * this is where we do the value assignments for the mib results.   */  switch(vp->magic) {    default:      ERROR_MSG("");  }  return 0;}/********************************************************/ /*   begin the vocal tables here                        *//********************************************************/// returns 0 on match_failure// returns index on success// vp is the oid not including index we should be looking for// name is the oid requested by the user, or what we returned from the //    previous getnext request// length is the number of "digits" (snmp gurus are going to kill)  in the oid// exact = true for snmpGet, false for snmpGetnext// **write_method isn't used since these are read only// maxOidLen is the length of a full oid in this specific tableulongheader_sip_table(struct variable *vp, 		 oid *name, 		 size_t *length,		 int exact, 		 size_t *var_len,		 WriteMethod **write_method,		 int maxOidLen){    oid newname[MAX_OID_LEN];    int result, getIndex = 0, nextIndex = 0;    int indexPosition = maxOidLen - 1;    applInfoT appl;        if (exact) {	if ((*length == indexPosition + 1) && 	    (snmp_oid_compare(vp->name, indexPosition - 1, name, *length) <= 0 )) {	    appl = TrapAgent_GetApplication((void *)trapAgent, name[indexPosition]);	    if (appl.index != 0 && appl.type == SERVER_SipStack) {		*var_len = sizeof(long);	/* default to 'long' results */		return appl.index;	    }	}	return MATCH_FAILED;    }        memcpy( (char *)newname,(char *)vp->name, (int)vp->namelen * sizeof(oid));    if (*length > indexPosition) // already within the table	result = snmp_oid_compare(name,  *length - 1, newname, (int)vp->namelen);    else // before/after the table	result = snmp_oid_compare(name,  *length, newname, (int)vp->namelen - 1);	    if (result > 0) // past end of table	return MATCH_FAILED;    // first entry into table || first of new oid    if (result < 0) {	getIndex = 0;    } else {	getIndex = name[indexPosition];    }    nextIndex = TrapAgent_GetNextIndex((void *)trapAgent, getIndex, SERVER_SipStack);// The index is the last of this row.  Go onto next row    if( nextIndex == 0) {	return MATCH_FAILED;    }     memcpy( (char *)name,(char *)newname, ((int)vp->namelen) * sizeof(oid));    *length = vp->namelen + 1;    name[indexPosition] = nextIndex;    *write_method = 0;    *var_len = sizeof(long);	/* default to 'long' results */    return nextIndex;}unsigned char *var_sipCommonCfgTable (struct variable *vp,    	    oid     *name,    	    size_t  *length,    	    int     exact,    	    size_t  *var_len,    	    WriteMethod **write_method){  /* variables we may use later */  static long long_ret;  static unsigned char string[SPRINT_MAX_LEN];  static oid objid[MAX_OID_LEN];  static struct counter64 c64;  int index, sipPort;  index = header_sip_table(vp,name,length,exact,var_len,write_method, 15);  if (index == MATCH_FAILED )    return 0;  sipPort = TrapAgent_GetStackPortFromIndex((void *)trapAgent, index);  if (sipPort == 0)      return 0;  switch(vp->magic) {      case sipProtocolVersion   :	  if (requestSipString(vp->magic, string, SPRINT_MAX_LEN, sipPort  ) != voSuccess) {	      return 0;	  }	  *var_len = strlen(string);	  return (unsigned char *) string;      case sipServiceStartTime  :      case sipServiceLastChange :	  if (requestSipCounter(vp->magic, &long_ret, sipPort) != voSuccess) {	      return 0;	  }	  if (long_ret > sysStartTime.tv_sec) {	      long_ret = long_ret - sysStartTime.tv_sec;	  } else {	      long_ret = 0;	  }	  return (unsigned char *) &long_ret;      case sipServiceOperStatus :      case sipMaxTransactions   :	  if (requestSipCounter(vp->magic, &long_ret, sipPort) != voSuccess) {	      return 0;	  }	  return (unsigned char *) &long_ret;	  // todo: the following are not yet implemented	  // because they are read/write      case sipServiceAdminStatus :      case  sipOrganization     :      case  sipHideOperation    :      case sipUserLocationServerAddr :	  return 0;    default:      ERROR_MSG(" Invalid request in sipCommonCfgTable");  }  return 0;}unsigned char *var_sipPortTable (struct variable *vp,    	    oid     *name,    	    size_t  *length,    	    int     exact,    	    size_t  *var_len,    	    WriteMethod **write_method){  /* variables we may use later */  static long long_ret;  static unsigned char string[SPRINT_MAX_LEN];  static oid objid[MAX_OID_LEN];  static struct counter64 c64;  int index, sipPort;  index = header_sip_table(vp,name,length,exact,var_len,write_method, 15);  if (index == MATCH_FAILED )    return 0;  sipPort = TrapAgent_GetStackPortFromIndex((void *)trapAgent, index);  if (sipPort == 0)      return 0;  switch(vp->magic) {	  // todo: the following are not yet implemented	  // because they are read/write      case sipTransport:      case sipPortStatus:	  return 0;    default:      ERROR_MSG("Invalid request in sipPortTable");  }  return 0;}unsigned char *var_sipUriSupportedTable (struct variable *vp,    	    oid     *name,    	    size_t  *length,    	    int     exact,    	    size_t  *var_len,    	    WriteMethod **write_method){  /* variables we may use later */  static long long_ret;  static unsigned char string[SPRINT_MAX_LEN];  static oid objid[MAX_OID_LEN];  static struct counter64 c64;  int index, sipPort;  index = header_sip_table(vp,name,length,exact,var_len,write_method, 16);  if (index == MATCH_FAILED )    return 0;  sipPort = TrapAgent_GetStackPortFromIndex((void *)trapAgent, index);  if (sipPort == 0)      return 0;  // todo:  This is a 2 index table.  We will deal with it later.  return 0;}unsigned char *var_sipFtrSupportedTable (struct variable *vp,    	    oid     *name,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -