Module: kamailio
Branch: 5.7
Commit: b0864208cc818ee6ed568485c9f25640fad9e620
URL:
https://github.com/kamailio/kamailio/commit/b0864208cc818ee6ed568485c9f2564…
Author: Xenofon Karamanos <22965395+xkaraman(a)users.noreply.github.com>
Committer: Xenofon Karamanos <xk(a)gilawa.com>
Date: 2024-11-14T16:35:21Z
tm: Emit request event when cancel is called
(cherry picked from commit faca8e7a20255d90a4786fd4043005ead9dfc5df)
---
Modified: src/modules/tm/t_cancel.c
---
Diff:
https://github.com/kamailio/kamailio/commit/b0864208cc818ee6ed568485c9f2564…
Patch:
https://github.com/kamailio/kamailio/commit/b0864208cc818ee6ed568485c9f2564…
---
diff --git a/src/modules/tm/t_cancel.c b/src/modules/tm/t_cancel.c
index 18452a46967..f9a0951603e 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);
}