Пример #1
0
void SIPTransaction::writeMessage(SIPMessage::Ptr pMsg)
{
  OSS::mutex_lock lock(_mutex);

  if (!_transport)
  {
    OSS_LOG_ERROR("SIPTransaction::writeMessage - Transport is NULL while attempting to send a request.");
    return;
  }

  if (SIPXOR::isEnabled() && _isXOREncrypted)
  {
    pMsg->setProperty("xor", "1");
  }

  std::ostringstream logMsg;
  logMsg << _logId << ">>> " << pMsg->startLine()
  << " LEN: " << pMsg->data().size()
  << " SRC: " << _transport->getLocalAddress().toIpPortString()
  << " DST: " << _transport->getRemoteAddress().toIpPortString()
  << " ENC: " << _isXOREncrypted
  << " PROT: " << _transport->getTransportScheme();
  OSS::log_information(logMsg.str());

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

  if (_fsm->onSendMessage(pMsg))
  {
    _transport->writeMessage(pMsg);
  }
}
Пример #2
0
void SIPTransaction::writeMessage(SIPMessage::Ptr pMsg, const OSS::IPAddress& remoteAddress)
{
  OSS::mutex_lock lock(_mutex);

  if (!_transport)
  {
    OSS_LOG_ERROR("SIPTransaction::writeMessage does not have a transport to use");
    return;
  }

  if (SIPXOR::isEnabled() && _isXOREncrypted)
  {
    pMsg->setProperty("xor", "1");
  }

  if (_fsm->onSendMessage(pMsg))
  {
    std::ostringstream logMsg;
    logMsg << _logId << ">>> " << pMsg->startLine()
    << " LEN: " << pMsg->data().size()
    << " SRC: " << _transport->getLocalAddress().toIpPortString()
    << " DST: " << remoteAddress.toIpPortString()
    << " ENC: " << _isXOREncrypted
    << " PROT: " << _transport->getTransportScheme();
    OSS::log_information(logMsg.str());
    if (OSS::log_get_level() >= OSS::PRIO_DEBUG)
      OSS::log_debug(pMsg->createLoggerData());

    _transport->writeMessage(pMsg,
    remoteAddress.toString(),
    OSS::string_from_number<unsigned short>(remoteAddress.getPort()));
  }
}
Пример #3
0
SIPTransaction::Ptr SIPFSMDispatch::createClientTransaction(const SIPMessage::Ptr& pRequest)
{
  if (!pRequest->isRequest())
    throw OSS::SIP::SIPException("Sending a response using sendRequest() method is illegal");

  std::string id;
  if (!pRequest->getTransactionId(id))
    throw OSS::SIP::SIPException("Unable to determine transaction identifier");

  SIPTransaction::Ptr trn;
  SIPTransportSession::Ptr nullTransport;
  bool isAck = false;
  if (OSS::string_caseless_starts_with(pRequest->startLine(), "invite"))
  {
    //
    // This is an ICT
    //
    trn = _ict.findTransaction(pRequest, nullTransport);
  }
  else
  {
    //
    // This is an NICT
    //
    isAck = pRequest->isRequest(OSS::SIP::REQ_ACK);
    if (!isAck)
    {
      trn = _nict.findTransaction(pRequest, nullTransport);
    }
  }
  
  return trn;
}
Пример #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);
    }
  }
}
Пример #5
0
void EndpointListener::monitorEvents()
{
  OSS_LOG_NOTICE("EndpointListener::monitorEvents( " << _endpointName << " ) - STARTED processing events");
  handleStart();
  while(!_isTerminating)
  {
    SIPMessage::Ptr pRequest;
    _eventQueue.dequeue(pRequest);
    if (pRequest)
    {
      OSS_LOG_DEBUG(pRequest->createContextId(true) << "EndpointListener::monitorEvents( " << _endpointName << " ) - processing event " << pRequest->startLine());
      onHandleEvent(pRequest);
    }
    else
    {
      OSS_LOG_DEBUG("EndpointListener::monitorEvents( " << _endpointName << " ) - dropping NULL event");
    }
  }
  handleStop();
  OSS_LOG_NOTICE("EndpointListener::monitorEvents( " << _endpointName << " ) TERMINATED");
}
Пример #6
0
void EndpointListener::dispatchMessage(const SIPMessage::Ptr& pRequest)
{
  if (_dispatch)
  {
    OSS_LOG_DEBUG(pRequest->createContextId(true) << "EndpointListener::dispatchMessage( " << pRequest->startLine() << " )");
    pRequest->setProperty(OSS::PropertyMap::PROP_EndpointName, _endpointName);
    pRequest->commitData();
    _dispatch(pRequest, _pConnection);
  }
  else
  {
    OSS_LOG_ERROR(pRequest->createContextId(true) << "EndpointListener::dispatchMessage( NULL )");
  }
}
Пример #7
0
void SIPFSMDispatch::onReceivedMessage(SIPMessage::Ptr pMsg, SIPTransportSession::Ptr pTransport)
{
  if (!pTransport->isEndpoint() && pTransport->getLastReadCount() < MIN_DATAGRAM_SIZE && !pTransport->isReliableTransport())
  {
    //
    // datagram is too short to be a SIP Message
    // Bailing out.  Take note that streamed connection
    // can split SIP messages to smaller frames
    // and the last frame can be smaller than MIN_DATAGRAM_SIZE
    // so we do not impose a limit for streams
    //
    return;
  }

  try
  {
    pMsg->parse();
  }
  catch(OSS::Exception e)
  {
    std::ostringstream logMsg;
    logMsg << "Incoming message failed to be parsed - " << e.message()
      << " LEN: " << pTransport->getLastReadCount()
      << " SRC: " << pTransport->getRemoteAddress().toIpPortString();
    OSS::log_warning(logMsg.str());
    return;
  }

  std::string id;
  if (!pMsg->getTransactionId(id))
    return;  // don't throw here
             // we don't have control over what we receive from the transport

  SIPTransaction::Ptr trn;
  SIPTransaction::Type transactionType = SIPTransaction::TYPE_UNKNOWN;
  if (pMsg->isRequest())
  {
    if (OSS::string_caseless_starts_with(pMsg->startLine(), "invite"))
    {
      transactionType = SIPTransaction::TYPE_IST;
      if (_istBlocker.has(id))
      {
        OSS_LOG_WARNING("Blocked request retransmission - " <<  pMsg->startLine());
        return;
      }
      
      trn = _ist.findTransaction(pMsg, pTransport);
    }
    else if (OSS::string_caseless_starts_with(pMsg->startLine(), "ack"))
    {
      //
      // ACK for error responses will get matched to a transaction
      //
      transactionType = SIPTransaction::TYPE_IST;
      trn = _ist.findTransaction(pMsg, pTransport, false);
    }
    else
    {
      transactionType = SIPTransaction::TYPE_NIST;
      trn = _nist.findTransaction(pMsg, pTransport);
    }
  }
  else if (!pMsg->isRequest())
  {
    std::string cseq;
    cseq = pMsg->hdrGet(OSS::SIP::HDR_CSEQ);
    if (OSS::string_caseless_ends_with(cseq, "invite"))
    {
      transactionType = SIPTransaction::TYPE_ICT;
      trn = _ict.findTransaction(pMsg, pTransport, false);
    }
    else
    {
      transactionType = SIPTransaction::TYPE_NICT;
      trn = _nict.findTransaction(pMsg, pTransport, false);
    }
  }
  if (trn)
  {
    std::ostringstream logMsg;
    if (!trn->getLogId().empty())
    {
      logMsg << trn->getLogId() << "Found Transaction " << trn->getId();
      OSS::log_debug(logMsg.str());
    }
    else
    {
      trn->setLogId(pMsg->createContextId(true));
      logMsg << trn->getLogId() << "Transaction " << trn->getId() << " CREATED";
      OSS::log_information(logMsg.str());
    }
  }

  if (!trn)
  {
    //
    // We did not get a transaction, check if this is an ack and find the IST ACK transaction
    //
    if (transactionType == SIPTransaction::TYPE_IST && pMsg->isRequest("ACK"))
    {
        //
        // No IST is existing in the ackable Pool.
        // Report this ACK as orphaned to the UA CORE
        //
        if (_ackOr2xxTransactionHandler)
          _ackOr2xxTransactionHandler(pMsg, pTransport);
    }
    else if (transactionType == SIPTransaction::TYPE_ICT && pMsg->is2xx())
    {
      if (_ackOr2xxTransactionHandler)
        _ackOr2xxTransactionHandler(pMsg, pTransport);
    }
    else
    {
      std::ostringstream logMsg;
      logMsg << pMsg->createContextId(true) << "Unable to match incoming request to a transaction - "
        << pMsg->startLine();
      OSS::log_warning(logMsg.str());
    }
  }
  else
  {
    if (!trn->transportService())
    {
      //
      // This is a newly created transaction
      //
      trn->transportService() = &_transport;
      trn->transport() = pTransport;
    }
    trn->onReceivedMessage(pMsg, pTransport);
  }
}