void SIPTransaction::sendResponse( const SIPMessage::Ptr& pResponse, const OSS::IPAddress& sendAddress) { if (!pResponse->isResponse()) throw OSS::SIP::SIPException("Sending a REQUEST using sendResponse() is illegal!"); SIPTransaction::Ptr pParent = getParent(); if (!_transport && isParent()) throw OSS::SIP::SIPException("Transport Not Ready!"); else if (!isParent() && pParent) _transport = pParent->_transport; if (_sendAddress.getPort() == 0) _sendAddress = sendAddress; SIPTransaction::Ptr pBranch = findBranch(pResponse); if (pBranch) { pBranch->sendResponse(pResponse, sendAddress); return; } else { // // No branch is found. This instance will handle the response // if (_transport && _transport->isReliableTransport()) { if (_transport->writeKeepAlive()) { writeMessage(pResponse); } else { // // Keep-alive failed so create a new transport // if (_localAddress.isValid() && _sendAddress.isValid()) { // // According to RFC 3261, if there is any transport failure, we must try to // re-estabish a connectoin to the via sentby parameter instead // std::string transport; if (SIPVia::msgGetTopViaTransport(pResponse.get(), transport)) { _transport = _transportService->createClientTransport(_localAddress, _sendAddress, transport); writeMessage(pResponse); } } else { OSS_LOG_ERROR("SIPTransaction::sendResponse - Unable to re-establish transport to send response."); } } } else if (_transport) { // // This is UDP so a keep-alive check won't do us any good // writeMessage(pResponse, _sendAddress); } else { OSS_LOG_ERROR("SIPTransaction::sendResponse - Transport is NULL."); } } }