[sr-dev] git:master:2d9a1a77: tm: sdded support to execute kemi callback on event tm:local-request

Daniel-Constantin Mierla miconda at gmail.com
Fri Nov 18 15:19:12 CET 2016


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

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2016-11-18T15:08:06+01:00

tm: sdded support to execute kemi callback on event tm:local-request

- new parameter event_callback to set the name of the function

---

Modified: modules/tm/tm.c
Modified: modules/tm/uac.c

---

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

---

diff --git a/modules/tm/tm.c b/modules/tm/tm.c
index d1bf564..0dbbea8 100644
--- a/modules/tm/tm.c
+++ b/modules/tm/tm.c
@@ -231,6 +231,8 @@ int tm_dns_reuse_rcv_socket = 0;
 
 static rpc_export_t tm_rpc[];
 
+str tm_event_callback = STR_NULL;
+
 static int fixup_t_check_status(void** param, int param_no);
 
 static cmd_export_t cmds[]={
@@ -469,6 +471,7 @@ static param_export_t params[]={
 	{"e2e_cancel_reason",   PARAM_INT, &default_tm_cfg.e2e_cancel_reason     },
 #endif /* CANCEL_REASON_SUPPORT */
 	{"xavp_contact",        PARAM_STR, &ulattrs_xavp_name                    },
+	{"event_callback",      PARAM_STR, &tm_event_callback                    },
 	{0,0,0}
 };
 
@@ -812,7 +815,7 @@ static int mod_init(void)
 	goto_on_local_req=route_lookup(&event_rt, "tm:local-request");
 	if (goto_on_local_req>=0 && event_rt.rlist[goto_on_local_req]==0)
 		goto_on_local_req=-1; /* disable */
-	if (goto_on_local_req>=0)
+	if (goto_on_local_req>=0 || tm_event_callback.len>0)
 		set_child_rpc_sip_mode();
 #endif /* WITH_EVENT_LOCAL_REQUEST */
 	if (goto_on_sl_reply && onreply_rt.rlist[goto_on_sl_reply]==0)
diff --git a/modules/tm/uac.c b/modules/tm/uac.c
index bb4149a..34e2677 100644
--- a/modules/tm/uac.c
+++ b/modules/tm/uac.c
@@ -19,8 +19,8 @@
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License 
- * along with this program; if not, write to the Free Software 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  *
  */
@@ -69,10 +69,11 @@ int goto_on_local_req=-1; /* default disabled */
 
 static char from_tag[FROM_TAG_LEN + 1];
 
+extern str tm_event_callback;
 /*
  * Initialize UAC
  */
-int uac_init(void) 
+int uac_init(void)
 {
 	str src[3];
 	struct socket_info *si;
@@ -232,6 +233,8 @@ static inline int t_run_local_req(
 	int backup_branch;
 	unsigned int backup_msgid;
 	int refresh_shortcuts = 0;
+	sr_kemi_eng_t *keng = NULL;
+	str evname = str_init("tm:local-request");
 
 	DBG("executing event_route[tm:local-request]\n");
 	if (unlikely(t_build_msg_from_buf(&lreq, *buf, *buf_len, uac_r, &request->dst))) {
@@ -261,7 +264,20 @@ static inline int t_run_local_req(
 	/* fake transaction and message id */
 	global_msg_id=lreq.id;
 	set_t(new_cell, T_BR_UNDEFINED);
-	run_top_route(event_rt.rlist[goto_on_local_req], &lreq, 0);
+	if(goto_on_local_req>=0) {
+		run_top_route(event_rt.rlist[goto_on_local_req], &lreq, 0);
+	} else {
+		keng = sr_kemi_eng_get();
+		if(keng==NULL) {
+			LM_WARN("event callback (%s) set, but no cfg engine\n",
+					tm_event_callback.s);
+		} else {
+			if(keng->froute(&lreq, EVENT_ROUTE,
+						&tm_event_callback, &evname)<0) {
+				LM_ERR("error running event route kemi callback\n");
+			}
+		}
+	}
 	/* restore original environment */
 	set_t(backup_t, backup_branch);
 	global_msg_id=backup_msgid;
@@ -479,7 +495,7 @@ static inline int t_uac_prepare(uac_req_t *uac_r,
 	}
 
 #ifdef WITH_EVENT_LOCAL_REQUEST
-	if (unlikely(goto_on_local_req>=0)) {
+	if (unlikely(goto_on_local_req>=0 || tm_event_callback.len>0)) {
 		refresh_shortcuts = t_run_local_req(&buf, &buf_len, uac_r, new_cell, request);
 	}
 #endif




More information about the sr-dev mailing list