use of gov.nist.javax.sip.header.CSeq in project XobotOS by xamarin.
the class SIPDialog method handlePrack.
/**
* Do the processing necessary for the PRACK
*
* @param prackRequest
* @return true if this is the first time the tx has seen the prack ( and hence needs to be
* passed up to the TU)
*/
public boolean handlePrack(SIPRequest prackRequest) {
/*
* The RAck header is sent in a PRACK request to support reliability of provisional
* responses. It contains two numbers and a method tag. The first number is the value from
* the RSeq header in the provisional response that is being acknowledged. The next
* number, and the method, are copied from the CSeq in the response that is being
* acknowledged. The method name in the RAck header is case sensitive.
*/
if (!this.isServer()) {
if (sipStack.isLoggingEnabled())
sipStack.getStackLogger().logDebug("Dropping Prack -- not a server Dialog");
return false;
}
SIPServerTransaction sipServerTransaction = (SIPServerTransaction) this.getFirstTransaction();
SIPResponse sipResponse = sipServerTransaction.getReliableProvisionalResponse();
if (sipResponse == null) {
if (sipStack.isLoggingEnabled())
sipStack.getStackLogger().logDebug("Dropping Prack -- ReliableResponse not found");
return false;
}
RAck rack = (RAck) prackRequest.getHeader(RAckHeader.NAME);
if (rack == null) {
if (sipStack.isLoggingEnabled())
sipStack.getStackLogger().logDebug("Dropping Prack -- rack header not found");
return false;
}
CSeq cseq = (CSeq) sipResponse.getCSeq();
if (!rack.getMethod().equals(cseq.getMethod())) {
if (sipStack.isLoggingEnabled())
sipStack.getStackLogger().logDebug("Dropping Prack -- CSeq Header does not match PRACK");
return false;
}
if (rack.getCSeqNumberLong() != cseq.getSeqNumber()) {
if (sipStack.isLoggingEnabled())
sipStack.getStackLogger().logDebug("Dropping Prack -- CSeq Header does not match PRACK");
return false;
}
RSeq rseq = (RSeq) sipResponse.getHeader(RSeqHeader.NAME);
if (rack.getRSequenceNumber() != rseq.getSeqNumber()) {
if (sipStack.isLoggingEnabled())
sipStack.getStackLogger().logDebug("Dropping Prack -- RSeq Header does not match PRACK");
return false;
}
return sipServerTransaction.prackRecieved();
}
use of gov.nist.javax.sip.header.CSeq in project XobotOS by xamarin.
the class SIPDialog method createRequest.
/**
* The method that actually does the work of creating a request.
*
* @param method
* @param response
* @return
* @throws SipException
*/
private Request createRequest(String method, SIPResponse sipResponse) throws SipException {
if (method == null || sipResponse == null)
throw new NullPointerException("null argument");
if (method.equals(Request.CANCEL))
throw new SipException("Dialog.createRequest(): Invalid request");
if (this.getState() == null || (this.getState().getValue() == TERMINATED_STATE && !method.equalsIgnoreCase(Request.BYE)) || (this.isServer() && this.getState().getValue() == EARLY_STATE && method.equalsIgnoreCase(Request.BYE)))
throw new SipException("Dialog " + getDialogId() + " not yet established or terminated " + this.getState());
SipUri sipUri = null;
if (this.getRemoteTarget() != null)
sipUri = (SipUri) this.getRemoteTarget().getURI().clone();
else {
sipUri = (SipUri) this.getRemoteParty().getURI().clone();
sipUri.clearUriParms();
}
CSeq cseq = new CSeq();
try {
cseq.setMethod(method);
cseq.setSeqNumber(this.getLocalSeqNumber());
} catch (Exception ex) {
if (sipStack.isLoggingEnabled())
sipStack.getStackLogger().logError("Unexpected error");
InternalErrorHandler.handleException(ex);
}
/*
* Add a via header for the outbound request based on the transport of the message
* processor.
*/
ListeningPointImpl lp = (ListeningPointImpl) this.sipProvider.getListeningPoint(sipResponse.getTopmostVia().getTransport());
if (lp == null) {
if (sipStack.isLoggingEnabled())
sipStack.getStackLogger().logError("Cannot find listening point for transport " + sipResponse.getTopmostVia().getTransport());
throw new SipException("Cannot find listening point for transport " + sipResponse.getTopmostVia().getTransport());
}
Via via = lp.getViaHeader();
From from = new From();
from.setAddress(this.localParty);
To to = new To();
to.setAddress(this.remoteParty);
SIPRequest sipRequest = sipResponse.createRequest(sipUri, via, cseq, from, to);
if (SIPRequest.isTargetRefresh(method)) {
ContactHeader contactHeader = ((ListeningPointImpl) this.sipProvider.getListeningPoint(lp.getTransport())).createContactHeader();
((SipURI) contactHeader.getAddress().getURI()).setSecure(this.isSecure());
sipRequest.setHeader(contactHeader);
}
try {
/*
* Guess of local sequence number - this is being re-set when the request is actually
* dispatched
*/
cseq = (CSeq) sipRequest.getCSeq();
cseq.setSeqNumber(this.localSequenceNumber + 1);
} catch (InvalidArgumentException ex) {
InternalErrorHandler.handleException(ex);
}
if (method.equals(Request.SUBSCRIBE)) {
if (eventHeader != null)
sipRequest.addHeader(eventHeader);
}
try {
if (this.getLocalTag() != null) {
from.setTag(this.getLocalTag());
} else {
from.removeTag();
}
if (this.getRemoteTag() != null) {
to.setTag(this.getRemoteTag());
} else {
to.removeTag();
}
} catch (ParseException ex) {
InternalErrorHandler.handleException(ex);
}
// get the route list from the dialog.
this.updateRequest(sipRequest);
return sipRequest;
}
Aggregations