📄 sipagent.cxx
字号:
/* ==================================================================== * 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/>. * */static const char* const SipAgent_cxx_Version = "$Id: SipAgent.cxx,v 1.41 2002/11/09 02:15:49 derekm Exp $";#include <iostream>#include "Lock.hxx"#include "Mutex.hxx"#include "SipAgent.hxx"#include "SipSnmpDetails.hxx"#include "cpLog.h"#include "SnmpCommon.h"#include "symbols.hxx"using namespace Vocal;using namespace Vocal::Threads;SipAgent::Table SipAgent::SipCountersTable;voidSipAgent::setName(const Data& data){ name = data;}SipAgent::SipAgent( const Data& inname) : AgentApi(SERVER_SipStack, inname.convertString()){ name = inname; run(); unsigned long zerop, ulongp; for (int i = agentApiMibVarFirstEntry; i < agentApiMibVarLastEntry; i++) { zerop = 0; ulongp = i; SipCountersTable.insert(pair < unsigned long, unsigned long > (ulongp, zerop)); } if ( name.length() == 0) { snmpdetails = 0; cpLog (LOG_ERR, "Application Name needed" ); } else { snmpdetails = new SipSnmpDetails(this, name); }}SipAgent::~SipAgent(){ for (int i = agentApiMibVarFirstEntry; i < agentApiMibVarLastEntry; i++) { SipCountersTable.erase(i); } shutdown(); join();}voReturnStatusSipAgent::updateSipCounter(AgentApiMibVarT inCounterName){ cpLog(LOG_DEBUG_STACK, "updateSipCounter %d", inCounterName); TableIter aCounter; Lock lockHelper(itsMutex); aCounter = SipCountersTable.find((int) inCounterName); if ( aCounter != SipCountersTable.end() ) { aCounter->second ++; cpLog(LOG_DEBUG_STACK, "new value = %d", aCounter->second); return voSuccess; } else { cpLog (LOG_DEBUG_STACK, "updatesipcounter failed to find counter"); return voUnknown; }}intSipAgent::getSipCounter(AgentApiMibVarT counter){ int number = -1; TableIter aCounter; Lock lockHelper(itsMutex); aCounter = SipCountersTable.find((int) counter); if ( aCounter != SipCountersTable.end() ) { number = aCounter->second ; cpLog(LOG_DEBUG_STACK, "returning value = %d", aCounter->second); } else { cpLog (LOG_DEBUG_STACK, "getSipCounter failed to find counter"); } return number;}voReturnStatusSipAgent::processMessage(ipcMessage *inmessage, NetworkAddress *sender){ TableIter aCounter; int classvalue = 0; switch (inmessage->action) { case Get : { if (inmessage->mibVariable >= sipSummaryInRequests && inmessage->mibVariable <= sipNumUnsupportedUris) { aCounter = SipCountersTable.find(inmessage->mibVariable); if (aCounter != SipCountersTable.end() ) { return sendResponse(aCounter->second, sender); } else { return sendResponse(VO_NA_INT, sender); } } else { switch (inmessage->mibVariable) { case sipProtocolVersion : { snmpData snmdata = getstackData(sipProtocolVersion); string s = snmdata.getData().convertString(); return sendResponse( s , sender); } break; case sipServiceOperStatus : { snmpData snmdata = getstackData(sipServiceOperStatus); return sendResponse( static_cast<int>(snmdata.getData().convertInt()), sender); } break; case sipServiceAdminStatus : { snmpData snmdata = getstackData(sipServiceAdminStatus); return sendResponse( VO_NA_INT, sender); } break; case sipServiceStartTime : { snmpData snmdata = getstackData(sipServiceStartTime); return sendResponse( (unsigned long)snmdata.getData().convertInt() , sender); } break; case sipServiceLastChange : { snmpData snmdata = getstackData(sipServiceLastChange); return sendResponse((unsigned long)snmdata.getData().convertInt() , sender); } break; case sipTransport : { return sendResponse(VO_NA_INT , sender); } break; case sipUriSupported : { return sendResponse(VO_NA_STRING , sender); } break; case sipFtrSupported : { return sendResponse(VO_NA_STRING , sender); } break; case sipOrganization : { return sendResponse(VO_NA_STRING , sender); } break; case sipMaxTransactions : { snmpData snmdata = getstackData(sipMaxTransactions); return sendResponse((unsigned long)snmdata.getData().convertInt() , sender); } break; case sipRequestDfltExpires : { snmpData snmdata = getstackData(sipRequestDfltExpires); return sendResponse((unsigned long)snmdata.getData().convertInt() , sender); } break; case sipHideOperation : { return sendResponse(VO_NA_INT , sender); } break; case sipUserLocationServerAddr : { return sendResponse(VO_NA_STRING , sender); } break; //handles the high level stack data. case sipStatsInfoClassIns : { classvalue += getSipCounter( sipStatsInfoIns); classvalue += getSipCounter( sipStatsInfoTryingIns); classvalue += getSipCounter( sipStatsInfoRingingIns); classvalue += getSipCounter( sipStatsInfoForwardedIns); classvalue += getSipCounter( sipStatsInfoQueuedIns); classvalue += getSipCounter( sipStatsInfoSessionProgIns); return sendResponse(classvalue , sender); } break; case sipStatsInfoClassOuts : { classvalue += getSipCounter( sipStatsInfoOuts); classvalue += getSipCounter( sipStatsInfoTryingOuts); classvalue += getSipCounter( sipStatsInfoRingingOuts); classvalue += getSipCounter( sipStatsInfoForwardedOuts); classvalue += getSipCounter( sipStatsInfoQueuedOuts); classvalue += getSipCounter( sipStatsInfoSessionProgOuts); return sendResponse(classvalue , sender); } break; case sipStatsSuccessClassIns : { classvalue += getSipCounter( sipStatsSuccessOkIns); return sendResponse(classvalue , sender); } break; case sipStatsSuccessClassOuts : { classvalue += getSipCounter( sipStatsSuccessOkOuts); return sendResponse(classvalue , sender); } break; case sipStatsRedirClassIns : { classvalue += getSipCounter( sipStatsRedirMultipleChoiceIns); classvalue += getSipCounter( sipStatsRedirMovedPermIns); classvalue += getSipCounter( sipStatsRedirMovedTempIns); classvalue += getSipCounter( sipStatsRedirSeeOtherIns); classvalue += getSipCounter( sipStatsRedirUseProxyIns); classvalue += getSipCounter( sipStatsRedirAltServiceIns); return sendResponse(classvalue , sender); } break; case sipStatsRedirClassOuts : { classvalue += getSipCounter( sipStatsRedirMultipleChoiceOuts); classvalue += getSipCounter( sipStatsRedirMovedPermOuts); classvalue += getSipCounter( sipStatsRedirMovedTempOuts); classvalue += getSipCounter( sipStatsRedirSeeOtherOuts); classvalue += getSipCounter( sipStatsRedirUseProxyOuts); classvalue += getSipCounter( sipStatsRedirAltServiceOuts); return sendResponse(classvalue , sender); } break; case sipStatsReqFailClassIns : { classvalue += getSipCounter( sipStatsClientBadRequestIns); classvalue += getSipCounter( sipStatsClientUnauthorizedIns); classvalue += getSipCounter( sipStatsClientPaymentReqdIns); classvalue += getSipCounter( sipStatsClientForbiddenIns); classvalue += getSipCounter( sipStatsClientNotFoundIns); classvalue += getSipCounter( sipStatsClientMethNotAllowedIns); classvalue += getSipCounter( sipStatsClientNotAcceptableIns); classvalue += getSipCounter( sipStatsClientProxyAuthReqdIns); classvalue += getSipCounter( sipStatsClientReqTimeoutIns); classvalue += getSipCounter( sipStatsClientConflictIns); classvalue += getSipCounter( sipStatsClientGoneIns); classvalue += getSipCounter( sipStatsClientLengthRequiredIns); classvalue += getSipCounter( sipStatsClientReqEntTooLargeIns); classvalue += getSipCounter(sipStatsClientReqURITooLargeIns); classvalue += getSipCounter(sipStatsClientNoSupMediaTypeIns); classvalue += getSipCounter(sipStatsClientBadExtensionIns); classvalue += getSipCounter(sipStatsClientTempNotAvailIns); classvalue += getSipCounter(sipStatsClientCallLegNoExistIns); classvalue += getSipCounter( sipStatsClientLoopDetectedIns); classvalue += getSipCounter( sipStatsClientTooManyHopsIns); classvalue += getSipCounter( sipStatsClientAddrIncompleteIns); classvalue += getSipCounter( sipStatsClientAmbiguousIns); classvalue += getSipCounter( sipStatsClientBusyHereIns ); return sendResponse(classvalue , sender); } break; case sipStatsReqFailClassOuts : { classvalue += getSipCounter( sipStatsClientBadRequestOuts); classvalue += getSipCounter(sipStatsClientUnauthorizedOuts); classvalue += getSipCounter(sipStatsClientPaymentReqdOuts); classvalue += getSipCounter(sipStatsClientForbiddenOuts); classvalue += getSipCounter(sipStatsClientNotFoundOuts); classvalue += getSipCounter( sipStatsClientMethNotAllowedOuts); classvalue += getSipCounter(sipStatsClientNotAcceptableOuts); classvalue += getSipCounter( sipStatsClientProxyAuthReqdOuts); classvalue += getSipCounter(sipStatsClientReqTimeoutOuts); classvalue += getSipCounter(sipStatsClientConflictOuts); classvalue += getSipCounter(sipStatsClientGoneOuts); classvalue += getSipCounter(sipStatsClientLengthRequiredOuts); classvalue += getSipCounter(sipStatsClientReqEntTooLargeOuts); classvalue += getSipCounter(sipStatsClientReqURITooLargeOuts); classvalue += getSipCounter(sipStatsClientNoSupMediaTypeOuts); classvalue += getSipCounter(sipStatsClientBadExtensionOuts); classvalue += getSipCounter(sipStatsClientTempNotAvailOuts); classvalue += getSipCounter(sipStatsClientCallLegNoExistOuts); classvalue += getSipCounter(sipStatsClientLoopDetectedOuts); classvalue += getSipCounter(sipStatsClientTooManyHopsOuts); classvalue += getSipCounter(sipStatsClientAddrIncompleteOuts); classvalue += getSipCounter( sipStatsClientAmbiguousOuts); classvalue += getSipCounter(sipStatsClientBusyHereOuts); return sendResponse(classvalue , sender); } break; case sipStatsServerFailClassIns : { classvalue += getSipCounter(sipStatsServerIntErrorIns); classvalue += getSipCounter(sipStatsServerNotImplementedIns); classvalue += getSipCounter(sipStatsServerBadGatewayIns); classvalue += getSipCounter(sipStatsServerServiceUnavailIns); classvalue += getSipCounter( sipStatsServerGatewayTimeoutIns); classvalue += getSipCounter(sipStatsServerBadSipVersionIns); return sendResponse(classvalue, sender); } break; case sipStatsServerFailClassOuts : { classvalue += getSipCounter(sipStatsServerIntErrorOuts); classvalue += getSipCounter(sipStatsServerNotImplementedOuts); classvalue += getSipCounter(sipStatsServerBadGatewayOuts); classvalue += getSipCounter(sipStatsServerServiceUnavailOuts); classvalue += getSipCounter( sipStatsServerGatewayTimeoutOuts); classvalue += getSipCounter(sipStatsServerBadSipVersionOuts); return sendResponse(classvalue, sender); } break; case sipStatsGlobalFailClassIns : { classvalue += getSipCounter(sipStatsGlobalBusyEverywhereIns); classvalue += getSipCounter( sipStatsGlobalDeclineIns); classvalue += getSipCounter( sipStatsGlobalNotAnywhereIns); classvalue += getSipCounter(sipStatsGlobalNotAcceptableIns); return sendResponse(classvalue , sender); } break; case sipStatsGlobalFailClassOuts : { classvalue += getSipCounter(sipStatsGlobalBusyEverywhereOuts); classvalue += getSipCounter( sipStatsGlobalDeclineOuts); classvalue += getSipCounter( sipStatsGlobalNotAnywhereOuts); classvalue += getSipCounter(sipStatsGlobalNotAcceptableOuts); return sendResponse(classvalue , sender); } break; case DebugLevel : { return sendResponse(cpLogGetPriority() , sender); } break; default : { return voUnknown; } break; } } } case Set : { switch (inmessage->mibVariable) { case DebugLevel : {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -