Skip to content

Commit

Permalink
Merge branch 'async'
Browse files Browse the repository at this point in the history
Conflicts:
	Makefile
	context.h
	modules/dialog/dialog.c
	modules/dispatcher/README
	modules/dispatcher/doc/dispatcher_admin.xml
	modules/dispatcher/ds_fixups.c
	modules/exec/exec.c
	modules/exec/exec.h
	modules/exec/exec_mod.c
	modules/tm/t_ctx.c
	modules/tm/tm.c
	msg_translator.c
  • Loading branch information
bogdan-iancu committed Dec 19, 2014
2 parents 487e7b5 + e7a090f commit 1bbe2ef
Show file tree
Hide file tree
Showing 195 changed files with 2,396 additions and 1,018 deletions.
15 changes: 15 additions & 0 deletions action.c
Expand Up @@ -1869,6 +1869,21 @@ int do_action(struct action* a, struct sip_msg* msg)
LM_ALERT("BUG in module call\n");
}
break;
case ASYNC_T:
/* first param - an ACTIONS_ST containing an ACMD_ST
* second param - a NUMBER_ST pointing to resume route */
aitem = (struct action *)(a->elem[0].u.data);
if (async_start_f==NULL || a->elem[0].type!=ACTIONS_ST ||
a->elem[1].type!=NUMBER_ST || aitem->type!=AMODULE_T) {
LM_ALERT("BUG in async expresion\n");
} else {
script_trace("async", ((acmd_export_t*)(aitem->elem[0].u.data))->name,
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) ;
msg->msg_flags|=FL_FORCE_RPORT;
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
44 changes: 44 additions & 0 deletions async.c
@@ -0,0 +1,44 @@
/*
* Copyright (C) 2014 OpenSIPS Solutions
*
* This file is part of opensips, a free SIP server.
*
* opensips is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* opensips is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* 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
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*
* history:
* ---------
* 2014-10-15 created (bogdan)
*/

#include "dprint.h"
#include "async.h"

async_start_function *async_start_f = NULL;
async_resume_function *async_resume_f = NULL;


int register_async_handlers(async_start_function *f1, async_resume_function *f2)
{
if (async_start_f) {
LM_ERR("aync handler already registered, it cannot be override\n");
return -1;
}

async_start_f = f1;
async_resume_f = f2;

return 0;
}
65 changes: 65 additions & 0 deletions async.h
@@ -0,0 +1,65 @@
/*
* Copyright (C) 2014 OpenSIPS Solutions
*
* This file is part of opensips, a free SIP server.
*
* opensips is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* opensips is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* 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
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*
* history:
* ---------
* 2014-10-15 created (bogdan)
*/


#ifndef _ASYNC_H_
#define _ASYNC_H_

#include "route_struct.h"
#include "parser/msg_parser.h"


/* function to handle script function in async mode.
Input: the sip message, the function/action (MODULE_T) and the ID of
the resume route (where to continue after the I/O is done).
Output: 0 if the async call was successfuly done and script execution
must be terminated.
-1 some error happened and the async call did not happened.
*/


/* internal used functions to start (from script) and
* to continue (from reactor) async I/O ops */
typedef int (async_start_function)
(struct sip_msg *msg, struct action* a , int resume_route);

typedef int (async_resume_function)
(int fd, void *param);

extern async_start_function *async_start_f;
extern async_resume_function *async_resume_f;

int register_async_handlers(async_start_function *f1, async_resume_function *f2);


/* async related functions to be used by the
* functions exported by modules */
enum async_ret_code {ASYNC_DONE, ASYNC_CONTINUE, ASYNC_ERROR};

typedef enum async_ret_code (async_resume_module)
(int fd, struct sip_msg *msg, void *param);

#endif

12 changes: 6 additions & 6 deletions cfg.lex
Expand Up @@ -212,8 +212,8 @@ SUBSCRIBE_EVENT "subscribe_event"
CONSTRUCT_URI "construct_uri"
GET_TIMESTAMP "get_timestamp"
SCRIPT_TRACE "script_trace"
EVENT_ROUTE_SYNC sync
EVENT_ROUTE_ASYNC async
SYNC_TOKEN "sync"
ASYNC_TOKEN "async"

/*ACTION LVALUES*/
URIHOST "uri:host"
Expand Down Expand Up @@ -570,10 +570,10 @@ IMPORTFILE "import_file"
return GET_TIMESTAMP;}
<INITIAL>{SCRIPT_TRACE} { count(); yylval.strval=yytext;
return SCRIPT_TRACE;}
<INITIAL>{EVENT_ROUTE_SYNC} { count(); yylval.strval=yytext;
return EVENT_ROUTE_SYNC;}
<INITIAL>{EVENT_ROUTE_ASYNC} { count(); yylval.strval=yytext;
return EVENT_ROUTE_ASYNC;}
<INITIAL>{SYNC_TOKEN} { count(); yylval.strval=yytext;
return SYNC_TOKEN;}
<INITIAL>{ASYNC_TOKEN} { count(); yylval.strval=yytext;
return ASYNC_TOKEN;}
<INITIAL>{MAX_LEN} { count(); yylval.strval=yytext; return MAX_LEN; }

