New radius_paircreate() function that takes a REQUEST* and a
authoraland <aland>
Fri, 20 Apr 2007 14:30:11 +0000 (14:30 +0000)
committeraland <aland>
Fri, 20 Apr 2007 14:30:11 +0000 (14:30 +0000)
VALUE_PAIR**, along with the attr & type of paircreate().

It creates the pair (or exits if it can't, because it's OOM).
then adds the pair to the VP**.

This ends up removing a fair amount of code in the modules &&
server core, that did:

vp = pairmake()
if (!vp) {
oom
...
}

pairadd()

src/include/radiusd.h
src/main/valuepair.c

index cb340a0..56f8148 100644 (file)
@@ -419,6 +419,8 @@ int radius_compare_vps(REQUEST *request, VALUE_PAIR *check, VALUE_PAIR *vp);
 int radius_callback_compare(REQUEST *req, VALUE_PAIR *request,
                            VALUE_PAIR *check, VALUE_PAIR *check_pairs,
                            VALUE_PAIR **reply_pairs);
+VALUE_PAIR     *radius_paircreate(REQUEST *request, VALUE_PAIR **vps,
+                                 int attribute, int type);
 
 /* xlat.c */
 typedef int (*RADIUS_ESCAPE_STRING)(char *out, int outlen, const char *in);
index 982400e..a233147 100644 (file)
@@ -26,6 +26,7 @@
 RCSID("$Id$")
 
 #include <freeradius-devel/radiusd.h>
+#include <freeradius-devel/rad_assert.h>
 
 #ifdef HAVE_REGEX_H
 #      include <regex.h>
@@ -641,3 +642,28 @@ void pairxlatmove(REQUEST *req, VALUE_PAIR **to, VALUE_PAIR **from)
                }
        } /* loop over the 'from' list */
 }
+
+/*
+ *     Create a pair, and add it to a particular list of VPs
+ *
+ *     Note that this function ALWAYS returns.  If we're OOM, then
+ *     it causes the server to exit!
+ */
+VALUE_PAIR *radius_paircreate(REQUEST *request, VALUE_PAIR **vps,
+                             int attribute, int type)
+{
+       VALUE_PAIR *vp;
+
+       request = request;      /* -Wunused */
+
+       vp = paircreate(attribute, type);
+       if (!vp) {
+               radlog(L_ERR, "No memory!");
+               rad_assert("No memory" == NULL);
+               _exit(1);
+       }
+
+       pairadd(vps, vp);
+
+       return vp;
+}