[sr-dev] git:master:f39eca3d: siptrace: exec event_route[siptrace:msg] on message replication with core events

Daniel-Constantin Mierla miconda at gmail.com
Mon Jul 13 12:35:15 CEST 2020


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

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2020-07-13T12:24:44+02:00

siptrace: exec event_route[siptrace:msg] on message replication with core events

- new parameter evcb_msg to set the kemi function name to be executed
for this event callback
- alternative to GH #2374

---

Modified: src/modules/siptrace/siptrace.c

---

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

---

diff --git a/src/modules/siptrace/siptrace.c b/src/modules/siptrace/siptrace.c
index 1368e954a6..1b7b014d0e 100644
--- a/src/modules/siptrace/siptrace.c
+++ b/src/modules/siptrace/siptrace.c
@@ -178,6 +178,9 @@ socket_info_t *trace_send_sock_info = 0;
 str trace_dup_uri_str = {0, 0};
 sip_uri_t *trace_dup_uri = 0;
 
+static str _siptrace_evcb_msg = STR_NULL;
+static int _siptrace_evrt_msg_idx = -1;
+
 static unsigned short traced_user_avp_type = 0;
 static int_str traced_user_avp;
 static str traced_user_avp_str = {NULL, 0};
@@ -254,6 +257,7 @@ static param_export_t params[] = {
 	{"trace_db_mode", INT_PARAM, &trace_db_mode},
 	{"trace_init_mode", PARAM_INT, &_siptrace_init_mode},
 	{"trace_mode", PARAM_INT, &_siptrace_mode},
+	{"evcb_msg", PARAM_STR, &_siptrace_evcb_msg},
 	{0, 0, 0}
 };
 /* clang-format on */
@@ -302,6 +306,8 @@ static int mod_init(void)
 	}
 #endif
 
+	_siptrace_evrt_msg_idx = route_lookup(&event_rt, "siptrace:msg");
+
 	if(trace_db_delayed!=0) {
 		trace_db_mode = 1;
 	}
@@ -2017,6 +2023,56 @@ static void trace_free_info(void* trace_info)
 	shm_free(trace_info);
 }
 
+static int siptrace_exec_evcb_msg(siptrace_data_t *sto)
+{
+	int backup_rt;
+	run_act_ctx_t ctx;
+	run_act_ctx_t *bctx;
+	sr_kemi_eng_t *keng = NULL;
+	str evname = str_init("siptrace:msg");
+	sip_msg_t msg;
+
+	if(_siptrace_evrt_msg_idx < 0 && _siptrace_evcb_msg.len<=0) {
+		return 0;
+	}
+
+	if(sto == NULL || sto->body.s == NULL || sto->body.len <= 0) {
+		return -1;
+	}
+
+	memset(&msg, 0, sizeof(sip_msg_t));
+	msg.buf = sto->body.s;
+	msg.len = sto->body.len;
+	if(parse_msg(msg.buf, msg.len, &msg) != 0) {
+		LM_DBG("parse_msg failed\n");
+		return -1;
+	}
+
+	backup_rt = get_route_type();
+	set_route_type(EVENT_ROUTE);
+	init_run_actions_ctx(&ctx);
+
+	if(_siptrace_evrt_msg_idx>=0) {
+		run_top_route(event_rt.rlist[_siptrace_evrt_msg_idx], &msg, 0);
+	} else {
+		keng = sr_kemi_eng_get();
+		if (keng!=NULL) {
+			bctx = sr_kemi_act_ctx_get();
+			sr_kemi_act_ctx_set(&ctx);
+			(void)sr_kemi_route(keng, &msg, EVENT_ROUTE,
+						&_siptrace_evcb_msg, &evname);
+			sr_kemi_act_ctx_set(bctx);
+		}
+	}
+
+	free_sip_msg(&msg);
+	set_route_type(backup_rt);
+	if(ctx.run_flags & DROP_R_F) {
+		return DROP_R_F;
+	}
+	return RETURN_R_F;
+}
+
 /**
  *
  */
@@ -2067,6 +2123,11 @@ int siptrace_net_data_recv(sr_event_param_t *evp)
 
 	sto.dir = "in";
 
+	if(siptrace_exec_evcb_msg(&sto) == DROP_R_F) {
+		/* drop() used in event_route - all done */
+		return 0;
+	}
+
 	if(_siptrace_mode & SIPTRACE_MODE_HEP) {
 		trace_send_hep_duplicate(&sto.body, &sto.fromip, &sto.toip, NULL, NULL);
 	}
@@ -2187,6 +2248,11 @@ int siptrace_net_data_send(sr_event_param_t *evp)
 
 	sto.dir = "out";
 
+	if(siptrace_exec_evcb_msg(&sto) == DROP_R_F) {
+		/* drop() used in event_route - all done */
+		return 0;
+	}
+
 	if(_siptrace_mode & SIPTRACE_MODE_HEP) {
 		trace_send_hep_duplicate(&sto.body, &sto.fromip, &sto.toip, NULL, NULL);
 	}




More information about the sr-dev mailing list