Jelajahi Sumber

- more flexible - the values from db_query response can be STRING and STR

Bogdan-Andrei Iancu 21 tahun lalu
induk
melakukan
fd4e86ccba
1 mengubah file dengan 12 tambahan dan 7 penghapusan
  1. 12 7
      usr_avp.c

+ 12 - 7
usr_avp.c

@@ -185,8 +185,9 @@ inline static int validate_db_row(struct db_row *row, unsigned int *val_type,
 		return -1;
 	}
 	/* check the value types */
-	if (row->values[0].type!=DB_STRING || row->values[1].type!=DB_STRING ||
-	row->values[2].type!=DB_INT ) {
+	if ( (row->values[0].type!=DB_STRING && row->values[0].type!=DB_STR)
+	||  (row->values[1].type!=DB_STRING && row->values[1].type!=DB_STR)
+	|| row->values[2].type!=DB_INT ) {
 		LOG(L_ERR,"ERROR:avp:validat_db_row: bad DB types in response\n");
 		return -1;
 	}
@@ -197,11 +198,15 @@ inline static int validate_db_row(struct db_row *row, unsigned int *val_type,
 			*val_type);
 		return -1;
 	}
-	/* convert from DB_STRING to DB_STR */
-	row->values[0].val.str_val.s =  (char*)row->values[0].val.string_val;
-	row->values[0].val.str_val.len = strlen(row->values[0].val.str_val.s);
-	row->values[1].val.str_val.s =  (char*)row->values[1].val.string_val;
-	row->values[1].val.str_val.len = strlen(row->values[1].val.str_val.s);
+	/* convert from DB_STRING to DB_STR if necesary */
+	if (row->values[0].type==DB_STRING) {
+		row->values[0].val.str_val.s =  (char*)row->values[0].val.string_val;
+		row->values[0].val.str_val.len = strlen(row->values[0].val.str_val.s);
+	}
+	if (row->values[1].type==DB_STRING) {
+		row->values[1].val.str_val.s =  (char*)row->values[1].val.string_val;
+		row->values[1].val.str_val.len = strlen(row->values[1].val.str_val.s);
+	}
 	/* if type is INT decode the value */
 	if ( *val_type==AVP_TYPE_INT &&
 	str2int( &row->values[1].val.str_val, uint_val)==-1 ) {