Module: kamailio
Branch: master
Commit: 6a5baa9bdab031064dbaf1d8cb78c9ae2882bd18
URL: 
https://github.com/kamailio/kamailio/commit/6a5baa9bdab031064dbaf1d8cb78c9ae2882bd18

Author: Daniel-Constantin Mierla <[email protected]>
Committer: Daniel-Constantin Mierla <[email protected]>
Date: 2026-01-21T09:52:13+01:00

tm: check the internal flag FL_MSG_APPLY_CHANGES

---

Modified: src/modules/tm/t_fwd.c
Modified: src/modules/tm/t_lookup.c
Modified: src/modules/tm/tm.c

---

Diff:  
https://github.com/kamailio/kamailio/commit/6a5baa9bdab031064dbaf1d8cb78c9ae2882bd18.diff
Patch: 
https://github.com/kamailio/kamailio/commit/6a5baa9bdab031064dbaf1d8cb78c9ae2882bd18.patch

---

diff --git a/src/modules/tm/t_fwd.c b/src/modules/tm/t_fwd.c
index 43e6790bd32..756b0ec015e 100644
--- a/src/modules/tm/t_fwd.c
+++ b/src/modules/tm/t_fwd.c
@@ -334,7 +334,9 @@ static int prepare_new_uac(struct cell *t, struct sip_msg 
*i_req, int branch,
        sip_msg_t l_req;
        sip_msg_t *b_req = NULL;
        char l_buf[BUF_SIZE];
+       int l_copy;
 
+       l_copy = 0;
        shbuf = 0;
        ret = E_UNSPEC;
        memset(&bbak, 0, sizeof(tm_branch_bak_t));
@@ -354,7 +356,11 @@ static int prepare_new_uac(struct cell *t, struct sip_msg 
*i_req, int branch,
         * the up-to-date values */
        membar_depends();
 
-       if(ksr_msg_apply_changes_mode == 1) {
+       if((ksr_msg_apply_changes_mode == 1)
+                       || (i_req->msg_flags & FL_MSG_APPLY_CHANGES)) {
+               l_copy = 1;
+       }
+       if(l_copy == 1) {
                memset(&l_req, 0, sizeof(sip_msg_t));
                l_req.buf = l_buf;
                l_buf[0] = '\0';
@@ -372,7 +378,7 @@ static int prepare_new_uac(struct cell *t, struct sip_msg 
*i_req, int branch,
        }
 
        if(unlikely(branch_route || has_tran_tmcbs(t, TMCB_REQUEST_FWDED))) {
-               if(ksr_msg_apply_changes_mode != 1) {
+               if(l_copy == 0) {
                        if(tm_branch_duplicate_msg_fields(i_req, uri, next_hop, 
path,
                                           instance, ruid, location_ua, flags, 
&bbak)
                                        < 0) {
@@ -421,7 +427,7 @@ static int prepare_new_uac(struct cell *t, struct sip_msg 
*i_req, int branch,
                                /* update dst send_flags  and send socket*/
                                snd_flags = b_req->fwd_send_flags;
                                fsocket = b_req->force_send_socket;
-                               if(ksr_msg_apply_changes_mode != 1) {
+                               if(l_copy == 0) {
                                        /* restore ireq_msg force_send_socket & 
flags */
                                        set_force_socket(i_req, 
bbak.force_send_socket_bak);
                                        i_req->fwd_send_flags = 
bbak.fwd_snd_flags_bak;
@@ -664,7 +670,7 @@ static int prepare_new_uac(struct cell *t, struct sip_msg 
*i_req, int branch,
 
 error01:
 error03:
-       if(ksr_msg_apply_changes_mode != 1) {
+       if(l_copy == 0) {
                /* Delete the duplicated lump lists, this will also delete
                 * all lumps created here, such as lumps created in per-branch
                 * routing sections, Via, and Content-Length headers created in
diff --git a/src/modules/tm/t_lookup.c b/src/modules/tm/t_lookup.c
index 86c5b093bcb..c1c19cb2552 100644
--- a/src/modules/tm/t_lookup.c
+++ b/src/modules/tm/t_lookup.c
@@ -1831,7 +1831,8 @@ static inline int new_t(struct sip_msg *p_msg)
 {
        struct cell *new_cell;
 
-       if(ksr_msg_apply_changes_mode == 1) {
+       if((ksr_msg_apply_changes_mode == 1)
+                       || (p_msg->msg_flags & FL_MSG_APPLY_CHANGES)) {
                if(sip_msg_apply_changes(p_msg) < 0) {
                        return E_BAD_REQ;
                }
diff --git a/src/modules/tm/tm.c b/src/modules/tm/tm.c
index e0d32ee1dfa..cca9851f28c 100644
--- a/src/modules/tm/tm.c
+++ b/src/modules/tm/tm.c
@@ -3418,12 +3418,15 @@ static int w_t_msg_apply_changes(sip_msg_t *msg, char 
*p1, char *p2)
                return -1;
        }
 
-       if(ksr_msg_apply_changes_mode != 1) {
+       if((ksr_msg_apply_changes_mode != 1)
+                       && !(msg->msg_flags & FL_MSG_APPLY_CHANGES)) {
+               LM_ERR("the function cannot be used\n");
                return -1;
        }
 
-       if(t_check(msg, 0) == -1)
+       if(t_check(msg, 0) == -1) {
                return 1;
+       }
        t = get_t();
        if(!t || !t->uas.request) {
                return -1;

_______________________________________________
Kamailio - Development Mailing List -- [email protected]
To unsubscribe send an email to [email protected]
Important: keep the mailing list in the recipients, do not reply only to the 
sender!

Reply via email to