]> git.ozlabs.org Git - ppp.git/blobdiff - pppd/plugins/radius/radiusclient/lib/avpair.c
add rc_avpair_copy() and use it when sending user-specified av's. This
[ppp.git] / pppd / plugins / radius / radiusclient / lib / avpair.c
index a20e24cc7f9df917d515c490897875a80fd384bb..5f0644bb37ca6bea2a14fc15381ed80165d0ecee 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: avpair.c,v 1.1 2002/01/22 16:03:02 dfs Exp $
+ * $Id: avpair.c,v 1.3 2002/11/13 18:19:26 fcusack Exp $
  *
  * Copyright (C) 1995 Lars Fenneberg
  *
@@ -361,13 +361,41 @@ VALUE_PAIR *rc_avpair_get (VALUE_PAIR *vp, UINT4 attr)
        return (vp);
 }
 
+/*
+ * Function: rc_avpair_copy
+ *
+ * Purpose: Return a copy of the existing list "p" ala strdup().
+ *
+ */
+VALUE_PAIR *rc_avpair_copy(VALUE_PAIR *p)
+{
+       VALUE_PAIR *vp, *fp = NULL, *lp = NULL;
+
+       while (p) {
+               vp = malloc(sizeof(VALUE_PAIR));
+               if (!vp) {
+                   rc_log(LOG_CRIT, "rc_avpair_copy: out of memory");
+                   return NULL; /* leaks a little but so what */
+               }
+               *vp = *p;
+               if (!fp)
+                       fp = vp;
+               if (lp)
+                       lp->next = vp;
+               lp = vp;
+               p = p->next;
+       }
+
+       return fp;
+}
+
 /*
  * Function: rc_avpair_insert
  *
  * Purpose: Given the address of an existing list "a" and a pointer
- *         to an entry "p" in that list, add the value pair "b" to
+ *         to an entry "p" in that list, add the list "b" to
  *         the "a" list after the "p" entry.  If "p" is NULL, add
- *         the value pair "b" to the end of "a".
+ *         the list "b" to the end of "a".
  *
  */
 
@@ -376,18 +404,15 @@ void rc_avpair_insert (VALUE_PAIR **a, VALUE_PAIR *p, VALUE_PAIR *b)
        VALUE_PAIR     *this_node = NULL;
        VALUE_PAIR     *vp;
 
-       if (b->next != (VALUE_PAIR *) NULL)
-       {
-               rc_log(LOG_CRIT, "rc_avpair_insert: value pair (0x%p) next ptr. (0x%p) not NULL", b, b->next);
-               abort ();
-       }
-
        if (*a == (VALUE_PAIR *) NULL)
        {
                *a = b;
                return;
        }
 
+       if (!b)
+               return;
+
        vp = *a;
 
        if ( p == (VALUE_PAIR *) NULL) /* run to end of "a" list */
@@ -398,7 +423,7 @@ void rc_avpair_insert (VALUE_PAIR **a, VALUE_PAIR *p, VALUE_PAIR *b)
                        vp = vp->next;
                }
        }
-       else /* look for the "p" entry in the "a" list */
+       else /* look for the "p" entry in the "a" list (or run to end) */
        {
                this_node = *a;
                while (this_node != (VALUE_PAIR *) NULL)
@@ -411,9 +436,15 @@ void rc_avpair_insert (VALUE_PAIR **a, VALUE_PAIR *p, VALUE_PAIR *b)
                }
        }
 
-       b->next = this_node->next;
+       /* add "b" at this_node */
+       vp = this_node->next;
        this_node->next = b;
 
+       /* run to end of "b" and connect the rest of "a" */
+       while (b->next)
+               b = b->next;
+       b->next = vp;
+
        return;
 }
 
@@ -563,6 +594,7 @@ int rc_avpair_parse (char *buffer, VALUE_PAIR **first_pair)
                        strcpy (pair->name, attr->name);
                        pair->attribute = attr->value;
                        pair->type = attr->type;
+                       pair->vendorcode = attr->vendorcode;
 
                        switch (pair->type)
                        {