Browse code

core: new internal msg flag to add srvid param to local via

Daniel-Constantin Mierla authored on 12/04/2018 07:51:10
Showing 2 changed files
... ...
@@ -2847,6 +2847,8 @@ char* create_via_hf( unsigned int *len,
2847 2847
 	char* via;
2848 2848
 	str extra_params;
2849 2849
 	struct hostport hp;
2850
+	char sbuf[24];
2851
+	int slen;
2850 2852
 #if defined USE_TCP || defined USE_SCTP
2851 2853
 	char* id_buf;
2852 2854
 	unsigned int id_len;
... ...
@@ -2906,6 +2908,29 @@ char* create_via_hf( unsigned int *len,
2906 2908
 		extra_params.s[extra_params.len]='\0';
2907 2909
 	}
2908 2910
 
2911
+	/* test and add srvid parameter to local via  */
2912
+	if(msg && msg->msg_flags&FL_ADD_SRVID && server_id!=0) {
2913
+		slen = snprintf(sbuf, 24, ";srvid=%u", (unsigned int)server_id);
2914
+		if(slen<=0 || slen>=24) {
2915
+			LM_WARN("failed to buld srvid parameter");
2916
+		} else {
2917
+			via = (char*)pkg_malloc(extra_params.len+slen+1);
2918
+			if(via==0) {
2919
+				LM_ERR("building srvid param failed\n");
2920
+				if (extra_params.s) pkg_free(extra_params.s);
2921
+				return 0;
2922
+			}
2923
+			if(extra_params.len != 0) {
2924
+				memcpy(via, extra_params.s, extra_params.len);
2925
+				pkg_free(extra_params.s);
2926
+			}
2927
+			memcpy(via + extra_params.len, sbuf, slen);
2928
+			extra_params.s = via;
2929
+			extra_params.len += slen;
2930
+			extra_params.s[extra_params.len] = '\0';
2931
+		}
2932
+	}
2933
+
2909 2934
 	set_hostport(&hp, msg);
2910 2935
 	via = via_builder( len, send_info, branch,
2911 2936
 							extra_params.len?&extra_params:0, &hp);
... ...
@@ -100,6 +100,7 @@ typedef enum request_method {
100 100
 #define FL_BODY_MULTIPART    (1<<17)  /* body modified is multipart */
101 101
 #define FL_RR_ADDED          (1<<18)  /* Record-Route header was added */
102 102
 #define FL_UAC_AUTH          (1<<19)  /* Proxy UAC-like authentication */
103
+#define FL_ADD_SRVID         (1<<20) /*!< add 'srvid' to local via hdr */
103 104
 
104 105
 /* WARNING: Value (1 << 28) is temporarily reserved for use in kamailio call_control
105 106
  * module (flag  FL_USE_CALL_CONTROL )! */