Skip to content

Commit

Permalink
set_debug() function replaced with $log_level
Browse files Browse the repository at this point in the history
The new script variables allows read and write operations. On write, it does exactly as the old set_debug() function (on writting the NULL value -> reset the log level)
  • Loading branch information
bogdan-iancu committed Feb 8, 2016
1 parent 46a26bf commit f174629
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 37 deletions.
8 changes: 0 additions & 8 deletions action.c
Expand Up @@ -682,14 +682,6 @@ int do_action(struct action* a, struct sip_msg* msg)
}
ret = (msg->len >= (unsigned int)a->elem[0].u.number) ? 1 : -1;
break;
case SET_DEBUG_T:
script_trace("core", "set_debug", msg, a->file, a->line) ;
if (a->elem[0].type==NUMBER_ST)
set_proc_log_level(a->elem[0].u.number);
else
reset_proc_log_level();
ret = 1;
break;
case SETFLAG_T:
script_trace("core", "setflag", msg, a->file, a->line) ;
ret = setflag( msg, a->elem[0].u.number );
Expand Down
2 changes: 0 additions & 2 deletions cfg.lex
Expand Up @@ -156,7 +156,6 @@ ROUTE_EVENT event_route
FORCE_RPORT "force_rport"|"add_rport"
FORCE_LOCAL_RPORT "force_local_rport"|"add_local_rport"
FORCE_TCP_ALIAS "force_tcp_alias"|"add_tcp_alias"
SETDEBUG "setdebug"
SETFLAG setflag
RESETFLAG resetflag
ISFLAGSET isflagset
Expand Down Expand Up @@ -426,7 +425,6 @@ IMPORTFILE "import_file"
<INITIAL>{SEND} { count(); yylval.strval=yytext; return SEND; }
<INITIAL>{LOG} { count(); yylval.strval=yytext; return LOG_TOK; }
<INITIAL>{ERROR} { count(); yylval.strval=yytext; return ERROR; }
<INITIAL>{SETDEBUG} { count(); yylval.strval=yytext; return SETDEBUG; }
<INITIAL>{SETFLAG} { count(); yylval.strval=yytext; return SETFLAG; }
<INITIAL>{RESETFLAG} { count(); yylval.strval=yytext; return RESETFLAG; }
<INITIAL>{ISFLAGSET} { count(); yylval.strval=yytext; return ISFLAGSET; }
Expand Down
6 changes: 0 additions & 6 deletions cfg.y
Expand Up @@ -271,7 +271,6 @@ static struct multi_str *tmp_mod;
%token USE_BLACKLIST
%token UNUSE_BLACKLIST
%token MAX_LEN
%token SETDEBUG
%token SETFLAG
%token RESETFLAG
%token ISFLAGSET
Expand Down Expand Up @@ -2091,11 +2090,6 @@ cmd: FORWARD LPAREN STRING RPAREN { mk_action2( $$, FORWARD_T,
| LOG_TOK error { $$=0; yyerror("missing '(' or ')' ?"); }
| LOG_TOK LPAREN error RPAREN { $$=0; yyerror("bad log"
"argument"); }
| SETDEBUG LPAREN snumber RPAREN {
mk_action2($$, SET_DEBUG_T, NUMBER_ST, 0, (void *)$3, 0 );
}
| SETDEBUG LPAREN RPAREN {mk_action2( $$, SET_DEBUG_T, 0, 0, 0, 0 ); }
| SETDEBUG error { $$=0; yyerror("missing '(' or ')'?"); }
| SETFLAG LPAREN NUMBER RPAREN {
mk_action2($$, SETFLAG_T, NUMBER_ST, 0, (void *)$3, 0 );
}
Expand Down
53 changes: 52 additions & 1 deletion pvar.c
@@ -1,5 +1,5 @@
/**
* Copyright (C) 2010-2014 OpenSIPS Solutions
* Copyright (C) 2010-2016 OpenSIPS Solutions
* Copyright (C) 2005-2009 Voice Sistem SRL
* Copyright (C) 2001-2003 FhG Fokus
*
Expand Down Expand Up @@ -3213,6 +3213,54 @@ int pv_get_cfg_file_name(struct sip_msg *msg, pv_param_t *param, pv_value_t *re
return 0;
}


int pv_set_log_level(struct sip_msg* msg, pv_param_t *param, int op,
pv_value_t *val)
{
if(param==NULL)
{
LM_ERR("bad parameters\n");
return -1;
}

if(val==NULL || (val->flags&(PV_VAL_NULL|PV_VAL_NONE))!=0) {
/* reset the value to default */
reset_proc_log_level();
} else {
if ((val->flags&PV_TYPE_INT)==0) {
LM_ERR("input for $log_level found not to be an interger\n");
return -1;
}
set_proc_log_level(val->ri);
}

return 0;
}

int pv_get_log_level(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
{
int l;

if (param==NULL) {
LM_CRIT("BUG - bad parameters\n");
return -1;
}

if(res == NULL) {
return -1;
}

res->ri = *log_level;
res->rs.s = int2str( (unsigned long)res->ri, &l);
res->rs.len = l;

res->flags = PV_VAL_STR|PV_VAL_INT|PV_TYPE_INT;

return 0;
}



/**
* the table with core pseudo-variables
*/
Expand Down Expand Up @@ -3365,6 +3413,9 @@ static pv_export_t _pv_names_table[] = {
{{"from.user", (sizeof("from.user")-1)}, /* */
PVT_FROM_USERNAME, pv_get_from_attr, 0,
0, 0, pv_init_iname, 2},
{{"log_level", (sizeof("log_level")-1)}, /* per process log level*/
PVT_LOG_LEVEL, pv_get_log_level, pv_set_log_level,
0, 0, 0, 0},
{{"mb", (sizeof("mb")-1)}, /* */
PVT_MSG_BUF, pv_get_msg_buf, 0,
0, 0, 0, 0},
Expand Down
2 changes: 1 addition & 1 deletion pvar.h
Expand Up @@ -108,7 +108,7 @@ enum _pv_type {
PVT_HDRCNT, PVT_AUTH_NONCE_COUNT, PVT_AUTH_QOP,
PVT_AUTH_ALGORITHM, PVT_AUTH_OPAQUE, PVT_AUTH_CNONCE,
PVT_RU_Q, PVT_ROUTE_PARAM, PVT_ROUTE_TYPE,
PVT_LINE_NUMBER, PVT_CFG_FILE_NAME,
PVT_LINE_NUMBER, PVT_CFG_FILE_NAME, PVT_LOG_LEVEL,
/* registered by json module */
PVT_JSON,

Expand Down
15 changes: 0 additions & 15 deletions route.c
Expand Up @@ -518,21 +518,6 @@ static int fix_actions(struct action* a)
t->elem[0].u.data=si;
t->elem[0].type=SOCKETINFO_ST;
break;
case SET_DEBUG_T:
if (t->elem[0].type==NOSUBTYPE)
break;
if (t->elem[0].type!=NUMBER_ST) {
LM_CRIT("BUG in setdebug() type %d\n",
t->elem[0].type );
ret=E_BUG;
goto error;
}
/* normalize the value */
if (t->elem[0].u.number>L_DBG)
t->elem[0].u.number = L_DBG;
else if (t->elem[0].u.number<L_ALERT)
t->elem[0].u.number = L_ALERT;
break;
case SETFLAG_T:
case RESETFLAG_T:
case ISFLAGSET_T:
Expand Down
3 changes: 0 additions & 3 deletions route_struct.c
Expand Up @@ -445,9 +445,6 @@ void print_action(struct action* t)
case LEN_GT_T:
LM_GEN1(L_DBG, "len_gt(");
break;
case SET_DEBUG_T:
LM_GEN1(L_DBG, "setdebug(");
break;
case SETFLAG_T:
LM_GEN1(L_DBG, "setflag(");
break;
Expand Down
2 changes: 1 addition & 1 deletion route_struct.h
Expand Up @@ -61,7 +61,7 @@ enum { METHOD_O=1, URI_O, FROM_URI_O, TO_URI_O, SRCIP_O, SRCPORT_O,

enum { FORWARD_T=1, SEND_T, ASSERT_T, DROP_T, LOG_T, ERROR_T, ROUTE_T, EXEC_T,
SET_HOST_T, SET_HOSTPORT_T, SET_USER_T, SET_USERPASS_T,
SET_PORT_T, SET_URI_T, IF_T, MODULE_T, AMODULE_T, SET_DEBUG_T,
SET_PORT_T, SET_URI_T, IF_T, MODULE_T, AMODULE_T,
SETFLAG_T, RESETFLAG_T, ISFLAGSET_T ,
SETSFLAG_T, RESETSFLAG_T, ISSFLAGSET_T ,
SETBFLAG_T, RESETBFLAG_T, ISBFLAGSET_T ,
Expand Down

0 comments on commit f174629

Please sign in to comment.