コード例 #1
0
  /**
   * Creates a default SIPResquest message that would cancel this request. Note that tag assignment
   * and removal of is left to the caller (we use whatever tags are present in the original
   * request).
   *
   * @return A CANCEL SIPRequest constructed according to RFC3261 section 9.1
   * @throws SipException
   * @throws ParseException
   */
  public SIPRequest createCancelRequest() throws SipException {

    // see RFC3261 9.1

    // A CANCEL request SHOULD NOT be sent to cancel a request other than
    // INVITE

    if (!this.getMethod().equals(Request.INVITE))
      throw new SipException("Attempt to create CANCEL for " + this.getMethod());

    /*
     * The following procedures are used to construct a CANCEL request. The Request-URI,
     * Call-ID, To, the numeric part of CSeq, and From header fields in the CANCEL request
     * MUST be identical to those in the request being cancelled, including tags. A CANCEL
     * constructed by a client MUST have only a single Via header field value matching the top
     * Via value in the request being cancelled. Using the same values for these header fields
     * allows the CANCEL to be matched with the request it cancels (Section 9.2 indicates how
     * such matching occurs). However, the method part of the CSeq header field MUST have a
     * value of CANCEL. This allows it to be identified and processed as a transaction in its
     * own right (See Section 17).
     */
    SIPRequest cancel = new SIPRequest();
    cancel.setRequestLine((RequestLine) this.requestLine.clone());
    cancel.setMethod(Request.CANCEL);
    cancel.setHeader((Header) this.callIdHeader.clone());
    cancel.setHeader((Header) this.toHeader.clone());
    cancel.setHeader((Header) cSeqHeader.clone());
    try {
      cancel.getCSeq().setMethod(Request.CANCEL);
    } catch (ParseException e) {
      e.printStackTrace(); // should not happen
    }
    cancel.setHeader((Header) this.fromHeader.clone());

    cancel.addFirst((Header) this.getTopmostVia().clone());
    cancel.setHeader((Header) this.maxForwardsHeader.clone());

    /*
     * If the request being cancelled contains a Route header field, the CANCEL request MUST
     * include that Route header field's values.
     */
    if (this.getRouteHeaders() != null) {
      cancel.setHeader((SIPHeaderList) this.getRouteHeaders().clone());
    }
    if (MessageFactoryImpl.getDefaultUserAgentHeader() != null) {
      cancel.setHeader(MessageFactoryImpl.getDefaultUserAgentHeader());
    }
    return cancel;
  }
コード例 #2
0
  /**
   * Creates an ACK for non-2xx responses according to RFC3261 17.1.1.3
   *
   * @return A SIPRequest with an ACK method.
   * @throws SipException
   * @throws NullPointerException
   * @throws ParseException
   * @author jvb
   */
  public final SIPRequest createErrorAck(To responseToHeader) throws SipException, ParseException {

    /*
     * The ACK request constructed by the client transaction MUST contain values for the
     * Call-ID, From, and Request-URI that are equal to the values of those header fields in
     * the request passed to the transport by the client transaction (call this the "original
     * request"). The To header field in the ACK MUST equal the To header field in the
     * response being acknowledged, and therefore will usually differ from the To header field
     * in the original request by the addition of the tag parameter. The ACK MUST contain a
     * single Via header field, and this MUST be equal to the top Via header field of the
     * original request. The CSeq header field in the ACK MUST contain the same value for the
     * sequence number as was present in the original request, but the method parameter MUST
     * be equal to "ACK".
     */
    SIPRequest newRequest = new SIPRequest();
    newRequest.setRequestLine((RequestLine) this.requestLine.clone());
    newRequest.setMethod(Request.ACK);
    newRequest.setHeader((Header) this.callIdHeader.clone());
    newRequest.setHeader((Header) this.maxForwardsHeader.clone()); // ISSUE
    // 130
    // fix
    newRequest.setHeader((Header) this.fromHeader.clone());
    newRequest.setHeader((Header) responseToHeader.clone());
    newRequest.addFirst((Header) this.getTopmostVia().clone());
    newRequest.setHeader((Header) cSeqHeader.clone());
    newRequest.getCSeq().setMethod(Request.ACK);

    /*
     * If the INVITE request whose response is being acknowledged had Route header fields,
     * those header fields MUST appear in the ACK. This is to ensure that the ACK can be
     * routed properly through any downstream stateless proxies.
     */
    if (this.getRouteHeaders() != null) {
      newRequest.setHeader((SIPHeaderList) this.getRouteHeaders().clone());
    }
    if (MessageFactoryImpl.getDefaultUserAgentHeader() != null) {
      newRequest.setHeader(MessageFactoryImpl.getDefaultUserAgentHeader());
    }
    return newRequest;
  }
