Add configuration parameter 'public_ip' and mechanisms to use it in SDP body generation.

git-svn-id: http://svn.berlios.de/svnroot/repos/sems/trunk@917 8eb893ce-cfd4-0310-b710-fb5ebe64c474
sayer/1.4-spce2.6
Richard Newman 18 years ago
parent 1f7cacd98c
commit 3c7c8297f5

@ -47,6 +47,7 @@ string AmConfig::ExcludePlugins = "";
string AmConfig::ExcludePayloads = "";
int AmConfig::DaemonMode = DEFAULT_DAEMON_MODE;
string AmConfig::LocalIP = "";
string AmConfig::PublicIP = "";
string AmConfig::PrefixSep = PREFIX_SEPARATOR;
int AmConfig::RtpLowPort = RTP_LOWPORT;
int AmConfig::RtpHighPort = RTP_HIGHPORT;
@ -146,6 +147,8 @@ int AmConfig::setDeadRtpTime(const string& drt)
int AmConfig::readConfiguration()
{
DBG("Reading configuration...");
AmConfigReader cfg;
if(cfg.loadFile(ConfigurationFile.c_str())){
@ -180,6 +183,15 @@ int AmConfig::readConfiguration()
if(cfg.hasParameter("sip_ip"))
LocalSIPIP = cfg.getParameter("sip_ip");
if(cfg.hasParameter("public_ip")){
string p_ip = cfg.getParameter("public_ip");
DBG("Setting public_ip parameter to %s.\n", p_ip.c_str());
PublicIP = p_ip;
}
else {
DBG("Config file has no public_ip parameter.");
}
// outbound_proxy
OutboundProxy = cfg.getParameter("outbound_proxy");

@ -62,8 +62,14 @@ struct AmConfig
//static unsigned int MaxRecordTime;
/** run the programm in daemon mode? */
static int DaemonMode;
/** local IP for SDP media advertising */
static string LocalIP;
/** public IP for SDP media advertising; we actually
* bind to local IP, but advertise public IP. */
static string PublicIP;
/** Separator character for uri application prefix (ex: voicemail+jiri@iptel.org) */
static string PrefixSep;
/** Lowest local RTP port */

@ -322,7 +322,7 @@ void AmSession::negotiate(const string& sdp_body,
if( sdp.remote_active || force_symmetric_rtp) {
DBG("The other UA is NATed: switched to passive mode.\n");
DBG("remote_active = %i; force_symmetric_rtp = %i\n",
sdp.remote_active,force_symmetric_rtp);
sdp.remote_active, force_symmetric_rtp);
passive_mode = true;
}
@ -339,7 +339,7 @@ void AmSession::negotiate(const string& sdp_body,
unlockAudio();
if(sdp_reply)
sdp.genResponse(AmConfig::LocalIP,rtp_str.getLocalPort(),*sdp_reply, AmConfig::SingleCodecInOK);
sdp.genResponse(advertisedIP(), rtp_str.getLocalPort(), *sdp_reply, AmConfig::SingleCodecInOK);
}
void AmSession::run()
@ -784,7 +784,7 @@ void AmSession::sendReinvite(bool updateSDP, const string& headers)
if (updateSDP) {
rtp_str.setLocalIP(AmConfig::LocalIP);
string sdp_body;
sdp.genResponse(AmConfig::LocalIP,rtp_str.getLocalPort(),sdp_body);
sdp.genResponse(advertisedIP(), rtp_str.getLocalPort(), sdp_body);
dlg.reinvite(headers, "application/sdp", sdp_body);
} else {
dlg.reinvite(headers, "", "");
@ -793,12 +793,13 @@ void AmSession::sendReinvite(bool updateSDP, const string& headers)
int AmSession::sendInvite(const string& headers)
{
// set local IP first, so that IP is set when
// getLocalPort/setLocalPort may bind
// Set local IP first, so that IP is set when
// getLocalPort/setLocalPort may bind.
rtp_str.setLocalIP(AmConfig::LocalIP);
// generate SDP
// Generate SDP.
string sdp_body;
sdp.genRequest(AmConfig::LocalIP,rtp_str.getLocalPort(),sdp_body);
sdp.genRequest(advertisedIP(), rtp_str.getLocalPort(), sdp_body);
return dlg.invite(headers, "application/sdp", sdp_body);
}
@ -811,3 +812,15 @@ void AmSession::setOnHold(bool hold)
sendReinvite();
unlockAudio();
}
// Utility for basic NAT handling: allow the config file to specify the IP
// address to use in SDP bodies and Contact header.
// TODO: Contact header! :)
string AmSession::advertisedIP()
{
string set_ip = AmConfig::PublicIP; // "public_ip" parameter. (NEW)
DBG("AmConfig::PublicIP is %s.", set_ip.c_str());
if (set_ip.empty())
return AmConfig::LocalIP; // "listen" parameter.
return set_ip;
}

@ -457,6 +457,9 @@ public:
const string& body,
string& hdrs,
int flags);
// The IP address to put as c= in SDP bodies and to use for Contact:.
string advertisedIP();
};
#endif

@ -162,13 +162,27 @@ media_processor_threads=1
# registrations.
# It defaults to the value of 'listen' (see above).
#
# Example :
# Example:
# sip_ip=10.0.0.34
#
# default: <listen ip address>
#
#sip_ip=10.0.0.34
# optional parameter: public_ip=<ip_address>
#
# - when running SEMS behind certain simple NAT configurations,
# you can use this parameter to inform SEMS of its public IP
# address. If this parameter is set, SEMS will write this value
# into SDP bodies.
# If this parameter is not set, the local IP address is used.
# N.B., there is no support for port translation; the local
# RTP port is used in either case.
#
# Example:
# public_sip=75.101.219.48
#
# optional parameter: sip_port=<port_number>
#
# - this informs SEMS about the port where its SIP stack is

@ -253,6 +253,7 @@ int main(int argc, char* argv[])
" plug-in path: %s\n"
" daemon mode: %i\n"
" local SIP IP: %s\n"
" public media IP: %s\n"
" local SIP port: %i\n"
" local media IP: %s\n"
" application: %s\n"
@ -261,6 +262,7 @@ int main(int argc, char* argv[])
AmConfig::PlugInPath.c_str(),
AmConfig::DaemonMode,
AmConfig::LocalSIPIP.c_str(),
AmConfig::PublicIP.c_str(),
AmConfig::LocalSIPPort,
AmConfig::LocalIP.c_str(),
AmConfig::Application.empty()?

Loading…
Cancel
Save