Commit 0c29f88d authored by yanmorin's avatar yanmorin
Browse files

Allow different stun server foreach account
parent b12aefb1
......@@ -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);
......
......@@ -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
......
......@@ -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();
......
......@@ -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();
}
}
......
......@@ -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;
......
......@@ -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"
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment