Commit d3b425f5 authored by Adrien Béraud's avatar Adrien Béraud
Browse files

sipcall: cleanup

Change-Id: Idab58d884268f94048c0ca52adb2bb5397aac95f
parent 7a1d95be
...@@ -174,12 +174,12 @@ getHostFromUri(std::string_view uri) ...@@ -174,12 +174,12 @@ getHostFromUri(std::string_view uri)
} }
void void
addContactHeader(const pj_str_t* contact_str, pjsip_tx_data* tdata) addContactHeader(pj_str_t contact_str, pjsip_tx_data* tdata)
{ {
pjsip_contact_hdr* contact = pjsip_contact_hdr_create(tdata->pool); pjsip_contact_hdr* contact = pjsip_contact_hdr_create(tdata->pool);
contact->uri = pjsip_parse_uri(tdata->pool, contact->uri = pjsip_parse_uri(tdata->pool,
contact_str->ptr, contact_str.ptr,
contact_str->slen, contact_str.slen,
PJSIP_PARSE_URI_AS_NAMEADDR); PJSIP_PARSE_URI_AS_NAMEADDR);
// remove old contact header (if present) // remove old contact header (if present)
pjsip_msg_find_remove_hdr(tdata->msg, PJSIP_H_CONTACT, NULL); pjsip_msg_find_remove_hdr(tdata->msg, PJSIP_H_CONTACT, NULL);
......
...@@ -96,7 +96,7 @@ std::string parseDisplayName(const pjsip_contact_hdr* header); ...@@ -96,7 +96,7 @@ std::string parseDisplayName(const pjsip_contact_hdr* header);
std::string_view getHostFromUri(std::string_view sipUri); std::string_view getHostFromUri(std::string_view sipUri);
void addContactHeader(const pj_str_t* contactStr, pjsip_tx_data* tdata); void addContactHeader(pj_str_t contactStr, pjsip_tx_data* tdata);
void addUserAgentHeader(const std::string& userAgent, pjsip_tx_data* tdata); void addUserAgentHeader(const std::string& userAgent, pjsip_tx_data* tdata);
std::string_view getPeerUserAgent(const pjsip_rx_data* rdata); std::string_view getPeerUserAgent(const pjsip_rx_data* rdata);
void logMessageHeaders(const pjsip_hdr* hdr_list); void logMessageHeaders(const pjsip_hdr* hdr_list);
......
/* /*
* Copyright (C) 2004-2021 Savoir-faire Linux Inc. * Copyright (C) 2004-2021 Savoir-faire Linux Inc.
* *
* Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com> * Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>
...@@ -188,7 +188,7 @@ SIPCall::findRtpStreamIndex(const std::string& label) const ...@@ -188,7 +188,7 @@ SIPCall::findRtpStreamIndex(const std::string& label) const
const auto iter = std::find_if(rtpStreams_.begin(), const auto iter = std::find_if(rtpStreams_.begin(),
rtpStreams_.end(), rtpStreams_.end(),
[&label](const RtpStream& rtp) { [&label](const RtpStream& rtp) {
return (label.compare(rtp.mediaAttribute_->label_) == 0); return label == rtp.mediaAttribute_->label_;
}); });
// Return the index if there is a match. // Return the index if there is a match.
...@@ -420,9 +420,9 @@ SIPCall::generateMediaPorts() ...@@ -420,9 +420,9 @@ SIPCall::generateMediaPorts()
} }
void void
SIPCall::setContactHeader(pj_str_t* contact) SIPCall::setContactHeader(pj_str_t contact)
{ {
pj_strcpy(&contactHeader_, contact); pj_strcpy(&contactHeader_, &contact);
} }
void void
...@@ -696,9 +696,8 @@ SIPCall::terminateSipSession(int status) ...@@ -696,9 +696,8 @@ SIPCall::terminateSipSession(int status)
if (tdata) { if (tdata) {
auto account = getSIPAccount(); auto account = getSIPAccount();
if (account) { if (account) {
auto contact = account->getContactHeader(transport_ ? transport_->get() sip_utils::addContactHeader(account->getContactHeader(transport_ ? transport_->get()
: nullptr); : nullptr), tdata);
sip_utils::addContactHeader(&contact, tdata);
// Add user-agent header // Add user-agent header
sip_utils::addUserAgentHeader(account->getUserAgentName(), tdata); sip_utils::addUserAgentHeader(account->getUserAgentName(), tdata);
} else { } else {
...@@ -745,8 +744,7 @@ SIPCall::answer() ...@@ -745,8 +744,7 @@ SIPCall::answer()
Manager::instance().sipVoIPLink().createSDPOffer(inviteSession_.get()); Manager::instance().sipVoIPLink().createSDPOffer(inviteSession_.get());
} }
pj_str_t contact(account->getContactHeader(transport_ ? transport_->get() : nullptr)); setContactHeader(account->getContactHeader(transport_ ? transport_->get() : nullptr));
setContactHeader(&contact);
pjsip_tx_data* tdata; pjsip_tx_data* tdata;
if (!inviteSession_->last_answer) if (!inviteSession_->last_answer)
...@@ -767,7 +765,7 @@ SIPCall::answer() ...@@ -767,7 +765,7 @@ SIPCall::answer()
getCallId().c_str(), getCallId().c_str(),
(int) contactHeader_.slen, (int) contactHeader_.slen,
contactHeader_.ptr); contactHeader_.ptr);
sip_utils::addContactHeader(&contactHeader_, tdata); sip_utils::addContactHeader(contactHeader_, tdata);
} }
// Add user-agent header // Add user-agent header
...@@ -880,8 +878,7 @@ SIPCall::answer(const std::vector<DRing::MediaMap>& mediaList) ...@@ -880,8 +878,7 @@ SIPCall::answer(const std::vector<DRing::MediaMap>& mediaList)
} }
} }
pj_str_t contact(account->getContactHeader(transport_ ? transport_->get() : nullptr)); setContactHeader(account->getContactHeader(transport_ ? transport_->get() : nullptr));
setContactHeader(&contact);
if (!inviteSession_->last_answer) if (!inviteSession_->last_answer)
throw std::runtime_error("Should only be called for initial answer"); throw std::runtime_error("Should only be called for initial answer");
...@@ -903,7 +900,7 @@ SIPCall::answer(const std::vector<DRing::MediaMap>& mediaList) ...@@ -903,7 +900,7 @@ SIPCall::answer(const std::vector<DRing::MediaMap>& mediaList)
getCallId().c_str(), getCallId().c_str(),
(int) contactHeader_.slen, (int) contactHeader_.slen,
contactHeader_.ptr); contactHeader_.ptr);
sip_utils::addContactHeader(&contactHeader_, tdata); sip_utils::addContactHeader(contactHeader_, tdata);
} }
// Add user-agent header // Add user-agent header
...@@ -993,7 +990,7 @@ SIPCall::answerMediaChangeRequest(const std::vector<DRing::MediaMap>& mediaList) ...@@ -993,7 +990,7 @@ SIPCall::answerMediaChangeRequest(const std::vector<DRing::MediaMap>& mediaList)
} }
if (contactHeader_.slen) { if (contactHeader_.slen) {
sip_utils::addContactHeader(&contactHeader_, tdata); sip_utils::addContactHeader(contactHeader_, tdata);
} }
// Add user-agent header // Add user-agent header
...@@ -2462,8 +2459,7 @@ SIPCall::onReceiveOffer(const pjmedia_sdp_session* offer, const pjsip_rx_data* r ...@@ -2462,8 +2459,7 @@ SIPCall::onReceiveOffer(const pjmedia_sdp_session* offer, const pjsip_rx_data* r
} }
// ContactStr must stay in scope as long as tdata // ContactStr must stay in scope as long as tdata
const pj_str_t contactStr(getSIPAccount()->getContactHeader(getTransport()->get())); sip_utils::addContactHeader(getSIPAccount()->getContactHeader(getTransport()->get()), tdata);
sip_utils::addContactHeader(&contactStr, tdata);
if (pjsip_inv_send_msg(inviteSession_.get(), tdata) != PJ_SUCCESS) { if (pjsip_inv_send_msg(inviteSession_.get(), tdata) != PJ_SUCCESS) {
JAMI_ERR("Could not send msg OK"); JAMI_ERR("Could not send msg OK");
...@@ -2759,8 +2755,8 @@ SIPCall::monitor() const ...@@ -2759,8 +2755,8 @@ SIPCall::monitor() const
} }
JAMI_DBG("- Call %s with %s:", getCallId().c_str(), getPeerNumber().c_str()); JAMI_DBG("- Call %s with %s:", getCallId().c_str(), getPeerNumber().c_str());
JAMI_DBG("\t- Duration: %s", dht::print_duration(getCallDuration()).c_str()); JAMI_DBG("\t- Duration: %s", dht::print_duration(getCallDuration()).c_str());
for (auto& mediaAttr : getMediaAttributeList()) for (const auto& stream : rtpStreams_)
JAMI_DBG("\t- Media: %s", mediaAttr.toString(true).c_str()); JAMI_DBG("\t- Media: %s", stream.mediaAttribute_->toString(true).c_str());
#ifdef ENABLE_VIDEO #ifdef ENABLE_VIDEO
if (auto codec = getVideoCodec()) if (auto codec = getVideoCodec())
JAMI_DBG("\t- Video codec: %s", codec->systemCodecInfo.name.c_str()); JAMI_DBG("\t- Video codec: %s", codec->systemCodecInfo.name.c_str());
......
...@@ -214,7 +214,7 @@ public: ...@@ -214,7 +214,7 @@ public:
void onMediaNegotiationComplete(); void onMediaNegotiationComplete();
// End fo SiPVoipLink events // End fo SiPVoipLink events
void setContactHeader(pj_str_t* contact); void setContactHeader(pj_str_t contact);
void setTransport(const std::shared_ptr<SipTransport>& t); void setTransport(const std::shared_ptr<SipTransport>& t);
......
...@@ -561,10 +561,7 @@ transaction_request_cb(pjsip_rx_data* rdata) ...@@ -561,10 +561,7 @@ transaction_request_cb(pjsip_rx_data* rdata)
return PJ_FALSE; return PJ_FALSE;
} }
// contactStr must stay in scope as long as tdata sip_utils::addContactHeader(account->getContactHeader(transport->get()), tdata);
const pj_str_t contactStr(account->getContactHeader(transport->get()));
sip_utils::addContactHeader(&contactStr, tdata);
if (pjsip_inv_send_msg(call->inviteSession_.get(), tdata) != PJ_SUCCESS) { if (pjsip_inv_send_msg(call->inviteSession_.get(), tdata) != PJ_SUCCESS) {
JAMI_ERR("Could not send msg RINGING"); JAMI_ERR("Could not send msg RINGING");
return PJ_FALSE; return PJ_FALSE;
......
Supports Markdown
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