Browse code

topos: added rr_update modparam

- control if record-route should be updated for requests within dialog

balajee authored on 07/01/2021 08:36:34 • Daniel-Constantin Mierla committed on 07/01/2021 09:24:13
Showing 3 changed files
... ...
@@ -78,6 +78,7 @@ sruid_t _tps_sruid;
78 78
 static str _tps_db_url = str_init(DEFAULT_DB_URL);
79 79
 int _tps_param_mask_callid = 0;
80 80
 int _tps_sanity_checks = 0;
81
+int _tps_rr_update = 0;
81 82
 str _tps_storage = str_init("db");
82 83
 
83 84
 extern int _tps_branch_expire;
... ...
@@ -141,6 +142,7 @@ static param_export_t params[]={
141 142
 	{"cparam_name",		PARAM_STR, &_tps_cparam_name},
142 143
 	{"a_contact_avp",	PARAM_STR, &_tps_acontact_avp},
143 144
 	{"b_contact_avp",	PARAM_STR, &_tps_bcontact_avp},
145
+	{"rr_update",       PARAM_INT, &_tps_rr_update},
144 146
 	{0,0,0}
145 147
 };
146 148
 
... ...
@@ -49,6 +49,7 @@
49 49
 extern int _tps_param_mask_callid;
50 50
 extern int _tps_contact_mode;
51 51
 extern str _tps_cparam_name;
52
+extern int _tps_rr_update;
52 53
 
53 54
 str _sr_hname_xbranch = str_init("P-SR-XBranch");
54 55
 str _sr_hname_xuuid = str_init("P-SR-XUID");
... ...
@@ -368,11 +369,18 @@ int tps_pack_message(sip_msg_t *msg, tps_data_t *ptsd)
368 369
 	int vlen;
369 370
 	int r2;
370 371
 	int isreq;
372
+	int rr_update = _tps_rr_update;
371 373
 
372 374
 	if(ptsd->cp==NULL) {
373 375
 		ptsd->cp = ptsd->cbuf;
374 376
 	}
375 377
 
378
+	if(_tps_rr_update) {
379
+		if((msg->first_line.type==SIP_REQUEST) && !(get_to(msg)->tag_value.len>0)) {
380
+			rr_update = 0;
381
+		}
382
+	}
383
+
376 384
 	i = 0;
377 385
 	for(hdr=msg->h_via1; hdr; hdr=next_sibling_hdr(hdr)) {
378 386
 		for(via=(struct via_body*)hdr->parsed; via; via=via->next) {
... ...
@@ -429,7 +437,7 @@ int tps_pack_message(sip_msg_t *msg, tps_data_t *ptsd)
429 437
 				LM_ERR("no more space to pack rr headers\n");
430 438
 				return -1;
431 439
 			}
432
-			if(isreq==1) {
440
+			if(isreq==1 || rr_update) {
433 441
 				/* sip request - get a+s-side record route */
434 442
 				if(i>1) {
435 443
 					if(i==2 &&r2==0) {
... ...
@@ -441,6 +449,12 @@ int tps_pack_message(sip_msg_t *msg, tps_data_t *ptsd)
441 449
 					*ptsd->cp = ',';
442 450
 					ptsd->cp++;
443 451
 					ptsd->a_rr.len++;
452
+					if(rr_update) {
453
+						ptsd->b_rr.len++;
454
+					}
455
+				}
456
+				if(i==1 && rr_update) {
457
+					ptsd->b_rr.s = ptsd->cp;
444 458
 				}
445 459
 				*ptsd->cp = '<';
446 460
 				if(i==1) {
... ...
@@ -458,6 +472,9 @@ int tps_pack_message(sip_msg_t *msg, tps_data_t *ptsd)
458 472
 
459 473
 				ptsd->cp++;
460 474
 				ptsd->a_rr.len++;
475
+				if(rr_update) {
476
+					ptsd->b_rr.len++;
477
+				}
461 478
 
462 479
 				memcpy(ptsd->cp, rr->nameaddr.uri.s, rr->nameaddr.uri.len);
463 480
 				if(i==1) {
... ...
@@ -483,6 +500,10 @@ int tps_pack_message(sip_msg_t *msg, tps_data_t *ptsd)
483 500
 				*ptsd->cp = '>';
484 501
 				ptsd->cp++;
485 502
 				ptsd->a_rr.len++;
503
+				if(rr_update) {
504
+					ptsd->b_rr.len += rr->nameaddr.uri.len;
505
+					ptsd->b_rr.len++;
506
+				}
486 507
 			} else {
487 508
 				/* sip response - get b-side record route */
488 509
 				if(i==1) {
... ...
@@ -879,6 +900,11 @@ int tps_request_received(sip_msg_t *msg, int dialog)
879 900
 	}
880 901
 	if(dialog!=0) {
881 902
 		tps_append_xuuid(msg, &stsd.a_uuid);
903
+		if(_tps_rr_update) {
904
+			if(tps_storage_update_dialog(msg, &mtsd, &stsd, TPS_DBU_RPLATTRS|TPS_DBU_BRR)<0) {
905
+				goto error;
906
+			}
907
+		}
882 908
 	}
883 909
 	return 0;
884 910
 
... ...
@@ -934,7 +960,9 @@ int tps_response_received(sip_msg_t *msg)
934 960
 				TPS_DBU_CONTACT|TPS_DBU_RPLATTRS)<0) {
935 961
 		goto error;
936 962
 	}
937
-	if(tps_storage_update_dialog(msg, &mtsd, &stsd, TPS_DBU_RPLATTRS)<0) {
963
+	if(tps_storage_update_dialog(msg, &mtsd, &stsd,
964
+			(_tps_rr_update)?(TPS_DBU_RPLATTRS|TPS_DBU_BRR|TPS_DBU_ARR)
965
+					:TPS_DBU_RPLATTRS)<0) {
938 966
 		goto error;
939 967
 	}
940 968
 	tps_storage_lock_release(&lkey);
... ...
@@ -1037,7 +1065,9 @@ int tps_request_sent(sip_msg_t *msg, int dialog, int local)
1037 1065
 
1038 1066
 	if(dialog!=0) {
1039 1067
 		tps_storage_end_dialog(msg, &mtsd, ptsd);
1040
-		if(tps_storage_update_dialog(msg, &mtsd, &stsd, TPS_DBU_CONTACT)<0) {
1068
+		if(tps_storage_update_dialog(msg, &mtsd, &stsd,
1069
+					(_tps_rr_update)?(TPS_DBU_CONTACT|TPS_DBU_ARR)
1070
+						:TPS_DBU_CONTACT)<0) {
1041 1071
 			goto error;
1042 1072
 		}
1043 1073
 	}
... ...
@@ -39,7 +39,9 @@
39 39
 
40 40
 #define TPS_DBU_CONTACT		(1<<0)
41 41
 #define TPS_DBU_RPLATTRS	(1<<1)
42
-#define TPS_DBU_ALL			(0xffffffff)
42
+#define TPS_DBU_ARR		(1<<2)
43
+#define TPS_DBU_BRR		(1<<3)
44
+#define TPS_DBU_ALL		(0xffffffff)
43 45
 
44 46
 #define TPS_DATA_SIZE	8192
45 47
 typedef struct tps_data {