📄 uafacade.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 UaFacade_cxx_Version = "$Id: UaFacade.cxx,v 1.22.2.11 2003/03/13 00:50:09 sprajpat Exp $";#include <sys/types.h>#include <sys/stat.h>#ifdef __FreeBSD__#include <sys/ioctl.h>#else#include <stropts.h>#endif#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <iostream.h>#include <unistd.h>#include "Fifo.h"#include "UaFacade.hxx"#include "SipThread.hxx"#include "SipTransceiver.hxx"#include "RegistrationManager.hxx"#include "UaConfiguration.hxx"#include "UaCommandLine.hxx"#include "UaCallControl.hxx"#include "UaCli.hxx"#include "Lock.hxx"//Libmedia#include "MediaController.hxx"//Devices#include "LinAudioDevice.hxx"#include "NullDevice.hxx"#include "FileMediaDevice.hxx"using Vocal::Threads::Lock;#ifdef USE_VM#include "VmcpDevice.hxx"#endif#ifdef USE_MPEGLIB#include "VideoDevice.hxx"#endif#define NamedDir "/tmp/sipset."#define NamedReadFile "GuiToUa."#define NamedWriteFile "UaToGui."using namespace Vocal;using namespace Vocal::UA;extern "C" { void UaFacade_destroy(void) { UaFacade::destroy(); }};UaFacade* UaFacade::myInstance = 0;voidUaFacade::destroy(){ myInstance->shutdown(); UaCallControl::destroy(); cpLog(LOG_DEBUG, "UaFacade::destroy()"); delete UaFacade::myInstance; UaFacade::myInstance = 0;}UaFacade&UaFacade::instance(){ assert(myInstance != 0); return *myInstance;}UaFacade&UaFacade::instance(const Data& applName, unsigned short defaultSipPort, bool filteron, bool nat){ assert(myInstance == 0); if(myInstance == 0) { myInstance = new UaFacade(applName,defaultSipPort,filteron,nat); } return *myInstance;}UaFacade::UaFacade( const Data& applName, unsigned short sipPort, bool filteron, bool nat){ myMode = CALL_MODE_UA; if(UaCommandLine::instance()->getIntOpt("annon")) { cpLog(LOG_INFO, "Agent running in announcement mode"); myMode = CALL_MODE_ANNON; } else if(UaCommandLine::instance()->getIntOpt("voicemail")) { cpLog(LOG_INFO, "Agent running in Voice Mail mode"); myMode = CALL_MODE_VMAIL; UaConfiguration::instance().setValue(RegisterOnTag, "false"); } //The object will try to bibd to port in range sipPort -> sipPort+10 as the //local sipPort, if it fails, it will send error application. cpLog(LOG_DEBUG, "UaFacade::UaFacade"); int defaultSipPort = sipPort; int startPort = defaultSipPort; bool guessSipPort = false; if(sipPort == 0) { //Guess the SIP port starting from 5060 till 5069 defaultSipPort = 5060; startPort = defaultSipPort; guessSipPort = true; } cpLog(LOG_DEBUG, "UaFacade::UaFacade using local port:%d", defaultSipPort); if (atexit(UaFacade_destroy) < 0) { cpLog(LOG_ALERT, "Failed to register with atexit()"); }; myInputEventFifo = new Fifo < Sptr < SipProxyEvent > >; assert( myInputEventFifo != 0 ); myWorkerThread = new UaWorkerThread(myInputEventFifo); //Setup the GUI event thread setUpGuiEventThread(); while(true) { try { mySipStack = new SipTransceiver(applName, defaultSipPort, nat); UaConfiguration::instance().setValue(LocalSipPortTag, Data(defaultSipPort).logData()); cpLog(LOG_INFO, "Listening on port %d for SIP", defaultSipPort); char buf[256]; sprintf(buf, "INFO Listening on port %d for SIP", defaultSipPort); postMsg(buf); assert( mySipStack != 0 ); SipTransceiver::reTransOn(); mySipThread = new SipThread(mySipStack, myInputEventFifo, false); //Start the registration manager to handle the registration myRegistrationManager = new RegistrationManager(mySipStack); NetworkAddress na(UaConfiguration::instance().getValue(ProxyServerTag)); Data NAT_HOST_FIX = UaConfiguration::instance().getValue(NATAddressIPTag); if(NAT_HOST_FIX.length()){ //Initialize libsip with LocalSipPort and Proxy Address libSipInit(na, defaultSipPort, NAT_HOST_FIX); } else { libSipInit(na, defaultSipPort, theSystem.gethostAddress()); } break; } catch(UdpStackException& e) { //Port is not free, try next if((defaultSipPort > startPort+9) || !guessSipPort) { char buf[256]; sprintf(buf, "ERROR Port in range %d->%d are not available", startPort, defaultSipPort); postMsg(buf); exit(-1); } defaultSipPort++; //Leave port 5061 as it is reserved for TLS if(defaultSipPort == 5061) defaultSipPort++; } } if(UaCommandLine::instance()->getIntOpt("cmdline")) { myUaCli = new UaCli(myWriteFd, myReadFd); } ///Initialize the MediaController library int minRtpPort = atoi(UaConfiguration::instance().getValue(MinRtpPortTag).c_str()); int maxRtpPort = atoi(UaConfiguration::instance().getValue(MaxRtpPortTag).c_str()); MediaController::instance(minRtpPort, maxRtpPort); cpLog(LOG_DEBUG, "Initialized UaFacade");}voidUaFacade::setUpGuiEventThread(){ cpLog(LOG_INFO, "Setting up GuiEventThread"); Data uId((int)getuid()); Data pId((int)getpid()); Data LocalDirectory = NamedDir; LocalDirectory += uId; LocalScopeAllocator lo; mkdir(LocalDirectory.getData(lo), 0700); chmod(LocalDirectory.getData(lo), 0700); struct stat statbuf; int err = lstat(LocalDirectory.getData(lo), &statbuf); if(err) { cpLog(LOG_ERR, "Cannot continue, failed to stat directory: %s", strerror(errno)); exit(-1); } if(statbuf.st_uid != getuid() || statbuf.st_mode != 0040700) { cpLog(LOG_ERR, "Cannot continue, directory %s does not have right permissions", LocalDirectory.getData(lo)); exit(-1); } myReadPath = LocalDirectory.getData(lo); myReadPath += "/"; myReadPath += NamedReadFile; myReadPath += pId.getData(lo); myWritePath = LocalDirectory.getData(lo); myWritePath += "/"; myWritePath += NamedWriteFile; myWritePath += pId.getData(lo); int retVal = mkfifo(myReadPath.c_str(), 0600); if(retVal < 0 && errno != EEXIST) { cpLog(LOG_ERR, "Can not continute, failed to create the named pipes, reason %s", strerror(errno)); exit(-1); } retVal = mkfifo(myWritePath.c_str(), 0600); if(retVal < 0 && errno != EEXIST) { cpLog(LOG_ERR, "Can not continute, failed to create the named pipes, reason %s", strerror(errno));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -