Module: kamailio
Branch: master
Commit: a83e44b7a942afcf1770fa179cda8e530c74e28a
URL:
https://github.com/kamailio/kamailio/commit/a83e44b7a942afcf1770fa179cda8e5…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2022-11-17T13:08:59+01:00
core: new global parameter return_mode
- control the return code evaluation mode:
- 0 (default) - evaluation is like so far (negative is false, positive
is true)
- 1 - propagate return value and evaluation has to be done with >0 or
<0, otherwise value!=0 is evaluated to true no matter is negative
or positive
---
Modified: src/core/action.c
Modified: src/core/cfg.lex
Modified: src/core/cfg.y
Modified: src/core/globals.h
Modified: src/core/rvalue.c
---
Diff:
https://github.com/kamailio/kamailio/commit/a83e44b7a942afcf1770fa179cda8e5…
Patch:
https://github.com/kamailio/kamailio/commit/a83e44b7a942afcf1770fa179cda8e5…
---
diff --git a/src/core/action.c b/src/core/action.c
index 48b150dd70..b95c531e1d 100644
--- a/src/core/action.c
+++ b/src/core/action.c
@@ -1065,7 +1065,7 @@ int do_action(struct run_act_ctx* h, struct action* a, struct
sip_msg* msg)
h->run_flags &= ~(RETURN_R_F|BREAK_R_F); /* catch return &
break in expr*/
ret=1; /*default is continue */
- if (v>0) {
+ if ((ksr_return_mode==0 && v>0) || (ksr_return_mode!=0 && v!=0))
{
if ((a->val[1].type==ACTIONS_ST)&&a->val[1].u.data){
ret=run_actions(h,
(struct action*)a->val[1].u.data, msg);
@@ -1363,12 +1363,13 @@ int do_action(struct run_act_ctx* h, struct action* a, struct
sip_msg* msg)
rve=(struct rval_expr*)a->val[0].u.data;
ret=1;
while(!(flags & (BREAK_R_F|RETURN_R_F|EXIT_R_F)) &&
- (rval_expr_eval_int(h, msg, &v, rve) == 0) && v){
+ (rval_expr_eval_int(h, msg, &v, rve) == 0) &&
+ ((ksr_return_mode==0 && v>0) || (ksr_return_mode!=0 && v!=0))) {
if (cfg_get(core, core_cfg, max_while_loops) > 0)
i++;
if (unlikely(i > cfg_get(core, core_cfg, max_while_loops))){
- LM_ERR("runaway while (%d, %d): more then %d loops\n",
+ LM_ERR("runaway while (%d, %d): more then %d loops\n",
rve->fpos.s_line, rve->fpos.s_col,
cfg_get(core, core_cfg, max_while_loops));
ret=-1;
diff --git a/src/core/cfg.lex b/src/core/cfg.lex
index cc0afb8f22..d4379da3fc 100644
--- a/src/core/cfg.lex
+++ b/src/core/cfg.lex
@@ -147,6 +147,7 @@ FORWARD_SCTP forward_sctp
DROP "drop"
EXIT "exit"
RETURN "return"
+RETURN_MODE "return_mode"
BREAK "break"
LOG log
ERROR error
@@ -1049,6 +1050,7 @@ IMPORTFILE "import_file"
<INITIAL>{CFGENGINE} { count(); yylval.strval=yytext; return CFGENGINE; }
<INITIAL>{URI_HOST_EXTRA_CHARS} { yylval.strval=yytext; return
URI_HOST_EXTRA_CHARS; }
<INITIAL>{HDR_NAME_EXTRA_CHARS} { yylval.strval=yytext; return
HDR_NAME_EXTRA_CHARS; }
+<INITIAL>{RETURN_MODE} { count(); yylval.strval=yytext; return RETURN_MODE; }
<INITIAL>{EQUAL} { count(); return EQUAL; }
<INITIAL>{ADDEQ} { count(); return ADDEQ; }
diff --git a/src/core/cfg.y b/src/core/cfg.y
index 89eb5c210f..230be193dd 100644
--- a/src/core/cfg.y
+++ b/src/core/cfg.y
@@ -227,6 +227,7 @@ extern char *default_routename;
%token EXIT
%token DROP
%token RETURN
+%token RETURN_MODE
%token BREAK
%token LOG_TOK
%token ERROR
@@ -1900,6 +1901,8 @@ assign_stm:
| WAIT_WORKER1_USLEEP EQUAL error { yyerror("number expected"); }
| SERVER_ID EQUAL NUMBER { server_id=$3; }
| SERVER_ID EQUAL error { yyerror("number expected"); }
+ | RETURN_MODE EQUAL NUMBER { ksr_return_mode=$3; }
+ | RETURN_MODE EQUAL error { yyerror("number expected"); }
| KEMI DOT ONSEND_ROUTE_CALLBACK EQUAL STRING {
kemi_onsend_route_callback.s = $5;
kemi_onsend_route_callback.len = strlen($5);
diff --git a/src/core/globals.h b/src/core/globals.h
index 03eb1ef897..8d72807aee 100644
--- a/src/core/globals.h
+++ b/src/core/globals.h
@@ -219,6 +219,7 @@ extern str _ksr_xavp_via_params;
extern str _ksr_xavp_via_fields;
extern int ksr_sip_parser_mode;
extern int ksr_cfg_print_mode;
+extern int ksr_return_mode;
extern int ksr_wait_worker1_mode;
extern int ksr_wait_worker1_time;
diff --git a/src/core/rvalue.c b/src/core/rvalue.c
index 9e5268c888..4ab93f44f4 100644
--- a/src/core/rvalue.c
+++ b/src/core/rvalue.c
@@ -82,6 +82,9 @@
#define rv_unref(rv) ((--(rv)->refcnt)==0)
+/* control return code evaluation mode */
+int ksr_return_mode = 0;
+
inline static void rval_force_clean(struct rvalue* rv)
{
if (rv->flags & RV_CNT_ALLOCED_F){
@@ -946,7 +949,11 @@ int rval_get_int(struct run_act_ctx* h, struct sip_msg* msg,
break;
case RV_ACTION_ST:
if (rv->v.action) {
- *i=(run_actions_safe(h, rv->v.action, msg)>0);
+ if(unlikely(ksr_return_mode==1)) {
+ *i=run_actions_safe(h, rv->v.action, msg);
+ } else {
+ *i=(run_actions_safe(h, rv->v.action, msg)>0);
+ }
h->run_flags &= ~(RETURN_R_F|BREAK_R_F);
/* catch return & break in expr*/
} else