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

Author: Daniel-Constantin Mierla <mico...@gmail.com>
Committer: Daniel-Constantin Mierla <mico...@gmail.com>
Date: 2025-01-21T21:43:06+01:00

core: reworked how rport, received and extra params are added to first via of 
generated replies

---

Modified: src/core/msg_translator.c

---

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

---

diff --git a/src/core/msg_translator.c b/src/core/msg_translator.c
index 7ad113aa955..6cd65716625 100644
--- a/src/core/msg_translator.c
+++ b/src/core/msg_translator.c
@@ -2667,57 +2667,50 @@ char *build_res_buf_from_sip_req(unsigned int code, str 
*text, str *new_tag,
                                if(unlikely(httpreq))
                                        pvia = p;
                                if(hdr == msg->h_via1) {
-                                       if(rport_buf) {
-                                               if(msg->via1->rport) { /* 
delete the old one */
-                                                       /* copy until rport */
-                                                       append_str_trans(p, 
hdr->name.s,
-                                                                       
msg->via1->rport->start - hdr->name.s - 1,
-                                                                       msg);
-                                                       /* copy new rport */
-                                                       append_str(p, 
rport_buf, rport_len);
-                                                       /* copy the rest of the 
via */
-                                                       append_str_trans(p,
-                                                                       
msg->via1->rport->start
-                                                                               
        + msg->via1->rport->size,
-                                                                       
hdr->body.s + hdr->body.len
-                                                                               
        - msg->via1->rport->start
-                                                                               
        - msg->via1->rport->size,
-                                                                       msg);
-                                               } else if(msg->via1->branch) { 
/* add after branch */
-                                                       /* copy until after 
branch */
-                                                       append_str_trans(p, 
hdr->name.s,
-                                                                       
msg->via1->branch->start - hdr->name.s
-                                                                               
        + msg->via1->branch->size,
-                                                                       msg);
-                                                       /* copy new rport */
-                                                       append_str(p, 
rport_buf, rport_len);
-                                                       /* copy the rest of the 
via */
-                                                       append_str_trans(p,
-                                                                       
msg->via1->branch->start
-                                                                               
        + msg->via1->branch->size,
-                                                                       
hdr->body.s + hdr->body.len
-                                                                               
        - msg->via1->branch->start
-                                                                               
        - msg->via1->branch->size,
-                                                                       msg);
-                                               } else { /* just append the new 
one */
-                                                       /* normal whole via 
copy */
-                                                       append_str_trans(p, 
hdr->name.s,
-                                                                       
(hdr->body.s + hdr->body.len) - hdr->name.s,
-                                                                       msg);
-                                                       append_str(p, 
rport_buf, rport_len);
-                                               }
-                                       } else {
-                                               /* normal whole via copy */
+                                       if(rport_buf && msg->via1->rport) { /* 
replace old rport */
+                                               /* copy until rport */
+                                               append_str_trans(p, hdr->name.s,
+                                                               
msg->via1->rport->start - hdr->name.s - 1, msg);
+                                       } else if(msg->via1->branch) { /* add 
after branch */
+                                               append_str_trans(p, hdr->name.s,
+                                                               
msg->via1->branch->start - hdr->name.s
+                                                                               
+ msg->via1->branch->size,
+                                                               msg);
+                                       } else { /* append after header */
                                                append_str_trans(p, hdr->name.s,
                                                                (hdr->body.s + 
hdr->body.len) - hdr->name.s,
                                                                msg);
                                        }
+                                       if(rport_buf) {
+                                               /* add rport */
+                                               append_str(p, rport_buf, 
rport_len);
+                                       }
                                        if(received_buf) {
+                                               /* add received */
                                                append_str(p, received_buf, 
received_len);
                                        }
                                        if(xparams.len > 0) {
+                                               /* add extra parameters */
                                                append_str(p, xparams.s, 
xparams.len);
                                        }
+                                       /* copy the rest of the via */
+                                       if(rport_buf && msg->via1->rport) {
+                                               append_str_trans(p,
+                                                               
msg->via1->rport->start
+                                                                               
+ msg->via1->rport->size,
+                                                               hdr->body.s + 
hdr->body.len
+                                                                               
- msg->via1->rport->start
+                                                                               
- msg->via1->rport->size,
+                                                               msg);
+                                       } else if(msg->via1->branch) {
+                                               append_str_trans(p,
+                                                               
msg->via1->branch->start
+                                                                               
+ msg->via1->branch->size,
+                                                               hdr->body.s + 
hdr->body.len
+                                                                               
- msg->via1->branch->start
+                                                                               
- msg->via1->branch->size,
+                                                               msg);
+                                       }
                                } else {
                                        /* normal whole via copy */
                                        append_str_trans(p, hdr->name.s,

_______________________________________________
Kamailio - Development Mailing List -- sr-dev@lists.kamailio.org
To unsubscribe send an email to sr-dev-le...@lists.kamailio.org
Important: keep the mailing list in the recipients, do not reply only to the 
sender!

Reply via email to