Search in sources :

Example 6 with From

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

the class FromParser method parse.

public SIPHeader parse() throws ParseException {
    From from = new From();
    this.lexer.match(TokenTypes.FROM);
    this.lexer.SPorHT();
    this.lexer.match(':');
    this.lexer.SPorHT();
    super.parse(from);
    this.lexer.match('\n');
    return from;
}
Also used : From(gov.nist.javax.sip.header.From)

Example 7 with From

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

the class SIPResponse method getDialogId.

public String getDialogId(boolean isServer, String toTag) {
    CallID cid = (CallID) this.getCallId();
    From from = (From) this.getFrom();
    StringBuffer retval = new StringBuffer(cid.getCallId());
    if (!isServer) {
        //retval.append(COLON).append(from.getUserAtHostPort());
        if (from.getTag() != null) {
            retval.append(COLON);
            retval.append(from.getTag());
        }
        //retval.append(COLON).append(to.getUserAtHostPort());
        if (toTag != null) {
            retval.append(COLON);
            retval.append(toTag);
        }
    } else {
        //retval.append(COLON).append(to.getUserAtHostPort());
        if (toTag != null) {
            retval.append(COLON);
            retval.append(toTag);
        }
        //retval.append(COLON).append(from.getUserAtHostPort());
        if (from.getTag() != null) {
            retval.append(COLON);
            retval.append(from.getTag());
        }
    }
    return retval.toString().toLowerCase();
}
Also used : CallID(gov.nist.javax.sip.header.CallID) From(gov.nist.javax.sip.header.From)

Example 8 with From

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

the class SIPResponse method getDialogId.

/** Get a dialog identifier.
     * Generates a string that can be used as a dialog identifier.
     *
     * @param isServer is set to true if this is the UAS
     * and set to false if this is the UAC
     */
public String getDialogId(boolean isServer) {
    CallID cid = (CallID) this.getCallId();
    From from = (From) this.getFrom();
    To to = (To) this.getTo();
    StringBuffer retval = new StringBuffer(cid.getCallId());
    if (!isServer) {
        //retval.append(COLON).append(from.getUserAtHostPort());
        if (from.getTag() != null) {
            retval.append(COLON);
            retval.append(from.getTag());
        }
        //retval.append(COLON).append(to.getUserAtHostPort());
        if (to.getTag() != null) {
            retval.append(COLON);
            retval.append(to.getTag());
        }
    } else {
        //retval.append(COLON).append(to.getUserAtHostPort());
        if (to.getTag() != null) {
            retval.append(COLON);
            retval.append(to.getTag());
        }
        //retval.append(COLON).append(from.getUserAtHostPort());
        if (from.getTag() != null) {
            retval.append(COLON);
            retval.append(from.getTag());
        }
    }
    return retval.toString().toLowerCase();
}
Also used : CallID(gov.nist.javax.sip.header.CallID) From(gov.nist.javax.sip.header.From) To(gov.nist.javax.sip.header.To)

Example 9 with From

use of gov.nist.javax.sip.header.From 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)

Example 10 with From

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

the class SIPMessage method getTransactionId.

/**
     * Generate (compute) a transaction ID for this SIP message.
     * 
     * @return A string containing the concatenation of various portions of the From,To,Via and
     *         RequestURI portions of this message as specified in RFC 2543: All responses to a
     *         request contain the same values in the Call-ID, CSeq, To, and From fields (with the
     *         possible addition of a tag in the To field (section 10.43)). This allows responses
     *         to be matched with requests. Incorporates a bug fix for a bug sent in by Gordon
     *         Ledgard of IPera for generating transactionIDs when no port is present in the via
     *         header. Incorporates a bug fix for a bug report sent in by Chris Mills of Nortel
     *         Networks (converts to lower case when returning the transaction identifier).
     * 
     * @return a string that can be used as a transaction identifier for this message. This can be
     *         used for matching responses and requests (i.e. an outgoing request and its matching
     *         response have the same computed transaction identifier).
     */
public String getTransactionId() {
    Via topVia = null;
    if (!this.getViaHeaders().isEmpty()) {
        topVia = (Via) this.getViaHeaders().getFirst();
    }
    // Branch Id prefix is not case sensitive.
    if (topVia != null && topVia.getBranch() != null && topVia.getBranch().toUpperCase().startsWith(SIPConstants.BRANCH_MAGIC_COOKIE_UPPER_CASE)) {
        // identifier.
        if (this.getCSeq().getMethod().equals(Request.CANCEL))
            return (topVia.getBranch() + ":" + this.getCSeq().getMethod()).toLowerCase();
        else
            return topVia.getBranch().toLowerCase();
    } else {
        // Old style client so construct the transaction identifier
        // from various fields of the request.
        StringBuffer retval = new StringBuffer();
        From from = (From) this.getFrom();
        To to = (To) this.getTo();
        // retval.append(hpFrom).append(":");
        if (from.hasTag())
            retval.append(from.getTag()).append("-");
        // String hpTo = to.getUserAtHostPort();
        // retval.append(hpTo).append(":");
        String cid = this.callIdHeader.getCallId();
        retval.append(cid).append("-");
        retval.append(this.cSeqHeader.getSequenceNumber()).append("-").append(this.cSeqHeader.getMethod());
        if (topVia != null) {
            retval.append("-").append(topVia.getSentBy().encode());
            if (!topVia.getSentBy().hasPort()) {
                retval.append("-").append(5060);
            }
        }
        if (this.getCSeq().getMethod().equals(Request.CANCEL)) {
            retval.append(Request.CANCEL);
        }
        return retval.toString().toLowerCase().replace(":", "-").replace("@", "-") + Utils.getSignature();
    }
}
Also used : From(gov.nist.javax.sip.header.From) To(gov.nist.javax.sip.header.To) InReplyTo(gov.nist.javax.sip.header.InReplyTo) Via(gov.nist.javax.sip.header.Via)

Aggregations

From (gov.nist.javax.sip.header.From)11 To (gov.nist.javax.sip.header.To)9 CSeq (gov.nist.javax.sip.header.CSeq)6 CallID (gov.nist.javax.sip.header.CallID)5 MaxForwards (gov.nist.javax.sip.header.MaxForwards)5 ContentLength (gov.nist.javax.sip.header.ContentLength)4 InReplyTo (gov.nist.javax.sip.header.InReplyTo)4 SIPHeader (gov.nist.javax.sip.header.SIPHeader)4 Via (gov.nist.javax.sip.header.Via)4 ParseException (java.text.ParseException)4 InvalidArgumentException (javax.sip.InvalidArgumentException)4 SIPRequest (gov.nist.javax.sip.message.SIPRequest)3 IOException (java.io.IOException)3 DialogDoesNotExistException (javax.sip.DialogDoesNotExistException)3 ObjectInUseException (javax.sip.ObjectInUseException)3 SipException (javax.sip.SipException)3 TransactionDoesNotExistException (javax.sip.TransactionDoesNotExistException)3 ListeningPointImpl (gov.nist.javax.sip.ListeningPointImpl)2 SIPHeaderList (gov.nist.javax.sip.header.SIPHeaderList)2 SipURI (javax.sip.address.SipURI)2