Browse code

(expr1 != expr2) is evaluated true if at least one of the expressions does not exist, which can be a missing AVP or select. (expr1 != expr2) and !(expr1 == expr2) mean the same from now in this case.

Miklos Tirpak authored on 13/04/2008 05:12:55
Showing 1 changed files
... ...
@@ -44,6 +44,8 @@
44 44
  *  2005-12-19  select framework (mma)
45 45
  *  2006-01-30  removed rec. protection from eval_expr (andrei)
46 46
  *  2006-02-06  added named route tables (andrei)
47
+ *  2008-04-14  (expr1 != expr2) is evaluated true if at least one of
48
+ *		the expressions does not exist (Miklos)
47 49
  */
48 50
 
49 51
 
... ...
@@ -575,7 +577,7 @@ inline static int comp_num(int op, long left, int rtype, union exp_op* r)
575 575
 	if (rtype == AVP_ST) {
576 576
 		avp = search_avp_by_index(r->attr->type, r->attr->name, &val, r->attr->index);
577 577
 		if (avp && !(avp->flags & AVP_VAL_STR)) right = val.n;
578
-		else return 0; /* Always fail */
578
+		else return (op == DIFF_OP);
579 579
 	} else if (rtype == NUMBER_ST) {
580 580
 		right = r->numval;
581 581
 	} else {
... ...
@@ -615,10 +617,10 @@ inline static int comp_str(int op, str* left, int rtype, union exp_op* r, struct
615 615
 	if (rtype == AVP_ST) {
616 616
 		avp = search_avp_by_index(r->attr->type, r->attr->name, &val, r->attr->index);
617 617
 		if (avp && (avp->flags & AVP_VAL_STR)) right = &val.s;
618
-		else return 0;
618
+		else return (op == DIFF_OP);
619 619
 	} else if (rtype == SELECT_ST) {
620 620
 		ret = run_select(&v, r->select, msg);
621
-		if (ret > 0) return 0;       /* Not found */
621
+		if (ret > 0) return (op == DIFF_OP); /* Not found */
622 622
 		else if (ret < 0) goto error; /* Error */
623 623
 		right = &v;
624 624
 	} else if ((op == MATCH_OP && rtype == RE_ST)) {
... ...
@@ -713,7 +715,7 @@ inline static int comp_string(int op, char* left, int rtype, union exp_op* r)
713 713
 	if (rtype == AVP_ST) {
714 714
 		avp = search_avp_by_index(r->attr->type, r->attr->name, &val, r->attr->index);
715 715
 		if (avp && (avp->flags & AVP_VAL_STR)) right = val.s.s;
716
-		else return 0; /* Always fail */
716
+		else return (op == DIFF_OP);
717 717
 	} else if (rtype == STRING_ST) {
718 718
 		right = r->str.s;
719 719
 	}
... ...
@@ -767,7 +769,7 @@ inline static int comp_avp(int op, avp_spec_t* spec, int rtype, union exp_op* r,
767 767
 		return (avp!=0);
768 768
 	}
769 769
 	avp = search_avp_by_index(spec->type, spec->name, &val, spec->index);
770
-	if (!avp) return 0;
770
+	if (!avp) return (op == DIFF_OP);
771 771
 
772 772
 	switch(op) {
773 773
 	case NO_OP:
... ...
@@ -830,7 +832,7 @@ inline static int comp_select(int op, select_t* sel, int rtype, union exp_op* r,
830 830
 
831 831
 	ret = run_select(&val, sel, msg);
832 832
 	if (ret < 0) return -1;
833
-	if (ret > 0) return 0;
833
+	if (ret > 0) return (op == DIFF_OP);
834 834
 
835 835
 	switch(op) {
836 836
 	case NO_OP: return (val.len>0);