Search in sources :

Example 6 with To

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

the class SIPDialog method createRequest.

/**
     * The method that actually does the work of creating a request.
     * 
     * @param method
     * @param response
     * @return
     * @throws SipException
     */
private Request createRequest(String method, SIPResponse sipResponse) throws SipException {
    if (method == null || sipResponse == null)
        throw new NullPointerException("null argument");
    if (method.equals(Request.CANCEL))
        throw new SipException("Dialog.createRequest(): Invalid request");
    if (this.getState() == null || (this.getState().getValue() == TERMINATED_STATE && !method.equalsIgnoreCase(Request.BYE)) || (this.isServer() && this.getState().getValue() == EARLY_STATE && method.equalsIgnoreCase(Request.BYE)))
        throw new SipException("Dialog  " + getDialogId() + " not yet established or terminated " + this.getState());
    SipUri sipUri = null;
    if (this.getRemoteTarget() != null)
        sipUri = (SipUri) this.getRemoteTarget().getURI().clone();
    else {
        sipUri = (SipUri) this.getRemoteParty().getURI().clone();
        sipUri.clearUriParms();
    }
    CSeq cseq = new CSeq();
    try {
        cseq.setMethod(method);
        cseq.setSeqNumber(this.getLocalSeqNumber());
    } catch (Exception ex) {
        if (sipStack.isLoggingEnabled())
            sipStack.getStackLogger().logError("Unexpected error");
        InternalErrorHandler.handleException(ex);
    }
    /*
         * Add a via header for the outbound request based on the transport of the message
         * processor.
         */
    ListeningPointImpl lp = (ListeningPointImpl) this.sipProvider.getListeningPoint(sipResponse.getTopmostVia().getTransport());
    if (lp == null) {
        if (sipStack.isLoggingEnabled())
            sipStack.getStackLogger().logError("Cannot find listening point for transport " + sipResponse.getTopmostVia().getTransport());
        throw new SipException("Cannot find listening point for transport " + sipResponse.getTopmostVia().getTransport());
    }
    Via via = lp.getViaHeader();
    From from = new From();
    from.setAddress(this.localParty);
    To to = new To();
    to.setAddress(this.remoteParty);
    SIPRequest sipRequest = sipResponse.createRequest(sipUri, via, cseq, from, to);
    if (SIPRequest.isTargetRefresh(method)) {
        ContactHeader contactHeader = ((ListeningPointImpl) this.sipProvider.getListeningPoint(lp.getTransport())).createContactHeader();
        ((SipURI) contactHeader.getAddress().getURI()).setSecure(this.isSecure());
        sipRequest.setHeader(contactHeader);
    }
    try {
        /*
             * Guess of local sequence number - this is being re-set when the request is actually
             * dispatched
             */
        cseq = (CSeq) sipRequest.getCSeq();
        cseq.setSeqNumber(this.localSequenceNumber + 1);
    } catch (InvalidArgumentException ex) {
        InternalErrorHandler.handleException(ex);
    }
    if (method.equals(Request.SUBSCRIBE)) {
        if (eventHeader != null)
            sipRequest.addHeader(eventHeader);
    }
    try {
        if (this.getLocalTag() != null) {
            from.setTag(this.getLocalTag());
        } else {
            from.removeTag();
        }
        if (this.getRemoteTag() != null) {
            to.setTag(this.getRemoteTag());
        } else {
            to.removeTag();
        }
    } catch (ParseException ex) {
        InternalErrorHandler.handleException(ex);
    }
    // get the route list from the dialog.
    this.updateRequest(sipRequest);
    return sipRequest;
}
Also used : ContactHeader(javax.sip.header.ContactHeader) ListeningPointImpl(gov.nist.javax.sip.ListeningPointImpl) CSeq(gov.nist.javax.sip.header.CSeq) From(gov.nist.javax.sip.header.From) SipUri(gov.nist.javax.sip.address.SipUri) SipURI(javax.sip.address.SipURI) SIPRequest(gov.nist.javax.sip.message.SIPRequest) DialogDoesNotExistException(javax.sip.DialogDoesNotExistException) InvalidArgumentException(javax.sip.InvalidArgumentException) ParseException(java.text.ParseException) ObjectInUseException(javax.sip.ObjectInUseException) SipException(javax.sip.SipException) IOException(java.io.IOException) TransactionDoesNotExistException(javax.sip.TransactionDoesNotExistException) Via(gov.nist.javax.sip.header.Via) InvalidArgumentException(javax.sip.InvalidArgumentException) To(gov.nist.javax.sip.header.To) ParseException(java.text.ParseException) SipException(javax.sip.SipException)

Example 7 with To

use of gov.nist.javax.sip.header.To 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 8 with To

use of gov.nist.javax.sip.header.To 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 9 with To

use of gov.nist.javax.sip.header.To 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)9 To (gov.nist.javax.sip.header.To)9 CSeq (gov.nist.javax.sip.header.CSeq)6 MaxForwards (gov.nist.javax.sip.header.MaxForwards)5 CallID (gov.nist.javax.sip.header.CallID)4 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