Allow suppressing the port at the end of a MGCP endpoint ID.

git-svn-id: http://voip.null.ro/svn/yate@4461 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
paulc 2011-06-21 16:21:43 +00:00
parent 7045b59444
commit 55d646062d
4 changed files with 33 additions and 18 deletions

View File

@ -137,6 +137,9 @@
;host=
; port: int: Remote port to send packets to
; Zero uses the protocol default 2427
; A negative value suppresses :port at end of ID
; A value of -1 uses default 2427 but doesn't add at end of ID
;port=2427
; address: ipaddress: IP address of the gateway, if present will override

View File

@ -30,9 +30,10 @@ using namespace TelEngine;
*/
// Construct the id. Append itself to the engine's list
MGCPEndpoint::MGCPEndpoint(MGCPEngine* engine, const char* user,
const char* host, int port)
: MGCPEndpointId(user,host,port), Mutex(false,"MGCPEndpoint"),
m_engine(engine)
const char* host, int port, bool addPort)
: MGCPEndpointId(user,host,port,addPort),
Mutex(false,"MGCPEndpoint"),
m_engine(engine)
{
if (!m_engine) {
Debug(DebugNote,"Can't construct endpoint without engine [%p]",this);
@ -57,9 +58,12 @@ MGCPEpInfo* MGCPEndpoint::append(const char* endpoint, const char* host, int por
if (!endpoint)
endpoint = user();
if (!port)
bool addPort = (port >= 0);
if (port < -1)
port = -port;
else if (port <= 0)
port = m_engine->defaultPort(!m_engine->gateway());
MGCPEpInfo* ep = new MGCPEpInfo(endpoint,host,port);
MGCPEpInfo* ep = new MGCPEpInfo(endpoint,host,port,addPort);
if (!ep->valid() || find(ep->id()))
TelEngine::destruct(ep);
else
@ -98,7 +102,7 @@ MGCPEpInfo* MGCPEndpoint::peer()
* MGCPEndpointId
*/
// Set this endpoint id. Convert it to lower case
void MGCPEndpointId::set(const char* endpoint, const char* host, int port)
void MGCPEndpointId::set(const char* endpoint, const char* host, int port, bool addPort)
{
m_id = "";
m_endpoint = endpoint;
@ -107,7 +111,7 @@ void MGCPEndpointId::set(const char* endpoint, const char* host, int port)
m_host.toLower();
m_port = port;
m_id << m_endpoint << "@" << m_host;
if (m_port)
if (m_port && addPort)
m_id << ":" << m_port;
}

View File

@ -506,18 +506,20 @@ public:
* @param value Original Endpoint ID to copy
*/
inline MGCPEndpointId(const MGCPEndpointId& value)
: m_port(0)
{ set(value.user(),value.host(),value.port()); }
: m_id(value.id()), m_endpoint(value.user()),
m_host(value.host()), m_port(value.port())
{ }
/**
* Constructor. Construct this endpoint id
* @param endpoint The user part of the endpoint's URI
* @param host The IP address of the endpoint's URI
* @param port The port used by the endpoint to receive data
* @param addPort Add :port at end of id only if port is not zero
*/
inline MGCPEndpointId(const char* endpoint, const char* host, int port)
inline MGCPEndpointId(const char* endpoint, const char* host, int port, bool addPort = true)
: m_port(0)
{ set(endpoint,host,port); }
{ set(endpoint,host,port,addPort); }
/**
* Get the full id of the endpoint
@ -550,17 +552,19 @@ public:
/**
* Set the port used by this endpoint
* @param newPort The new port used by this endpoint
* @param addPort Add :port at end of id only if port is not zero
*/
inline void port(int newPort)
{ set(m_endpoint,m_host,newPort); }
inline void port(int newPort, bool addPort = true)
{ set(m_endpoint,m_host,newPort,addPort); }
/**
* Set this endpoint id. Convert it to lower case
* @param endpoint The user part of the endpoint's URI
* @param host The IP address of the endpoint's URI
* @param port The port used by the endpoint to receive data
* @param addPort Add :port at end of id only if port is not zero
*/
void set(const char* endpoint, const char* host, int port);
void set(const char* endpoint, const char* host, int port, bool addPort = true);
/**
* Set this endpoint id. Convert it to lower case
@ -601,9 +605,10 @@ public:
* @param endpoint The endpoint part of the endpoint's id
* @param host The IP address of this endpoint
* @param port The port used to send data to this endpoint
* @param addPort Add :port at end of id only if port is not zero
*/
inline MGCPEpInfo(const char* endpoint, const char* host, int port)
: MGCPEndpointId(endpoint,host,port), address(AF_INET) {
inline MGCPEpInfo(const char* endpoint, const char* host, int port, bool addPort = true)
: MGCPEndpointId(endpoint,host,port,addPort), address(AF_INET) {
address.host(host);
address.port(port);
}
@ -642,8 +647,9 @@ public:
* @param user The user part of the endpoint's id
* @param host The host part of the endpoint's id
* @param port The port part of the endpoint's id
* @param addPort Add :port at end of id only if port is not zero
*/
MGCPEndpoint(MGCPEngine* engine, const char* user, const char* host, int port);
MGCPEndpoint(MGCPEngine* engine, const char* user, const char* host, int port, bool addPort = true);
/**
* Destructor. Remove itself from engine's list
@ -672,6 +678,8 @@ public:
* @param port The port used to send data to this endpoint.
* Set to 0 to set it to the default port defined by the protocol and the
* opposite of the engine's mode
* A value of -1 uses the default but doesn't add :port at end of ID
* Other negative values use specified port but don't add :port at end
* @return Valid MGCPEpInfo pointer or 0 if the data wasn't added
*/
MGCPEpInfo* append(const char* endpoint, const char* host, int port = 0);

View File

@ -894,7 +894,7 @@ MGCPSpan* MGCPSpan::findNotify(const String& id)
MGCPSpan::MGCPSpan(const NamedList& params, const char* name, const MGCPEpInfo& ep)
: SignallingCircuitSpan(params.getValue("debugname",name),
static_cast<SignallingCircuitGroup*>(params.getObject("SignallingCircuitGroup"))),
static_cast<SignallingCircuitGroup*>(params.getObject("SignallingCircuitGroup"))),
m_circuits(0), m_count(0), m_epId(ep), m_operational(false),
m_rtpForward(false), m_sdpForward(false), m_fxo(false), m_fxs(false),
m_rqntEmbed(true), m_rqntType(RqntOnce)