Commit ba5c49e6 authored by Adrien Béraud's avatar Adrien Béraud

sip: provide transport to getContactHeader()

The transport can now be different between the account and the call.
For IP2IP TLS, the transport is even only set in the call.

getContactHeader() uses information from the account to build the contact header,
but needs a transport to guess the local IP.

Refs #53057 #56312

Change-Id: Ief4cd632cb299cbe06725067fc405197b857c8c0
parent 4d7e38b1
......@@ -227,7 +227,11 @@ DHTAccount::SIPStartCall(const std::shared_ptr<SIPCall>& call)
std::string from(getFromUri());
pj_str_t pjFrom = pj_str((char*) from.c_str());
pj_str_t pjContact(getContactHeader());
pj_str_t pjContact;
{
auto transport = call->getTransport();
pjContact = getContactHeader(transport ? transport->get() : nullptr);
}
const std::string debugContactHeader(pj_strbuf(&pjContact), pj_strlen(&pjContact));
DEBUG("contact header: %s / %s -> %s",
......@@ -605,9 +609,11 @@ std::string DHTAccount::getToUri(const std::string& to) const
}
pj_str_t
DHTAccount::getContactHeader()
DHTAccount::getContactHeader(pjsip_transport* t)
{
if (transport_ == nullptr)
if (!t && transport_)
t = transport_->get();
if (!t)
ERROR("Transport not created yet");
// The transport type must be specified, in our case START_OTHER refers to stun transport
......@@ -620,7 +626,7 @@ DHTAccount::getContactHeader()
std::string address = "dht.invalid";
pj_uint16_t port = getTlsListenerPort();
link_->sipTransport->findLocalAddressFromTransport(transport_->get(), transportType, hostname_, address, port);
link_->sipTransport->findLocalAddressFromTransport(t, transportType, hostname_, address, port);
#if HAVE_IPV6
/* Enclose IPv6 address in square brackets */
......
......@@ -149,7 +149,7 @@ class DHTAccount : public SIPAccountBase {
* Get the contact header for
* @return pj_str_t The contact header based on account information
*/
pj_str_t getContactHeader();
pj_str_t getContactHeader(pjsip_transport* = nullptr);
void setReceivedParameter(const std::string &received) {
receivedParameter_ = received;
......
......@@ -239,7 +239,7 @@ SIPAccount::newOutgoingCall(const std::string& id, const std::string& toUrl)
toUri = getToUri(to);
call->setTransport(transport_);
// FIXME : for now, use the same address family as the SIP tranport
// FIXME : for now, use the same address family as the SIP transport
family = pjsip_transport_type_get_af(getTransportType());
DEBUG("UserAgent: New registered account call to %s", toUrl.c_str());
......@@ -312,8 +312,13 @@ SIPAccount::SIPStartCall(std::shared_ptr<SIPCall>& call)
std::string from(getFromUri());
pj_str_t pjFrom = pj_str((char*) from.c_str());
pj_str_t pjContact(getContactHeader());
auto transport = call->getTransport();
if (!transport) {
ERROR("Unable to start call without transport");
return false;
}
pj_str_t pjContact = getContactHeader(transport->get());
const std::string debugContactHeader(pj_strbuf(&pjContact), pj_strlen(&pjContact));
DEBUG("contact header: %s / %s -> %s",
debugContactHeader.c_str(), from.c_str(), toUri.c_str());
......@@ -363,7 +368,7 @@ SIPAccount::SIPStartCall(std::shared_ptr<SIPCall>& call)
return false;
}
const pjsip_tpselector tp_sel = SipTransportBroker::getTransportSelector(call->getTransport()->get());
const pjsip_tpselector tp_sel = SipTransportBroker::getTransportSelector(transport->get());
if (pjsip_dlg_set_transport(dialog, &tp_sel) != PJ_SUCCESS) {
ERROR("Unable to associate transport for invite session dialog");
return false;
......@@ -1370,9 +1375,11 @@ std::string SIPAccount::getServerUri() const
pj_str_t
SIPAccount::getContactHeader()
SIPAccount::getContactHeader(pjsip_transport* t)
{
if (!transport_)
if (!t && transport_)
t = transport_->get();
if (!t)
ERROR("Transport not created yet");
if (contact_.slen and contactOverwritten_)
......@@ -1389,7 +1396,7 @@ SIPAccount::getContactHeader()
pj_uint16_t port;
link_->sipTransport->findLocalAddressFromTransport(
transport_ ? transport_->get() : nullptr,
t,
transportType,
hostname_,
address, port);
......@@ -1400,7 +1407,7 @@ SIPAccount::getContactHeader()
DEBUG("Using published address %s and port %d", address.c_str(), port);
} else if (stunEnabled_) {
link_->sipTransport->findLocalAddressFromSTUN(
transport_ ? transport_->get() : nullptr,
t,
&stunServerName_,
stunPort_,
address, port);
......
......@@ -365,7 +365,7 @@ class SIPAccount : public SIPAccountBase {
* Get the contact header for
* @return pj_str_t The contact header based on account information
*/
pj_str_t getContactHeader();
pj_str_t getContactHeader(pjsip_transport* = nullptr);
std::string getServiceRoute() const {
......
......@@ -241,7 +241,7 @@ public:
* Get the contact header for
* @return pj_str_t The contact header based on account information
*/
virtual pj_str_t getContactHeader() = 0;
virtual pj_str_t getContactHeader(pjsip_transport* = nullptr) = 0;
virtual std::string getToUri(const std::string& username) const = 0;
......
......@@ -276,7 +276,7 @@ void SIPCall::answer()
updateSDPFromSTUN();
}
pj_str_t contact(account.getContactHeader());
pj_str_t contact(account.getContactHeader(transport_ ? transport_->get() : nullptr));
setContactHeader(&contact);
pjsip_tx_data *tdata;
......
......@@ -470,7 +470,7 @@ transaction_request_cb(pjsip_rx_data *rdata)
}
// contactStr must stay in scope as long as tdata
const pj_str_t contactStr(account->getContactHeader());
const pj_str_t contactStr(account->getContactHeader(transport->get()));
sip_utils::addContactHeader(&contactStr, tdata);
if (pjsip_inv_send_msg(call->inv.get(), tdata) != PJ_SUCCESS) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment