Browse code

dialog: enable execution of dialog event routes via kemi

- requires to set the event_callback parameters

Daniel-Constantin Mierla authored on 04/04/2017 13:23:07
Showing 2 changed files
... ...
@@ -110,6 +110,7 @@ int dlg_ka_failed_limit = 1;
110 110
 int dlg_enable_dmq = 0;
111 111
 
112 112
 int dlg_event_rt[DLG_EVENTRT_MAX];
113
+str dlg_event_callback = STR_NULL;
113 114
 
114 115
 str dlg_bridge_controller = str_init("sip:controller@kamailio.org");
115 116
 
... ...
@@ -299,6 +300,7 @@ static param_export_t mod_params[]={
299 299
 	{ "db_skip_load",          INT_PARAM, &db_skip_load             },
300 300
 	{ "ka_failed_limit",       INT_PARAM, &dlg_ka_failed_limit      },
301 301
 	{ "enable_dmq",            INT_PARAM, &dlg_enable_dmq           },
302
+	{"event_callback",         PARAM_STR, &dlg_event_callback       },
302 303
 	{ 0,0,0 }
303 304
 };
304 305
 
... ...
@@ -37,6 +37,7 @@
37 37
 #include "../../core/action.h"
38 38
 #include "../../core/script_cb.h"
39 39
 #include "../../core/pt.h"
40
+#include "../../core/kemi.h"
40 41
 #include "../../core/fmsg.h"
41 42
 #include "../../core/parser/parse_from.h"
42 43
 #include "../../core/parser/parse_cseq.h"
... ...
@@ -76,6 +77,8 @@ extern struct rr_binds d_rrb;		/*!< binding to record-routing module */
76 76
 
77 77
 extern pv_elem_t *ruri_param_model;	/*!< pv-string to get r-uri */
78 78
 
79
+extern str dlg_event_callback;
80
+
79 81
 static unsigned int CURR_DLG_LIFETIME = 0;	/*!< current dialog lifetime */
80 82
 static unsigned int CURR_DLG_STATUS = 0;	/*!< current dialog state */
81 83
 static unsigned int CURR_DLG_ID  = 0xffffffff;	/*!< current dialog id */
... ...
@@ -1509,6 +1512,8 @@ void dlg_ontimeout(struct dlg_tl *tl)
1509 1509
 	int new_state, old_state, unref;
1510 1510
 	sip_msg_t *fmsg;
1511 1511
 	void* timeout_cb = 0;
1512
+	sr_kemi_eng_t *keng = NULL;
1513
+	str evname;
1512 1514
 
1513 1515
 	/* get the dialog tl payload */
