Module: kamailio
Branch: 5.7
Commit: 1666d4bce924b8c0d44119491199a164c9642469
URL:
https://github.com/kamailio/kamailio/commit/1666d4bce924b8c0d44119491199a16…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2024-03-14T10:12:11+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)
(cherry picked from commit 45ee72fcf0ae8aeb135196ef8729fe0cea14048e)
---
Modified: src/modules/topos/tps_storage.c
---
Diff:
https://github.com/kamailio/kamailio/commit/1666d4bce924b8c0d44119491199a16…
Patch:
https://github.com/kamailio/kamailio/commit/1666d4bce924b8c0d44119491199a16…
---
diff --git a/src/modules/topos/tps_storage.c b/src/modules/topos/tps_storage.c
index 1399017cf77..a7b331ca7f4 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) {
@@ -315,21 +316,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 == 2) {
if(dir == TPS_DIR_DOWNSTREAM) {
@@ -342,6 +349,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(
@@ -352,11 +360,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 == 1) && (dir == TPS_DIR_DOWNSTREAM)
- && (curi.user.len <= 0))) {
+ if(cuser_len > 0) {
*td->cp = '@';
td->cp++;
}