2
0
Эх сурвалжийг харах

- load_avp() returns false if no avp was loaded

Bogdan-Andrei Iancu 21 жил өмнө
parent
commit
32a19992f1
2 өөрчлөгдсөн 48 нэмэгдсэн , 44 устгасан
  1. 3 2
      action.c
  2. 45 42
      usr_avp.c

+ 3 - 2
action.c

@@ -667,11 +667,12 @@ int do_action(struct action* a, struct sip_msg* msg)
 				break;
 			}
 			/* load the attribute(s)*/
-			if ( load_avp( msg, (int)a->p1.number, a->p2.string,
-			(int)a->p3.number)!=0 ) {
+			if ( (ret=load_avp( msg, (int)a->p1.number, a->p2.string,
+			(int)a->p3.number))==-1 ) {
 				LOG(L_ERR,"ERROR:do_action: load avp failed\n");
 				ret=E_UNSPEC;
 			}
+			ret = (ret==0)?1/*success*/:E_UNSPEC/*notfound*/;
 			break;
 		default:
 			LOG(L_CRIT, "BUG: do_action: unknown type %d\n", a->type);

+ 45 - 42
usr_avp.c

@@ -226,7 +226,11 @@ inline static int validate_db_row(struct db_row *row, unsigned int *val_type,
 		memcpy( _p_, (_ss_).s, (_ss_).len);\
 		(_p_) += (_ss_).len;\
 	}while(0)
-
+/*
+ * Returns:   -1 : error
+ *             0 : sucess and avp(s) loaded
+ *             1 : sucess but no avp loaded
+ */
 int load_avp( struct sip_msg *msg, int uri_type, char *attr, int use_dom)
 {
 	db_res_t          *res;
@@ -239,10 +243,6 @@ int load_avp( struct sip_msg *msg, int uri_type, char *attr, int use_dom)
 	int               len;
 	char              *p;
 
-	/*
-	DBG("----load_avp:%d,%s,%d\n",uri_type,attr?attr:"NULL",use_dom);
-	*/
-
 	/* featch the user name [and domain] */
 	switch (uri_type) {
 		case 0: /* RURI */
@@ -291,44 +291,47 @@ int load_avp( struct sip_msg *msg, int uri_type, char *attr, int use_dom)
 		DBG("DEBUG:load_avp: no avp found for %.*s@%.*s <%s>\n",
 			uri.user.len,uri.user.s,(use_dom!=0)*uri.host.len,uri.host.s,
 			attr?attr:"NULL");
-	} else {
-		for( n=0 ; n<res->n ; n++) {
-			/* validate row */
-			if (validate_db_row( &res->rows[n] ,&val_type, &uint_val) < 0 )
-				continue;
-			/* what do we have here?! */
-			DBG("DEBUG:load_avp: found avp: <%s,%s,%d>\n",
-				res->rows[n].values[0].val.string_val,
-				res->rows[n].values[1].val.string_val,
-				res->rows[n].values[2].val.int_val);
-			/* build a new avp struct */
-			len = sizeof(struct usr_avp);
-			len += res->rows[n].values[0].val.str_val.len ;
-			if (val_type==AVP_TYPE_STR)
-				len += res->rows[n].values[1].val.str_val.len ;
-			avp = (struct usr_avp*)pkg_malloc( len );
-			if (avp==0) {
-				LOG(L_ERR,"ERROR:load_avp: no more pkg mem\n");
-				continue;
-			}
-			/* fill the structure in */
-			p = ((char*)avp) + sizeof(struct usr_avp);
-			avp->id = compute_ID( &res->rows[n].values[0].val.str_val );
-			avp->val_type = val_type;
-			/* attribute name */
-			copy_str( p, avp->attr, res->rows[n].values[0].val.str_val);
-			if (val_type==AVP_TYPE_INT) {
-				/* INT */
-				avp->val.uint_val = uint_val;
-			} else {
-				/* STRING */
-				copy_str( p, avp->val.str_val,
-					res->rows[n].values[1].val.str_val);
-			}
-			/* add avp to internal list */
-			avp->next = users_avps;
-			users_avps = avp;
+		db_free_query( avp_db_con, res);
+		/*no avp found*/
+		return 1;
+	}
+
+	for( n=0 ; n<res->n ; n++) {
+		/* validate row */
+		if (validate_db_row( &res->rows[n] ,&val_type, &uint_val) < 0 )
+			continue;
+		/* what do we have here?! */
+		DBG("DEBUG:load_avp: found avp: <%s,%s,%d>\n",
+			res->rows[n].values[0].val.string_val,
+			res->rows[n].values[1].val.string_val,
+		res->rows[n].values[2].val.int_val);
+		/* build a new avp struct */
+		len = sizeof(struct usr_avp);
+		len += res->rows[n].values[0].val.str_val.len ;
+		if (val_type==AVP_TYPE_STR)
+			len += res->rows[n].values[1].val.str_val.len ;
+		avp = (struct usr_avp*)pkg_malloc( len );
+		if (avp==0) {
+			LOG(L_ERR,"ERROR:load_avp: no more pkg mem\n");
+			continue;
+		}
+		/* fill the structure in */
+		p = ((char*)avp) + sizeof(struct usr_avp);
+		avp->id = compute_ID( &res->rows[n].values[0].val.str_val );
+		avp->val_type = val_type;
+		/* attribute name */
+		copy_str( p, avp->attr, res->rows[n].values[0].val.str_val);
+		if (val_type==AVP_TYPE_INT) {
+			/* INT */
+			avp->val.uint_val = uint_val;
+		} else {
+			/* STRING */
+			copy_str( p, avp->val.str_val,
+				res->rows[n].values[1].val.str_val);
 		}
+		/* add avp to internal list */
+		avp->next = users_avps;
+		users_avps = avp;
 	}
 
 	db_free_query( avp_db_con, res);