Module: kamailio
Branch: master
Commit: deb886a63ad2d9b62c78c56724db0a5f8031c73f
URL:
https://github.com/kamailio/kamailio/commit/deb886a63ad2d9b62c78c56724db0a5…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: GitHub <noreply(a)github.com>
Date: 2020-08-18T17:54:53+02:00
Merge pull request #2445 from tao-communications/master
uac: added uac_event_callback for kemi
---
Modified: src/modules/uac/doc/uac_admin.xml
Modified: src/modules/uac/uac.c
Modified: src/modules/uac/uac_send.c
---
Diff:
https://github.com/kamailio/kamailio/commit/deb886a63ad2d9b62c78c56724db0a5…
Patch:
https://github.com/kamailio/kamailio/commit/deb886a63ad2d9b62c78c56724db0a5…
---
diff --git a/src/modules/uac/doc/uac_admin.xml b/src/modules/uac/doc/uac_admin.xml
index 64aabf2190..7029449ac3 100644
--- a/src/modules/uac/doc/uac_admin.xml
+++ b/src/modules/uac/doc/uac_admin.xml
@@ -593,6 +593,38 @@ modparam("uac", "reg_gc_interval", 60)
</example>
</section>
+ <section id="uac.p.event_callback">
+ <title><varname>event_callback</varname> (str)</title>
+ <para>
+ The name of the function in the kemi configuration file (embedded
+ scripting language such as Lua, Python, ...) to be executed instead
+ of event_route[uac:reply] block.
+ </para>
+ <para>
+ The function receives a string parameter with the name of the event,
+ the value can be: 'uac:reply'.
+ </para>
+ <para>
+ <emphasis>
+ Default value is 'empty' (no function is executed for events).
+ </emphasis>
+ </para>
+ <example>
+ <title>Set <varname>event_callback</varname> parameter</title>
+ <programlisting format="linespecific">
+ ...
+modparam("uac", "event_callback", "ksr_uac_event")
+
+function ksr_uac_event(evname)
+ KSR.info("===== uac module triggered event: " .. evname .. "\n");
+ return 1;
+end
+ ...
+ </programlisting>
+ </example>
+ </section>
+
+
</section>
<section>
diff --git a/src/modules/uac/uac.c b/src/modules/uac/uac.c
index 3212960f4e..0988669f67 100644
--- a/src/modules/uac/uac.c
+++ b/src/modules/uac/uac.c
@@ -93,6 +93,8 @@ pv_spec_t auth_password_spec;
str uac_default_socket = STR_NULL;
struct socket_info * uac_default_sockinfo = NULL;
+str uac_event_callback = STR_NULL;
+
static int w_replace_from(struct sip_msg* msg, char* p1, char* p2);
static int w_restore_from(struct sip_msg* msg, char* p1, char* p2);
static int w_replace_to(struct sip_msg* msg, char* p1, char* p2);
@@ -178,6 +180,7 @@ static param_export_t params[] = {
{"reg_active", INT_PARAM, ®_active_param },
{"reg_gc_interval", INT_PARAM, &_uac_reg_gc_interval },
{"default_socket", PARAM_STR, &uac_default_socket},
+ {"event_callback", PARAM_STR, &uac_event_callback},
{0, 0, 0}
};
diff --git a/src/modules/uac/uac_send.c b/src/modules/uac/uac_send.c
index 409980aea9..d906a1c27f 100644
--- a/src/modules/uac/uac_send.c
+++ b/src/modules/uac/uac_send.c
@@ -36,6 +36,7 @@
#include "../../core/parser/parse_to.h"
#include "../../core/parser/contact/parse_contact.h"
#include "../../core/fmsg.h"
+#include "../../core/kemi.h"
#include "auth.h"
#include "auth_hdr.h"
@@ -82,6 +83,8 @@ typedef struct _uac_send_info {
static struct _uac_send_info _uac_req;
+extern str uac_event_callback;
+
void uac_send_info_copy(uac_send_info_t *src, uac_send_info_t *dst)
{
memcpy(dst, src, sizeof(uac_send_info_t));
@@ -630,12 +633,27 @@ void uac_req_run_event_route(sip_msg_t *msg, uac_send_info_t *tp,
int rcode)
int rt, backup_rt;
struct run_act_ctx ctx;
sip_msg_t *fmsg;
+ sr_kemi_eng_t *keng = NULL;
+ int kemi_evroute = 0;
+
+ if(uac_event_callback.s!=NULL && uac_event_callback.len>0) {
+ keng = sr_kemi_eng_get();
+ if(keng==NULL) {
+ LM_DBG("event callback (%s) set, but no cfg engine\n",
+ uac_event_callback.s);
+ return;
+ } else {
+ kemi_evroute = 1;
+ }
+ }
- rt = route_get(&event_rt, evrtname);
- if (rt < 0 || event_rt.rlist[rt] == NULL)
- {
- LM_DBG("event_route[uac:reply] does not exist\n");
- return;
+ if (kemi_evroute==0) {
+ rt = route_get(&event_rt, evrtname);
+ if (rt < 0 || event_rt.rlist[rt] == NULL)
+ {
+ LM_DBG("event_route[uac:reply] does not exist\n");
+ return;
+ }
}
uac_send_info_copy(tp, &_uac_req);
@@ -652,7 +670,17 @@ void uac_req_run_event_route(sip_msg_t *msg, uac_send_info_t *tp, int
rcode)
backup_rt = get_route_type();
set_route_type(REQUEST_ROUTE);
init_run_actions_ctx(&ctx);
- run_top_route(event_rt.rlist[rt], fmsg, 0);
+
+ if (kemi_evroute==1) {
+ str evrtname = str_init("uac:reply");
+
+ if(sr_kemi_route(keng, fmsg, EVENT_ROUTE,
+ &uac_event_callback, &evrtname)<0) {
+ LM_ERR("error running event route kemi callback\n");
+ }
+ } else {
+ run_top_route(event_rt.rlist[rt], fmsg, 0);
+ }
set_route_type(backup_rt);
}