Browse code

core: new option BUILD_NEW_LOCAL_VIA to recreate the local via

- to be used from tm uac when a local-generated request has to update
the via header following the event route execution

Daniel-Constantin Mierla authored on 17/02/2021 07:21:36
Showing 2 changed files
... ...
@@ -1971,7 +1971,7 @@ clean:
1971 1971
   * depending on the presence of the BUILD_IN_SHM flag, needs freeing when
1972 1972
   *   done) and sets returned_len or 0 on error.
1973 1973
   */
1974
-char * build_req_buf_from_sip_req( struct sip_msg* msg,
1974
+char * build_req_buf_from_sip_req(struct sip_msg* msg,
1975 1975
 								unsigned int *returned_len,
1976 1976
 								struct dest_info* send_info,
1977 1977
 								unsigned int mode)
... ...
@@ -1987,6 +1987,7 @@ char * build_req_buf_from_sip_req( struct sip_msg* msg,
1987 1987
 	unsigned int offset, s_offset, size;
1988 1988
 	struct lump* via_anchor;
1989 1989
 	struct lump* via_lump;
1990
+	struct lump* via_rm;
1990 1991
 	struct lump* via_insert_param;
1991 1992
 	struct lump* path_anchor;
1992 1993
 	struct lump* path_lump;
... ...
@@ -2032,11 +2033,22 @@ char * build_req_buf_from_sip_req( struct sip_msg* msg,
2032 2033
 
2033 2034
 	via_anchor=anchor_lump(msg, msg->via1->hdr.s-buf, 0, HDR_VIA_T);
2034 2035
 	if (unlikely(via_anchor==0)) goto error00;
2035
-	line_buf = create_via_hf( &via_len, msg, send_info, &branch);
2036
+	line_buf = create_via_hf(&via_len, msg, send_info, &branch);
2036 2037
 	if (unlikely(!line_buf)){
2037 2038
 		LM_ERR("could not create Via header\n");
2038 2039
 		goto error00;
2039 2040
 	}
2041
+	if(unlikely(mode&BUILD_NEW_LOCAL_VIA)) {
2042
+		/* delete exiting top Via header */
2043
+		via_rm = del_lump(msg, msg->h_via1->name.s - msg->buf,
2044
+				msg->h_via1->len, 0);
2045
+		if (via_rm==0) {
2046
+			LM_ERR("failed to remove exiting Via header\n");
2047
+			goto error00;
2048
+		}
2049
+		/* do not update old Via header anymore */
2050
+		mode |= BUILD_NO_VIA1_UPDATE;
2051
+	}
2040 2052
 after_local_via:
2041 2053
 	if(unlikely(mode&BUILD_NO_VIA1_UPDATE))
2042 2054
 		goto after_update_via1;
... ...
@@ -49,6 +49,7 @@
49 49
 #define BUILD_NO_LOCAL_VIA		(1<<0)
50 50
 #define BUILD_NO_VIA1_UPDATE	(1<<1)
51 51
 #define BUILD_NO_PATH			(1<<2)
52
+#define BUILD_NEW_LOCAL_VIA		(1<<3)
52 53
 #define BUILD_IN_SHM			(1<<7)
53 54
 
54 55
 #include "parser/msg_parser.h"