use of gov.nist.javax.sip.header.SIPHeader in project XobotOS by xamarin.
the class SIPMessage method getHeaderNames.
/**
* Get the header names.
*
* @return a list iterator to a list of header names. These are ordered in the same order as
* are present in the message.
*/
public ListIterator<String> getHeaderNames() {
Iterator<SIPHeader> li = this.headers.iterator();
LinkedList<String> retval = new LinkedList<String>();
while (li.hasNext()) {
SIPHeader sipHeader = (SIPHeader) li.next();
String name = sipHeader.getName();
retval.add(name);
}
return retval.listIterator();
}
use of gov.nist.javax.sip.header.SIPHeader in project XobotOS by xamarin.
the class SIPMessage method getMessageAsEncodedStrings.
/**
* Get the headers as a linked list of encoded Strings
*
* @return a linked list with each element of the list containing a string encoded header in
* canonical form.
*/
public LinkedList<String> getMessageAsEncodedStrings() {
LinkedList<String> retval = new LinkedList<String>();
Iterator<SIPHeader> li = headers.iterator();
while (li.hasNext()) {
SIPHeader sipHeader = (SIPHeader) li.next();
if (sipHeader instanceof SIPHeaderList) {
SIPHeaderList<?> shl = (SIPHeaderList<?>) sipHeader;
retval.addAll(shl.getHeadersAsEncodedStrings());
} else {
retval.add(sipHeader.encode());
}
}
return retval;
}
use of gov.nist.javax.sip.header.SIPHeader in project XobotOS by xamarin.
the class SIPMessage method setHeader.
/**
* Attach a header (replacing the original header).
*
* @param sipHeader SIPHeader that replaces a header of the same type.
*/
public void setHeader(Header sipHeader) {
SIPHeader header = (SIPHeader) sipHeader;
if (header == null)
throw new IllegalArgumentException("null header!");
try {
if (header instanceof SIPHeaderList) {
SIPHeaderList<?> hl = (SIPHeaderList<?>) header;
// Ignore empty lists.
if (hl.isEmpty())
return;
}
this.removeHeader(header.getHeaderName());
attachHeader(header, true, false);
} catch (SIPDuplicateHeaderException ex) {
InternalErrorHandler.handleException(ex);
}
}
use of gov.nist.javax.sip.header.SIPHeader in project XobotOS by xamarin.
the class SIPMessage method merge.
/**
* Merge a request with a template
*
* @param template -- template to merge with.
*
*/
public void merge(Object template) {
if (!template.getClass().equals(this.getClass()))
throw new IllegalArgumentException("Bad class " + template.getClass());
SIPMessage templateMessage = (SIPMessage) template;
Object[] templateHeaders = templateMessage.headers.toArray();
for (int i = 0; i < templateHeaders.length; i++) {
SIPHeader hdr = (SIPHeader) templateHeaders[i];
String hdrName = hdr.getHeaderName();
List<SIPHeader> myHdrs = this.getHeaderList(hdrName);
if (myHdrs == null) {
this.attachHeader(hdr);
} else {
ListIterator<SIPHeader> it = myHdrs.listIterator();
while (it.hasNext()) {
SIPHeader sipHdr = (SIPHeader) it.next();
sipHdr.merge(hdr);
}
}
}
}
use of gov.nist.javax.sip.header.SIPHeader 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