Module: kamailio
Branch: 5.8
Commit: 45ee72fcf0ae8aeb135196ef8729fe0cea14048e
URL:
https://github.com/kamailio/kamailio/commit/45ee72fcf0ae8aeb135196ef8729fe0…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2024-03-14T09:59:37+01:00
topos: properly handle cases of no user in contact for mode 1
- contact mode 1 accepted cases with no-user in contact uri but not in
r-uri, however, requests within dialog can have one's contact in r-uri
and then processing failed
(cherry picked from commit 24e410f9a20d004f55bcc79cd10fb35cb26e4570)
---
Modified: src/modules/topos/tps_storage.c
---
Diff:
https://github.com/kamailio/kamailio/commit/45ee72fcf0ae8aeb135196ef8729fe0…
Patch:
https://github.com/kamailio/kamailio/commit/45ee72fcf0ae8aeb135196ef8729fe0…
---
diff --git a/src/modules/topos/tps_storage.c b/src/modules/topos/tps_storage.c
index bb153bb780a..946092c04f9 100644
--- a/src/modules/topos/tps_storage.c
+++ b/src/modules/topos/tps_storage.c
@@ -223,6 +223,7 @@ int tps_storage_fill_contact(
int i;
int contact_len;
int cparam_len;
+ int cuser_len = 0;
sr_xavp_t *vavu = NULL;
if(dir == TPS_DIR_DOWNSTREAM) {
@@ -317,21 +318,27 @@ int tps_storage_fill_contact(
LM_ERR("failed to parse the contact uri\n");
return -1;
}
- memcpy(td->cp, curi.user.s, curi.user.len);
- td->cp += curi.user.len;
+ if(curi.user.len > 0) {
+ memcpy(td->cp, curi.user.s, curi.user.len);
+ td->cp += curi.user.len;
+ cuser_len = curi.user.len;
+ } else {
+ LM_DBG("no contact user - skipping it\n");
+ }
} else {
/* extract the ruri */
if(parse_sip_msg_uri(msg) < 0) {
LM_ERR("failed to parse r-uri\n");
return -1;
}
- if(msg->parsed_uri.user.len == 0) {
- LM_ERR("no r-uri user\n");
- return -1;
+ if(msg->parsed_uri.user.len > 0) {
+ memcpy(td->cp, msg->parsed_uri.user.s,
+ msg->parsed_uri.user.len);
+ td->cp += msg->parsed_uri.user.len;
+ cuser_len = msg->parsed_uri.user.len;
+ } else {
+ LM_DBG("no r-uri user - skipping it\n");
}
- memcpy(td->cp, msg->parsed_uri.user.s,
- msg->parsed_uri.user.len);
- td->cp += msg->parsed_uri.user.len;
}
} else if(ctmode == TPS_CONTACT_MODE_XAVPUSER) {
if(dir == TPS_DIR_DOWNSTREAM) {
@@ -344,6 +351,7 @@ int tps_storage_fill_contact(
}
memcpy(td->cp, vavu->val.v.s.s, vavu->val.v.s.len);
td->cp += vavu->val.v.s.len;
+ cuser_len = vavu->val.v.s.len;
} else {
/* extract the b contact */
vavu = xavu_get_child_with_sval(
@@ -354,11 +362,11 @@ int tps_storage_fill_contact(
}
memcpy(td->cp, vavu->val.v.s.s, vavu->val.v.s.len);
td->cp += vavu->val.v.s.len;
+ cuser_len = vavu->val.v.s.len;
}
}
- if(!((ctmode == TPS_CONTACT_MODE_RURIUSER)
- && (dir == TPS_DIR_DOWNSTREAM) && (curi.user.len <= 0))) {
+ if(cuser_len > 0) {
*td->cp = '@';
td->cp++;
}