Commit e1dd5aa0 authored by Simon Morlat's avatar Simon Morlat

Fix issue with x-target-uri handling. It shall be removed all the time when...

Fix issue with x-target-uri handling. It shall be removed all the time when resolved, unless for fallback route, which is by definition not something used when a target uri is resolved.
parent a09056f8
Pipeline #2790 passed with stages
in 29 minutes and 52 seconds
......@@ -73,12 +73,14 @@ struct ExtendedContact {
time_t mExpireNotAtMessage; // real expires time but not for message
time_t mUpdatedTime;
uint32_t mCSeq;
bool mAlias;
std::list<std::string> mAcceptHeader;
bool mUsedAsRoute; /*whether the contact information shall be used as a route when forming a request, instead of
replacing the request-uri*/
uintptr_t mConnId; // a unique id shared with associate t_port
SofiaAutoHome mHome;
bool mAlias;
bool mUsedAsRoute; /*whether the contact information shall be used as a route when forming a request, instead of
replacing the request-uri*/
bool mIsFallback = false; // boolean indicating whether this ExtendedContact is a fallback route or not. There is no need for it to be serialized to database.
const char *callId() const {
return mCallId.c_str();
......@@ -144,7 +146,7 @@ struct ExtendedContact {
ExtendedContact(const char *contactId, const char *uniqueId, const char* fullUrl)
: mCallId(), mUserAgent(), mSipContact(nullptr), mQ(1.0), mExpireAt(LONG_MAX), mExpireNotAtMessage(LONG_MAX),
mUpdatedTime(0), mCSeq(0), mAlias(false), mAcceptHeader({}), mUsedAsRoute(false), mConnId(0), mHome() {
mUpdatedTime(0), mCSeq(0), mAcceptHeader({}), mConnId(0), mHome(), mAlias(false), mUsedAsRoute(false) {
if (contactId) mContactId = contactId;
if (uniqueId) mUniqueId = uniqueId;
extractInfoFromUrl(fullUrl);
......@@ -155,7 +157,7 @@ struct ExtendedContact {
time_t updateTime, bool alias, const std::list<std::string> &acceptHeaders, const std::string &userAgent)
: mContactId(common.mContactId), mCallId(common.mCallId), mUniqueId(common.mUniqueId), mPath(common.mPath),
mUserAgent(userAgent), mSipContact(nullptr), mQ(1.0),mExpireNotAtMessage(global_expire), mUpdatedTime(updateTime),
mCSeq(cseq), mAlias(alias), mAcceptHeader(acceptHeaders), mUsedAsRoute(false), mConnId(0), mHome() {
mCSeq(cseq), mAcceptHeader(acceptHeaders), mConnId(0), mHome(), mAlias(alias), mUsedAsRoute(false) {
mSipContact = sip_contact_dup(mHome.home(), sip_contact);
mSipContact->m_next = nullptr;
......@@ -164,15 +166,15 @@ struct ExtendedContact {
ExtendedContact(const url_t *url, const std::string &route, const float q = 1.0)
: mContactId(), mCallId(), mUniqueId(), mPath({route}), mUserAgent(), mSipContact(nullptr), mQ(q), mExpireAt(LONG_MAX),
mExpireNotAtMessage(LONG_MAX), mUpdatedTime(0), mCSeq(0), mAlias(false), mAcceptHeader({}), mUsedAsRoute(false),
mConnId(0), mHome() {
mExpireNotAtMessage(LONG_MAX), mUpdatedTime(0), mCSeq(0), mAcceptHeader({}),
mConnId(0), mHome(), mAlias(false), mUsedAsRoute(false) {
mSipContact = sip_contact_create(mHome.home(), (url_string_t*)url, nullptr);
}
ExtendedContact(const ExtendedContact &ec)
: mContactId(ec.mContactId), mCallId(ec.mCallId), mUniqueId(ec.mUniqueId), mPath(ec.mPath), mUserAgent(ec.mUserAgent),
mSipContact(nullptr), mQ(ec.mQ), mExpireAt(ec.mExpireAt), mExpireNotAtMessage(ec.mExpireNotAtMessage), mUpdatedTime(ec.mUpdatedTime),
mCSeq(ec.mCSeq), mAlias(ec.mAlias), mAcceptHeader(ec.mAcceptHeader), mUsedAsRoute(ec.mUsedAsRoute), mConnId(ec.mConnId), mHome() {
mCSeq(ec.mCSeq), mAcceptHeader(ec.mAcceptHeader), mConnId(ec.mConnId), mHome(), mAlias(ec.mAlias), mUsedAsRoute(ec.mUsedAsRoute), mIsFallback(ec.mIsFallback){
mSipContact = sip_contact_dup(mHome.home(), ec.mSipContact);
mSipContact->m_next = nullptr;
}
......
......@@ -289,6 +289,14 @@ bool ModuleRouter::dispatch(const shared_ptr<RequestSipEvent> &ev, const shared_
r->r_next = final_route;
}
}
if (!contact->mIsFallback){
/* If the original request received contained a X-Target-Uris, it shall be removed now, except
* in the case where we send to a fallback route, because in this case the actual resolution of the X-Target-Uris is
* actually not done at all. */
sip_unknown_t *h = ModuleToolbox::getCustomHeaderByName(new_ev->getMsgSip()->getSip(), "X-Target-Uris");
if (h) sip_header_remove(new_ev->getMsgSip()->getMsg(), new_ev->getMsgSip()->getSip(), (sip_header_t *)h);
}
if (!targetUris.empty()) {
sip_header_insert(new_msg, new_sip, (sip_header_t *)sip_unknown_format(msg_home(new_msg), "X-Target-Uris: %s",
targetUris.c_str()));
......@@ -776,14 +784,6 @@ class TargetUriListFetcher : public ContactUpdateListener,
mListener->onError();
}else{
if (mRecord->count() > 0){
/*
* When contacts are found, we then remove the X-target-uris.
* If no contacts are found, the X-target-uris is left as it is, so that if a fallback route is specified,
* the proxy pointed by this fallback route will process it.
*/
sip_unknown_t *h = ModuleToolbox::getCustomHeaderByName(mEv->getMsgSip()->getSip(), "X-Target-Uris");
if (h) sip_header_remove(mEv->getMsgSip()->getMsg(), mEv->getMsgSip()->getSip(), (sip_header_t *)h);
/*also add aliases in the ExtendedContact list for the searched AORs, so that they are added to the ForkMap.*/
sip_route_t *iter;
for (iter = mUriList; iter != NULL; iter = iter->r_next) {
......@@ -832,6 +832,7 @@ class OnFetchForRoutingListener : public ContactUpdateListener {
if (!fallbackRoute.empty()) {
if (!ModuleToolbox::viaContainsUrlHost(mEv->getMsgSip()->getSip()->sip_via, mModule->getFallbackRouteParsed())) {
shared_ptr<ExtendedContact> fallback = make_shared<ExtendedContact>(mSipUri, fallbackRoute, 0.0);
fallback->mIsFallback = true;
r->pushContact(fallback);
SLOGD << "Record [" << r << "] Fallback route '" << fallbackRoute << "' added: " << *fallback;
}else{
......
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