Search in sources :

Example 1 with CSeq

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

the class SIPDialog method createAck.

/*
     * (non-Javadoc) The UAC core MUST generate an ACK request for each 2xx received from the
     * transaction layer. The header fields of the ACK are constructed in the same way as for any
     * request sent within a dialog (see Section 12) with the exception of the CSeq and the header
     * fields related to authentication. The sequence number of the CSeq header field MUST be the
     * same as the INVITE being acknowledged, but the CSeq method MUST be ACK. The ACK MUST
     * contain the same credentials as the INVITE. If the 2xx contains an offer (based on the
     * rules above), the ACK MUST carry an answer in its body. If the offer in the 2xx response is
     * not acceptable, the UAC core MUST generate a valid answer in the ACK and then send a BYE
     * immediately.
     * 
     * Note that for the case of forked requests, you can create multiple outgoing invites each
     * with a different cseq and hence you need to supply the invite.
     * 
     * @see javax.sip.Dialog#createAck(long)
     */
public Request createAck(long cseqno) throws InvalidArgumentException, SipException {
    // then send INVITE+ACK later on
    if (!method.equals(Request.INVITE))
        throw new SipException("Dialog was not created with an INVITE" + method);
    if (cseqno <= 0)
        throw new InvalidArgumentException("bad cseq <= 0 ");
    else if (cseqno > ((((long) 1) << 32) - 1))
        throw new InvalidArgumentException("bad cseq > " + ((((long) 1) << 32) - 1));
    if (this.remoteTarget == null) {
        throw new SipException("Cannot create ACK - no remote Target!");
    }
    if (this.sipStack.isLoggingEnabled()) {
        this.sipStack.getStackLogger().logDebug("createAck " + this + " cseqno " + cseqno);
    }
    // out of order ACK sending. Old ACKs seqno's can always be ACKed.
    if (lastInviteOkReceived < cseqno) {
        if (sipStack.isLoggingEnabled()) {
            this.sipStack.getStackLogger().logDebug("WARNING : Attempt to crete ACK without OK " + this);
            this.sipStack.getStackLogger().logDebug("LAST RESPONSE = " + this.lastResponse);
        }
        throw new SipException("Dialog not yet established -- no OK response!");
    }
    try {
        // JvB: Transport from first entry in route set, or remote Contact
        // if none
        // Only used to find correct LP & create correct Via
        SipURI uri4transport = null;
        if (this.routeList != null && !this.routeList.isEmpty()) {
            Route r = (Route) this.routeList.getFirst();
            uri4transport = ((SipURI) r.getAddress().getURI());
        } else {
            // should be !=null, checked above
            uri4transport = ((SipURI) this.remoteTarget.getURI());
        }
        String transport = uri4transport.getTransportParam();
        if (transport == null) {
            // JvB fix: also support TLS
            transport = uri4transport.isSecure() ? ListeningPoint.TLS : ListeningPoint.UDP;
        }
        ListeningPointImpl lp = (ListeningPointImpl) sipProvider.getListeningPoint(transport);
        if (lp == null) {
            if (sipStack.isLoggingEnabled()) {
                sipStack.getStackLogger().logError("remoteTargetURI " + this.remoteTarget.getURI());
                sipStack.getStackLogger().logError("uri4transport = " + uri4transport);
                sipStack.getStackLogger().logError("No LP found for transport=" + transport);
            }
            throw new SipException("Cannot create ACK - no ListeningPoint for transport towards next hop found:" + transport);
        }
        SIPRequest sipRequest = new SIPRequest();
        sipRequest.setMethod(Request.ACK);
        sipRequest.setRequestURI((SipUri) getRemoteTarget().getURI().clone());
        sipRequest.setCallId(this.callIdHeader);
        sipRequest.setCSeq(new CSeq(cseqno, Request.ACK));
        List<Via> vias = new ArrayList<Via>();
        // Via via = lp.getViaHeader();
        // The user may have touched the sentby for the response.
        // so use the via header extracted from the response for the ACK =>
        // https://jain-sip.dev.java.net/issues/show_bug.cgi?id=205
        // strip the params from the via of the response and use the params from the
        // original request
        Via via = this.lastResponse.getTopmostVia();
        via.removeParameters();
        if (originalRequest != null && originalRequest.getTopmostVia() != null) {
            NameValueList originalRequestParameters = originalRequest.getTopmostVia().getParameters();
            if (originalRequestParameters != null && originalRequestParameters.size() > 0) {
                via.setParameters((NameValueList) originalRequestParameters.clone());
            }
        }
        // new branch
        via.setBranch(Utils.getInstance().generateBranchId());
        vias.add(via);
        sipRequest.setVia(vias);
        From from = new From();
        from.setAddress(this.localParty);
        from.setTag(this.myTag);
        sipRequest.setFrom(from);
        To to = new To();
        to.setAddress(this.remoteParty);
        if (hisTag != null)
            to.setTag(this.hisTag);
        sipRequest.setTo(to);
        sipRequest.setMaxForwards(new MaxForwards(70));
        if (this.originalRequest != null) {
            Authorization authorization = this.originalRequest.getAuthorization();
            if (authorization != null)
                sipRequest.setHeader(authorization);
        }
        // ACKs for 2xx responses
        // use the Route values learned from the Record-Route of the 2xx
        // responses.
        this.updateRequest(sipRequest);
        return sipRequest;
    } catch (Exception ex) {
        InternalErrorHandler.handleException(ex);
        throw new SipException("unexpected exception ", ex);
    }
}
Also used : ListeningPointImpl(gov.nist.javax.sip.ListeningPointImpl) CSeq(gov.nist.javax.sip.header.CSeq) NameValueList(gov.nist.core.NameValueList) ArrayList(java.util.ArrayList) MaxForwards(gov.nist.javax.sip.header.MaxForwards) From(gov.nist.javax.sip.header.From) 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) Authorization(gov.nist.javax.sip.header.Authorization) InvalidArgumentException(javax.sip.InvalidArgumentException) To(gov.nist.javax.sip.header.To) SipException(javax.sip.SipException) RecordRoute(gov.nist.javax.sip.header.RecordRoute) Route(gov.nist.javax.sip.header.Route)

