public boolean doesCancelMatchTransaction(SIPRequest requestToTest) {
// List of Via headers in the message to test
ViaList viaHeaders;
// Topmost Via header in the list
Via topViaHeader;
// Branch code in the topmost Via header
String messageBranch;
// Flags whether the select message is part of this transaction
boolean transactionMatches;
transactionMatches = false;
if (this.getOriginalRequest() == null
|| this.getOriginalRequest().getMethod().equals(Request.CANCEL))
return false;
// Get the topmost Via header and its branch parameter
viaHeaders = requestToTest.getViaHeaders();
if (viaHeaders != null) {
topViaHeader = (Via) viaHeaders.getFirst();
messageBranch = topViaHeader.getBranch();
if (messageBranch != null) {
// If the branch parameter exists but
// does not start with the magic cookie,
if (!messageBranch.toLowerCase().startsWith(SIPConstants.BRANCH_MAGIC_COOKIE_LOWER_CASE)) {
// Flags this as old
// (RFC2543-compatible) client
// version
messageBranch = null;
}
}
// If a new branch parameter exists,
if (messageBranch != null && this.getBranch() != null) {
// If the branch equals the branch in
// this message,
if (getBranch().equalsIgnoreCase(messageBranch)
&& topViaHeader.getSentBy().equals(
((Via) getOriginalRequest().getViaHeaders()
.getFirst()).getSentBy())) {
transactionMatches = true;
if (sipStack.isLoggingEnabled(LogWriter.TRACE_DEBUG))
sipStack.getStackLogger().logDebug("returning true");
}
} else {
// If this is an RFC2543-compliant message,
// If RequestURI, To tag, From tag,
// CallID, CSeq number, and top Via
// headers are the same,
if (sipStack.isLoggingEnabled(LogWriter.TRACE_DEBUG))
sipStack.getStackLogger().logDebug("testing against "
+ getOriginalRequest());
if (getOriginalRequest().getRequestURI().equals(
requestToTest.getRequestURI())
&& getOriginalRequest().getTo().equals(
requestToTest.getTo())
&& getOriginalRequest().getFrom().equals(
requestToTest.getFrom())
&& getOriginalRequest().getCallId().getCallId().equals(
requestToTest.getCallId().getCallId())
&& getOriginalRequest().getCSeq().getSeqNumber() == requestToTest
.getCSeq().getSeqNumber()
&& topViaHeader.equals(getOriginalRequest()
.getViaHeaders().getFirst())) {
transactionMatches = true;
}