コード例 #1
0
    @Override
    public long perform() {
      request = (MgcpRequest) getEvent().getMessage();

      Parameter callID = request.getParameter(Parameter.CALL_ID);
      connectionID = request.getParameter(Parameter.CONNECTION_ID);

      if (callID == null && connectionID == null) {
        this.deleteForEndpoint(request);
        return 0;
      }

      if (callID != null && connectionID == null) {
        this.deleteForCall(callID, request);
        return 0;
      }

      if (callID == null) {
        throw new MgcpCommandException(MgcpResponseCode.PROTOCOL_ERROR, CALLID_MISSING);
      }

      // getting call
      MgcpCall call = transaction().getCall(callID.getValue().hexToInteger(), false);
      if (call == null) {
        throw new MgcpCommandException(MgcpResponseCode.INCORRECT_CALL_ID, UNKNOWN_CALL_IDENTIFIER);
      }

      if (connectionID == null) {
        throw new MgcpCommandException(MgcpResponseCode.PROTOCOL_ERROR, CONNECTIONID_EXPECTED);
      }

      // getting endpoint name
      request.getEndpoint().divide('@', endpointName);
      // searching endpoint
      try {
        int n = transaction().find(localName, endpoints);
        if (n == 0) {
          throw new MgcpCommandException(
              MgcpResponseCode.ENDPOINT_NOT_AVAILABLE, new Text("Endpoint not available"));
        }
      } catch (UnknownEndpointException e) {
        throw new MgcpCommandException(
            MgcpResponseCode.ENDPOINT_UNKNOWN, new Text("Endpoint not available"));
      }
      // extract found endpoint
      endpoint = endpoints[0];

      MgcpConnection connection = endpoint.getConnection(connectionID.getValue().hexToInteger());

      if (connection != null) {
        rx = connection.getPacketsReceived();
        tx = connection.getPacketsTransmitted();

        endpoint.deleteConnection(connectionID.getValue().hexToInteger());
      }

      return 0;
    }
コード例 #2
0
    private void deleteForCall(Parameter callID, MgcpRequest request) {
      // getting call
      MgcpCall call = transaction().getCall(callID.getValue().hexToInteger(), false);
      if (call == null) {
        throw new MgcpCommandException(MgcpResponseCode.INCORRECT_CALL_ID, UNKNOWN_CALL_IDENTIFIER);
      }

      call.deleteConnections();
    }
コード例 #3
0
    @Override
    public long perform() {
      request = (MgcpRequest) getEvent().getMessage();

      Parameter callID = request.getParameter(Parameter.CALL_ID);
      if (callID == null) {
        throw new MgcpCommandException(MgcpResponseCode.PROTOCOL_ERROR, CALLID_MISSING);
      }

      // modify local connection options
      Parameter l = request.getParameter(Parameter.LOCAL_CONNECTION_OPTIONS);
      if (l != null) {
        lcOptions.setValue(l.getValue());
      } else {
        lcOptions.setValue(null);
      }

      // getting call
      MgcpCall call = transaction().getCall(callID.getValue().hexToInteger(), false);
      if (call == null) {
        throw new MgcpCommandException(MgcpResponseCode.INCORRECT_CALL_ID, UNKNOWN_CALL_IDENTIFIER);
      }

      connectionID = request.getParameter(Parameter.CONNECTION_ID);
      if (connectionID == null) {
        throw new MgcpCommandException(MgcpResponseCode.PROTOCOL_ERROR, CONNECTIONID_EXPECTED);
      }

      try {
        mgcpConnection = call.getMgcpConnection(connectionID.getValue().hexToInteger());
      } catch (Exception e) {
        throw new MgcpCommandException(
            MgcpResponseCode.CONNECTION_WAS_DELETED,
            new Text("Unknown connectionidentifier, probably it was deleted"));
      }

      if (mgcpConnection == null)
        throw new MgcpCommandException(
            MgcpResponseCode.CONNECTION_WAS_DELETED,
            new Text("Unknown connectionidentifier, probably it was deleted"));

      // set SDP if requested
      Parameter sdp = request.getParameter(Parameter.SDP);
      Parameter mode = request.getParameter(Parameter.MODE);

      if (sdp != null) {
        try {
          mgcpConnection.setOtherParty(sdp.getValue());
        } catch (IOException e) {
          logger.error("Could not set remote peer", e);
          throw new MgcpCommandException(MgcpResponseCode.UNSUPPORTED_SDP, SDP_NEGOTIATION_FAILED);
        }
      }

      if (mode != null) {
        try {
          mgcpConnection.setMode(mode.getValue());
        } catch (ModeNotSupportedException e) {
          throw new MgcpCommandException(
              MgcpResponseCode.INVALID_OR_UNSUPPORTED_MODE, new Text("problem with mode"));
        }
      }

      mgcpConnection.setDtmfClamp(lcOptions.getDtmfClamp());

      MgcpEvent evt =
          transaction().getProvider().createEvent(MgcpEvent.RESPONSE, getEvent().getAddress());
      MgcpResponse response = (MgcpResponse) evt.getMessage();
      response.setResponseCode(MgcpResponseCode.TRANSACTION_WAS_EXECUTED);
      response.setResponseString(SUCCESS);
      response.setTxID(transaction().getId());

      if (connectionID != null) {
        response.setParameter(Parameter.CONNECTION_ID, connectionID.getValue());
      }

      Text descriptor = mgcpConnection.getDescriptor();
      if (descriptor != null) response.setParameter(Parameter.SDP, mgcpConnection.getDescriptor());

      try {
        transaction().getProvider().send(evt);
      } catch (IOException e) {
        logger.error(e);
      } finally {
        evt.recycle();
      }

      return 0;
    }