Skip to content

Commit

Permalink
dispatcher: enable execution of event routes via kemi
Browse files Browse the repository at this point in the history
  • Loading branch information
miconda committed Apr 4, 2017
1 parent 6d87794 commit 6aa2173
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 11 deletions.
45 changes: 36 additions & 9 deletions src/modules/dispatcher/dispatch.c
Expand Up @@ -51,6 +51,7 @@
#include "../../lib/srdb1/db_res.h"
#include "../../core/str.h"
#include "../../core/script_cb.h"
#include "../../core/kemi.h"
#include "../../core/fmsg.h"

#include "ds_ht.h"
Expand All @@ -72,6 +73,7 @@ static ds_ht_t *_dsht_load = NULL;
static int *_ds_ping_active = NULL;

extern int ds_force_dst;
extern str ds_event_callback;

static db_func_t ds_dbf;
static db1_con_t *ds_db_handle = NULL;
Expand Down Expand Up @@ -2263,6 +2265,8 @@ static void ds_run_route(sip_msg_t *msg, str *uri, char *route)
int rt, backup_rt;
struct run_act_ctx ctx;
sip_msg_t *fmsg;
sr_kemi_eng_t *keng = NULL;
str evname;

if(route == NULL) {
LM_ERR("bad route\n");
Expand All @@ -2271,10 +2275,20 @@ static void ds_run_route(sip_msg_t *msg, str *uri, char *route)

LM_DBG("ds_run_route event_route[%s]\n", route);

rt = route_get(&event_rt, route);
if(rt < 0 || event_rt.rlist[rt] == NULL) {
LM_DBG("route does not exist");
return;
rt = -1;
if(ds_event_callback.s==NULL || ds_event_callback.len<=0) {
rt = route_lookup(&event_rt, route);
if(rt < 0 || event_rt.rlist[rt] == NULL) {
LM_DBG("route does not exist");
return;
}
} else {
keng = sr_kemi_eng_get();
if(keng==NULL) {
LM_DBG("event callback (%s) set, but no cfg engine\n",
ds_event_callback.s);
return;
}
}

if(msg == NULL) {
Expand All @@ -2289,11 +2303,24 @@ static void ds_run_route(sip_msg_t *msg, str *uri, char *route)
fmsg = msg;
}

backup_rt = get_route_type();
set_route_type(REQUEST_ROUTE);
init_run_actions_ctx(&ctx);
run_top_route(event_rt.rlist[rt], fmsg, 0);
set_route_type(backup_rt);
if(rt>=0 || ds_event_callback.len>0) {
backup_rt = get_route_type();
set_route_type(REQUEST_ROUTE);
init_run_actions_ctx(&ctx);
if(rt>=0) {
run_top_route(event_rt.rlist[rt], fmsg, 0);
} else {
if(keng!=NULL) {
evname.s = route;
evname.len = strlen(evname.s);
if(keng->froute(fmsg, EVENT_ROUTE,
&ds_event_callback, &evname)<0) {
LM_ERR("error running event route kemi callback\n");
}
}
}
set_route_type(backup_rt);
}
}


Expand Down
3 changes: 3 additions & 0 deletions src/modules/dispatcher/dispatcher.c
Expand Up @@ -136,6 +136,8 @@ pv_spec_t ds_setid_pv;
str ds_attrs_pvname = STR_NULL;
pv_spec_t ds_attrs_pv;

str ds_event_callback = STR_NULL;

/** module functions */
static int mod_init(void);
static int child_init(int);
Expand Down Expand Up @@ -248,6 +250,7 @@ static param_export_t params[]={
{"outbound_proxy", PARAM_STR, &ds_outbound_proxy},
{"ds_default_socket", PARAM_STR, &ds_default_socket},
{"ds_timer_mode", PARAM_INT, &ds_timer_mode},
{"event_callback", PARAM_STR, &ds_event_callback},
{0,0,0}
};

Expand Down
4 changes: 2 additions & 2 deletions src/modules/htable/htable.c
Expand Up @@ -263,7 +263,7 @@ static int child_init(int rank)
rtb = get_route_type();
set_route_type(REQUEST_ROUTE);
init_run_actions_ctx(&ctx);
if(rt>0) {
if(rt>=0) {
run_top_route(event_rt.rlist[rt], fmsg, &ctx);
} else {
if(keng!=NULL) {
Expand All @@ -274,11 +274,11 @@ static int child_init(int rank)
}
}
}
set_route_type(rtb);
if(ctx.run_flags&DROP_R_F) {
LM_ERR("exit due to 'drop' in event route\n");
return -1;
}
set_route_type(rtb);
}

done:
Expand Down

0 comments on commit 6aa2173

Please sign in to comment.