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;
}
Aggregations