/** * Find a matching client SUBSCRIBE to the incoming notify. NOTIFY requests are matched to such * SUBSCRIBE requests if they contain the same "Call-ID", a "To" header "tag" parameter which * matches the "From" header "tag" parameter of the SUBSCRIBE, and the same "Event" header field. * Rules for comparisons of the "Event" headers are described in section 7.2.1. If a matching * NOTIFY request contains a "Subscription-State" of "active" or "pending", it creates a new * subscription and a new dialog (unless they have already been created by a matching response, as * described above). * * @param notifyMessage */ public SIPClientTransaction findSubscribeTransaction(SIPRequest notifyMessage) { synchronized (clientTransactions) { Iterator<SIPClientTransaction> it = clientTransactions.iterator(); String thisToTag = notifyMessage.getTo().getTag(); if (thisToTag == null) return null; Event eventHdr = (Event) notifyMessage.getHeader(EventHeader.NAME); if (eventHdr == null) return null; while (it.hasNext()) { SIPClientTransaction ct = (SIPClientTransaction) it.next(); // SIPRequest sipRequest = ct.getOriginalRequest(); String fromTag = ct.from.getTag(); Event hisEvent = ct.event; // Event header is mandatory but some slopply clients // dont include it. if (hisEvent == null) continue; if (ct.method.equals(Request.SUBSCRIBE) && fromTag.equalsIgnoreCase(thisToTag) && hisEvent != null && eventHdr.match(hisEvent) && notifyMessage.getCallId().getCallId().equalsIgnoreCase(ct.callId.getCallId())) return ct; } } return null; }