コード例 #3
0
  /**
   * Creates a default ACK SIPRequest message for this original request. Note that the defaultACK
   * SIPRequest does not include the content of the original SIPRequest. If responseToHeader is null
   * then the toHeader of this request is used to construct the ACK. Note that tag fields are just
   * copied from the original SIP Request. Added by Jeff Keyser.
   *
   * @param responseToHeader To header to use for this request.
   * @return A SIPRequest with an ACK method.
   */
  public SIPRequest createAckRequest(To responseToHeader) {
    SIPRequest newRequest;
    Iterator headerIterator;
    SIPHeader nextHeader;

    newRequest = new SIPRequest();
    newRequest.setRequestLine((RequestLine) this.requestLine.clone());
    newRequest.setMethod(Request.ACK);
    headerIterator = getHeaders();
    while (headerIterator.hasNext()) {
      nextHeader = (SIPHeader) headerIterator.next();
      if (nextHeader instanceof RouteList) {
        // Ack and cancel do not get ROUTE headers.
        // Route header for ACK is assigned by the
        // Dialog if necessary.
        continue;
      } else if (nextHeader instanceof ProxyAuthorization) {
        // Remove proxy auth header.
        // Assigned by the Dialog if necessary.
        continue;
      } else if (nextHeader instanceof ContentLength) {
        // Adding content is responsibility of user.
        nextHeader = (SIPHeader) nextHeader.clone();
        try {
          ((ContentLength) nextHeader).setContentLength(0);
        } catch (InvalidArgumentException e) {
        }
      } else if (nextHeader instanceof ContentType) {
        // Content type header is removed since
        // content length is 0.
        continue;
      } else if (nextHeader instanceof CSeq) {
        // The CSeq header field in the
        // ACK MUST contain the same value for the
        // sequence number as was present in the
        // original request, but the method parameter
        // MUST be equal to "ACK".
        CSeq cseq = (CSeq) nextHeader.clone();
        try {
          cseq.setMethod(Request.ACK);
        } catch (ParseException e) {
        }
        nextHeader = cseq;
      } else if (nextHeader instanceof To) {
        if (responseToHeader != null) {
          nextHeader = responseToHeader;
        } else {
          nextHeader = (SIPHeader) nextHeader.clone();
        }
      } else if (nextHeader instanceof ContactList || nextHeader instanceof Expires) {
        // CONTACT header does not apply for ACK requests.
        continue;
      } else if (nextHeader instanceof ViaList) {
        // Bug reported by Gianluca Martinello
        // The ACK MUST contain a single Via header field,
        // and this MUST be equal to the top Via header
        // field of the original
        // request.

        nextHeader = (SIPHeader) ((ViaList) nextHeader).getFirst().clone();
      } else {
        nextHeader = (SIPHeader) nextHeader.clone();
      }

      try {
        newRequest.attachHeader(nextHeader, false);
      } catch (SIPDuplicateHeaderException e) {
        e.printStackTrace();
      }
    }
    if (MessageFactoryImpl.getDefaultUserAgentHeader() != null) {
      newRequest.setHeader(MessageFactoryImpl.getDefaultUserAgentHeader());
    }
    return newRequest;
  }