Module: kamailio
Branch: master
Commit: faca8e7a20255d90a4786fd4043005ead9dfc5df
URL: 
https://github.com/kamailio/kamailio/commit/faca8e7a20255d90a4786fd4043005ead9dfc5df
Author: Xenofon Karamanos <22965395+xkara...@users.noreply.github.com>
Committer: Henning Westerholt <h...@gilawa.com>
Date: 2024-09-16T15:21:51+02:00

tm: Emit request event when cancel is called

---

Modified: src/modules/tm/t_cancel.c

---

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

---

diff --git a/src/modules/tm/t_cancel.c b/src/modules/tm/t_cancel.c
index 68dae04fbc8..03e919f6abe 100644
--- a/src/modules/tm/t_cancel.c
+++ b/src/modules/tm/t_cancel.c
@@ -29,6 +29,7 @@
 #include "t_funcs.h"
 #include "../../core/dprint.h"
 #include "../../core/ut.h"
+#include "../../core/kemi.h"
 #include "t_reply.h"
 #include "t_cancel.h"
 #include "t_msgbuilder.h"
@@ -36,6 +37,8 @@
 #include "t_hooks.h"
 
 
+extern str tm_event_callback;
+
 typedef struct cancel_reason_map
 {
        int code;
@@ -86,6 +89,11 @@ void prepare_to_cancel(
        int i;
        int branches_no;
        branch_bm_t mask;
+       int rt, backup_rt;
+       struct run_act_ctx ctx;
+       sip_msg_t msg;
+       sr_kemi_eng_t *keng = NULL;
+       str evname = str_init("tm:local-request");
 
        *cancel_bm = 0;
        branches_no = t->nr_of_outgoings;
@@ -95,6 +103,49 @@ void prepare_to_cancel(
                *cancel_bm |= ((mask & (1 << i)) && prepare_cancel_branch(t, i, 
1))
                                          << i;
        }
+
+       rt = -1;
+       if(tm_event_callback.s == NULL || tm_event_callback.len <= 0) {
+               rt = route_lookup(&event_rt, "tm:local-request");
+               if(rt < 0 || event_rt.rlist[rt] == NULL) {
+                       LM_DBG("tm:local-request not found\n");
+                       return;
+               }
+       } else {
+               keng = sr_kemi_eng_get();
+               if(keng == NULL) {
+                       LM_DBG("event callback (%s) set, but no cfg engine\n",
+                                       tm_event_callback.s);
+                       return;
+               }
+       }
+
+       /* Check if msg is null */
+       if(build_sip_msg_from_buf(
+                          &msg, t->uac->request.buffer, 
t->uac->request.buffer_len, 0)
+                       < 0) {
+               LM_ERR("fail to parse msg\n");
+               return;
+       }
+
+       /* Call event */
+       backup_rt = get_route_type();
+       set_route_type(REQUEST_ROUTE);
+       init_run_actions_ctx(&ctx);
+       if(rt >= 0) {
+               run_top_route(event_rt.rlist[rt], &msg, 0);
+       } else {
+               if(keng != NULL) {
+
+                       if(sr_kemi_route(
+                                          keng, &msg, EVENT_ROUTE, 
&tm_event_callback, &evname)
+                                       < 0) {
+                               LM_ERR("error running event route kemi 
callback\n");
+                       }
+               }
+       }
+       set_route_type(backup_rt);
+       free_sip_msg(&msg);
 }
 
 

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

Reply via email to