Skip to content
Snippets Groups Projects
Commit abebe234 authored by Alexandre Savard's avatar Alexandre Savard
Browse files

#3674: Apply contact header update optionnaly

parent 0661b858
No related branches found
No related tags found
No related merge requests found
......@@ -59,6 +59,7 @@ SIPAccount::SIPAccount(const std::string& accountID)
, cred_(NULL)
, tlsSetting_()
, contactHeader_()
, contactUpdateEnabled_(false)
, stunServerName_()
, stunPort_(0)
, dtmfType_(OVERRTP_STR)
......@@ -760,6 +761,24 @@ std::string SIPAccount::getServerUri() const
return "<" + scheme + hostname_ + transport + ">";
}
void SIPAccount::setContactHeader(std::string address, std::string port)
{
std::string scheme;
std::string transport;
// UDP does not require the transport specification
if (transportType_ == PJSIP_TRANSPORT_TLS) {
scheme = "sips:";
transport = ";transport=" + std::string(pjsip_transport_get_type_name(transportType_));
} else
scheme = "sip:";
contactHeader_ = displayName_ + (displayName_.empty() ? "" : " ") + "<" +
scheme + username_ + (username_.empty() ? "":"@") +
address + ":" + port + transport + ">";
}
std::string SIPAccount::getContactHeader() const
{
std::string scheme;
......
......@@ -364,10 +364,7 @@ class SIPAccount : public Account {
* @param port Optional port. Otherwise set to the port defined for that account.
* @param hostname Optional local address. Otherwise set to the hostname defined for that account.
*/
void setContactHeader(std::string& contact)
{
contactHeader_ = contact;
}
void setContactHeader(std::string address, std::string port);
/**
* Get the contact header for
......@@ -375,6 +372,24 @@ class SIPAccount : public Account {
*/
std::string getContactHeader(void) const;
/**
* The contact header can be rewritten based on the contact provided by the registrar in 200 OK
*/
void enableContactUpdate(void) {
contactUpdateEnabled_ = true;
}
/**
* The contact header is not updated even if the registrar
*/
void disableContactUpdate(void) {
contactUpdateEnabled_ = false;
}
bool isContactUpdateEnabled(void) {
return contactUpdateEnabled_;
}
/**
* Get the local interface name on which this account is bound.
*/
......@@ -572,6 +587,11 @@ class SIPAccount : public Account {
*/
std::string contactHeader_;
/**
* Enble the contact header based on the header received from the registrar in 200 OK
*/
bool contactUpdateEnabled_;
/**
* The STUN server name (hostname)
*/
......
......@@ -304,8 +304,7 @@ void SIPVoIPLink::sendRegister(Account *a)
std::string from(account->getFromUri());
pj_str_t pjFrom = pj_str((char*) from.c_str());
// Store the CONTACT header for future usage
// account->setContactHeader(address, port);
// Get the contact header for this account
std::string contact(account->getContactHeader());
pj_str_t pjContact = pj_str((char*) contact.c_str());
......@@ -1618,10 +1617,12 @@ static void update_contact_header(struct pjsip_regc_cbparam *param, SIPAccount *
pj_pool_t *pool = NULL;
pjsip_contact_hdr *contact_hdr = NULL;
pjsip_sip_uri *uri = NULL;
std::string currentContactHeader = "";
// if(!account->updateContactAllowed())
// return;
SIPVoIPLink *siplink = dynamic_cast<SIPVoIPLink *>(account->getVoIPLink());
if(siplink == NULL) {
ERROR("SIPVoIPLink: Could not find voip link from account");
return;
}
pool = pj_pool_create(&cp_->factory, "tmp", 512, 512, NULL);
if(pool == NULL) {
......@@ -1655,13 +1656,34 @@ static void update_contact_header(struct pjsip_regc_cbparam *param, SIPAccount *
std::stringstream ss;
ss << uri->port;
std::string recvContactPort = ss.str();
DEBUG("SIPVoIPLink: Current contact header %s:%s", recvContactHost.c_str(), recvContactPort.c_str());
currentContactHeader = account->getContactHeader();
DEBUG("SIPVoIPLink: Current contact header %s", currentContactHeader.c_str());
std::string currentAddress, currentPort;
siplink->findLocalAddressFromTransport(account->transport_, PJSIP_TRANSPORT_UDP, currentAddress, currentPort);
DEBUG("SIPVoIPLink: Current contact header %s:%s\n", currentAddress.c_str(), currentPort.c_str());
// DEBUG("Received contact header %s",
bool updateContact = false;
std::string currentContactHeader = account->getContactHeader();
size_t foundHost = currentContactHeader.find(recvContactHost);
if(foundHost == std::string::npos) {
DEBUG("SIPVoIPLink: Host %s not in current contact header\n", recvContactHost.c_str());
updateContact = true;
}
size_t foundPort = currentContactHeader.find(recvContactPort);
if(foundPort == std::string::npos) {
DEBUG("SIPVoIPLink: Port %s not in current contact header\n", recvContactPort.c_str());
updateContact = true;
}
if(updateContact) {
account->setContactHeader(recvContactHost, recvContactPort);
siplink->sendRegister(account);
}
pj_pool_release(pool);
}
......@@ -1682,7 +1704,9 @@ void registration_cb(struct pjsip_regc_cbparam *param)
}
DEBUG("SipVoipLink: Contact header from UAS, %d contact(s)", param->contact_cnt);
update_contact_header(param, account);
if(account->isContactUpdateEnabled()) {
update_contact_header(param, account);
}
const pj_str_t *description = pjsip_get_status_text(param->code);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment