Skip to content

Commit

Permalink
Run POST script CBs after all ASYNC resumes.
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdan-iancu committed Nov 24, 2014
1 parent 4b9b183 commit 50623c1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
2 changes: 2 additions & 0 deletions action.c
Expand Up @@ -1881,6 +1881,8 @@ int do_action(struct action* a, struct sip_msg* msg)
msg, a->file, a->line) ;
ret = async_start_f( msg, aitem, a->elem[1].u.number);
}
action_flags |= ACT_FL_TBCONT;
ret = 0;
break;
case FORCE_RPORT_T:
script_trace("core", "force_rport", msg, a->file, a->line) ;
Expand Down
7 changes: 4 additions & 3 deletions action.h
Expand Up @@ -32,9 +32,10 @@
#include "parser/msg_parser.h"
#include "route_struct.h"

#define ACT_FL_EXIT 1
#define ACT_FL_RETURN 2
#define ACT_FL_DROP 4
#define ACT_FL_EXIT (1<<0)
#define ACT_FL_RETURN (1<<1)
#define ACT_FL_DROP (2<<2)
#define ACT_FL_TBCONT (2<<3)

extern int action_flags;
extern int use_script_trace;
Expand Down
18 changes: 13 additions & 5 deletions modules/tm/async.c
Expand Up @@ -41,6 +41,16 @@ typedef struct _async_ctx {
extern int return_code; /* from action.c, return code */



static inline void run_resume_route( int resume_route, struct sip_msg *msg)
{
/* run the resume route and if it ends the msg handling (no other aysnc
* started), run the post script callbacks. */
if ( (run_top_route(rlist[resume_route].a, msg) & ACT_FL_TBCONT) == 0 )
exec_post_req_cb(msg);
}


/* function triggered from reactor in order to continue the processing
*/
int t_resume_async(int fd, void *param)
Expand Down Expand Up @@ -92,7 +102,7 @@ int t_resume_async(int fd, void *param)
close(fd);

/* run the resume_route[] */
run_top_route( rlist[ctx->resume_route].a, &faked_req);
run_resume_route( ctx->resume_route, &faked_req);

restore:
/* restore original environment */
Expand Down Expand Up @@ -176,8 +186,6 @@ int t_handle_async(struct sip_msg *msg, struct action* a , int resume_route)
ctx->resume_route = resume_route;
ctx->t = t;

set_kr(REQ_FWDED);

/* place the FD + resume function (as param) into reactor */
if (reactor_add_reader( fd, F_SCRIPT_ASYNC, (void*)ctx)<0 ) {
LM_ERR("failed to add async FD to reactor -> act in sync mode\n");
Expand All @@ -193,7 +201,7 @@ int t_handle_async(struct sip_msg *msg, struct action* a , int resume_route)
/* run the resume function */
ctx_f( fd, msg, ctx_p );
/* run the resume route in sync mode */
run_top_route(rlist[resume_route].a, msg);
run_resume_route( resume_route, msg);
/* break original script */
return 0;

Expand All @@ -202,7 +210,7 @@ int t_handle_async(struct sip_msg *msg, struct action* a , int resume_route)
/* execute here the resume route with failure indication */
return_code = -1; /* FIXME */
/* run the resume route */
run_top_route(rlist[resume_route].a, msg);
run_resume_route( resume_route, msg);
/* the triggering route is terminated and whole script ended */
return 0;
}
Expand Down

0 comments on commit 50623c1

Please sign in to comment.