Module: kamailio
Branch: 5.8
Commit: c08bade8f570e0505a2498131faded9785c7fae0
URL:
https://github.com/kamailio/kamailio/commit/c08bade8f570e0505a2498131faded9…
Author: Xenofon Karamanos <22965395+xkaraman(a)users.noreply.github.com>
Committer: Xenofon Karamanos <xk(a)gilawa.com>
Date: 2024-11-14T16:31:43Z
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/c08bade8f570e0505a2498131faded9…
Patch:
https://github.com/kamailio/kamailio/commit/c08bade8f570e0505a2498131faded9…
---
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);
}