Search in sources :

Example 6 with SIPHeaderList

use of gov.nist.javax.sip.header.SIPHeaderList in project XobotOS by xamarin.

the class SIPMessage method match.

/**
     * Template match for SIP messages. The matchObj is a SIPMessage template to match against.
     * This method allows you to do pattern matching with incoming SIP messages. Null matches wild
     * card.
     * 
     * @param other is the match template to match against.
     * @return true if a match occured and false otherwise.
     */
public boolean match(Object other) {
    if (other == null)
        return true;
    if (!other.getClass().equals(this.getClass()))
        return false;
    SIPMessage matchObj = (SIPMessage) other;
    Iterator<SIPHeader> li = matchObj.getHeaders();
    while (li.hasNext()) {
        SIPHeader hisHeaders = (SIPHeader) li.next();
        List<SIPHeader> myHeaders = this.getHeaderList(hisHeaders.getHeaderName());
        // Could not find a header to match his header.
        if (myHeaders == null || myHeaders.size() == 0)
            return false;
        if (hisHeaders instanceof SIPHeaderList) {
            ListIterator<?> outerIterator = ((SIPHeaderList<?>) hisHeaders).listIterator();
            while (outerIterator.hasNext()) {
                SIPHeader hisHeader = (SIPHeader) outerIterator.next();
                if (hisHeader instanceof ContentLength)
                    continue;
                ListIterator<?> innerIterator = myHeaders.listIterator();
                boolean found = false;
                while (innerIterator.hasNext()) {
                    SIPHeader myHeader = (SIPHeader) innerIterator.next();
                    if (myHeader.match(hisHeader)) {
                        found = true;
                        break;
                    }
                }
                if (!found)
                    return false;
            }
        } else {
            SIPHeader hisHeader = hisHeaders;
            ListIterator<SIPHeader> innerIterator = myHeaders.listIterator();
            boolean found = false;
            while (innerIterator.hasNext()) {
                SIPHeader myHeader = (SIPHeader) innerIterator.next();
                if (myHeader.match(hisHeader)) {
                    found = true;
                    break;
                }
            }
            if (!found)
                return false;
        }
    }
    return true;
}
Also used : SIPHeaderList(gov.nist.javax.sip.header.SIPHeaderList) SIPHeader(gov.nist.javax.sip.header.SIPHeader) ContentLength(gov.nist.javax.sip.header.ContentLength)

Aggregations

SIPHeaderList (gov.nist.javax.sip.header.SIPHeaderList)6 SIPHeader (gov.nist.javax.sip.header.SIPHeader)5 ContentLength (gov.nist.javax.sip.header.ContentLength)3 CSeq (gov.nist.javax.sip.header.CSeq)2 CallID (gov.nist.javax.sip.header.CallID)2 From (gov.nist.javax.sip.header.From)2 InReplyTo (gov.nist.javax.sip.header.InReplyTo)2 MaxForwards (gov.nist.javax.sip.header.MaxForwards)2 To (gov.nist.javax.sip.header.To)2 Token (gov.nist.core.Token)1 ParseException (java.text.ParseException)1 LinkedList (java.util.LinkedList)1 InvalidArgumentException (javax.sip.InvalidArgumentException)1