Wip: adds multiple interface to config reader

sayer/1.4-spce2.6
Raphael Coeffic 15 years ago
parent 5ff20f5bfc
commit aafc7ba080

@ -240,7 +240,7 @@ void C2DCallerDialog::createCalleeSession()
other_id = AmSession::getNewId();
callee_dlg.local_tag = other_id;
callee_dlg.callid = AmSession::getNewId() + "@" + AmConfig::LocalIP;
callee_dlg.callid = AmSession::getNewId() + "@" + AmConfig::LocalIP();
callee_dlg.local_party = dlg.local_party;
callee_dlg.remote_party = dlg.remote_party;
callee_dlg.remote_uri = dlg.remote_uri;

@ -783,7 +783,7 @@ void ConferenceDialog::createDialoutParticipant(const string& uri_user)
AmSipDialog& dialout_dlg = dialout_session->dlg;
dialout_dlg.local_tag = dialout_id;
dialout_dlg.callid = AmSession::getNewId() + "@" + AmConfig::LocalIP;
dialout_dlg.callid = AmSession::getNewId() + "@" + AmConfig::LocalIP();
if (from_header.length() > 0) {
dialout_dlg.local_party = from_header;
@ -795,7 +795,7 @@ void ConferenceDialog::createDialoutParticipant(const string& uri_user)
string body;
int local_port = dialout_session->RTPStream()->getLocalPort();
dialout_session->sdp.genRequest(AmConfig::LocalIP,local_port,body);
dialout_session->sdp.genRequest(AmConfig::LocalIP(),local_port,body);
if (extra_headers.length() == 0) {
extra_headers = "";
@ -885,7 +885,7 @@ void ConferenceDialog::onSipRequest(const AmSipRequest& req)
string body;
int local_port = RTPStream()->getLocalPort();
sdp.genRequest(AmConfig::LocalIP,local_port,body);
sdp.genRequest(AmConfig::LocalIP(),local_port,body);
dlg.sendRequest("INVITE","application/sdp",body,"");
transfer_req.reset(new AmSipRequest(req));

@ -803,7 +803,7 @@ void IvrDialog::createCalleeSession()
other_id = AmSession::getNewId();
callee_dlg.local_tag = other_id;
callee_dlg.callid = AmSession::getNewId() + "@" + AmConfig::LocalIP;
callee_dlg.callid = AmSession::getNewId() + "@" + AmConfig::LocalIP();
// this will be overwritten by ConnectLeg event
callee_dlg.remote_party = dlg.local_party;

@ -73,7 +73,7 @@ SIPRegistration::SIPRegistration(const string& handle,
req.from_tag = handle;
req.to = req.from;
req.to_tag = "";
req.callid = AmSession::getNewId() + "@" + AmConfig::LocalIP;
req.callid = AmSession::getNewId() + "@" + AmConfig::LocalIP();
//
// clear dlg.callid? ->reregister?

@ -988,7 +988,7 @@ void SBCDialog::createCalleeSession()
callee_dlg.local_tag = other_id;
callee_dlg.callid = callid.empty() ?
AmSession::getNewId() + "@" + AmConfig::LocalIP : callid;
AmSession::getNewId() + "@" + AmConfig::LocalIP() : callid;
// this will be overwritten by ConnectLeg event
callee_dlg.remote_party = to;

@ -246,7 +246,7 @@ void AmB2ABCallerSession::setupCalleeSession(AmB2ABCalleeSession* callee_session
assert(callee_session);
AmSipDialog& callee_dlg = callee_session->dlg;
callee_dlg.callid = AmSession::getNewId() + "@" + AmConfig::LocalIP;
callee_dlg.callid = AmSession::getNewId() + "@" + AmConfig::LocalIP();
callee_dlg.local_tag = other_id;

@ -673,7 +673,7 @@ void AmB2BCallerSession::createCalleeSession() {
other_id = AmSession::getNewId();
callee_dlg.local_tag = other_id;
callee_dlg.callid = AmSession::getNewId() + "@" + AmConfig::LocalIP;
callee_dlg.callid = AmSession::getNewId() + "@" + AmConfig::LocalIP();
callee_dlg.local_party = dlg.remote_party;
callee_dlg.remote_party = dlg.local_party;

@ -50,6 +50,9 @@ string AmConfig::ExcludePayloads = "";
int AmConfig::LogLevel = L_INFO;
bool AmConfig::LogStderr = false;
vector<AmConfig::IP_interface> AmConfig::Ifs;
map<string,unsigned short> AmConfig::If_names;
#ifndef DISABLE_DAEMON_MODE
bool AmConfig::DaemonMode = DEFAULT_DAEMON_MODE;
string AmConfig::DaemonPidFile = DEFAULT_DAEMON_PID_FILE;
@ -59,15 +62,9 @@ string AmConfig::DaemonGid = DEFAULT_DAEMON_GID;
unsigned int AmConfig::MaxShutdownTime = DEFAULT_MAX_SHUTDOWN_TIME;
string AmConfig::LocalIP = "";
string AmConfig::PublicIP = "";
int AmConfig::RtpLowPort = RTP_LOWPORT;
int AmConfig::RtpHighPort = RTP_HIGHPORT;
int AmConfig::SessionProcessorThreads = NUM_SESSION_PROCESSORS;
int AmConfig::MediaProcessorThreads = NUM_MEDIA_PROCESSORS;
int AmConfig::SIPServerThreads = NUM_SIP_SERVERS;
int AmConfig::LocalSIPPort = 5060;
string AmConfig::LocalSIPIP = "";
string AmConfig::OutboundProxy = "";
bool AmConfig::ForceOutboundProxy = false;
bool AmConfig::ProxyStickyAuth = false;
@ -101,29 +98,7 @@ AmConfig::DefaultDTMFDetector = Dtmf::SEMSInternal;
bool AmConfig::IgnoreSIGCHLD = true;
bool AmConfig::IgnoreSIGPIPE = true;
int AmConfig::setSIPPort(const string& port)
{
if(sscanf(port.c_str(),"%u",&LocalSIPPort) != 1) {
return 0;
}
return 1;
}
int AmConfig::setRtpLowPort(const string& port)
{
if(sscanf(port.c_str(),"%i",&RtpLowPort) != 1) {
return 0;
}
return 1;
}
int AmConfig::setRtpHighPort(const string& port)
{
if(sscanf(port.c_str(),"%i",&RtpHighPort) != 1) {
return 0;
}
return 1;
}
static int readInterfaces(AmConfigReader& cfg);
int AmConfig::setLogLevel(const string& level, bool apply)
{
@ -255,29 +230,9 @@ int AmConfig::readConfiguration()
if(!ModConfigPath.empty() && (ModConfigPath[ModConfigPath.length()-1] != '/'))
ModConfigPath += '/';
// listen, sip_ip, sip_port, and media_ip
if(cfg.hasParameter("sip_ip")) {
LocalSIPIP = cfg.getParameter("sip_ip");
}
if(cfg.hasParameter("sip_port")){
if(!setSIPPort(cfg.getParameter("sip_port").c_str())){
ERROR("invalid sip port specified\n");
ret = -1;
}
}
if(cfg.hasParameter("media_ip")) {
LocalIP = cfg.getParameter("media_ip");
}
// public_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.");
}
// Reads IP and port parameters
if(readInterfaces(cfg) == -1)
ret = -1;
// outbound_proxy
if (cfg.hasParameter("outbound_proxy"))
@ -407,22 +362,6 @@ int AmConfig::readConfiguration()
MaxShutdownTime = cfg.getParameterInt("max_shutdown_time",
DEFAULT_MAX_SHUTDOWN_TIME);
// rtp_low_port
if(cfg.hasParameter("rtp_low_port")){
if(!setRtpLowPort(cfg.getParameter("rtp_low_port"))){
ERROR("invalid rtp low port specified\n");
ret = -1;
}
}
// rtp_high_port
if(cfg.hasParameter("rtp_high_port")){
if(!setRtpHighPort(cfg.getParameter("rtp_high_port"))){
ERROR("invalid rtp high port specified\n");
ret = -1;
}
}
if(cfg.hasParameter("session_processor_threads")){
#ifdef SESSION_THREADPOOL
if(!setSessionProcessorThreads(cfg.getParameter("session_processor_threads"))){
@ -529,3 +468,133 @@ int AmConfig::readConfiguration()
return ret;
}
static int readInterface(AmConfigReader& cfg, const string& i_name)
{
int ret=0;
AmConfig::IP_interface intf;
intf.LocalSIPIP = "";
intf.LocalSIPPort = 5060;
intf.LocalIP = "";
intf.PublicIP = "";
intf.RtpLowPort = RTP_LOWPORT;
intf.RtpHighPort = RTP_HIGHPORT;
string suffix;
if(!i_name.empty())
suffix = "_" + i_name;
// listen, sip_ip, sip_port, and media_ip
if(cfg.hasParameter("sip_ip" + suffix)) {
intf.LocalSIPIP = cfg.getParameter("sip_ip" + suffix);
}
else if(!suffix.empty()) {
ERROR("sip_ip%s parameter is required",suffix.c_str());
ret = -1;
}
if(cfg.hasParameter("sip_port" + suffix)){
string sip_port_str = cfg.getParameter("sip_port" + suffix);
if(sscanf(sip_port_str.c_str(),"%u",
&(intf.LocalSIPPort)) != 1){
ERROR("sip_port%s: invalid sip port specified (%s)\n",
suffix.c_str(),
sip_port_str.c_str());
ret = -1;
}
}
if(cfg.hasParameter("media_ip" + suffix)) {
intf.LocalIP = cfg.getParameter("media_ip" + suffix);
}
else if(!suffix.empty()) {
ERROR("media_ip%s parameter is required",suffix.c_str());
ret = -1;
}
// public_ip
if(cfg.hasParameter("public_ip" + suffix)){
string p_ip = cfg.getParameter("public_ip" + suffix);
DBG("Setting public_ip%s parameter to %s.\n", suffix.c_str(), p_ip.c_str());
intf.PublicIP = p_ip;
}
//else {
// DBG("Config file has no public_ip%s parameter.",suffix.c_str());
//}
// rtp_low_port
if(cfg.hasParameter("rtp_low_port" + suffix)){
string rtp_low_port_str = cfg.getParameter("rtp_low_port" + suffix);
if(sscanf(rtp_low_port_str.c_str(),"%u",
&(intf.RtpLowPort)) != 1){
ERROR("rtp_low_port%s: invalid port number (%s)\n",
suffix.c_str(),rtp_low_port_str.c_str());
ret = -1;
}
}
// rtp_high_port
if(cfg.hasParameter("rtp_high_port" + suffix)){
string rtp_high_port_str = cfg.getParameter("rtp_high_port" + suffix);
if(sscanf(rtp_high_port_str.c_str(),"%u",
&(intf.RtpHighPort)) != 1){
ERROR("rtp_high_port%s: invalid port number (%s)\n",
suffix.c_str(),rtp_high_port_str.c_str());
ret = -1;
}
}
AmConfig::Ifs.push_back(intf);
return ret;
}
static int readInterfaces(AmConfigReader& cfg)
{
int ret = 0;
AmConfig::Ifs.clear();
// read default params first
if(readInterface(cfg,"") < 0) {
return -1;
}
vector<string> if_names;
if(cfg.hasParameter("additional_interfaces")) {
string ifs_str = cfg.getParameter("additional_interfaces");
if(!ifs_str.empty())
if_names = explode(ifs_str,",");
}
for(vector<string>::iterator it = if_names.begin();
it != if_names.end(); it++) {
if(readInterface(cfg,*it) < 0){
ret = -1;
}
if(AmConfig::Ifs.size() > 0)
AmConfig::If_names[*it] = AmConfig::Ifs.size()-1;
}
//debug
if(ret != -1) {
for(map<string,unsigned short>::iterator it = AmConfig::If_names.begin();
it != AmConfig::If_names.end(); it++) {
DBG("BEGIN: interface: '%s'",it->first.c_str());
AmConfig::IP_interface& it_ref = AmConfig::Ifs[it->second];
DBG("\tLocalIP='%s'",it_ref.LocalIP.c_str());
DBG("\tPublicIP='%s'",it_ref.PublicIP.c_str());
DBG("\tLocalSIPIP='%s'",it_ref.LocalSIPIP.c_str());
DBG("\tLocalSIPPort=%u",it_ref.LocalSIPPort);
DBG("\tRtpLowPort=%u",it_ref.RtpLowPort);
DBG("\tRtpHighPort=%u",it_ref.RtpHighPort);
}
}
return ret;
}

@ -35,6 +35,8 @@
#include <string>
using std::string;
#include <map>
using std::map;
#include <utility>
/**
@ -75,27 +77,59 @@ struct AmConfig
static unsigned int MaxShutdownTime;
/** 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;
/** Lowest local RTP port */
static int RtpLowPort;
/** Highest local RTP port */
static int RtpHighPort;
struct IP_interface {
/** local IP for SDP media advertising */
string LocalIP;
/** public IP for SDP media advertising; we actually
* bind to local IP, but advertise public IP. */
string PublicIP;
/** Lowest local RTP port */
int RtpLowPort;
/** Highest local RTP port */
int RtpHighPort;
/** the interface SIP requests are sent from - needed for registrar_client */
string LocalSIPIP;
/** the port SIP requests are sent from - optional (default 5060) */
int LocalSIPPort;
};
static vector<IP_interface> Ifs;
static map<string,unsigned short> If_names;
static string& LocalIP() {
return (Ifs[0].LocalIP);
}
static string& PublicIP() {
return (Ifs[0].PublicIP);
}
static int& RtpLowPort() {
return (Ifs[0].RtpLowPort);
}
static int& RtpHighPort() {
return (Ifs[0].RtpHighPort);
}
static string& LocalSIPIP() {
return (Ifs[0].LocalSIPIP);
}
static int& LocalSIPPort() {
return (Ifs[0].LocalSIPPort);
}
/** number of session (signaling/application) processor threads */
static int SessionProcessorThreads;
/** number of media processor threads */
static int MediaProcessorThreads;
/** number of SIP server threads */
static int SIPServerThreads;
/** the interface SIP requests are sent from - needed for registrar_client */
static string LocalSIPIP;
/** the port SIP requests are sent from - optional (default 5060) */
static int LocalSIPPort;
/** Outbound Proxy (optional, outgoing calls only) */
static string OutboundProxy;
/** force Outbound Proxy to be used for in dialog requests */
@ -188,6 +222,7 @@ struct AmConfig
static int setSIPServerThreads(const string& th);
/** Setter for parameter DeadRtpTime, returns 0 on invalid value */
static int setDeadRtpTime(const string& drt);
};
#endif

@ -85,14 +85,14 @@ int AmRtpStream::getNextPort()
port_mut.lock();
if(next_port < 0){
next_port = AmConfig::RtpLowPort;
next_port = AmConfig::RtpLowPort();
}
port = next_port & 0xfffe;
next_port += 2;
if(next_port >= AmConfig::RtpHighPort){
next_port = AmConfig::RtpLowPort;
if(next_port >= AmConfig::RtpHighPort()){
next_port = AmConfig::RtpLowPort();
}
port_mut.unlock();

@ -283,7 +283,7 @@ void AmSession::negotiate(const string& sdp_body,
lockAudio();
try {
RTPStream()->setLocalIP(AmConfig::LocalIP);
RTPStream()->setLocalIP(AmConfig::LocalIP());
RTPStream()->setPassiveMode(passive_mode);
RTPStream()->setRAddr(r_host, r_port);
} catch (const string& err_str) {
@ -1042,7 +1042,7 @@ string AmSession::sid4dbg()
int AmSession::sendReinvite(bool updateSDP, const string& headers, int flags)
{
if (updateSDP) {
RTPStream()->setLocalIP(AmConfig::LocalIP);
RTPStream()->setLocalIP(AmConfig::LocalIP());
string sdp_body;
sdp.genResponse(advertisedIP(), RTPStream()->getLocalPort(), sdp_body);
return dlg.reinvite(headers, SIP_APPLICATION_SDP, sdp_body, flags);
@ -1057,7 +1057,7 @@ int AmSession::sendInvite(const string& headers)
// Set local IP first, so that IP is set when
// getLocalPort/setLocalPort may bind.
RTPStream()->setLocalIP(AmConfig::LocalIP);
RTPStream()->setLocalIP(AmConfig::LocalIP());
// Generate SDP.
string sdp_body;
@ -1100,10 +1100,10 @@ void AmSession::onFailure(AmSipDialogEventHandler::FailureCause cause,
// address to use in SDP bodies
string AmSession::advertisedIP()
{
string set_ip = AmConfig::PublicIP; // "public_ip" parameter.
string set_ip = AmConfig::PublicIP(); // "public_ip" parameter.
DBG("AmConfig::PublicIP is %s.\n", set_ip.c_str());
if (set_ip.empty())
return AmConfig::LocalIP; // "listen" parameter.
return AmConfig::LocalIP(); // "listen" parameter.
return set_ip;
}

@ -503,10 +503,10 @@ string AmSipDialog::getContactHdr()
}
contact_uri += (AmConfig::PublicIP.empty() ?
AmConfig::LocalSIPIP : AmConfig::PublicIP )
contact_uri += (AmConfig::PublicIP().empty() ?
AmConfig::LocalSIPIP() : AmConfig::PublicIP() )
+ ":";
contact_uri += int2str(AmConfig::LocalSIPPort);
contact_uri += int2str(AmConfig::LocalSIPPort());
contact_uri += ">";
contact_uri += CRLF;

@ -55,7 +55,7 @@ AmSession* AmUAC::dialout(const string& user,
req.from_tag = local_tag;
req.to = to;
req.to_tag = "";
req.callid = AmSession::getNewId() + "@" + AmConfig::LocalIP;
req.callid = AmSession::getNewId() + "@" + AmConfig::LocalIP();
req.hdrs = hdrs;
return AmSessionContainer::instance()->startSessionUAC(req, session_params);

@ -61,8 +61,8 @@ int SipCtrlInterface::udp_rcvbuf = -1;
int SipCtrlInterface::load()
{
INFO("SIP bind_addr: `%s'.\n", AmConfig::LocalSIPIP.c_str());
INFO("SIP bind_port: `%i'.\n", AmConfig::LocalSIPPort);
INFO("SIP bind_addr: `%s'.\n", AmConfig::LocalSIPIP().c_str());
INFO("SIP bind_port: `%i'.\n", AmConfig::LocalSIPPort());
if (!AmConfig::OutboundProxy.empty()) {
sip_uri parsed_uri;

@ -104,6 +104,33 @@ rtp_low_port=10000
# - sets highest for RTP used port
rtp_high_port=60000
# Additional IFs (optional):
# additional_interface = <list of interfaces>
#
# For each additional interface, a set of parameters
# suffixed with the interface name should be defined.
#
# Please note that for each additional interface,
# 'sip_ip' and 'media_ip' are mandatory. The other
# parameters are optional.
#
# Example:
# additional_interfaces=intern,extern
#
# sip_ip_intern=192.168.0.5
# sip_port_intern=5060
# media_ip_intern=192.168.10.5
# rtp_low_port_intern=2000
# rtp_high_port_intern=5000
#
# sip_ip_extern=213.192.59.73
# sip_port_extern=5060
# media_ip_extern=213.192.59.73
# rtp_low_port_extern=2000
# rtp_high_port_extern=5000
# public_ip_extern=213.192.35.73
#
############################################################
# modules and application configuration
#

@ -104,6 +104,33 @@ rtp_low_port=10000
# - sets highest for RTP used port
rtp_high_port=60000
# Additional IFs (optional):
# additional_interface = <list of interfaces>
#
# For each additional interface, a set of parameters
# suffixed with the interface name should be defined.
#
# Please note that for each additional interface,
# 'sip_ip' and 'media_ip' are mandatory. The other
# parameters are optional.
#
# Example:
# additional_interfaces=intern,extern
#
# sip_ip_intern=192.168.0.5
# sip_port_intern=5060
# media_ip_intern=192.168.10.5
# rtp_low_port_intern=2000
# rtp_high_port_intern=5000
#
# sip_ip_extern=213.192.59.73
# sip_port_extern=5060
# media_ip_extern=213.192.59.73
# rtp_low_port_extern=2000
# rtp_high_port_extern=5000
# public_ip_extern=213.192.35.73
#
############################################################
# modules and application configuration
#

@ -145,7 +145,7 @@ static bool apply_args(std::map<char,string>& args)
switch( it->first ){
case 'd':
AmConfig::LocalIP = it->second;
AmConfig::LocalIP() = it->second;
break;
case 'D':
@ -453,15 +453,15 @@ int main(int argc, char* argv[])
goto error;
}
AmConfig::LocalIP = getLocalIP(AmConfig::LocalIP);
if (AmConfig::LocalIP.empty()) {
AmConfig::LocalIP() = getLocalIP(AmConfig::LocalIP());
if (AmConfig::LocalIP().empty()) {
ERROR("Cannot determine proper local address for media advertising!\n"
"Try using 'ifconfig -a' to find a proper interface and configure SEMS to use it.\n");
goto error;
}
if (AmConfig::LocalSIPIP.empty()) {
AmConfig::LocalSIPIP = AmConfig::LocalIP;
if (AmConfig::LocalSIPIP().empty()) {
AmConfig::LocalSIPIP() = AmConfig::LocalIP();
}
printf("Configuration:\n"
@ -494,10 +494,10 @@ int main(int argc, char* argv[])
AmConfig::DaemonUid.empty() ? "<not set>" : AmConfig::DaemonUid.c_str(),
AmConfig::DaemonGid.empty() ? "<not set>" : AmConfig::DaemonGid.c_str(),
#endif
AmConfig::LocalSIPIP.c_str(),
AmConfig::PublicIP.c_str(),
AmConfig::LocalSIPPort,
AmConfig::LocalIP.c_str(),
AmConfig::LocalSIPIP().c_str(),
AmConfig::PublicIP().c_str(),
AmConfig::LocalSIPPort(),
AmConfig::LocalIP().c_str(),
AmConfig::OutboundProxy.c_str(),
AmConfig::Application.empty() ? "<not set>" : AmConfig::Application.c_str());
@ -628,7 +628,7 @@ int main(int argc, char* argv[])
INFO("Starting SIP stack (control interface)\n");
sip_ctrl.load();
sip_ctrl.run(AmConfig::LocalSIPIP, AmConfig::LocalSIPPort);
sip_ctrl.run(AmConfig::LocalSIPIP(), AmConfig::LocalSIPPort());
success = true;

Loading…
Cancel
Save