(cherry picked from commit 767d3ca88a4e4fa093a6a81a36d95d116251b578)
... | ... |
@@ -593,6 +593,38 @@ modparam("uac", "reg_gc_interval", 60) |
593 | 593 |
</example> |
594 | 594 |
</section> |
595 | 595 |
|
596 |
+ <section id="uac.p.event_callback"> |
|
597 |
+ <title><varname>event_callback</varname> (str)</title> |
|
598 |
+ <para> |
|
599 |
+ The name of the function in the kemi configuration file (embedded |
|
600 |
+ scripting language such as Lua, Python, ...) to be executed instead |
|
601 |
+ of event_route[uac:reply] block. |
|
602 |
+ </para> |
|
603 |
+ <para> |
|
604 |
+ The function receives a string parameter with the name of the event, |
|
605 |
+ the value can be: 'uac:reply'. |
|
606 |
+ </para> |
|
607 |
+ <para> |
|
608 |
+ <emphasis> |
|
609 |
+ Default value is 'empty' (no function is executed for events). |
|
610 |
+ </emphasis> |
|
611 |
+ </para> |
|
612 |
+ <example> |
|
613 |
+ <title>Set <varname>event_callback</varname> parameter</title> |
|
614 |
+ <programlisting format="linespecific"> |
|
615 |
+ ... |
|
616 |
+modparam("uac", "event_callback", "ksr_uac_event") |
|
617 |
+ |
|
618 |
+function ksr_uac_event(evname) |
|
619 |
+ KSR.info("===== uac module triggered event: " .. evname .. "\n"); |
|
620 |
+ return 1; |
|
621 |
+end |
|
622 |
+ ... |
|
623 |
+ </programlisting> |
|
624 |
+ </example> |
|
625 |
+ </section> |
|
626 |
+ |
|
627 |
+ |
|
596 | 628 |
</section> |
597 | 629 |
|
598 | 630 |
<section> |
... | ... |
@@ -93,6 +93,8 @@ pv_spec_t auth_password_spec; |
93 | 93 |
str uac_default_socket = STR_NULL; |
94 | 94 |
struct socket_info * uac_default_sockinfo = NULL; |
95 | 95 |
|
96 |
+str uac_event_callback = STR_NULL; |
|
97 |
+ |
|
96 | 98 |
static int w_replace_from(struct sip_msg* msg, char* p1, char* p2); |
97 | 99 |
static int w_restore_from(struct sip_msg* msg, char* p1, char* p2); |
98 | 100 |
static int w_replace_to(struct sip_msg* msg, char* p1, char* p2); |
... | ... |
@@ -178,6 +180,7 @@ static param_export_t params[] = { |
178 | 180 |
{"reg_active", INT_PARAM, ®_active_param }, |
179 | 181 |
{"reg_gc_interval", INT_PARAM, &_uac_reg_gc_interval }, |
180 | 182 |
{"default_socket", PARAM_STR, &uac_default_socket}, |
183 |
+ {"event_callback", PARAM_STR, &uac_event_callback}, |
|
181 | 184 |
{0, 0, 0} |
182 | 185 |
}; |
183 | 186 |
|
... | ... |
@@ -36,6 +36,7 @@ |
36 | 36 |
#include "../../core/parser/parse_to.h" |
37 | 37 |
#include "../../core/parser/contact/parse_contact.h" |
38 | 38 |
#include "../../core/fmsg.h" |
39 |
+#include "../../core/kemi.h" |
|
39 | 40 |
|
40 | 41 |
#include "auth.h" |
41 | 42 |
#include "auth_hdr.h" |
... | ... |
@@ -82,6 +83,8 @@ typedef struct _uac_send_info { |
82 | 83 |
|
83 | 84 |
static struct _uac_send_info _uac_req; |
84 | 85 |
|
86 |
+extern str uac_event_callback; |
|
87 |
+ |
|
85 | 88 |
void uac_send_info_copy(uac_send_info_t *src, uac_send_info_t *dst) |
86 | 89 |
{ |
87 | 90 |
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) |
630 | 633 |
int rt, backup_rt; |
631 | 634 |
struct run_act_ctx ctx; |
632 | 635 |
sip_msg_t *fmsg; |
636 |
+ sr_kemi_eng_t *keng = NULL; |
|
637 |
+ int kemi_evroute = 0; |
|
638 |
+ |
|
639 |
+ if(uac_event_callback.s!=NULL && uac_event_callback.len>0) { |
|
640 |
+ keng = sr_kemi_eng_get(); |
|
641 |
+ if(keng==NULL) { |
|
642 |
+ LM_DBG("event callback (%s) set, but no cfg engine\n", |
|
643 |
+ uac_event_callback.s); |
|
644 |
+ return; |
|
645 |
+ } else { |
|
646 |
+ kemi_evroute = 1; |
|
647 |
+ } |
|
648 |
+ } |
|
633 | 649 |
|
634 |
- rt = route_get(&event_rt, evrtname); |
|
635 |
- if (rt < 0 || event_rt.rlist[rt] == NULL) |
|
636 |
- { |
|
637 |
- LM_DBG("event_route[uac:reply] does not exist\n"); |
|
638 |
- return; |
|
650 |
+ if (kemi_evroute==0) { |
|
651 |
+ rt = route_get(&event_rt, evrtname); |
|
652 |
+ if (rt < 0 || event_rt.rlist[rt] == NULL) |
|
653 |
+ { |
|
654 |
+ LM_DBG("event_route[uac:reply] does not exist\n"); |
|
655 |
+ return; |
|
656 |
+ } |
|
639 | 657 |
} |
640 | 658 |
|
641 | 659 |
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) |
652 | 670 |
backup_rt = get_route_type(); |
653 | 671 |
set_route_type(REQUEST_ROUTE); |
654 | 672 |
init_run_actions_ctx(&ctx); |
655 |
- run_top_route(event_rt.rlist[rt], fmsg, 0); |
|
673 |
+ |
|
674 |
+ if (kemi_evroute==1) { |
|
675 |
+ str evrtname = str_init("uac:reply"); |
|
676 |
+ |
|
677 |
+ if(sr_kemi_route(keng, fmsg, EVENT_ROUTE, |
|
678 |
+ &uac_event_callback, &evrtname)<0) { |
|
679 |
+ LM_ERR("error running event route kemi callback\n"); |
|
680 |
+ } |
|
681 |
+ } else { |
|
682 |
+ run_top_route(event_rt.rlist[rt], fmsg, 0); |
|
683 |
+ } |
|
656 | 684 |
set_route_type(backup_rt); |
657 | 685 |
} |
658 | 686 |
|