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;
final SIPRequest origRequest = getOriginalRequest();
if (origRequest == null
|| this.getMethod().equals(Request.CANCEL))
return false;
// Get the topmost Via header and its branch parameter
topViaHeader = requestToTest.getTopmostVia();
if (topViaHeader != 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(
origRequest.getTopmostVia().getSentBy())) {
transactionMatches = true;
if (logger.isLoggingEnabled(LogWriter.TRACE_DEBUG))
logger.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 (logger.isLoggingEnabled(LogWriter.TRACE_DEBUG))
logger.logDebug("testing against "
+ origRequest);
if (origRequest.getRequestURI().equals(
requestToTest.getRequestURI())
&& origRequest.getTo().equals(
requestToTest.getTo())
&& origRequest.getFrom().equals(
requestToTest.getFrom())
&& origRequest.getCallId().getCallId().equals(
requestToTest.getCallId().getCallId())
&& origRequest.getCSeq().getSeqNumber() == requestToTest
.getCSeq().getSeqNumber()
&& topViaHeader.equals(origRequest.getTopmostVia())) {
transactionMatches = true;
}
}