Пример #1
0
  /**
   * Responds with <i>resp</i>. This method can be called when the InviteDialog is in D_INVITED or
   * D_BYED states.
   *
   * <p>If the CSeq method is INVITE and the response is 2xx, it moves to state D_ACCEPTED, adds a
   * new listener to the SipProviderListener, and creates new AckTransactionServer
   *
   * <p>If the CSeq method is INVITE and the response is not 2xx, it moves to state D_REFUSED, and
   * sends the response.
   */
  public void respond(Message resp)
        // private void respond(Message resp)
      {
    printLog("inside respond(resp)", LogLevel.MEDIUM);
    String method = resp.getCSeqHeader().getMethod();
    if (method.equals(SipMethods.INVITE)) {
      if (!verifyStatus(statusIs(D_INVITED) || statusIs(D_ReINVITED))) {
        printLog(
            "respond(): InviteDialog not in (re)invited state: No response now", LogLevel.HIGH);
        return;
      }

      int code = resp.getStatusLine().getCode();
      // 1xx provisional responses
      if (code >= 100 && code < 200) {
        invite_ts.respondWith(resp);
        return;
      }
      // For all final responses establish the dialog
      if (code >= 200) { // changeStatus(D_ACCEPTED);
        update(Dialog.UAS, resp);
      }
      // 2xx success responses
      if (code >= 200 && code < 300) {
        if (statusIs(D_INVITED)) changeStatus(D_ACCEPTED);
        else changeStatus(D_ReACCEPTED);
        // terminates the INVITE Transaction server and activates an ACK
        // Transaction server
        invite_ts.terminate();
        ConnectionIdentifier conn_id = invite_ts.getConnectionId();
        ack_ts = new AckTransactionServer(sip_provider, conn_id, resp, this);
        ack_ts.respond();
        // if (statusIs(D_ReACCEPTED))
        // listener.onDlgReInviteAccepted(this);
        // else listener.onDlgAccepted(this);
        return;
      } else
      // 300-699 failure responses
      // if (code>=300)
      {
        if (statusIs(D_INVITED)) changeStatus(D_REFUSED);
        else changeStatus(D_ReREFUSED);
        invite_ts.respondWith(resp);
        // if (statusIs(D_ReREFUSED))
        // listener.onDlgReInviteRefused(this);
        // else listener.onDlgRefused(this);
        return;
      }
    }
    if (method.equals(SipMethods.BYE)) {
      if (!verifyStatus(statusIs(D_BYED))) return;
      bye_ts.respondWith(resp);
    }
  }