[sr-dev] git:master: core: do not repeat key names on xavp_get_list_key_names function result

Victor Seva linuxmaniac at torreviejawireless.org
Wed Jun 12 15:59:49 CEST 2013


Module: sip-router
Branch: master
Commit: 519fe88fc41cae4674ce4bc943b84eb522af654b
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=519fe88fc41cae4674ce4bc943b84eb522af654b

Author: Victor Seva <linuxmaniac at torreviejawireless.org>
Committer: Victor Seva <linuxmaniac at torreviejawireless.org>
Date:   Wed Jun 12 15:58:29 2013 +0200

core: do not repeat key names on xavp_get_list_key_names function result

---

 xavp.c |   32 +++++++++++++++++++++++++-------
 1 files changed, 25 insertions(+), 7 deletions(-)

diff --git a/xavp.c b/xavp.c
index adce5d1..ceb405d 100644
--- a/xavp.c
+++ b/xavp.c
@@ -546,15 +546,20 @@ void xavp_print_list(sr_xavp_t **head)
  * $xavp(test[0]=>two) = "2"
  * $xavp(test[0]=>three) = 3
  * $xavp(test[0]=>four) = $xavp(whatever)
+ * $xavp(test[0]=>two) = "other 2"
  *
  * xavp_get_list_keys_names(test[0]) returns
  * {"one", "two", "three", "four"}
+ *
+ * free the struct str_list afterwards
+ * but do *NO* free the strings inside
  */
 struct str_list *xavp_get_list_key_names(sr_xavp_t *xavp)
 {
 	sr_xavp_t *avp = NULL;
 	struct str_list *result = NULL;
 	struct str_list *r = NULL;
+	struct str_list *f = NULL;
 	int total = 0;
 
 	if(xavp==NULL){
@@ -585,14 +590,27 @@ struct str_list *xavp_get_list_key_names(sr_xavp_t *xavp)
 
 	while(avp)
 	{
-		r = append_str_list(avp->name.s, avp->name.len, &r, &total);
-		if(r==NULL){
-			while(result){
-				r = result;
-				result = result->next;
-				pkg_free(r);
+		f = result;
+		while(f)
+		{
+			if((avp->name.len==f->s.len)&&
+				(strncmp(avp->name.s, f->s.s, f->s.len)==0))
+			{
+				break; /* name already on list */
+			}
+			f = f->next;
+		}
+		if (f==NULL)
+		{
+			r = append_str_list(avp->name.s, avp->name.len, &r, &total);
+			if(r==NULL){
+				while(result){
+					r = result;
+					result = result->next;
+					pkg_free(r);
+				}
+				return 0;
 			}
-			return 0;
 		}
 		avp = avp->next;
 	}




More information about the sr-dev mailing list