From da0a6d48debb9c69c5a06a9e702a4378c61eaac7 Mon Sep 17 00:00:00 2001 From: Daniel-Constantin Mierla Date: Wed, 17 Feb 2021 08:21:36 +0100 Subject: [PATCH] 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 --- src/core/msg_translator.c | 16 ++++++++++++++-- src/core/msg_translator.h | 1 + 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/core/msg_translator.c b/src/core/msg_translator.c index f895df96834..c3587d2e88c 100644 --- a/src/core/msg_translator.c +++ b/src/core/msg_translator.c @@ -1971,7 +1971,7 @@ int check_boundaries(struct sip_msg *msg, struct dest_info *send_info) * depending on the presence of the BUILD_IN_SHM flag, needs freeing when * done) and sets returned_len or 0 on error. */ -char * build_req_buf_from_sip_req( struct sip_msg* msg, +char * build_req_buf_from_sip_req(struct sip_msg* msg, unsigned int *returned_len, struct dest_info* send_info, unsigned int mode) @@ -1987,6 +1987,7 @@ char * build_req_buf_from_sip_req( struct sip_msg* msg, unsigned int offset, s_offset, size; struct lump* via_anchor; struct lump* via_lump; + struct lump* via_rm; struct lump* via_insert_param; struct lump* path_anchor; struct lump* path_lump; @@ -2032,11 +2033,22 @@ char * build_req_buf_from_sip_req( struct sip_msg* msg, via_anchor=anchor_lump(msg, msg->via1->hdr.s-buf, 0, HDR_VIA_T); if (unlikely(via_anchor==0)) goto error00; - line_buf = create_via_hf( &via_len, msg, send_info, &branch); + line_buf = create_via_hf(&via_len, msg, send_info, &branch); if (unlikely(!line_buf)){ LM_ERR("could not create Via header\n"); goto error00; } + if(unlikely(mode&BUILD_NEW_LOCAL_VIA)) { + /* delete exiting top Via header */ + via_rm = del_lump(msg, msg->h_via1->name.s - msg->buf, + msg->h_via1->len, 0); + if (via_rm==0) { + LM_ERR("failed to remove exiting Via header\n"); + goto error00; + } + /* do not update old Via header anymore */ + mode |= BUILD_NO_VIA1_UPDATE; + } after_local_via: if(unlikely(mode&BUILD_NO_VIA1_UPDATE)) goto after_update_via1; diff --git a/src/core/msg_translator.h b/src/core/msg_translator.h index 4d14ce0fb27..9b9802ad1e5 100644 --- a/src/core/msg_translator.h +++ b/src/core/msg_translator.h @@ -49,6 +49,7 @@ #define BUILD_NO_LOCAL_VIA (1<<0) #define BUILD_NO_VIA1_UPDATE (1<<1) #define BUILD_NO_PATH (1<<2) +#define BUILD_NEW_LOCAL_VIA (1<<3) #define BUILD_IN_SHM (1<<7) #include "parser/msg_parser.h"