Browse code

- numeric avp compared with string value fix: the value will be converted to int on-the-fly if possible (unfortunately we don't have enough information to do it on fixup).

- HTTP_VERSION_LEN macrodef. typo fix

Andrei Pelinescu-Onciul authored on 07/06/2006 21:55:25
Showing 4 changed files
... ...
@@ -860,7 +860,7 @@ int do_action(struct action* a, struct sip_msg* msg)
860 860
 
861 861
 			/* If the action is assign then remove the old avp value
862 862
 			 * before adding new ones */
863
-//			if ((unsigned char)a->type == ASSIGN_T) delete_avp(flags, name);
863
+/*			if ((unsigned char)a->type == ASSIGN_T) delete_avp(flags, name); */
864 864
 			if (add_avp(flags & ~AVP_INDEX_ALL, name, value) < 0) {
865 865
 				LOG(L_CRIT, "ERROR: Failed to assign value to attribute\n");
866 866
 				ret=E_UNSPEC;
... ...
@@ -44,7 +44,7 @@
44 44
 #define SIP_VERSION_LEN 7
45 45
 
46 46
 #define HTTP_VERSION "HTTP/1."
47
-#define HTTP_VERSION_LEN (sizeof(HTTP_VERSION - 1))
47
+#define HTTP_VERSION_LEN (sizeof(HTTP_VERSION)-1)
48 48
 
49 49
 #define CANCEL "CANCEL"
50 50
 #define ACK    "ACK"
... ...
@@ -745,6 +745,8 @@ inline static int comp_avp(int op, avp_spec_t* spec, int rtype, union exp_op* r,
745 745
 {
746 746
 	avp_t* avp;
747 747
 	int_str val;
748
+	union exp_op num_val;
749
+	str tmp;
748 750
 
749 751
 	if (spec->type & AVP_INDEX_ALL) {
750 752
 		avp = search_first_avp(spec->type & ~AVP_INDEX_ALL, spec->name, NULL, NULL);
... ...
@@ -774,7 +776,30 @@ inline static int comp_avp(int op, avp_spec_t* spec, int rtype, union exp_op* r,
774 774
 	if (avp->flags & AVP_VAL_STR) {
775 775
 		return comp_str(op, &val.s, rtype, r, msg);
776 776
 	} else {
777
-		return comp_num(op, val.n, rtype, r);
777
+		switch(rtype){
778
+			case NUMBER_ST:
779
+				return comp_num(op, val.n, rtype, r);
780
+			case STRING_ST:
781
+				tmp.s=r->string;
782
+				tmp.len=strlen(r->string);
783
+				if (str2int(&tmp, (unsigned int*)&num_val.intval)<0){
784
+					LOG(L_ERR, "ERROR: comp_avp: cannot convert string value"
785
+								" to int (%s)\n", ZSW(r->string));
786
+					return -1;
787
+				}
788
+				return comp_num(op, val.n, NUMBER_ST, &num_val);
789
+			case STR_ST:
790
+				if (str2int(&r->str, (unsigned int*)&num_val.intval)<0){
791
+					LOG(L_ERR, "ERROR: comp_avp: cannot convert str value"
792
+								" to int (%.*s)\n", r->str.len, ZSW(r->str.s));
793
+					return -1;
794
+				}
795
+				return comp_num(op, val.n, NUMBER_ST, &num_val);
796
+			default:
797
+				LOG(L_CRIT, "BUG: comp_avp: invalid type for numeric avp "
798
+							"comparison (%d)\n", rtype);
799
+				return -1;
800
+		}
778 801
 	}
779 802
 }
780 803
 
... ...
@@ -795,7 +795,7 @@ int parse_avp_ident( str *name, avp_ident_t* attr)
795 795
 
796 796
 	attr->index = 0;
797 797
 	DBG("Parsing '%.*s'\n", name->len, name->s);
798
-	if (name->len>=2 && name->s[1]==':') { // old fashion i: or s:
798
+	if (name->len>=2 && name->s[1]==':') { /* old fashion i: or s: */
799 799
 		WARN("i: and s: avp name syntax is deprecated!\n");
800 800
 		c = name->s[0];
801 801
 		name->s += 2;
... ...
@@ -874,7 +874,7 @@ int parse_avp_ident( str *name, avp_ident_t* attr)
874 874
 				goto error;
875 875
 			}
876 876
 			s.s=p+1;
877
-			s.len=name->len-(p-name->s)-2; // [ and ]
877
+			s.len=name->len-(p-name->s)-2; /* [ and ] */
878 878
 			if (s.len == 0) {
879 879
 				attr->flags |= AVP_INDEX_ALL;
880 880
 			} else {