Centralizes use of Contact header generation.

cusax-fix
Emil Ivov 17 years ago
parent 57d5c4961e
commit f2b166a153

@ -1001,55 +1001,6 @@ public MaxForwardsHeader getMaxForwardsHeader() throws
return maxForwardsHeader;
}
/**
* Returns a Contact header containing a sip URI based on the local-host
* address that <b>seemed</b> most suitable for use according what we
* guessed while looking at <tt>request</tt>.
*
* @param request the request that we are preparing to answer with the
* response that we are building a <tt>Contact</tt> header for.
*
* @return a Contact header based upon a local inet address.
*/
public ContactHeader getContactHeaderForResponse(Request request)
{
//emil: so here's the thing. ideally we should use the address and
//port that this request arrived at. However there's no way for us
//to know this. First because jain-sip does not provide such a way
//and second (more important :) ) because the JRE itself does not,
//provide away of retrieving the specific local address for a
//datagram was received on a 0.0.0.0/::0 bound sock.
//therefore, since jain-sip will (normally be sending our response to
//the address in the topmost Via .. we use it to determine a local
//address.
ViaHeader via = (ViaHeader)request.getHeader(ViaHeader.NAME);
SipURI intendedDestinationURI;
String transport = via.getTransport();
String host = via.getHost();
int port = via.getPort();
try
{
intendedDestinationURI = addressFactory.createSipURI(null, host);
intendedDestinationURI.setPort(port);
if(transport != null)
intendedDestinationURI.setTransportParam(transport);
}
catch (ParseException e)
{
logger.debug(via + " does not seem to be a valid header.");
FromHeader from = (FromHeader)request.getHeader(From.NAME);
intendedDestinationURI = (SipURI)from.getAddress().getURI();
}
return getContactHeader(intendedDestinationURI);
}
/**
* Returns a Contact header containing a sip URI based on a localhost
* address and therefore usable in REGISTER requests only.

@ -306,7 +306,51 @@ private Message attachScSpecifics(Message message)
*/
private Message attachContactHeader(Message message)
{
//creates a Contact header
if(message instanceof Request)
{
Request request = (Request)message;
SipURI requestURI = (SipURI)request.getRequestURI();
request.setHeader(protocolProvider.getContactHeader(requestURI));
return request;
}
else
{
Response response = (Response)message;
ViaHeader via = (ViaHeader)response.getHeader(ViaHeader.NAME);
SipURI intendedDestinationURI;
String transport = via.getTransport();
String host = via.getHost();
int port = via.getPort();
try
{
intendedDestinationURI = protocolProvider.getAddressFactory()
.createSipURI(null, host);
intendedDestinationURI.setPort(port);
if(transport != null)
intendedDestinationURI.setTransportParam(transport);
}
catch (ParseException e)
{
logger.debug(via + " does not seem to be a valid header.");
FromHeader from = (FromHeader)response.getHeader(From.NAME);
intendedDestinationURI = (SipURI)from.getAddress().getURI();
}
ContactHeader contactHeader
= protocolProvider.getContactHeader(intendedDestinationURI);
response.setHeader(contactHeader);
return response;
}
}
/**

Loading…
Cancel
Save