[sr-dev] git:master:a8d4ca29: topos: detect first direction for dlg requests before linking contact

Daniel-Constantin Mierla miconda at gmail.com
Tue Jul 3 09:51:17 CEST 2018


Module: kamailio
Branch: master
Commit: a8d4ca293dba19b4b44110e9e7f5be71ce3c090b
URL: https://github.com/kamailio/kamailio/commit/a8d4ca293dba19b4b44110e9e7f5be71ce3c090b

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2018-07-03T09:50:46+02:00

topos: detect first direction for dlg requests before linking contact

- related to GH #1571

---

Modified: src/modules/topos/tps_msg.c
Modified: src/modules/topos/tps_storage.c
Modified: src/modules/topos/tps_storage.h

---

Diff:  https://github.com/kamailio/kamailio/commit/a8d4ca293dba19b4b44110e9e7f5be71ce3c090b.diff
Patch: https://github.com/kamailio/kamailio/commit/a8d4ca293dba19b4b44110e9e7f5be71ce3c090b.patch

---

diff --git a/src/modules/topos/tps_msg.c b/src/modules/topos/tps_msg.c
index 0027a08203..41cb7ef416 100644
--- a/src/modules/topos/tps_msg.c
+++ b/src/modules/topos/tps_msg.c
@@ -936,7 +936,7 @@ int tps_request_sent(sip_msg_t *msg, int dialog, int local)
 	memset(&mtsd, 0, sizeof(tps_data_t));
 	memset(&btsd, 0, sizeof(tps_data_t));
 	memset(&stsd, 0, sizeof(tps_data_t));
-	ptsd = &mtsd;
+	ptsd = NULL;
 
 	if(tps_pack_message(msg, &mtsd)<0) {
 		LM_ERR("failed to extract and pack the headers\n");
@@ -956,14 +956,6 @@ int tps_request_sent(sip_msg_t *msg, int dialog, int local)
 
 	tps_storage_lock_get(&lkey);
 
-	if(tps_storage_load_branch(msg, &mtsd, &btsd, 0)!=0) {
-		if(tps_storage_record(msg, ptsd, dialog)<0) {
-			goto error;
-		}
-	} else {
-		ptsd = &btsd;
-	}
-
 	if(dialog!=0) {
 		if(tps_storage_load_dialog(msg, &mtsd, &stsd)==0) {
 			ptsd = &stsd;
@@ -975,6 +967,16 @@ int tps_request_sent(sip_msg_t *msg, int dialog, int local)
 		mtsd.direction = direction;
 	}
 
+	if(tps_storage_load_branch(msg, &mtsd, &btsd, 0)!=0) {
+		if(tps_storage_record(msg, &mtsd, dialog, direction)<0) {
+			goto error;
+		}
+	} else {
+		if(ptsd==NULL) ptsd = &btsd;
+	}
+
+	if(ptsd==NULL) ptsd = &mtsd;
+
 	/* local generated requests */
 	if(local) {
 		/* ACK and CANCEL go downstream */
diff --git a/src/modules/topos/tps_storage.c b/src/modules/topos/tps_storage.c
index 5e0e87b249..08bf15ec8a 100644
--- a/src/modules/topos/tps_storage.c
+++ b/src/modules/topos/tps_storage.c
@@ -360,7 +360,7 @@ int tps_storage_link_msg(sip_msg_t *msg, tps_data_t *td, int dir)
 		}
 	}
 
-	LM_DBG("downstream: %s acontact: [%.*s] bcontact: [%.*s]\n",
+	LM_DBG("downstream: %s - acontact: [%.*s] - bcontact: [%.*s]\n",
 			(dir==TPS_DIR_DOWNSTREAM)?"yes":"no",
 			td->a_contact.len, (td->a_contact.len>0)?td->a_contact.s:"",
 			td->b_contact.len, (td->b_contact.len>0)?td->b_contact.s:"");
@@ -374,7 +374,7 @@ int tps_storage_link_msg(sip_msg_t *msg, tps_data_t *td, int dir)
 /**
  *
  */
-int tps_storage_record(sip_msg_t *msg, tps_data_t *td, int dialog)
+int tps_storage_record(sip_msg_t *msg, tps_data_t *td, int dialog, int dir)
 {
 	int ret = -1; /* error if dialog == 0 */
 	str suid;
@@ -399,7 +399,7 @@ int tps_storage_record(sip_msg_t *msg, tps_data_t *td, int dialog)
 	ret = tps_storage_fill_contact(msg, td, &suid, TPS_DIR_UPSTREAM);
 	if(ret<0) goto error;
 
-	ret = tps_storage_link_msg(msg, td, TPS_DIR_DOWNSTREAM);
+	ret = tps_storage_link_msg(msg, td, dir);
 	if(ret<0) goto error;
 	if(dialog==0) {
 		if(td->as_contact.len <= 0 && td->bs_contact.len <= 0) {
diff --git a/src/modules/topos/tps_storage.h b/src/modules/topos/tps_storage.h
index c10c3f2699..fc69ccca4c 100644
--- a/src/modules/topos/tps_storage.h
+++ b/src/modules/topos/tps_storage.h
@@ -87,7 +87,7 @@ int tps_storage_branch_find(sip_msg_t *msg, tps_data_t *td);
 int tps_storage_branch_save(sip_msg_t *msg, tps_data_t *td);
 int tps_storage_branch_rm(sip_msg_t *msg, tps_data_t *td);
 
-int tps_storage_record(sip_msg_t *msg, tps_data_t *td, int dialog);
+int tps_storage_record(sip_msg_t *msg, tps_data_t *td, int dialog, int dir);
 int tps_storage_load_branch(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd,
 		uint32_t mode);
 int tps_storage_update_branch(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd,




More information about the sr-dev mailing list