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

sipcall: cleanup

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