Module: kamailio
Branch: master
Commit: 7b190e644c4b1c18055ededa7f4b5d5f2c1b6ca1
URL:
https://github.com/kamailio/kamailio/commit/7b190e644c4b1c18055ededa7f4b5d5…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2017-04-17T20:27:01+02:00
xhttp: allow execution of callback function for event route via kemi
- new parameter event_callback
---
Modified: src/modules/xhttp/xhttp_mod.c
---
Diff:
https://github.com/kamailio/kamailio/commit/7b190e644c4b1c18055ededa7f4b5d5…
Patch:
https://github.com/kamailio/kamailio/commit/7b190e644c4b1c18055ededa7f4b5d5…
---
diff --git a/src/modules/xhttp/xhttp_mod.c b/src/modules/xhttp/xhttp_mod.c
index d104883..d41fc47 100644
--- a/src/modules/xhttp/xhttp_mod.c
+++ b/src/modules/xhttp/xhttp_mod.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2010 Daniel-Constantin Mierla (
asipto.com)
+ * Copyright (C) 2010-2017 Daniel-Constantin Mierla (
asipto.com)
*
* This file is part of Kamailio, a free SIP server.
*
@@ -13,8 +13,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
*
*/
@@ -67,6 +67,7 @@ static regex_t xhttp_url_skip_regexp;
/** SL API structure */
sl_api_t slb;
+static str xhttp_event_callback = STR_NULL;
static cmd_export_t cmds[] = {
{"xhttp_reply", (cmd_function)w_xhttp_send_reply,
@@ -87,6 +88,7 @@ static pv_export_t mod_pvs[] = {
static param_export_t params[] = {
{"url_match", PARAM_STRING, &xhttp_url_match},
{"url_skip", PARAM_STRING, &xhttp_url_skip},
+ {"event_callback", PARAM_STR, &xhttp_event_callback},
{0, 0, 0}
};
@@ -120,18 +122,28 @@ static int mod_init(void)
{
struct nonsip_hook nsh;
int route_no;
-
- route_no=route_get(&event_rt, "xhttp:request");
- if (route_no==-1)
- {
- LM_ERR("failed to find event_route[xhttp:request]\n");
- return -1;
- }
- if (event_rt.rlist[route_no]==0)
- {
- LM_WARN("event_route[xhttp:request] is empty\n");
+ sr_kemi_eng_t *keng = NULL;
+
+ if(xhttp_event_callback.s!=NULL && xhttp_event_callback.len>0) {
+ keng = sr_kemi_eng_get();
+ if(keng==NULL) {
+ LM_ERR("failed to find kemi engine\n");
+ return -1;
+ }
+ xhttp_route_no=-1;
+ } else {
+ route_no=route_lookup(&event_rt, "xhttp:request");
+ if (route_no==-1)
+ {
+ LM_ERR("failed to find event_route[xhttp:request]\n");
+ return -1;
+ }
+ if (event_rt.rlist[route_no]==0)
+ {
+ LM_WARN("event_route[xhttp:request] is empty\n");
+ }
+ xhttp_route_no=route_no;
}
- xhttp_route_no=route_no;
/* bind the SL API */
if (sl_load_api(&slb)!=0) {
@@ -241,10 +253,14 @@ static int xhttp_process_request(sip_msg_t* orig_msg,
char* new_buf, unsigned int new_len)
{
int ret;
+ int backup_rt;
sip_msg_t tmp_msg, *msg;
struct run_act_ctx ra_ctx;
-
+ sr_kemi_eng_t *keng = NULL;
+ str evrtname = str_init("xhttp:request");
+
ret=0;
+ backup_rt = get_route_type();
if (new_buf && new_len)
{
memset(&tmp_msg, 0, sizeof(sip_msg_t));
@@ -270,17 +286,31 @@ static int xhttp_process_request(sip_msg_t* orig_msg,
LM_CRIT("strange message: %.*s\n", msg->len, msg->buf);
goto error;
}
+
+ set_route_type(EVENT_ROUTE);
if (exec_pre_script_cb(msg, REQUEST_CB_TYPE) == 0)
{
goto done;
}
init_run_actions_ctx(&ra_ctx);
- if (run_actions(&ra_ctx, event_rt.rlist[xhttp_route_no], msg) < 0)
- {
- ret=-1;
- LM_DBG("error while trying script\n");
- goto done;
+ if(xhttp_route_no>=0) {
+ if (run_actions(&ra_ctx, event_rt.rlist[xhttp_route_no], msg) < 0)
+ {
+ ret=-1;
+ LM_DBG("error while trying script\n");
+ goto done;
+ }
+ } else {
+ keng = sr_kemi_eng_get();
+ if(keng!=NULL) {
+ if(keng->froute(msg, EVENT_ROUTE,
+ &xhttp_event_callback, &evrtname)<0) {
+ LM_ERR("error running event route kemi callback\n");
+ }
+ } else {
+ LM_ERR("no event route or kemi callback found for execution\n");
+ }
}
done:
@@ -289,6 +319,7 @@ static int xhttp_process_request(sip_msg_t* orig_msg,
{
free_sip_msg(msg);
}
+ set_route_type(backup_rt);
return ret;
error:
@@ -538,4 +569,4 @@ int mod_register(char *path, int *dlflags, void *p1, void *p2)
return register_trans_mod(path, mod_trans);
}
-/** @} */
\ No newline at end of file
+/** @} */