浏览代码

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

- new parameter event_callback to set the name of the function
Daniel-Constantin Mierla 8 年之前
父节点
当前提交
2d9a1a774f
共有 2 个文件被更改,包括 25 次插入6 次删除
  1. 4 1
      modules/tm/tm.c
  2. 21 5
      modules/tm/uac.c

+ 4 - 1
modules/tm/tm.c

@@ -231,6 +231,8 @@ int tm_dns_reuse_rcv_socket = 0;
 
 
 static rpc_export_t tm_rpc[];
 static rpc_export_t tm_rpc[];
 
 
+str tm_event_callback = STR_NULL;
+
 static int fixup_t_check_status(void** param, int param_no);
 static int fixup_t_check_status(void** param, int param_no);
 
 
 static cmd_export_t cmds[]={
 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     },
 	{"e2e_cancel_reason",   PARAM_INT, &default_tm_cfg.e2e_cancel_reason     },
 #endif /* CANCEL_REASON_SUPPORT */
 #endif /* CANCEL_REASON_SUPPORT */
 	{"xavp_contact",        PARAM_STR, &ulattrs_xavp_name                    },
 	{"xavp_contact",        PARAM_STR, &ulattrs_xavp_name                    },
+	{"event_callback",      PARAM_STR, &tm_event_callback                    },
 	{0,0,0}
 	{0,0,0}
 };
 };
 
 
@@ -812,7 +815,7 @@ static int mod_init(void)
 	goto_on_local_req=route_lookup(&event_rt, "tm:local-request");
 	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)
 	if (goto_on_local_req>=0 && event_rt.rlist[goto_on_local_req]==0)
 		goto_on_local_req=-1; /* disable */
 		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();
 		set_child_rpc_sip_mode();
 #endif /* WITH_EVENT_LOCAL_REQUEST */
 #endif /* WITH_EVENT_LOCAL_REQUEST */
 	if (goto_on_sl_reply && onreply_rt.rlist[goto_on_sl_reply]==0)
 	if (goto_on_sl_reply && onreply_rt.rlist[goto_on_sl_reply]==0)

+ 21 - 5
modules/tm/uac.c

@@ -19,8 +19,8 @@
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  * 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
  * 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];
 static char from_tag[FROM_TAG_LEN + 1];
 
 
+extern str tm_event_callback;
 /*
 /*
  * Initialize UAC
  * Initialize UAC
  */
  */
-int uac_init(void) 
+int uac_init(void)
 {
 {
 	str src[3];
 	str src[3];
 	struct socket_info *si;
 	struct socket_info *si;
@@ -232,6 +233,8 @@ static inline int t_run_local_req(
 	int backup_branch;
 	int backup_branch;
 	unsigned int backup_msgid;
 	unsigned int backup_msgid;
 	int refresh_shortcuts = 0;
 	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");
 	DBG("executing event_route[tm:local-request]\n");
 	if (unlikely(t_build_msg_from_buf(&lreq, *buf, *buf_len, uac_r, &request->dst))) {
 	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 */
 	/* fake transaction and message id */
 	global_msg_id=lreq.id;
 	global_msg_id=lreq.id;
 	set_t(new_cell, T_BR_UNDEFINED);
 	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 */
 	/* restore original environment */
 	set_t(backup_t, backup_branch);
 	set_t(backup_t, backup_branch);
 	global_msg_id=backup_msgid;
 	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
 #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);
 		refresh_shortcuts = t_run_local_req(&buf, &buf_len, uac_r, new_cell, request);
 	}
 	}
 #endif
 #endif