Browse code

core: do not repeat key names on xavp_get_list_key_names function result

Victor Seva authored on 12/06/2013 13:58:29
Showing 1 changed files
... ...
@@ -546,15 +546,20 @@ void xavp_print_list(sr_xavp_t **head)
546 546
  * $xavp(test[0]=>two) = "2"
547 547
  * $xavp(test[0]=>three) = 3
548 548
  * $xavp(test[0]=>four) = $xavp(whatever)
549
+ * $xavp(test[0]=>two) = "other 2"
549 550
  *
550 551
  * xavp_get_list_keys_names(test[0]) returns
551 552
  * {"one", "two", "three", "four"}
553
+ *
554
+ * free the struct str_list afterwards
555
+ * but do *NO* free the strings inside
552 556
  */
553 557
 struct str_list *xavp_get_list_key_names(sr_xavp_t *xavp)
554 558
 {
555 559
 	sr_xavp_t *avp = NULL;
556 560
 	struct str_list *result = NULL;
557 561
 	struct str_list *r = NULL;
562
+	struct str_list *f = NULL;
558 563
 	int total = 0;
559 564
 
560 565
 	if(xavp==NULL){
... ...
@@ -585,14 +590,27 @@ struct str_list *xavp_get_list_key_names(sr_xavp_t *xavp)
585 585
 
586 586
 	while(avp)
587 587
 	{
588
-		r = append_str_list(avp->name.s, avp->name.len, &r, &total);
589
-		if(r==NULL){
590
-			while(result){
591
-				r = result;
592
-				result = result->next;
593
-				pkg_free(r);
588
+		f = result;
589
+		while(f)
590
+		{
591
+			if((avp->name.len==f->s.len)&&
592
+				(strncmp(avp->name.s, f->s.s, f->s.len)==0))
593
+			{
594
+				break; /* name already on list */
595
+			}
596
+			f = f->next;
597
+		}
598
+		if (f==NULL)
599
+		{
600
+			r = append_str_list(avp->name.s, avp->name.len, &r, &total);
601
+			if(r==NULL){
602
+				while(result){
603
+					r = result;
604
+					result = result->next;
605
+					pkg_free(r);
606
+				}
607
+				return 0;
594 608
 			}
595
-			return 0;
596 609
 		}
597 610
 		avp = avp->next;
598 611
 	}