diff --git a/src/managerimpl.cpp b/src/managerimpl.cpp index 3085ce1c8de60a116c303da573c9b907b3a71091..8358521828010951ae6c7aca7e3d36fec3130172 100644 --- a/src/managerimpl.cpp +++ b/src/managerimpl.cpp @@ -926,14 +926,11 @@ ManagerImpl::getStunInfo (StunAddress4& stunSvrAddr, int port) } bool -ManagerImpl::behindNat(int port) +ManagerImpl::behindNat(const std::string& svr, int port) { StunAddress4 stunSvrAddr; stunSvrAddr.addr = 0; - // Stun server - std::string svr = getConfigString(SIGNALISATION, STUN_SERVER); - // Convert char* to StunAddress4 structure bool ret = stunParseServerName ((char*)svr.data(), stunSvrAddr); if (!ret) { @@ -986,19 +983,19 @@ ManagerImpl::initConfigFile (void) std::string section; section = SIGNALISATION; fill_config_int(SYMMETRIC, YES_STR); - fill_config_str(FULL_NAME, EMPTY_FIELD); - fill_config_str(USER_PART, EMPTY_FIELD); - fill_config_str(AUTH_USER_NAME, EMPTY_FIELD); - fill_config_str(PASSWORD, EMPTY_FIELD); - fill_config_str(HOST_PART, EMPTY_FIELD); - fill_config_str(PROXY, EMPTY_FIELD); - fill_config_int(AUTO_REGISTER, YES_STR); + //fill_config_str(FULL_NAME, EMPTY_FIELD); + //fill_config_str(USER_PART, EMPTY_FIELD); + //fill_config_str(AUTH_USER_NAME, EMPTY_FIELD); + //fill_config_str(PASSWORD, EMPTY_FIELD); + //fill_config_str(HOST_PART, EMPTY_FIELD); + //fill_config_str(PROXY, EMPTY_FIELD); + //fill_config_int(AUTO_REGISTER, YES_STR); fill_config_int(PLAY_DTMF, YES_STR); fill_config_int(PLAY_TONES, YES_STR); fill_config_int(PULSE_LENGTH, DFT_PULSE_LENGTH_STR); fill_config_int(SEND_DTMF_AS, SIP_INFO_STR); - fill_config_str(STUN_SERVER, DFT_STUN_SERVER); - fill_config_int(USE_STUN, NO_STR); + //fill_config_str(STUN_SERVER, DFT_STUN_SERVER); + //fill_config_int(USE_STUN, NO_STR); section = AUDIO; fill_config_int(DRIVER_NAME, DFT_DRIVER_STR); diff --git a/src/managerimpl.h b/src/managerimpl.h index e47b2a4cca91c13f6996eb071a5faee744d84bc6..90f379499cad922b1fac599d1a797f1a08eeeba9 100644 --- a/src/managerimpl.h +++ b/src/managerimpl.h @@ -258,8 +258,8 @@ public: */ bool getStunInfo(StunAddress4& stunSvrAddr, int port); - inline int getFirewallPort (void) { return _firewallPort; } - inline void setFirewallPort (int port) { _firewallPort = port; } + inline int getFirewallPort(void) { return _firewallPort; } + inline void setFirewallPort(int port) { _firewallPort = port; } inline std::string getFirewallAddress (void) { return _firewallAddr; } /** @@ -267,11 +267,12 @@ public: * STUN configuration(you can change this one by default) to give you an * public IP address and assign a port number. * Note: Set firewall port/address retreive - * @param port : on which port we want to listen to + * @param svr : serveur on which to send request + * @param port : on which port we want to listen to * * Return true if we are behind a NAT (without error) */ - bool behindNat(int port); + bool behindNat(const std::string& svr, int port); /** * Init default values for the different fields diff --git a/src/sipaccount.cpp b/src/sipaccount.cpp index 54d9d5cfad2a38e32703ad8e88526500a8f44126..838b6128d754c0703771fb5be02f29993eef2d5b 100644 --- a/src/sipaccount.cpp +++ b/src/sipaccount.cpp @@ -84,8 +84,10 @@ SIPAccount::init() _link->setFullName(Manager::instance().getConfigString(_accountID,SIP_FULL_NAME)); _link->setHostName(Manager::instance().getConfigString(_accountID,SIP_HOST_PART)); int useStun = Manager::instance().getConfigInt(_accountID,SIP_USE_STUN); + SIPVoIPLink* tmplink = dynamic_cast<SIPVoIPLink*> (_link); if (tmplink) { + tmplink->setStunServer(Manager::instance().getConfigString(_accountID,SIP_STUN_SERVER)); tmplink->setUseStun( useStun!=0 ? true : false); } _link->init(); diff --git a/src/sipvoiplink.cpp b/src/sipvoiplink.cpp index 9214b097222dac6b357745f4fa36f3e583fcb7f5..636828e7d3d91b1105d658d37f68ac0ac44ebc78 100644 --- a/src/sipvoiplink.cpp +++ b/src/sipvoiplink.cpp @@ -95,9 +95,9 @@ SIPVoIPLink::init() int iTry = 1; // try number.. do { - if (_useStun && !Manager::instance().behindNat(port)) { + if (_useStun && !Manager::instance().behindNat(_stunServer, port)) { port = RANDOM_SIP_PORT; - if (!Manager::instance().behindNat(port)) { + if (!Manager::instance().behindNat(_stunServer, port)) { _debug("SIP FAILURE: Unable to check NAT setting\n"); return false; // hoho we can't use the random sip port too... } @@ -1061,7 +1061,7 @@ SIPVoIPLink::setCallAudioLocal(SIPCall* call) unsigned int callLocalExternAudioPort = callLocalAudioPort; if (_useStun) { // If use Stun server - if (Manager::instance().behindNat(callLocalAudioPort)) { + if (Manager::instance().behindNat(_stunServer, callLocalAudioPort)) { callLocalExternAudioPort = Manager::instance().getFirewallPort(); } } diff --git a/src/sipvoiplink.h b/src/sipvoiplink.h index b9f87bab7582ae0722eae87e6116bac04ccfca12..4c67fee05c3a607569d235458c2158f489e11547 100644 --- a/src/sipvoiplink.h +++ b/src/sipvoiplink.h @@ -66,6 +66,7 @@ public: * @param use true if we use STUN */ void setUseStun(bool use) { _useStun = use; } + void setStunServer(const std::string& server) { _stunServer = server; } void setProxy(const std::string& proxy) { _proxy = proxy; } void setUserPart(const std::string& userpart) { _userpart = userpart; } void setAuthName(const std::string& authname) { _authname = authname; } @@ -242,6 +243,8 @@ private: /** Do we use stun? */ bool _useStun; + /** What is the stun server? */ + std::string _stunServer; /** Local Extern Address is the IP address seens by peers for SIP listener */ std::string _localExternAddress; diff --git a/src/user_cfg.h b/src/user_cfg.h index 1237e55a32f80c4493360fafab843f0abf0862d1..a03b1de6f132f91677dfafa850fedac1b3588c33 100644 --- a/src/user_cfg.h +++ b/src/user_cfg.h @@ -42,22 +42,22 @@ // Fields to fill -#define VOIP_LINK_ID "VoIPLink.index" +//#define VOIP_LINK_ID "VoIPLink.index" #define SYMMETRIC "VoIPLink.symmetric" -#define FULL_NAME "SIP.fullName" -#define USER_PART "SIP.userPart" -#define AUTH_USER_NAME "SIP.username" -#define PASSWORD "SIP.password" -#define HOST_PART "SIP.hostPart" -#define PROXY "SIP.proxy" -#define AUTO_REGISTER "SIP.autoregister" +//#define FULL_NAME "SIP.fullName" +//#define USER_PART "SIP.userPart" +//#define AUTH_USER_NAME "SIP.username" +//#define PASSWORD "SIP.password" +//#define HOST_PART "SIP.hostPart" +//#define PROXY "SIP.proxy" +//#define AUTO_REGISTER "SIP.autoregister" #define PLAY_DTMF "DTMF.playDtmf" #define PLAY_TONES "DTMF.playTones" #define PULSE_LENGTH "DTMF.pulseLength" #define SEND_DTMF_AS "DTMF.sendDTMFas" -#define STUN_SERVER "STUN.STUNserver" -#define USE_STUN "STUN.useStun" +//#define STUN_SERVER "STUN.STUNserver" +//#define USE_STUN "STUN.useStun" #define DRIVER_NAME "Drivers.driverName" #define DRIVER_NAME_IN "Drivers.driverNameIn" #define DRIVER_NAME_OUT "Drivers.driverNameOut"