浏览代码

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
Daniel-Constantin Mierla 1 年之前
父节点
当前提交
24e410f9a2
共有 1 个文件被更改,包括 18 次插入10 次删除
  1. 18 10
      src/modules/topos/tps_storage.c

+ 18 - 10
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++;
 		}