Browse code

topos: swapping direction handling for contact in response

Daniel-Constantin Mierla authored on 30/03/2016 12:28:27
Showing 2 changed files
... ...
@@ -624,7 +624,7 @@ int tps_reappend_route(sip_msg_t *msg, tps_data_t *ptsd, str *hbody, int rev)
624 624
 	if(rev==1) {
625 625
 		c = 0;
626 626
 		sb.len = 1;
627
-		for(i=hbody->len-2; i>=0; i++) {
627
+		for(i=hbody->len-2; i>=0; i--) {
628 628
 			if(hbody->s[i]==',') {
629 629
 				c = 1;
630 630
 				if(sb.len>0) {
... ...
@@ -707,7 +707,7 @@ int tps_request_received(sip_msg_t *msg, int dialog)
707 707
 	if(stsd.a_tag.len!=ftag.len) {
708 708
 		direction = TPS_DIR_UPSTREAM;
709 709
 	} else {
710
-		if(memcpy(stsd.a_tag.s, ftag.s, ftag.len)==0) {
710
+		if(memcmp(stsd.a_tag.s, ftag.s, ftag.len)==0) {
711 711
 			direction = TPS_DIR_DOWNSTREAM;
712 712
 		} else {
713 713
 			direction = TPS_DIR_UPSTREAM;
... ...
@@ -718,9 +718,9 @@ int tps_request_received(sip_msg_t *msg, int dialog)
718 718
 	tps_storage_lock_release(&lkey);
719 719
 
720 720
 	if(direction == TPS_DIR_UPSTREAM) {
721
-		nuri = stsd.b_contact;
722
-	} else {
723 721
 		nuri = stsd.a_contact;
722
+	} else {
723
+		nuri = stsd.b_contact;
724 724
 	}
725 725
 	if(nuri.len>0) {
726 726
 		if(rewrite_uri(msg, &nuri)<0) {
... ...
@@ -804,7 +804,7 @@ int tps_response_received(sip_msg_t *msg)
804 804
 	if(stsd.a_tag.len!=ftag.len) {
805 805
 		direction = TPS_DIR_UPSTREAM;
806 806
 	} else {
807
-		if(memcpy(stsd.a_tag.s, ftag.s, ftag.len)==0) {
807
+		if(memcmp(stsd.a_tag.s, ftag.s, ftag.len)==0) {
808 808
 			direction = TPS_DIR_DOWNSTREAM;
809 809
 		} else {
810 810
 			direction = TPS_DIR_UPSTREAM;
... ...
@@ -311,10 +311,18 @@ int tps_storage_link_msg(sip_msg_t *msg, tps_data_t *td, int dir)
311 311
 		LM_ERR("bad Contact header\n");
312 312
 		return -1;
313 313
 	}
314
-	if(dir==TPS_DIR_DOWNSTREAM) {
315
-		td->a_contact = ((contact_body_t*)msg->contact->parsed)->contacts->uri;
314
+	if(msg->first_line.type==SIP_REQUEST) {
315
+		if(dir==TPS_DIR_DOWNSTREAM) {
316
+			td->a_contact = ((contact_body_t*)msg->contact->parsed)->contacts->uri;
317
+		} else {
318
+			td->b_contact = ((contact_body_t*)msg->contact->parsed)->contacts->uri;
319
+		}
316 320
 	} else {
317
-		td->b_contact = ((contact_body_t*)msg->contact->parsed)->contacts->uri;
321
+		if(dir==TPS_DIR_DOWNSTREAM) {
322
+			td->b_contact = ((contact_body_t*)msg->contact->parsed)->contacts->uri;
323
+		} else {
324
+			td->a_contact = ((contact_body_t*)msg->contact->parsed)->contacts->uri;
325
+		}
318 326
 	}
319 327
 
320 328
 	return 0;
... ...
@@ -862,21 +870,38 @@ int tps_storage_load_dialog(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd)
862 870
 	if(msg==NULL || md==NULL || sd==NULL || _tps_db_handle==NULL)
863 871
 		return -1;
864 872
 
873
+	if(md->a_uuid.len<=0 && md->b_uuid.len<=0) {
874
+		LM_ERR("no dlg uuid provided\n");
875
+		return -1;
876
+	}
877
+
865 878
 	nr_keys = 0;
866 879
 	nr_cols = 0;
867 880
 
868
-	db_keys[nr_keys]=&td_col_a_uuid;
869 881
 	db_ops[nr_keys]=OP_EQ;
870 882
 	db_vals[nr_keys].type = DB1_STR;
871 883
 	db_vals[nr_keys].nul = 0;
872
-	if(md->a_uuid.len>0 && md->a_uuid.s[0]=='a') {
873
-		db_vals[nr_keys].val.str_val = TPS_STRZ(md->a_uuid);
884
+	db_vals[nr_keys].val.str_val.len = 0;
885
+	if(md->a_uuid.len>0) {
886
+		if(md->a_uuid.s[0]=='a') {
887
+			db_keys[nr_keys]=&td_col_a_uuid;
888
+			db_vals[nr_keys].val.str_val = TPS_STRZ(md->a_uuid);
889
+		} else if(md->a_uuid.s[0]=='b') {
890
+			db_keys[nr_keys]=&td_col_b_uuid;
891
+			db_vals[nr_keys].val.str_val = TPS_STRZ(md->a_uuid);
892
+		}
874 893
 	} else {
875
-		if(md->b_uuid.len<=0) {
876
-			LM_ERR("no valid dlg uuid\n");
877
-			return -1;
894
+		if(md->b_uuid.s[0]=='a') {
895
+			db_keys[nr_keys]=&td_col_a_uuid;
896
+			db_vals[nr_keys].val.str_val = TPS_STRZ(md->b_uuid);
897
+		} else if(md->b_uuid.s[0]=='b') {
898
+			db_keys[nr_keys]=&td_col_b_uuid;
899
+			db_vals[nr_keys].val.str_val = TPS_STRZ(md->b_uuid);
878 900
 		}
879
-		db_vals[nr_keys].val.str_val = TPS_STRZ(md->b_uuid);
901
+	}
902
+	if(db_vals[nr_keys].val.str_val.len<=0) {
903
+		LM_ERR("invalid dlg uuid provided\n");
904
+		return -1;
880 905
 	}
881 906
 	nr_keys++;
882 907