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

Author: Daniel-Constantin Mierla <mico...@gmail.com>
Committer: Daniel-Constantin Mierla <mico...@gmail.com>
Date: 2024-11-01T21:24:52+01:00

tm: new function t_cell_append_branches(tindex, tlabel)

- append current branches to a specific transaction identified by index
  and label

---

Modified: src/modules/tm/t_append_branches.c
Modified: src/modules/tm/t_append_branches.h
Modified: src/modules/tm/tm.c

---

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

---

diff --git a/src/modules/tm/t_append_branches.c 
b/src/modules/tm/t_append_branches.c
index 47e05809ae1..d871ba239fd 100644
--- a/src/modules/tm/t_append_branches.c
+++ b/src/modules/tm/t_append_branches.c
@@ -273,3 +273,51 @@ int t_append_branches(str *contact)
        }
        return ret;
 }
+
+/**
+ *
+ */
+int t_cell_append_branches(int tindex, int tlabel)
+{
+       tm_cell_t *t = NULL;
+       /* a pointer to an existing transaction or 0 if lookup fails */
+       tm_cell_t *orig_t = NULL;
+       int ret;
+       int orig_branch;
+       str contact = STR_NULL;
+
+       orig_t = get_t();
+       orig_branch = get_t_branch();
+
+       /* lookup a transaction based on its identifier (hash_index:label) */
+       if(t_lookup_ident(&t, tindex, tlabel) < 0) {
+               LM_ERR("transaction [%u:%u] not found\n", tindex, tlabel);
+               ret = -1;
+               goto done;
+       }
+
+       /* check if the dialog is still in the early stage */
+       if(t->flags & T_CANCELED) {
+               LM_DBG("transaction [%u:%u] was cancelled\n", tindex, tlabel);
+               ret = -2;
+               goto done;
+       }
+
+       if(t->uas.status >= 200) {
+               LM_DBG("transaction [%u:%u] sent out a final response already - 
%d\n",
+                               tindex, tlabel, t->uas.status);
+               ret = -3;
+               goto done;
+       }
+
+       ret = t_append_branches(&contact);
+
+done:
+       /* unref the transaction which had been referred by t_lookup_ident() 
call.
+        * - restore the original transaction (if any) */
+       if(t)
+               unref_cell(t);
+       set_t(orig_t, orig_branch);
+
+       return ret;
+}
diff --git a/src/modules/tm/t_append_branches.h 
b/src/modules/tm/t_append_branches.h
index 4e71f5862e2..1be1306efae 100644
--- a/src/modules/tm/t_append_branches.h
+++ b/src/modules/tm/t_append_branches.h
@@ -34,4 +34,6 @@
 int t_append_branches(str *contact);
 typedef int (*t_append_branches_f)(str *contact);
 
+int t_cell_append_branches(int tindex, int tlabel);
+
 #endif
diff --git a/src/modules/tm/tm.c b/src/modules/tm/tm.c
index 0b099701587..7c7d26e2312 100644
--- a/src/modules/tm/tm.c
+++ b/src/modules/tm/tm.c
@@ -212,6 +212,7 @@ static int w_t_get_status_code(sip_msg_t *msg, char *p1, 
char *p2);
 
 static int t_clean(struct sip_msg *msg, char *key, char *value);
 static int w_t_exists(struct sip_msg *msg, char *p1, char *p2);
+static int w_t_cell_append_branches(sip_msg_t *msg, char *pindex, char 
*plabel);
 
 /* by default the fr timers avps are not set, so that the avps won't be
  * searched for nothing each time a new transaction is created */
@@ -442,6 +443,8 @@ static cmd_export_t cmds[] = {
        {"t_next_contact_flow", t_next_contact_flow, 0, 0, 0, REQUEST_ROUTE},
        {"t_clean", t_clean, 0, 0, 0, ANY_ROUTE},
        {"t_exists", w_t_exists, 0, 0, 0, ANY_ROUTE},
+       {"t_cell_append_branches", w_t_cell_append_branches, 2, fixup_igp_igp,
+                       fixup_free_igp_igp, ANY_ROUTE},
 
        /* not applicable from the script */
        {"load_tm", (cmd_function)load_tm, NO_SCRIPT, 0, 0, 0},
@@ -3209,6 +3212,26 @@ static int w_t_exists(struct sip_msg *msg, char *p1, 
char *p2)
        return ki_t_exists(msg);
 }
 
+static int w_t_cell_append_branches(sip_msg_t *msg, char *pindex, char *plabel)
+{
+       int tindex = 0;
+       int tlabel = 0;
+       int ret;
+
+       if(fixup_get_ivalue(msg, (gparam_t *)pindex, &tindex) != 0) {
+               LM_ERR("invalid index parameter\n");
+               return -1;
+       }
+       if(fixup_get_ivalue(msg, (gparam_t *)plabel, &tlabel) != 0) {
+               LM_ERR("invalid label parameter\n");
+               return -1;
+       }
+
+       ret = t_cell_append_branches(tindex, tlabel);
+
+       return (ret == 0) ? 1 : ret;
+}
+
 #ifdef USE_DNS_FAILOVER
 /* parse reply codes for failover given in module parameter */
 static int t_failover_parse_reply_codes()

_______________________________________________
Kamailio (SER) - Development Mailing List
To unsubscribe send an email to sr-dev-le...@lists.kamailio.org

Reply via email to