Ejemplo n.º 1
0
bool SIPNict::onSendMessage(SIPMessage::Ptr pMsg)
{
  SIPTransaction::Ptr pTransaction = static_cast<SIPTransaction::WeakPtr*>(_owner)->lock();
  if (!pTransaction)
    return false;

  if (pTransaction->getState() == SIPTransaction::TRN_STATE_IDLE)
  {
    startTimerMaxLifetime(300000); /// five minutes
    _pRequest = pMsg;
    pTransaction->setState(TRYING);

    std::string sTimeout;
    if (pMsg->getProperty(OSS::PropertyMap::PROP_TransactionTimeout, sTimeout) && !sTimeout.empty())
    {
      _timerEValue = OSS::string_to_number<unsigned long>(sTimeout.c_str()) / 64;
    }
    else
    {
      _timerEValue = _timerProps.timerE();
    }

    if (!pTransaction->transport()->isReliableTransport())
    {
      startTimerE(_timerEValue);
      startTimerF(_timerEValue*64);
    }
    else
    {
      startTimerF(RELIABLE_TIMER_F_VALUE);
    }
    
    return true;
  }
  return false;
}
Ejemplo n.º 2
0
void OSSSIP::sendRequestDirect(const SIPMessage::Ptr& pRequest,
  const OSS::IPAddress& localAddress,
  const OSS::IPAddress& remoteAddress)
{

  std::string transport;
  if (SIPVia::msgGetTopViaTransport(pRequest.get(), transport))
  {
    std::string transportId;
    pRequest->getProperty("transport-id", transportId);
    if (transportId.empty())
      transportId="0";
    OSS_LOG_DEBUG("Sending request directly protocol=" << transport << " id=" << transportId);
    SIPTransportSession::Ptr client = _fsmDispatch.transport().createClientTransport(localAddress, remoteAddress, transport, transportId);
    if (client)
      client->writeMessage(pRequest, remoteAddress.toString(), OSS::string_from_number(remoteAddress.getPort()));
    else
      OSS_LOG_ERROR("OSSSIP::sendRequestDirect failed - Unable to create client transport");
  }
  else
  {
    OSS_LOG_ERROR("OSSSIP::sendRequestDirect failed - Unable to determine transport protocol.")
  }
}
Ejemplo n.º 3
0
void SIPTransaction::sendRequest(
    const SIPMessage::Ptr& pRequest,
    const OSS::IPAddress& localAddress,
    const OSS::IPAddress& remoteAddress,
    SIPTransaction::Callback callback)
{
  OSS::mutex_lock lock(_mutex);

  if (!pRequest->isRequest())
  {
    throw OSS::SIP::SIPException("Sending a REQUEST using sendRequest() is illegal!");
  }

  if (!_pInitialRequest)
  {
    _pInitialRequest = pRequest;
    if (_logId.empty())
      _logId = pRequest->createContextId(true);
    
    if (SIPXOR::isEnabled() && !_isXOREncrypted)
    {
      std::string isXOR;
      _isXOREncrypted = pRequest->getProperty("xor", isXOR) && isXOR == "1";
    }
  }

  if (!_responseTU)
    _responseTU = callback;

  if (_localAddress.getPort() == 0)
    _localAddress = localAddress;

  if (_remoteAddress.getPort() == 0)
    _remoteAddress = remoteAddress;

  if (!_transport)
  {
    if (!_transportService)
      throw OSS::SIP::SIPException("Transport Not Ready!");


    std::string transport;
    if (pRequest->getProperty("target-transport", transport))
    {
      std::string transportId;
      pRequest->getProperty("transport-id", transportId);
      _transport = _transportService->createClientTransport(localAddress, remoteAddress, transport, transportId);
    }else if (SIPVia::msgGetTopViaTransport(pRequest.get(), transport))
    {
      _transport = _transportService->createClientTransport(localAddress, remoteAddress, transport);
    }
    if (!_transport)
      throw OSS::SIP::SIPException("Unable to create transport!");
  }

  if (_transport->isReliableTransport())
  {
    writeMessage(pRequest);
  }
  else
  {
    writeMessage(pRequest, remoteAddress);
  }
}
Ejemplo n.º 4
0
void SIPTransaction::onReceivedMessage(SIPMessage::Ptr pMsg, SIPTransportSession::Ptr pTransport)
{
  OSS::mutex_lock lock(_mutex);

  bool isAck = pMsg->isRequest("ACK");

  if (pMsg->isRequest() && !_pInitialRequest && !isAck)
    _pInitialRequest = pMsg;

  if (_logId.empty())
    _logId = pMsg->createContextId(true);

  if (!_transport)
    _transport = pTransport;

  if (!_localAddress.isValid())
    _localAddress = pTransport->getLocalAddress();

  if (!_remoteAddress.isValid())
    _remoteAddress = pTransport->getRemoteAddress();

  if (SIPXOR::isEnabled() && !_isXOREncrypted)
  {
    std::string isXOR;
    _isXOREncrypted = pMsg->getProperty("xor", isXOR) && isXOR == "1";
  }

  if (isParent())
  {
    std::ostringstream logMsg;
    logMsg << _logId << "<<< " << pMsg->startLine()
    << " LEN: " << pTransport->getLastReadCount()
    << " SRC: " << _remoteAddress.toIpPortString()
    << " DST: " << _localAddress.toIpPortString()
    << " EXT: " << "[" << pTransport->getExternalAddress() << "]"
    << " FURI: " << pMsg->hdrGet("from")
    << " ENC: " << _isXOREncrypted
    << " PROT: " << pTransport->getTransportScheme();
    OSS::log_information(logMsg.str());

    if (OSS::log_get_level() >= OSS::PRIO_DEBUG)
      OSS::log_debug(pMsg->createLoggerData());
  }

  //
  // If this is a request and is not an ACK, then the parent IST fsm must always handle it
  //
  if (isParent() && pMsg->isRequest() && !isAck)
  {
    _fsm->onReceivedMessage(pMsg, pTransport);
  }
  else if (!pMsg->isRequest() || isAck)
  {
    //
    // This is a response or an ACK and the transaction could have branched out
    //
    if (!isParent())
    {
      _fsm->onReceivedMessage(pMsg, pTransport);
    }
    else
    {
      SIPTransaction::Ptr pBranch = findBranch(pMsg);
      if (pBranch)
        pBranch->onReceivedMessage(pMsg, pTransport);
      else
        _fsm->onReceivedMessage(pMsg, pTransport);
    }
  }
}