Example #1
0
  /**
   * Handle 403 error. First do re-register then send request again
   *
   * @param request The request was responded with 403
   */
  public void handle403Forbidden(SipResponse resp) {
    if (logger.isActivated()) {
      logger.debug("handle403Forbidden() entry");
    }
    boolean isRegistered =
        imsService
            .getImsModule()
            .getCurrentNetworkInterface()
            .getRegistrationManager()
            .registration();
    if (logger.isActivated()) {
      logger.debug("re-register isRegistered: " + isRegistered);
    }
    if (isRegistered) {
      String callId = dialogPath.getCallId();
      SipRequest invite = createSipInvite(callId);
      if (invite != null) {
        try {
          sendInvite(invite);
        } catch (SipException e) {
          if (logger.isActivated()) {
            logger.debug("re send sip request failed.");
          }
          e.printStackTrace();
        }

      } else {
        if (logger.isActivated()) {
          logger.debug("handle403Forbidden() invite is null");
        }
      }
    }
    if (logger.isActivated()) {
      logger.debug("handle403Forbidden() exit");
    }
    handleDefaultError(resp);
  }
  private SipRequest createSipInvite() {
    logger.debug("createSipInvite()");
    // Set setup mode
    String localSetup = createSetupOffer();
    if (logger.isActivated()) {
      logger.debug("Local setup attribute is " + localSetup);
    }

    // Set local port
    int localMsrpPort = 9; // See RFC4145, Page 4

    // Create the MSRP manager
    String localIpAddress =
        getImsService()
            .getImsModule()
            .getCurrentNetworkInterface()
            .getNetworkAccess()
            .getIpAddress();
    msrpMgr = new MsrpManager(localIpAddress, localMsrpPort);

    // Build SDP part
    String ntpTime = SipUtils.constructNTPtime(System.currentTimeMillis());
    String ipAddress = getDialogPath().getSipStack().getLocalIpAddress();
    /** M: add for MSRPoTLS @{ */
    String protocol = getCurrentProtocol();
    String sdp = null;
    if (PROTOCOL_TLS.equals(protocol)) {
      sdp =
          "v=0"
              + SipUtils.CRLF
              + "o=- "
              + ntpTime
              + " "
              + ntpTime
              + " IN IP4 "
              + ipAddress
              + SipUtils.CRLF
              + "s=-"
              + SipUtils.CRLF
              + "c=IN IP4 "
              + ipAddress
              + SipUtils.CRLF
              + "t=0 0"
              + SipUtils.CRLF
              + "m=message "
              + localMsrpPort
              + " TCP/TLS/MSRP *"
              + SipUtils.CRLF
              + "a=path:"
              + msrpMgr.getLocalMsrpsPath()
              + SipUtils.CRLF
              + "a=fingerprint:"
              + KeyStoreManager.getFingerPrint()
              + SipUtils.CRLF
              + "a=setup:"
              + localSetup
              + SipUtils.CRLF
              + "a=accept-types: "
              + getContent().getEncoding()
              + SipUtils.CRLF
              + "a=file-transfer-id:"
              + getFileTransferId()
              + SipUtils.CRLF
              + "a=file-disposition:attachment"
              + SipUtils.CRLF
              + "a=sendonly"
              + SipUtils.CRLF;
    } else {
      sdp =
          "v=0"
              + SipUtils.CRLF
              + "o=- "
              + ntpTime
              + " "
              + ntpTime
              + " IN IP4 "
              + ipAddress
              + SipUtils.CRLF
              + "s=-"
              + SipUtils.CRLF
              + "c=IN IP4 "
              + ipAddress
              + SipUtils.CRLF
              + "t=0 0"
              + SipUtils.CRLF
              + "m=message "
              + localMsrpPort
              + " TCP/MSRP *"
              + SipUtils.CRLF
              + "a=path:"
              + msrpMgr.getLocalMsrpPath()
              + SipUtils.CRLF
              + "a=setup:"
              + localSetup
              + SipUtils.CRLF
              + "a=accept-types: "
              + getContent().getEncoding()
              + SipUtils.CRLF
              + "a=file-transfer-id:"
              + getFileTransferId()
              + SipUtils.CRLF
              + "a=file-disposition:attachment"
              + SipUtils.CRLF
              + "a=sendonly"
              + SipUtils.CRLF;
    }
    int maxSize = FileSharingSession.getMaxFileSharingSize();
    if (maxSize > 0) {
      sdp += "a=max-size:" + maxSize + SipUtils.CRLF;
    }

    /** @} */
    // Set File-selector attribute
    String selector = getFileSelectorAttribute();
    if (selector != null) {
      sdp += "a=file-selector:" + selector + SipUtils.CRLF;
    }

    // Set File-location attribute
    String location = getFileLocationAttribute();
    if (location != null) {
      sdp += "a=file-location:" + location + SipUtils.CRLF;
    }

    // Set the local SDP part in the dialog path
    getDialogPath().setLocalContent(sdp);

    // Create an INVITE request
    if (logger.isActivated()) {
      logger.info("Create INVITE");
    }
    try {
      SipRequest invite;
      invite =
          SipMessageFactory.createInvite(
              getDialogPath(), InstantMessagingService.FT_FEATURE_TAGS, sdp);
      // Set the Authorization header
      getAuthenticationAgent().setAuthorizationHeader(invite);

      // Set initial request in the dialog path
      getDialogPath().setInvite(invite);
      return invite;
    } catch (SipException e) {
      e.printStackTrace();
    } catch (CoreException e) {
      e.printStackTrace();
    }
    logger.error("Create sip invite failed, return null.");
    return null;
  }