Example 2 with CSeq

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

the class SIPMessage method removeHeader.

/**
     * Remove a header given its name. If multiple headers of a given name are present then the
     * top flag determines which end to remove headers from.
     * 
     * @param headerName is the name of the header to remove.
     * @param top -- flag that indicates which end of header list to process.
     */
public void removeHeader(String headerName, boolean top) {
    String headerNameLowerCase = SIPHeaderNamesCache.toLowerCase(headerName);
    SIPHeader toRemove = (SIPHeader) nameTable.get(headerNameLowerCase);
    // nothing to do then we are done.
    if (toRemove == null)
        return;
    if (toRemove instanceof SIPHeaderList) {
        SIPHeaderList<?> hdrList = (SIPHeaderList<?>) toRemove;
        if (top)
            hdrList.removeFirst();
        else
            hdrList.removeLast();
        // Clean up empty list
        if (hdrList.isEmpty()) {
            Iterator<SIPHeader> li = this.headers.iterator();
            while (li.hasNext()) {
                SIPHeader sipHeader = (SIPHeader) li.next();
                if (sipHeader.getName().equalsIgnoreCase(headerNameLowerCase))
                    li.remove();
            }
            // JvB: also remove it from the nameTable! Else NPE in
            // DefaultRouter
            nameTable.remove(headerNameLowerCase);
        }
    } else {
        this.nameTable.remove(headerNameLowerCase);
        if (toRemove instanceof From) {
            this.fromHeader = null;
        } else if (toRemove instanceof To) {
            this.toHeader = null;
        } else if (toRemove instanceof CSeq) {
            this.cSeqHeader = null;
        } else if (toRemove instanceof CallID) {
            this.callIdHeader = null;
        } else if (toRemove instanceof MaxForwards) {
            this.maxForwardsHeader = null;
        } else if (toRemove instanceof ContentLength) {
            this.contentLengthHeader = null;
        }
        Iterator<SIPHeader> li = this.headers.iterator();
        while (li.hasNext()) {
            SIPHeader sipHeader = (SIPHeader) li.next();
            if (sipHeader.getName().equalsIgnoreCase(headerName))
                li.remove();
        }
    }
}
Also used : SIPHeaderList(gov.nist.javax.sip.header.SIPHeaderList) CSeq(gov.nist.javax.sip.header.CSeq) SIPHeader(gov.nist.javax.sip.header.SIPHeader) CallID(gov.nist.javax.sip.header.CallID) MaxForwards(gov.nist.javax.sip.header.MaxForwards) From(gov.nist.javax.sip.header.From) To(gov.nist.javax.sip.header.To) InReplyTo(gov.nist.javax.sip.header.InReplyTo) ContentLength(gov.nist.javax.sip.header.ContentLength)

