[sr-dev] git:master:7c48b0fc: topos: swapping direction handling for contact in response

Daniel-Constantin Mierla miconda at gmail.com
Wed Mar 30 14:29:16 CEST 2016


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

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2016-03-30T14:28:27+02:00

topos: swapping direction handling for contact in response

---

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

---

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

---

diff --git a/modules/topos/tps_msg.c b/modules/topos/tps_msg.c
index 4d747cd..2f398e8 100644
--- a/modules/topos/tps_msg.c
+++ b/modules/topos/tps_msg.c
@@ -624,7 +624,7 @@ int tps_reappend_route(sip_msg_t *msg, tps_data_t *ptsd, str *hbody, int rev)
 	if(rev==1) {
 		c = 0;
 		sb.len = 1;
-		for(i=hbody->len-2; i>=0; i++) {
+		for(i=hbody->len-2; i>=0; i--) {
 			if(hbody->s[i]==',') {
 				c = 1;
 				if(sb.len>0) {
@@ -707,7 +707,7 @@ int tps_request_received(sip_msg_t *msg, int dialog)
 	if(stsd.a_tag.len!=ftag.len) {
 		direction = TPS_DIR_UPSTREAM;
 	} else {
-		if(memcpy(stsd.a_tag.s, ftag.s, ftag.len)==0) {
+		if(memcmp(stsd.a_tag.s, ftag.s, ftag.len)==0) {
 			direction = TPS_DIR_DOWNSTREAM;
 		} else {
 			direction = TPS_DIR_UPSTREAM;
@@ -718,9 +718,9 @@ int tps_request_received(sip_msg_t *msg, int dialog)
 	tps_storage_lock_release(&lkey);
 
 	if(direction == TPS_DIR_UPSTREAM) {
-		nuri = stsd.b_contact;
-	} else {
 		nuri = stsd.a_contact;
+	} else {
+		nuri = stsd.b_contact;
 	}
 	if(nuri.len>0) {
 		if(rewrite_uri(msg, &nuri)<0) {
@@ -804,7 +804,7 @@ int tps_response_received(sip_msg_t *msg)
 	if(stsd.a_tag.len!=ftag.len) {
 		direction = TPS_DIR_UPSTREAM;
 	} else {
-		if(memcpy(stsd.a_tag.s, ftag.s, ftag.len)==0) {
+		if(memcmp(stsd.a_tag.s, ftag.s, ftag.len)==0) {
 			direction = TPS_DIR_DOWNSTREAM;
 		} else {
 			direction = TPS_DIR_UPSTREAM;
diff --git a/modules/topos/tps_storage.c b/modules/topos/tps_storage.c
index 8852369..a78cca3 100644
--- a/modules/topos/tps_storage.c
+++ b/modules/topos/tps_storage.c
@@ -311,10 +311,18 @@ int tps_storage_link_msg(sip_msg_t *msg, tps_data_t *td, int dir)
 		LM_ERR("bad Contact header\n");
 		return -1;
 	}
-	if(dir==TPS_DIR_DOWNSTREAM) {
-		td->a_contact = ((contact_body_t*)msg->contact->parsed)->contacts->uri;
+	if(msg->first_line.type==SIP_REQUEST) {
+		if(dir==TPS_DIR_DOWNSTREAM) {
+			td->a_contact = ((contact_body_t*)msg->contact->parsed)->contacts->uri;
+		} else {
+			td->b_contact = ((contact_body_t*)msg->contact->parsed)->contacts->uri;
+		}
 	} else {
-		td->b_contact = ((contact_body_t*)msg->contact->parsed)->contacts->uri;
+		if(dir==TPS_DIR_DOWNSTREAM) {
+			td->b_contact = ((contact_body_t*)msg->contact->parsed)->contacts->uri;
+		} else {
+			td->a_contact = ((contact_body_t*)msg->contact->parsed)->contacts->uri;
+		}
 	}
 
 	return 0;
@@ -862,21 +870,38 @@ int tps_storage_load_dialog(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd)
 	if(msg==NULL || md==NULL || sd==NULL || _tps_db_handle==NULL)
 		return -1;
 
+	if(md->a_uuid.len<=0 && md->b_uuid.len<=0) {
+		LM_ERR("no dlg uuid provided\n");
+		return -1;
+	}
+
 	nr_keys = 0;
 	nr_cols = 0;
 
-	db_keys[nr_keys]=&td_col_a_uuid;
 	db_ops[nr_keys]=OP_EQ;
 	db_vals[nr_keys].type = DB1_STR;
 	db_vals[nr_keys].nul = 0;
-	if(md->a_uuid.len>0 && md->a_uuid.s[0]=='a') {
-		db_vals[nr_keys].val.str_val = TPS_STRZ(md->a_uuid);
+	db_vals[nr_keys].val.str_val.len = 0;
+	if(md->a_uuid.len>0) {
+		if(md->a_uuid.s[0]=='a') {
+			db_keys[nr_keys]=&td_col_a_uuid;
+			db_vals[nr_keys].val.str_val = TPS_STRZ(md->a_uuid);
+		} else if(md->a_uuid.s[0]=='b') {
+			db_keys[nr_keys]=&td_col_b_uuid;
+			db_vals[nr_keys].val.str_val = TPS_STRZ(md->a_uuid);
+		}
 	} else {
-		if(md->b_uuid.len<=0) {
-			LM_ERR("no valid dlg uuid\n");
-			return -1;
+		if(md->b_uuid.s[0]=='a') {
+			db_keys[nr_keys]=&td_col_a_uuid;
+			db_vals[nr_keys].val.str_val = TPS_STRZ(md->b_uuid);
+		} else if(md->b_uuid.s[0]=='b') {
+			db_keys[nr_keys]=&td_col_b_uuid;
+			db_vals[nr_keys].val.str_val = TPS_STRZ(md->b_uuid);
 		}
-		db_vals[nr_keys].val.str_val = TPS_STRZ(md->b_uuid);
+	}
+	if(db_vals[nr_keys].val.str_val.len<=0) {
+		LM_ERR("invalid dlg uuid provided\n");
+		return -1;
 	}
 	nr_keys++;
 




More information about the sr-dev mailing list