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

Author: Daniel-Constantin Mierla <[email protected]>
Committer: Daniel-Constantin Mierla <[email protected]>
Date: 2020-02-21T08:58:24+01:00

tm: exported function to kemi returning the branch index

---

Modified: src/modules/tm/tm.c

---

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

---

diff --git a/src/modules/tm/tm.c b/src/modules/tm/tm.c
index b9b7f94877..8bcb1bd570 100644
--- a/src/modules/tm/tm.c
+++ b/src/modules/tm/tm.c
@@ -63,6 +63,7 @@
 #include "../../core/cfg/cfg.h"
 #include "../../core/globals.h"
 #include "../../core/timer_ticks.h"
+#include "../../core/dset.h"
 #include "../../core/mod_fix.h"
 #include "../../core/kemi.h"
 
@@ -922,6 +923,50 @@ static int w_t_get_status_code(sip_msg_t* msg, char *p1, 
char *p2)
        return ki_t_get_status_code(msg);
 }
 
+static int ki_t_get_branch_index(sip_msg_t* msg)
+{
+       tm_cell_t *t = 0;
+       tm_ctx_t *tcx = 0;
+       int idx = T_BR_UNDEFINED;
+
+       if(msg==NULL) {
+               return -1;
+       }
+
+       /* statefull replies have the branch_index set */
+       if(msg->first_line.type == SIP_REPLY) {
+               tcx = tm_ctx_get();
+               if(tcx != NULL) {
+                       idx = tcx->branch_index;
+               }
+       } else switch(route_type) {
+               case BRANCH_ROUTE:
+               case BRANCH_FAILURE_ROUTE:
+                       /* branch and branch_failure routes have their index 
set */
+                       tcx = tm_ctx_get();
+                       if(tcx != NULL) {
+                               idx = tcx->branch_index;
+                       }
+                       break;
+               case REQUEST_ROUTE:
+                       /* take the branch number from the number of added 
branches */
+                       idx = nr_branches;
+                       break;
+               case FAILURE_ROUTE:
+                       /* first get the transaction */
+                       t = get_t();
+                       if ( t == NULL || t == T_UNDEFINED ) {
+                               return -1;
+                       }
+                       /* add the currently added branches to the number of
+                        * completed branches in the transaction
+                        */
+                       idx = t->nr_of_outgoings + nr_branches;
+                       break;
+       }
+       return idx;
+}
+
 static int t_check_status(struct sip_msg* msg, char *p1, char *foo)
 {
        regmatch_t pmatch;
@@ -3162,6 +3207,11 @@ static sr_kemi_t tm_kemi_exports[] = {
                { SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
                        SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
        },
+       { str_init("tm"), str_init("t_get_branch_index"),
+               SR_KEMIP_INT, ki_t_get_branch_index,
+               { SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
+                       SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
+       },
 
        { {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } }
 };


_______________________________________________
Kamailio (SER) - Development Mailing List
[email protected]
https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-dev

Reply via email to