Example 3 with CSeq

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

the class SIPMessage method removeHeader.

/**
     * Remove all headers given its name.
     * 
     * @param headerName is the name of the header to remove.
     */
public void removeHeader(String headerName) {
    if (headerName == null)
        throw new NullPointerException("null arg");
    String headerNameLowerCase = SIPHeaderNamesCache.toLowerCase(headerName);
    SIPHeader removed = (SIPHeader) nameTable.remove(headerNameLowerCase);
    // nothing to do then we are done.
    if (removed == null)
        return;
    // Remove the fast accessor fields.
    if (removed instanceof From) {
        this.fromHeader = null;
    } else if (removed instanceof To) {
        this.toHeader = null;
    } else if (removed instanceof CSeq) {
        this.cSeqHeader = null;
    } else if (removed instanceof CallID) {
        this.callIdHeader = null;
    } else if (removed instanceof MaxForwards) {
        this.maxForwardsHeader = null;
    } else if (removed instanceof ContentLength) {
        this.contentLengthHeader = null;
    }
    Iterator<SIPHeader> li = this.headers.iterator();
    while (li.hasNext()) {
        SIPHeader sipHeader = (SIPHeader) li.next();
        if (sipHeader.getName().equalsIgnoreCase(headerNameLowerCase))
            li.remove();
    }
}
Also used : CSeq(gov.nist.javax.sip.header.CSeq) SIPHeader(gov.nist.javax.sip.header.SIPHeader) CallID(gov.nist.javax.sip.header.CallID) MaxForwards(gov.nist.javax.sip.header.MaxForwards) From(gov.nist.javax.sip.header.From) To(gov.nist.javax.sip.header.To) InReplyTo(gov.nist.javax.sip.header.InReplyTo) ContentLength(gov.nist.javax.sip.header.ContentLength)

Example 4 with CSeq

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

the class SIPMessage method attachHeader.

/**
     * Attach the header to the SIP Message structure at a specified position in its list of
     * headers.
     * 
     * @param header Header to attach.
     * @param replaceFlag If true then replace the existing header.
     * @param top Location in the header list to insert the header.
     * @exception SIPDuplicateHeaderException if the header is of a type that cannot tolerate
     *            duplicates and one of this type already exists (e.g. CSeq header).
     * @throws IndexOutOfBoundsException If the index specified is greater than the number of
     *         headers that are in this message.
     */
public void attachHeader(SIPHeader header, boolean replaceFlag, boolean top) throws SIPDuplicateHeaderException {
    if (header == null) {
        throw new NullPointerException("null header");
    }
    SIPHeader h;
    if (ListMap.hasList(header) && !SIPHeaderList.class.isAssignableFrom(header.getClass())) {
        SIPHeaderList<SIPHeader> hdrList = ListMap.getList(header);
        hdrList.add(header);
        h = hdrList;
    } else {
        h = header;
    }
    String headerNameLowerCase = SIPHeaderNamesCache.toLowerCase(h.getName());
    if (replaceFlag) {
        nameTable.remove(headerNameLowerCase);
    } else if (nameTable.containsKey(headerNameLowerCase) && !(h instanceof SIPHeaderList)) {
        if (h instanceof ContentLength) {
            try {
                ContentLength cl = (ContentLength) h;
                contentLengthHeader.setContentLength(cl.getContentLength());
            } catch (InvalidArgumentException e) {
            }
        }
        // Just ignore duplicate header.
        return;
    }
    SIPHeader originalHeader = (SIPHeader) getHeader(header.getName());
    // Delete the original header from our list structure.
    if (originalHeader != null) {
        Iterator<SIPHeader> li = headers.iterator();
        while (li.hasNext()) {
            SIPHeader next = (SIPHeader) li.next();
            if (next.equals(originalHeader)) {
                li.remove();
            }
        }
    }
    if (!nameTable.containsKey(headerNameLowerCase)) {
        nameTable.put(headerNameLowerCase, h);
        headers.add(h);
    } else {
        if (h instanceof SIPHeaderList) {
            SIPHeaderList<?> hdrlist = (SIPHeaderList<?>) nameTable.get(headerNameLowerCase);
            if (hdrlist != null)
                hdrlist.concatenate((SIPHeaderList) h, top);
            else
                nameTable.put(headerNameLowerCase, h);
        } else {
            nameTable.put(headerNameLowerCase, h);
        }
    }
    // Direct accessor fields for frequently accessed headers.
    if (h instanceof From) {
        this.fromHeader = (From) h;
    } else if (h instanceof ContentLength) {
        this.contentLengthHeader = (ContentLength) h;
    } else if (h instanceof To) {
        this.toHeader = (To) h;
    } else if (h instanceof CSeq) {
        this.cSeqHeader = (CSeq) h;
    } else if (h instanceof CallID) {
        this.callIdHeader = (CallID) h;
    } else if (h instanceof MaxForwards) {
        this.maxForwardsHeader = (MaxForwards) h;
    }
}
Also used : SIPHeaderList(gov.nist.javax.sip.header.SIPHeaderList) CSeq(gov.nist.javax.sip.header.CSeq) CallID(gov.nist.javax.sip.header.CallID) MaxForwards(gov.nist.javax.sip.header.MaxForwards) From(gov.nist.javax.sip.header.From) InvalidArgumentException(javax.sip.InvalidArgumentException) SIPHeader(gov.nist.javax.sip.header.SIPHeader) ContentLength(gov.nist.javax.sip.header.ContentLength) To(gov.nist.javax.sip.header.To) InReplyTo(gov.nist.javax.sip.header.InReplyTo)

