use of gov.nist.javax.sip.header.SIPHeader in project XobotOS by xamarin.
the class SIPMessage method equals.
/**
* Compare for equality.
*
* @param other -- the other object to compare with.
*/
public boolean equals(Object other) {
if (!other.getClass().equals(this.getClass())) {
return false;
}
SIPMessage otherMessage = (SIPMessage) other;
Collection<SIPHeader> values = this.nameTable.values();
Iterator<SIPHeader> it = values.iterator();
if (nameTable.size() != otherMessage.nameTable.size()) {
return false;
}
while (it.hasNext()) {
SIPHeader mine = (SIPHeader) it.next();
SIPHeader his = (SIPHeader) (otherMessage.nameTable.get(SIPHeaderNamesCache.toLowerCase(mine.getName())));
if (his == null) {
return false;
} else if (!his.equals(mine)) {
return false;
}
}
return true;
}
use of gov.nist.javax.sip.header.SIPHeader in project XobotOS by xamarin.
the class SIPMessage method encodeAsBytes.
/**
* Encode the message as a byte array. Use this when the message payload is a binary byte
* array.
*
* @return The Canonical byte array representation of the message (including the canonical
* byte array representation of the SDP payload if it exists all in one contiguous
* byte array).
*/
public byte[] encodeAsBytes(String transport) {
if (this instanceof SIPRequest && ((SIPRequest) this).isNullRequest()) {
return "\r\n\r\n".getBytes();
}
// JvB: added to fix case where application provides the wrong transport
// in the topmost Via header
ViaHeader topVia = (ViaHeader) this.getHeader(ViaHeader.NAME);
try {
topVia.setTransport(transport);
} catch (ParseException e) {
InternalErrorHandler.handleException(e);
}
StringBuffer encoding = new StringBuffer();
synchronized (this.headers) {
Iterator<SIPHeader> it = this.headers.iterator();
while (it.hasNext()) {
SIPHeader siphdr = (SIPHeader) it.next();
if (!(siphdr instanceof ContentLength))
siphdr.encode(encoding);
}
}
contentLengthHeader.encode(encoding);
encoding.append(NEWLINE);
byte[] retval = null;
byte[] content = this.getRawContent();
if (content != null) {
// Append the content
byte[] msgarray = null;
try {
msgarray = encoding.toString().getBytes(getCharset());
} catch (UnsupportedEncodingException ex) {
InternalErrorHandler.handleException(ex);
}
retval = new byte[msgarray.length + content.length];
System.arraycopy(msgarray, 0, retval, 0, msgarray.length);
System.arraycopy(content, 0, retval, msgarray.length, content.length);
} else {
try {
retval = encoding.toString().getBytes(getCharset());
} catch (UnsupportedEncodingException ex) {
InternalErrorHandler.handleException(ex);
}
}
return retval;
}
use of gov.nist.javax.sip.header.SIPHeader in project XobotOS by xamarin.
the class SIPMessage method encodeSIPHeaders.
/**
* Encode only the message and exclude the contents (for debugging);
*
* @return a string with all the headers encoded.
*/
protected String encodeSIPHeaders() {
StringBuffer encoding = new StringBuffer();
Iterator<SIPHeader> it = this.headers.iterator();
while (it.hasNext()) {
SIPHeader siphdr = (SIPHeader) it.next();
if (!(siphdr instanceof ContentLength))
siphdr.encode(encoding);
}
return contentLengthHeader.encode(encoding).append(NEWLINE).toString();
}
use of gov.nist.javax.sip.header.SIPHeader in project XobotOS by xamarin.
the class SIPMessage method clone.
/**
* clone this message (create a new deep physical copy). All headers in the message are
* cloned. You can modify the cloned copy without affecting the original. The content is
* handled as follows: If the content is a String, or a byte array, a new copy of the content
* is allocated and copied over. If the content is an Object that supports the clone method,
* then the clone method is invoked and the cloned content is the new content. Otherwise, the
* content of the new message is set equal to the old one.
*
* @return A cloned copy of this object.
*/
public Object clone() {
SIPMessage retval = (SIPMessage) super.clone();
retval.nameTable = new Hashtable<String, SIPHeader>();
retval.fromHeader = null;
retval.toHeader = null;
retval.cSeqHeader = null;
retval.callIdHeader = null;
retval.contentLengthHeader = null;
retval.maxForwardsHeader = null;
if (this.headers != null) {
retval.headers = new ConcurrentLinkedQueue<SIPHeader>();
for (Iterator<SIPHeader> iter = headers.iterator(); iter.hasNext(); ) {
SIPHeader hdr = (SIPHeader) iter.next();
retval.attachHeader((SIPHeader) hdr.clone());
}
}
if (this.messageContentBytes != null)
retval.messageContentBytes = (byte[]) this.messageContentBytes.clone();
if (this.messageContentObject != null)
retval.messageContentObject = makeClone(messageContentObject);
retval.unrecognizedHeaders = this.unrecognizedHeaders;
return retval;
}
use of gov.nist.javax.sip.header.SIPHeader in project XobotOS by xamarin.
the class SIPResponse method createRequest.
/**
* Generate a request from a response.
*
* @param requestURI -- the request URI to assign to the request.
* @param via -- the Via header to assign to the request
* @param cseq -- the CSeq header to assign to the request
* @param from -- the From header to assign to the request
* @param to -- the To header to assign to the request
* @return -- the newly generated sip request.
*/
public SIPRequest createRequest(SipUri requestURI, Via via, CSeq cseq, From from, To to) {
SIPRequest newRequest = new SIPRequest();
String method = cseq.getMethod();
newRequest.setMethod(method);
newRequest.setRequestURI(requestURI);
this.setBranch(via, method);
newRequest.setHeader(via);
newRequest.setHeader(cseq);
Iterator headerIterator = getHeaders();
while (headerIterator.hasNext()) {
SIPHeader nextHeader = (SIPHeader) headerIterator.next();
// Some headers do not belong in a Request ....
if (SIPMessage.isResponseHeader(nextHeader) || nextHeader instanceof ViaList || nextHeader instanceof CSeq || nextHeader instanceof ContentType || nextHeader instanceof ContentLength || nextHeader instanceof RecordRouteList || nextHeader instanceof RequireList || // JvB: added
nextHeader instanceof ContactList || nextHeader instanceof ContentLength || nextHeader instanceof ServerHeader || nextHeader instanceof ReasonHeader || nextHeader instanceof SessionExpires || nextHeader instanceof ReasonList) {
continue;
}
if (nextHeader instanceof To)
nextHeader = (SIPHeader) to;
else if (nextHeader instanceof From)
nextHeader = (SIPHeader) from;
try {
newRequest.attachHeader(nextHeader, false);
} catch (SIPDuplicateHeaderException e) {
//Should not happen!
e.printStackTrace();
}
}
try {
// JvB: all requests need a Max-Forwards
newRequest.attachHeader(new MaxForwards(70), false);
} catch (Exception d) {
}
if (MessageFactoryImpl.getDefaultUserAgentHeader() != null) {
newRequest.setHeader(MessageFactoryImpl.getDefaultUserAgentHeader());
}
return newRequest;
}
Aggregations