Prechádzať zdrojové kódy

- 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 19 rokov pred
rodič
commit
80d2811c92
4 zmenil súbory, kde vykonal 30 pridanie a 5 odobranie
  1. 1 1
      action.c
  2. 1 1
      parser/parse_fline.h
  3. 26 1
      route.c
  4. 2 2
      usr_avp.c

+ 1 - 1
action.c

@@ -860,7 +860,7 @@ int do_action(struct action* a, struct sip_msg* msg)
 
 			/* If the action is assign then remove the old avp value
 			 * before adding new ones */
-//			if ((unsigned char)a->type == ASSIGN_T) delete_avp(flags, name);
+/*			if ((unsigned char)a->type == ASSIGN_T) delete_avp(flags, name); */
 			if (add_avp(flags & ~AVP_INDEX_ALL, name, value) < 0) {
 				LOG(L_CRIT, "ERROR: Failed to assign value to attribute\n");
 				ret=E_UNSPEC;

+ 1 - 1
parser/parse_fline.h

@@ -44,7 +44,7 @@
 #define SIP_VERSION_LEN 7
 
 #define HTTP_VERSION "HTTP/1."
-#define HTTP_VERSION_LEN (sizeof(HTTP_VERSION - 1))
+#define HTTP_VERSION_LEN (sizeof(HTTP_VERSION)-1)
 
 #define CANCEL "CANCEL"
 #define ACK    "ACK"

+ 26 - 1
route.c

@@ -745,6 +745,8 @@ inline static int comp_avp(int op, avp_spec_t* spec, int rtype, union exp_op* r,
 {
 	avp_t* avp;
 	int_str val;
+	union exp_op num_val;
+	str tmp;
 
 	if (spec->type & AVP_INDEX_ALL) {
 		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,
 	if (avp->flags & AVP_VAL_STR) {
 		return comp_str(op, &val.s, rtype, r, msg);
 	} else {
-		return comp_num(op, val.n, rtype, r);
+		switch(rtype){
+			case NUMBER_ST:
+				return comp_num(op, val.n, rtype, r);
+			case STRING_ST:
+				tmp.s=r->string;
+				tmp.len=strlen(r->string);
+				if (str2int(&tmp, (unsigned int*)&num_val.intval)<0){
+					LOG(L_ERR, "ERROR: comp_avp: cannot convert string value"
+								" to int (%s)\n", ZSW(r->string));
+					return -1;
+				}
+				return comp_num(op, val.n, NUMBER_ST, &num_val);
+			case STR_ST:
+				if (str2int(&r->str, (unsigned int*)&num_val.intval)<0){
+					LOG(L_ERR, "ERROR: comp_avp: cannot convert str value"
+								" to int (%.*s)\n", r->str.len, ZSW(r->str.s));
+					return -1;
+				}
+				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);
+				return -1;
+		}
 	}
 }
 

+ 2 - 2
usr_avp.c

@@ -795,7 +795,7 @@ int parse_avp_ident( str *name, avp_ident_t* attr)
 
 	attr->index = 0;
 	DBG("Parsing '%.*s'\n", name->len, name->s);
-	if (name->len>=2 && name->s[1]==':') { // old fashion i: or s:
+	if (name->len>=2 && name->s[1]==':') { /* old fashion i: or s: */
 		WARN("i: and s: avp name syntax is deprecated!\n");
 		c = name->s[0];
 		name->s += 2;
@@ -874,7 +874,7 @@ int parse_avp_ident( str *name, avp_ident_t* attr)
 				goto error;
 			}
 			s.s=p+1;
-			s.len=name->len-(p-name->s)-2; // [ and ]
+			s.len=name->len-(p-name->s)-2; /* [ and ] */
 			if (s.len == 0) {
 				attr->flags |= AVP_INDEX_ALL;
 			} else {