Example 5 with CSeq

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

the class SIPDialog method handlePrack.

/**
     * Do the processing necessary for the PRACK
     * 
     * @param prackRequest
     * @return true if this is the first time the tx has seen the prack ( and hence needs to be
     *         passed up to the TU)
     */
public boolean handlePrack(SIPRequest prackRequest) {
    /*
         * The RAck header is sent in a PRACK request to support reliability of provisional
         * responses. It contains two numbers and a method tag. The first number is the value from
         * the RSeq header in the provisional response that is being acknowledged. The next
         * number, and the method, are copied from the CSeq in the response that is being
         * acknowledged. The method name in the RAck header is case sensitive.
         */
    if (!this.isServer()) {
        if (sipStack.isLoggingEnabled())
            sipStack.getStackLogger().logDebug("Dropping Prack -- not a server Dialog");
        return false;
    }
    SIPServerTransaction sipServerTransaction = (SIPServerTransaction) this.getFirstTransaction();
    SIPResponse sipResponse = sipServerTransaction.getReliableProvisionalResponse();
    if (sipResponse == null) {
        if (sipStack.isLoggingEnabled())
            sipStack.getStackLogger().logDebug("Dropping Prack -- ReliableResponse not found");
        return false;
    }
    RAck rack = (RAck) prackRequest.getHeader(RAckHeader.NAME);
    if (rack == null) {
        if (sipStack.isLoggingEnabled())
            sipStack.getStackLogger().logDebug("Dropping Prack -- rack header not found");
        return false;
    }
    CSeq cseq = (CSeq) sipResponse.getCSeq();
    if (!rack.getMethod().equals(cseq.getMethod())) {
        if (sipStack.isLoggingEnabled())
            sipStack.getStackLogger().logDebug("Dropping Prack -- CSeq Header does not match PRACK");
        return false;
    }
    if (rack.getCSeqNumberLong() != cseq.getSeqNumber()) {
        if (sipStack.isLoggingEnabled())
            sipStack.getStackLogger().logDebug("Dropping Prack -- CSeq Header does not match PRACK");
        return false;
    }
    RSeq rseq = (RSeq) sipResponse.getHeader(RSeqHeader.NAME);
    if (rack.getRSequenceNumber() != rseq.getSeqNumber()) {
        if (sipStack.isLoggingEnabled())
            sipStack.getStackLogger().logDebug("Dropping Prack -- RSeq Header does not match PRACK");
        return false;
    }
    return sipServerTransaction.prackRecieved();
}
Also used : SIPResponse(gov.nist.javax.sip.message.SIPResponse) RAck(gov.nist.javax.sip.header.RAck) CSeq(gov.nist.javax.sip.header.CSeq) RSeq(gov.nist.javax.sip.header.RSeq)

Aggregations

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