コード例 #1
0
ファイル: InviteHandler.java プロジェクト: biddyweb/peers
  public void rejectCall(SipRequest sipRequest) {
    // TODO generate 486, etc.
    SipHeaders reqHeaders = sipRequest.getSipHeaders();
    SipHeaderFieldValue callId = reqHeaders.get(new SipHeaderFieldName(RFC3261.HDR_CALLID));

    Dialog dialog = dialogManager.getDialog(callId.getValue());

    // TODO manage auto reject Do not disturb (DND)
    SipResponse sipResponse =
        RequestManager.generateResponse(
            sipRequest, dialog, RFC3261.CODE_486_BUSYHERE, RFC3261.REASON_486_BUSYHERE);

    // TODO determine port and transport for server transaction>transport
    // from initial invite
    // FIXME determine port and transport for server transaction>transport
    ServerTransaction serverTransaction = transactionManager.getServerTransaction(sipRequest);

    serverTransaction.start();

    serverTransaction.receivedRequest(sipRequest);

    serverTransaction.sendReponse(sipResponse);

    dialog.receivedOrSent300To699();

    userAgent.getMediaManager().setDatagramSocket(null);
    //        setChanged();
    //        notifyObservers(sipRequest);
  }
コード例 #2
0
ファイル: InviteHandler.java プロジェクト: biddyweb/peers
  private synchronized void sendSuccessfulResponse(SipRequest sipRequest, Dialog dialog) {
    SipHeaders reqHeaders = sipRequest.getSipHeaders();
    SipHeaderFieldValue contentType =
        reqHeaders.get(new SipHeaderFieldName(RFC3261.HDR_CONTENT_TYPE));

    if (RFC3261.CONTENT_TYPE_SDP.equals(contentType)) {
      // TODO
      //            String sdpResponse;
      //            try {
      //                sdpResponse = sdpManager.handleOffer(
      //                        new String(sipRequest.getBody()));
      //            } catch (NoCodecException e) {
      //                sdpResponse = sdpManager.generateErrorResponse();
      //            }
    } else {
      // TODO manage empty bodies and non-application/sdp content type
    }

    // TODO if mode autoanswer just send 200 without asking any question
    SipResponse sipResponse =
        RequestManager.generateResponse(
            sipRequest, dialog, RFC3261.CODE_200_OK, RFC3261.REASON_200_OK);

    // TODO 13.3 dialog invite-specific processing

    // TODO timer if there is an Expires header in INVITE

    // TODO 3xx

    // TODO 486 or 600

    byte[] offerBytes = sipRequest.getBody();
    SessionDescription answer;
    try {
      DatagramSocket datagramSocket = getDatagramSocket();

      if (offerBytes != null
          && contentType != null
          && RFC3261.CONTENT_TYPE_SDP.equals(contentType.getValue())) {
        // create response in 200
        try {
          SessionDescription offer = sdpManager.parse(offerBytes);
          answer = sdpManager.createSessionDescription(offer, datagramSocket.getLocalPort());
          mediaDestination = sdpManager.getMediaDestination(offer);
        } catch (NoCodecException e) {
          answer = sdpManager.createSessionDescription(null, datagramSocket.getLocalPort());
        }
      } else {
        // create offer in 200 (never tested...)
        answer = sdpManager.createSessionDescription(null, datagramSocket.getLocalPort());
      }
      sipResponse.setBody(answer.toString().getBytes());
    } catch (IOException e) {
      logger.error(e.getMessage(), e);
    }

    SipHeaders respHeaders = sipResponse.getSipHeaders();
    respHeaders.add(
        new SipHeaderFieldName(RFC3261.HDR_CONTENT_TYPE),
        new SipHeaderFieldValue(RFC3261.CONTENT_TYPE_SDP));

    ArrayList<String> routeSet = dialog.getRouteSet();
    if (routeSet != null) {
      SipHeaderFieldName recordRoute = new SipHeaderFieldName(RFC3261.HDR_RECORD_ROUTE);
      for (String route : routeSet) {
        respHeaders.add(recordRoute, new SipHeaderFieldValue(route));
      }
    }

    // TODO determine port and transport for server transaction>transport
    // from initial invite
    // FIXME determine port and transport for server transaction>transport
    ServerTransaction serverTransaction = transactionManager.getServerTransaction(sipRequest);
    if (serverTransaction == null) {
      // in re-INVITE case, no serverTransaction has been created
      serverTransaction =
          (InviteServerTransaction)
              transactionManager.createServerTransaction(
                  sipResponse, userAgent.getSipPort(), RFC3261.TRANSPORT_UDP, this, sipRequest);
    }
    serverTransaction.start();

    serverTransaction.receivedRequest(sipRequest);

    serverTransaction.sendReponse(sipResponse);
    // TODO manage retransmission of the response (send to the transport)
    // until ACK arrives, if no ACK is received within 64*T1, confirm dialog
    // and terminate it with a BYE

    //        logger.getInstance().debug("before dialog.receivedOrSent2xx();");
    //        logger.getInstance().debug("dialog state: " + dialog.getState());
  }