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

Author: Daniel-Constantin Mierla <mico...@gmail.com>
Committer: Daniel-Constantin Mierla <mico...@gmail.com>
Date: 2025-02-13T10:32:51+01:00

tm: split reverse rte list function

---

Modified: src/modules/tm/t_msgbuilder.c

---

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

---

diff --git a/src/modules/tm/t_msgbuilder.c b/src/modules/tm/t_msgbuilder.c
index b2c101bf2b6..71fd4e644b3 100644
--- a/src/modules/tm/t_msgbuilder.c
+++ b/src/modules/tm/t_msgbuilder.c
@@ -750,6 +750,26 @@ static inline int get_contact_uri(struct sip_msg *msg, str 
*uri)
        return 0;
 }
 
+/**
+ * reverse rte list
+ */
+static inline rte_t *tm_reverse_rte_list(rte_t *head)
+{
+       rte_t *prev = NULL;
+       rte_t *current = NULL;
+       rte_t *next = NULL;
+
+       current = head;
+       while(current != NULL) {
+               next = current->next;
+               current->next = prev;
+               prev = current;
+               current = next;
+       }
+
+       return prev;
+}
+
 /**
  * Extract route set from the message (out of Record-Route, if reply, OR
  * Route, if request).
@@ -760,7 +780,7 @@ static inline int get_uac_rs(sip_msg_t *msg, int is_req, 
struct rte **rtset)
 {
        struct hdr_field *ptr;
        rr_t *p, *new_p;
-       struct rte *t, *head, *old_head;
+       struct rte *t, *head;
 
        head = 0;
        for(ptr = is_req ? msg->route : msg->record_route; ptr; ptr = 
ptr->next) {
@@ -810,14 +830,7 @@ static inline int get_uac_rs(sip_msg_t *msg, int is_req, 
struct rte **rtset)
        if(is_req) {
                /* harvesting the R/RR HF above inserts at head, which suites 
RRs (as
                 * they must be reversed, anyway), but not Rs => reverse once 
more */
-               old_head = head;
-               head = 0;
-               while(old_head) {
-                       t = old_head;
-                       old_head = old_head->next;
-                       t->next = head;
-                       head = t;
-               }
+               head = tm_reverse_rte_list(head);
        }
 
        *rtset = head;
@@ -827,7 +840,6 @@ static inline int get_uac_rs(sip_msg_t *msg, int is_req, 
struct rte **rtset)
        return -1;
 }
 
-
 static inline unsigned short uri2port(const struct sip_uri *puri)
 {
        if(puri->port.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