Skip to content

Commit

Permalink
tm: execute on_sl_reply callback via kemi
Browse files Browse the repository at this point in the history
- the value of the parameter on_sl_reply has to be the kemi function
name
  • Loading branch information
miconda committed Aug 26, 2019
1 parent 3f1b514 commit ce66124
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 15 deletions.
46 changes: 35 additions & 11 deletions src/modules/tm/t_reply.c
Expand Up @@ -2162,7 +2162,6 @@ enum rps local_reply( struct cell *t, struct sip_msg *p_msg, int branch,
*/
int reply_received( struct sip_msg *p_msg )
{

int msg_status;
int last_uac_status;
char *ack;
Expand Down Expand Up @@ -2192,6 +2191,8 @@ int reply_received( struct sip_msg *p_msg )
struct run_act_ctx ctx;
struct run_act_ctx *bctx;
sr_kemi_eng_t *keng = NULL;
int ret;
str evname = str_init("on_sl_reply");

/* make sure we know the associated transaction ... */
branch = T_BR_UNDEFINED;
Expand Down Expand Up @@ -2566,17 +2567,40 @@ int reply_received( struct sip_msg *p_msg )

trans_not_found:
/* transaction context was not found */
if (goto_on_sl_reply) {
/* The script writer has a chance to decide whether to
* forward the reply or not.
* Pre- and post-script callbacks have already
* been execueted by the core. (Miklos)
*/
return run_top_route(onreply_rt.rlist[goto_on_sl_reply], p_msg, 0);
} else {
/* let the core forward the reply */
return 1;
if(on_sl_reply_name.s!=NULL && on_sl_reply_name.len>0) {
keng = sr_kemi_eng_get();
if(keng==NULL) {
if (goto_on_sl_reply) {
/* The script writer has a chance to decide whether to
* forward the reply or not.
* Pre- and post-script callbacks have already
* been execueted by the core. (Miklos)
*/
return run_top_route(onreply_rt.rlist[goto_on_sl_reply], p_msg, 0);
} else {
/* let the core forward the reply */
return 1;
}
} else {
bctx = sr_kemi_act_ctx_get();
init_run_actions_ctx(&ctx);
sr_kemi_act_ctx_set(&ctx);
ret = sr_kemi_ctx_route(keng, &ctx, p_msg, EVENT_ROUTE,
&on_sl_reply_name, &evname);
sr_kemi_act_ctx_set(bctx);
if(ret<0) {
LM_ERR("error running on sl reply callback\n");
return -1;
}
if(unlikely(ctx.run_flags & DROP_R_F)) {
LM_DBG("drop flag set - skip forwarding the reply\n");
return 0;
}
/* let the core forward the reply */
return 1;
}
}
return 1;
}


Expand Down
13 changes: 9 additions & 4 deletions src/modules/tm/tm.c
Expand Up @@ -689,6 +689,8 @@ static int script_init( struct sip_msg *foo, unsigned int flags, void *bar)

static int mod_init(void)
{
sr_kemi_eng_t *keng = NULL;

DBG( "TM - (sizeof cell=%ld, sip_msg=%ld) initializing...\n",
(long)sizeof(struct cell), (long)sizeof(struct sip_msg));

Expand All @@ -701,10 +703,13 @@ static int mod_init(void)
}

if(on_sl_reply_name.s!=NULL && on_sl_reply_name.len>0) {
goto_on_sl_reply=route_get(&onreply_rt, on_sl_reply_name.s);
if (goto_on_sl_reply==-1){
LM_ERR("route get failed for on_sl_reply\n");
return -1;
keng = sr_kemi_eng_get();
if(keng==NULL) {
goto_on_sl_reply=route_get(&onreply_rt, on_sl_reply_name.s);
if (goto_on_sl_reply==-1){
LM_ERR("route get failed for on_sl_reply\n");
return -1;
}
}
}
if (init_callid() < 0) {
Expand Down

0 comments on commit ce66124

Please sign in to comment.