<INITIAL>{METHOD} { count(); yylval.strval=yytext; return METHOD; }
Expand Down
52 changes: 45 additions & 7 deletions cfg.y
@@ -1,6 +1,4 @@
/*
* $Id$
*
* cfg grammar
*
* Copyright (C) 2001-2003 FhG Fokus
Expand Down Expand Up @@ -432,8 +430,8 @@ extern char *finame;
%token DB_VERSION_TABLE
%token DB_DEFAULT_URL
%token DISABLE_503_TRANSLATION
%token EVENT_ROUTE_SYNC
%token EVENT_ROUTE_ASYNC
%token SYNC_TOKEN
%token ASYNC_TOKEN



Expand Down Expand Up @@ -493,7 +491,7 @@ extern char *finame;
/*non-terminals */
%type <expr> exp exp_elem exp_cond assignexp /*, condition*/
%type <action> action actions cmd if_cmd stm exp_stm assign_cmd while_cmd
foreach_cmd
foreach_cmd async_func
%type <action> switch_cmd switch_stm case_stms case_stm default_stm
%type <intval> module_func_param
%type <ipaddr> ipv4 ipv6 ipv6addr ip
Expand Down Expand Up @@ -1870,7 +1868,7 @@ event_route_stm: ROUTE_EVENT LBRACK route_name RBRACK LBRACE actions RBRACE {

push($6, &event_rlist[i_tmp].a);
}
| ROUTE_EVENT LBRACK route_name COMMA EVENT_ROUTE_SYNC RBRACK LBRACE actions RBRACE {
| ROUTE_EVENT LBRACK route_name COMMA SYNC_TOKEN RBRACK LBRACE actions RBRACE {

i_tmp = 1;
while (event_rlist[i_tmp].a !=0 && i_tmp < EVENT_RT_NO) {
Expand All @@ -1891,7 +1889,7 @@ event_route_stm: ROUTE_EVENT LBRACK route_name RBRACK LBRACE actions RBRACE {

push($8, &event_rlist[i_tmp].a);
}
| ROUTE_EVENT LBRACK route_name COMMA EVENT_ROUTE_ASYNC RBRACK LBRACE actions RBRACE {
| ROUTE_EVENT LBRACK route_name COMMA ASYNC_TOKEN RBRACK LBRACE actions RBRACE {

i_tmp = 1;
while (event_rlist[i_tmp].a !=0 && i_tmp < EVENT_RT_NO) {
Expand Down Expand Up @@ -2513,6 +2511,40 @@ route_param: STRING {
}
;

async_func: ID LPAREN RPAREN {
cmd_tmp=(void*)find_acmd_export_t($1, 0);
if (cmd_tmp==0){
yyerrorf("unknown async command <%s>, "
"missing loadmodule?", $1);
$$=0;
}else{
elems[0].type = ACMD_ST;
elems[0].u.data = cmd_tmp;
mk_action_($$, AMODULE_T, 1, elems);
}
}
| ID LPAREN module_func_param RPAREN {
cmd_tmp=(void*)find_acmd_export_t($1, $3);
if (cmd_tmp==0){
yyerrorf("unknown async command <%s>, "
"missing loadmodule?", $1);
$$=0;
}else{
elems[0].type = ACMD_ST;
elems[0].u.data = cmd_tmp;
mk_action_($$, AMODULE_T, $3+1, elems);
}
}
| ID LPAREN error RPAREN {
$$=0;
yyerrorf("bad arguments for command <%s>", $1);
}
| ID error {
$$=0;
yyerrorf("bare word <%s> found, command calls need '()'", $1);
}
;

cmd: FORWARD LPAREN STRING RPAREN { mk_action2( $$, FORWARD_T,
STRING_ST,
0,
Expand Down Expand Up @@ -3183,6 +3215,12 @@ cmd: FORWARD LPAREN STRING RPAREN { mk_action2( $$, FORWARD_T,
yyerror("error in second parameter");
mk_action3($$, SCRIPT_TRACE_T, NUMBER_ST,
SCRIPTVAR_ELEM_ST, STR_ST, (void *)$3, pvmodel, $7); }
| ASYNC_TOKEN LPAREN async_func COMMA route_name RPAREN {
i_tmp = get_script_route_idx( $5, rlist, RT_NO, 0);
if (i_tmp==-1) yyerror("too many script routes");
mk_action2($$, ASYNC_T, ACTIONS_ST, NUMBER_ST,
$3, (void*)(long)i_tmp);
}

;

Expand Down

0 comments on commit 1bbe2ef

Please sign in to comment.