1514 1516
 	dlg = ((struct dlg_cell*)((char *)(tl) -
... ...
@@ -1520,8 +1525,10 @@ void dlg_ontimeout(struct dlg_tl *tl)
1520 1520
 	if(dlg->state==DLG_STATE_CONFIRMED_NA
1521 1521
 				|| dlg->state==DLG_STATE_CONFIRMED)
1522 1522
 	{
1523
-		if(dlg->toroute>0 && dlg->toroute<main_rt.entries
1524
-			&& main_rt.rlist[dlg->toroute]!=NULL)
1523
+		if((dlg->toroute>0 && dlg->toroute<main_rt.entries
1524
+					&& main_rt.rlist[dlg->toroute]!=NULL)
1525
+				|| (dlg->toroute_name.len>0
1526
+					&& dlg_event_callback.s!=NULL && dlg_event_callback.len>0))
1525 1527
 		{
1526 1528
 			fmsg = faked_msg_next();
1527 1529
 			if (exec_pre_script_cb(fmsg, REQUEST_CB_TYPE)>0)
... ...
@@ -1530,7 +1537,18 @@ void dlg_ontimeout(struct dlg_tl *tl)
1530 1530
 				dlg_set_ctx_iuid(dlg);
1531 1531
 				LM_DBG("executing route %d on timeout\n", dlg->toroute);
1532 1532
 				set_route_type(REQUEST_ROUTE);
1533
-				run_top_route(main_rt.rlist[dlg->toroute], fmsg, 0);
1533
+				if(dlg->toroute>0) {
1534
+					run_top_route(main_rt.rlist[dlg->toroute], fmsg, 0);
1535
+				} else {
1536
+					if(keng!=NULL) {
1537
+						evname.s = "dialog:timeout";
1538
+						evname.len = sizeof("dialog:timeout") - 1;
1539
+						if(keng->froute(fmsg, EVENT_ROUTE,
1540
+									&dlg_event_callback, &evname)<0) {
1541
+							LM_ERR("error running event route kemi callback\n");
1542
+						}
1543
+					}
1544
+				}
1534 1545
 				dlg_reset_ctx_iuid();
1535 1546
 				exec_post_script_cb(fmsg, REQUEST_CB_TYPE);
1536 1547
 				dlg_unref(dlg, 1);
... ...
@@ -1656,6 +1674,8 @@ void dlg_run_event_route(dlg_cell_t *dlg, sip_msg_t *msg, int ostate, int nstate
1656 1656
 	sip_msg_t *fmsg;
1657 1657
 	int rt;
1658 1658
 	int bkroute;
1659
+	sr_kemi_eng_t *keng = NULL;
1660
+	str evname;
1659 1661
 
1660 1662
 	if(dlg==NULL)
1661 1663
 		return;
... ...
@@ -1663,31 +1683,59 @@ void dlg_run_event_route(dlg_cell_t *dlg, sip_msg_t *msg, int ostate, int nstate
1663 1663
 		return;
1664 1664
 
1665 1665
 	rt = -1;
1666
-	if(nstate==DLG_STATE_CONFIRMED_NA) {
1667
-		rt = dlg_event_rt[DLG_EVENTRT_START];
1668
-	} else if(nstate==DLG_STATE_DELETED) {
1669
-		if(ostate==DLG_STATE_CONFIRMED || ostate==DLG_STATE_CONFIRMED_NA)
1670
-			rt = dlg_event_rt[DLG_EVENTRT_END];
1671
-		else if(ostate==DLG_STATE_UNCONFIRMED || ostate==DLG_STATE_EARLY)
1672
-			rt = dlg_event_rt[DLG_EVENTRT_FAILED];
1666
+	if(dlg_event_callback.s==NULL || dlg_event_callback.len<=0) {
1667
+		if(nstate==DLG_STATE_CONFIRMED_NA) {
1668
+			rt = dlg_event_rt[DLG_EVENTRT_START];
1669
+			evname.s = "dialog:start";
1670
+			evname.len = sizeof("dialog:start") - 1;
1671
+		} else if(nstate==DLG_STATE_DELETED) {
1672
+			if(ostate==DLG_STATE_CONFIRMED || ostate==DLG_STATE_CONFIRMED_NA) {
1673
+				rt = dlg_event_rt[DLG_EVENTRT_END];
1674
+				evname.s = "dialog:end";
1675
+				evname.len = sizeof("dialog:end") - 1;
1676
+			} else if(ostate==DLG_STATE_UNCONFIRMED || ostate==DLG_STATE_EARLY) {
1677
+				evname.s = "dialog:failed";
1678
+				evname.len = sizeof("dialog:failed") - 1;
1679
+				rt = dlg_event_rt[DLG_EVENTRT_FAILED];
1680
+			}
1681
+		}
1682
+		if(rt==-1 || event_rt.rlist[rt]==NULL)
1683
+			return;
1684
+	}  else {
1685
+		keng = sr_kemi_eng_get();
1686
+		if(keng==NULL) {
1687
+			LM_DBG("event callback (%s) set, but no cfg engine\n",
1688
+					dlg_event_callback.s);
1689
+			return;
1690
+		}
1673 1691
 	}
1674 1692
 
1675
-	if(rt==-1 || event_rt.rlist[rt]==NULL)
1676
-		return;
1677 1693
 
1678 1694
 	if(msg==NULL)
1679 1695
 		fmsg = faked_msg_next();
1680 1696
 	else
1681 1697
 		fmsg = msg;
1682 1698
 
1683
-	if (exec_pre_script_cb(fmsg, LOCAL_CB_TYPE)>0)
1684
-	{
1699
+	if (exec_pre_script_cb(fmsg, LOCAL_CB_TYPE)<=0)
1700
+		return;
1701
+
1702
+	if(rt>=0 || dlg_event_callback.len>0) {
1685 1703
 		dlg_ref(dlg, 1);
1686 1704
 		dlg_set_ctx_iuid(dlg);
1687 1705
 		LM_DBG("executing event_route %d on state %d\n", rt, nstate);
1688 1706
 		bkroute = get_route_type();
1689 1707
 		set_route_type(LOCAL_ROUTE);
1690
-		run_top_route(event_rt.rlist[rt], fmsg, 0);
1708
+		if(rt>=0) {
1709
+			run_top_route(event_rt.rlist[rt], fmsg, 0);
1710
+		} else {
1711
+			if(keng!=NULL) {
1712
+				if(keng->froute(fmsg, EVENT_ROUTE,
1713
+							&dlg_event_callback, &evname)<0) {
1714
+					LM_ERR("error running event route kemi callback (%d %d)\n",
1715
+							ostate, nstate);
1716
+				}
1717
+			}
1718
+		}
1691 1719
 		dlg_reset_ctx_iuid();
1692 1720
 		exec_post_script_cb(fmsg, LOCAL_CB_TYPE);
1693 1721
 		dlg_unref(dlg, 1);