📄 digitcollector.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 DigitCollector_cxx_Version = "$Id: DigitCollector.cxx,v 1.27 2002/11/19 20:32:52 sprajpat Exp $";#include "global.h"#include <cassert>#include "DigitCollector.hxx"#include "SystemInfo.hxx"#include <Data.hxx>#include <cpLog.h>#include "UaDigitTimerEvent.hxx"#include "UaDevice.hxx"#include "UaConfiguration.hxx"using namespace Vocal;// TODO - replace tick count with time class and delay correct seconds// TODO - implement dial string matchingconst unsigned int DigitCollector::MAX_PREV_IN_URLS_SIZE = 10;DigitCollector::DigitCollector( Sptr < Fifo < Sptr < SipProxyEvent > > > cpq ){ UaConfiguration* configuration = UaConfiguration::instance(); string proxyServer = configuration->getProxyServer(); string::size_type colonPos = proxyServer.find( ":" ); destHostIpAddr = proxyServer.substr( 0, colonPos ); if ( colonPos < string::npos ) { sipPortNum = proxyServer.substr( proxyServer.rfind( ":" ) + 1 ); } else { sipPortNum = "5060"; } dial = ""; isNewDigit = false; dialMethod = INCOMPLETE_DIAL; myDialedUrl = ""; //initiate the inter-digit timeout timer interDigitTimeout = Sptr < DigitTimeout > (new DigitTimeout( cpq )); assert( interDigitTimeout != 0 ); interDigitTimeout->setInitTimeout( configuration->getInitialDigitTimeout() ); interDigitTimeout->setInterDigitTimeout( configuration->getInterDigitTimeout() ); DialingPlanListType dp = configuration->getDialPlans(); DialingPlanListType::iterator dpIter = dp.begin(); while ( dpIter != dp.end() ) { DialingPlan* dialPattern = new DialingPlan( *(*dpIter) ); addDialPlan( dialPattern ); dpIter++; } SpeedDialMapType sd = configuration->getSpeedDials(); SpeedDialMapType::iterator sdIter = sd.begin(); while ( sdIter != sd.end() ) { addSpeedDial( sdIter->first, sdIter->second ); sdIter++; } callProcessingQueue = cpq;}voidDigitCollector::reset(){ dial = ""; isNewDigit = false; dialMethod = INCOMPLETE_DIAL; myDialedUrl = ""; //reset the inter-digit timeout timer interDigitTimeout->timerReset();}voidDigitCollector::clear(){ dial = ""; isNewDigit = false; dialMethod = INCOMPLETE_DIAL; myDialedUrl = ""; //reset the inter-digit timeout timer interDigitTimeout->timerCancel();}voidDigitCollector::addDigit( char digit ){ //cancel the previous timeout timer interDigitTimeout->timerCancel(); dial += digit; isNewDigit = true; //start the inter-digit timeout timer for the next digit interDigitTimeout->timerStart(); // Check if dialing complete DialMethodsType stage = findDialPlan(); if ( !( stage == INCOMPLETE_DIAL || stage == WRONG_DIAL ) ) { // Notify call processing Sptr < UaDigitTimerEvent > timerEvent = new UaDigitTimerEvent( callProcessingQueue ); assert( timerEvent != 0 ); timerEvent->callId = UaDevice::instance()->getCallId(); callProcessingQueue->add( timerEvent ); }}voidDigitCollector::setDialedUrl(const string& url){ dialMethod = URL_DIAL; myDialedUrl = url; // Notify call processing Sptr < UaDigitTimerEvent > timerEvent = new UaDigitTimerEvent( callProcessingQueue ); assert( timerEvent != 0 ); timerEvent->callId = UaDevice::instance()->getCallId(); callProcessingQueue->add( timerEvent );}boolDigitCollector::isValidDial(){// if ( !isNewDigit ) return false; dialMethod = findDialPlan();// isNewDigit = false; if (INCOMPLETE_DIAL == dialMethod || WRONG_DIAL == dialMethod) { return false; } else { interDigitTimeout->timerCancel(); return true; }}boolDigitCollector::isDialTimeout(){ return interDigitTimeout->isInterDigitTimeout();}stringDigitCollector::getDial(){ return isDialTimeout() ? dial + string("T") : dial;}stringDigitCollector::getUrl(){ string url; switch ( dialMethod ) { case SPEED_DIAL: url = getUrlFromSpeedDial(); break; case SPECIAL_KEY_DIAL: url = getUrlFromSpecKeyDial(); break; case NORMAL_DIAL: url = getUrlFromPhoneNumDial(); break;// case INTERNAL_IP_DIAL:// url = getUrlFromIpAddr();// break; case CALL_RETURN_DIAL: url = getCallReturnUrl(); break; case INCOMPLETE_DIAL: case WRONG_DIAL: url = ""; break; case URL_DIAL: url = myDialedUrl; break; default: url = ""; break; } return url;}stringDigitCollector::getUrlFromPhoneNumDial(){ //get the current 3 digits of the IP address. string url = "sip:"; url += dial; url += string("@"); url += destHostIpAddr; if (sipPortNum == "" ) { url += ":5060"; } else { url += string(":"); url += sipPortNum; } cpLog( LOG_DEBUG , "DigitCollector url is returning %s", url.c_str()); dialedType = dial_phone; return url;}stringDigitCollector::getUrlFromSpecKeyDial(){ string dialStr = dial; if ( !dialStr.empty() ) dialStr.resize( dialStr.length() - 1 ); string url = "sip:"; url += dialStr; url += string("@"); url += destHostIpAddr; if (sipPortNum == "" ) { url += ":5060"; } else { url += string(":"); url += sipPortNum; } cpLog( LOG_DEBUG , "DigitCollector url is returning %s", url.c_str()); dialedType = dial_phone; return url;}stringDigitCollector::getUrlFromSpeedDial(){ regex_t re; //get the current 3 digits of the IP address. string phoneNum = ""; // String retrieved from speedDialMap string url = ""; // url that we return string userName = ""; string password = ""; string destination = ""; string sipPort = ""; SpeedDialMapType::iterator speedDialIt = speedDialMap.find(dial); if ( speedDialIt == speedDialMap.end() ) { cpLog( LOG_ERR, "Speed_Dial: %s not found.", dial.c_str() ); phoneNum = "0000000"; } else { phoneNum = speedDialIt->second; } if ( 0 == regcomp(&re, "[^0-9]", REG_EXTENDED) ) { string::size_type colonPos1, colonPos2, atPos;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -