unless the operator is DIFF_OP.
* 2006-02-06 added named route tables (andrei)
* 2008-04-14 (expr1 != expr2) is evaluated true if at least one of
* the expressions does not exist (Miklos)
* 2006-02-06 added named route tables (andrei)
* 2008-04-14 (expr1 != expr2) is evaluated true if at least one of
* the expressions does not exist (Miklos)
+ * 2008-04-23 errors are treated as false during expression evaluation
+ * unless the operator is DIFF_OP (Miklos)
else return (op == DIFF_OP);
} else if (rtype == SELECT_ST) {
ret = run_select(&v, r->select, msg);
else return (op == DIFF_OP);
} else if (rtype == SELECT_ST) {
ret = run_select(&v, r->select, msg);
- if (ret > 0) return (op == DIFF_OP); /* Not found */
- else if (ret < 0) goto error; /* Error */
+ if (ret != 0) return (op == DIFF_OP); /* Not found or error */
right = &v;
} else if ((op == MATCH_OP && rtype == RE_ST)) {
} else if (op != MATCH_OP && rtype == STRING_ST) {
right = &v;
} else if ((op == MATCH_OP && rtype == RE_ST)) {
} else if (op != MATCH_OP && rtype == STRING_ST) {
+ return (op == DIFF_OP) ? 1 : -1;
tmp.s=r->string;
tmp.len=strlen(r->string);
if (str2int(&tmp, &uval)<0){
tmp.s=r->string;
tmp.len=strlen(r->string);
if (str2int(&tmp, &uval)<0){
- LOG(L_ERR, "ERROR: comp_avp: cannot convert string value"
+ LOG(L_WARN, "WARNING: comp_avp: cannot convert string value"
" to int (%s)\n", ZSW(r->string));
" to int (%s)\n", ZSW(r->string));
}
num_val.numval=uval;
return comp_num(op, val.n, NUMBER_ST, &num_val);
case STR_ST:
if (str2int(&r->str, &uval)<0){
}
num_val.numval=uval;
return comp_num(op, val.n, NUMBER_ST, &num_val);
case STR_ST:
if (str2int(&r->str, &uval)<0){
- LOG(L_ERR, "ERROR: comp_avp: cannot convert str value"
+ LOG(L_WARN, "WARNING: comp_avp: cannot convert str value"
" to int (%.*s)\n", r->str.len, ZSW(r->str.s));
" to int (%.*s)\n", r->str.len, ZSW(r->str.s));
}
num_val.numval=uval;
return comp_num(op, val.n, NUMBER_ST, &num_val);
default:
LOG(L_CRIT, "BUG: comp_avp: invalid type for numeric avp "
"comparison (%d)\n", rtype);
}
num_val.numval=uval;
return comp_num(op, val.n, NUMBER_ST, &num_val);
default:
LOG(L_CRIT, "BUG: comp_avp: invalid type for numeric avp "
"comparison (%d)\n", rtype);
+error:
+ return (op == DIFF_OP) ? 1 : -1;
char empty_str=0;
ret = run_select(&val, sel, msg);
char empty_str=0;
ret = run_select(&val, sel, msg);
- if (ret < 0) return -1;
- if (ret > 0) return (op == DIFF_OP);
+ if (ret != 0) return (op == DIFF_OP);
switch(op) {
case NO_OP: return (val.len>0);
switch(op) {
case NO_OP: return (val.len>0);
case EQUAL_OP:
break;
case DIFF_OP:
case EQUAL_OP:
break;
case DIFF_OP:
break;
default:
LOG(L_CRIT, "BUG: check_self_op: invalid operator %d\n", op);
break;
default:
LOG(L_CRIT, "BUG: check_self_op: invalid operator %d\n", op);
- ret=comp_ip(EQUAL_OP, ip, rtype, r);
- if (ret>=0) ret=!ret;
+ ret=(comp_ip(EQUAL_OP, ip, rtype, r) > 0) ? 0 : 1;
break;
default:
goto error_op;
break;
default:
goto error_op;
+ return (e->op == DIFF_OP) ? 1 : -1;
-/* ret= 0/1 (true/false) , -1 on error */
+/* ret= 1/0 (true/false) , -1 on error (evaluates as false)*/
int eval_expr(struct run_act_ctx* h, struct expr* e, struct sip_msg* msg)
{
int ret;
int eval_expr(struct run_act_ctx* h, struct expr* e, struct sip_msg* msg)
{
int ret;
case LOGAND_OP:
ret=eval_expr(h, e->l.expr, msg);
/* if error or false stop evaluating the rest */
case LOGAND_OP:
ret=eval_expr(h, e->l.expr, msg);
/* if error or false stop evaluating the rest */
ret=eval_expr(h, e->r.expr, msg); /*ret1 is 1*/
break;
case LOGOR_OP:
ret=eval_expr(h, e->l.expr, msg);
ret=eval_expr(h, e->r.expr, msg); /*ret1 is 1*/
break;
case LOGOR_OP:
ret=eval_expr(h, e->l.expr, msg);
- /* if true or error stop evaluating the rest */
- if (ret!=0) break;
+ /* if true stop evaluating the rest */
+ if (ret > 0) break;
ret=eval_expr(h, e->r.expr, msg); /* ret1 is 0 */
break;
case NOT_OP:
ret=eval_expr(h, e->l.expr, msg);
ret=eval_expr(h, e->r.expr, msg); /* ret1 is 0 */
break;
case NOT_OP:
ret=eval_expr(h, e->l.expr, msg);
- if (ret<0) break;
- ret= ! ret;
break;
default:
LOG(L_CRIT, "BUG: eval_expr: unknown op %d\n", e->op);
break;
default:
LOG(L_CRIT, "BUG: eval_expr: unknown op %d\n", e->op);