Search in sources :

Example 6 with SIPHeader

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;
}
Also used : SIPHeader(gov.nist.javax.sip.header.SIPHeader)

Example 7 with SIPHeader

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;
}
Also used : ViaHeader(javax.sip.header.ViaHeader) SIPHeader(gov.nist.javax.sip.header.SIPHeader) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ParseException(java.text.ParseException) ContentLength(gov.nist.javax.sip.header.ContentLength)

Example 8 with SIPHeader

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();
}
Also used : SIPHeader(gov.nist.javax.sip.header.SIPHeader) ContentLength(gov.nist.javax.sip.header.ContentLength)

Example 9 with SIPHeader

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;
}
Also used : SIPHeader(gov.nist.javax.sip.header.SIPHeader)

Example 10 with SIPHeader

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;
}
Also used : RequireList(gov.nist.javax.sip.header.RequireList) SessionExpires(gov.nist.javax.sip.header.extensions.SessionExpires) ReasonList(gov.nist.javax.sip.header.ReasonList) CSeq(gov.nist.javax.sip.header.CSeq) ContentType(gov.nist.javax.sip.header.ContentType) MaxForwards(gov.nist.javax.sip.header.MaxForwards) ContactList(gov.nist.javax.sip.header.ContactList) From(gov.nist.javax.sip.header.From) ReasonHeader(javax.sip.header.ReasonHeader) ParseException(java.text.ParseException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ViaList(gov.nist.javax.sip.header.ViaList) SIPHeader(gov.nist.javax.sip.header.SIPHeader) Iterator(java.util.Iterator) RecordRouteList(gov.nist.javax.sip.header.RecordRouteList) ServerHeader(javax.sip.header.ServerHeader) ContentLength(gov.nist.javax.sip.header.ContentLength) To(gov.nist.javax.sip.header.To)

Aggregations

SIPHeader (gov.nist.javax.sip.header.SIPHeader)16 ContentLength (gov.nist.javax.sip.header.ContentLength)8 SIPHeaderList (gov.nist.javax.sip.header.SIPHeaderList)5 CSeq (gov.nist.javax.sip.header.CSeq)4 From (gov.nist.javax.sip.header.From)4 MaxForwards (gov.nist.javax.sip.header.MaxForwards)4 To (gov.nist.javax.sip.header.To)4 ParseException (java.text.ParseException)4 CallID (gov.nist.javax.sip.header.CallID)3 InReplyTo (gov.nist.javax.sip.header.InReplyTo)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 RecordRouteList (gov.nist.javax.sip.header.RecordRouteList)2 LinkedList (java.util.LinkedList)2 InvalidArgumentException (javax.sip.InvalidArgumentException)2 ContactList (gov.nist.javax.sip.header.ContactList)1 ContentType (gov.nist.javax.sip.header.ContentType)1 RSeq (gov.nist.javax.sip.header.RSeq)1 ReasonList (gov.nist.javax.sip.header.ReasonList)1 Require (gov.nist.javax.sip.header.Require)1 RequireList (gov.nist.javax.sip.header.RequireList)1