Browse code

topos: disable multiple comma separated values in One Single Via, Record-Route or Route header

emvondo authored on 18/08/2022 17:29:57
Showing 3 changed files
... ...
@@ -81,7 +81,7 @@ static str _tps_db_url = str_init(DEFAULT_DB_URL);
81 81
 int _tps_param_mask_callid = 0;
82 82
 int _tps_sanity_checks = 0;
83 83
 int _tps_rr_update = 0;
84
-int _tps_separate_via = 0;
84
+int _tps_separate_hv = 0;
85 85
 str _tps_storage = str_init("db");
86 86
 
87 87
 extern int _tps_branch_expire;
... ...
@@ -157,7 +157,7 @@ static param_export_t params[]={
157 157
 	{"db_url",		PARAM_STR, &_tps_db_url},
158 158
 	{"mask_callid",		PARAM_INT, &_tps_param_mask_callid},
159 159
 	{"sanity_checks",	PARAM_INT, &_tps_sanity_checks},
160
-	{"separate_via",    PARAM_INT, &_tps_separate_via},
160
+	{"separate_header_values",	PARAM_INT, &_tps_separate_hv},
161 161
 	{"branch_expire",	PARAM_INT, &_tps_branch_expire},
162 162
 	{"dialog_expire",	PARAM_INT, &_tps_dialog_expire},
163 163
 	{"clean_interval",	PARAM_INT, &_tps_clean_interval},
... ...
@@ -50,7 +50,7 @@ extern int _tps_param_mask_callid;
50 50
 extern int _tps_contact_mode;
51 51
 extern str _tps_cparam_name;
52 52
 extern int _tps_rr_update;
53
-extern int _tps_separate_via;
53
+extern int _tps_separate_hv;
54 54
 
55 55
 extern str _tps_context_param;
56 56
 extern str _tps_context_value;
... ...
@@ -632,9 +632,9 @@ int tps_remove_name_headers(sip_msg_t *msg, str *hname)
632 632
 /**
633 633
  *
634 634
  */
635
-int tps_reappend_via_separate_header(sip_msg_t *msg, tps_data_t *ptsd, str *hbody)
635
+int tps_reappend_separate_header_values(sip_msg_t *msg, tps_data_t *ptsd, str *hbody, str *hname)
636 636
 {
637
-        str hname = str_init("Via");
637
+
638 638
         int i;
639 639
         str sb;
640 640
         char *p = NULL;
... ...
@@ -649,7 +649,7 @@ int tps_reappend_via_separate_header(sip_msg_t *msg, tps_data_t *ptsd, str *hbod
649 649
                 if(sb.len>0) {
650 650
                     sb.s = p;
651 651
                     if(sb.s[sb.len-1]==',') sb.len--;
652
-                    if(tps_add_headers(msg, &hname, &sb, 0)<0) {
652
+                    if(tps_add_headers(msg, hname, &sb, 0)<0) {
653 653
                         return -1;
654 654
                     }
655 655
                 }
... ...
@@ -663,7 +663,7 @@ int tps_reappend_via_separate_header(sip_msg_t *msg, tps_data_t *ptsd, str *hbod
663 663
         if(sb.len>0) {
664 664
                 sb.s = p;
665 665
                 if(sb.s[sb.len-1]==',') sb.len--;
666
-                if(tps_add_headers(msg, &hname, &sb, 0)<0) {
666
+                if(tps_add_headers(msg, hname, &sb, 0)<0) {
667 667
                     return -1;
668 668
                 }
669 669
         }
... ...
@@ -676,8 +676,8 @@ int tps_reappend_via(sip_msg_t *msg, tps_data_t *ptsd, str *hbody)
676 676
 {
677 677
 	str hname = str_init("Via");
678 678
 
679
-    if (_tps_separate_via!= 0)
680
-        return tps_reappend_via_separate_header(msg, ptsd, hbody);
679
+	if (TPS_SEPERATE_VIA & _tps_separate_hv)
680
+		return tps_reappend_separate_header_values(msg, ptsd, hbody,&hname);
681 681
 
682 682
 	if(tps_add_headers(msg, &hname, hbody, 0)<0) {
683 683
 		return -1;
... ...
@@ -788,6 +788,9 @@ int tps_reappend_rr(sip_msg_t *msg, tps_data_t *ptsd, str *hbody)
788 788
 {
789 789
 	str hname = str_init("Record-Route");
790 790
 
791
+	if (TPS_SEPERATE_RECORD_ROUTE & _tps_separate_hv)
792
+		return tps_reappend_separate_header_values(msg, ptsd, hbody,&hname);
793
+
791 794
 	if(tps_add_headers(msg, &hname, hbody, 0)<0) {
792 795
 		return -1;
793 796
 	}
... ...
@@ -842,6 +845,8 @@ int tps_reappend_route(sip_msg_t *msg, tps_data_t *ptsd, str *hbody, int rev)
842 845
 	trim_zeros_lr(&sb);
843 846
 	trim(&sb);
844 847
 	if(sb.len>0 && sb.s[sb.len-1]==',') sb.len--;
848
+	if (TPS_SEPERATE_ROUTE & _tps_separate_hv)
849
+		return tps_reappend_separate_header_values(msg, ptsd, &sb,&hname);
845 850
 	if(tps_add_headers(msg, &hname, &sb, 0)<0) {
846 851
 		return -1;
847 852
 	}
... ...
@@ -31,6 +31,10 @@
31 31
 
32 32
 #include "../../core/parser/msg_parser.h"
33 33
 
34
+#define TPS_SEPERATE_VIA            (1<<0)
35
+#define TPS_SEPERATE_RECORD_ROUTE   (1<<1)
36
+#define TPS_SEPERATE_ROUTE          (1<<2)
37
+
34 38
 int tps_update_hdr_replaces(sip_msg_t *msg);
35 39
 char* tps_msg_update(sip_msg_t *msg, unsigned int *olen);
36 40
 int tps_skip_msg(sip_msg_t *msg);