Added new method to get name of enum from values
authorAlan T. DeKok <aland@freeradius.org>
Fri, 23 Dec 2011 14:15:53 +0000 (09:15 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Fri, 23 Dec 2011 14:20:26 +0000 (09:20 -0500)
This is simpler than having duplicate code throughout the
source.

src/include/libradius.h
src/lib/dict.c

index b3fa8da..ea14111 100644 (file)
@@ -274,6 +274,7 @@ DICT_ATTR   *dict_attrbyvalue(unsigned int attr, unsigned int vendor);
 DICT_ATTR      *dict_attrbyname(const char *attr);
 DICT_VALUE     *dict_valbyattr(unsigned int attr, unsigned int vendor, int val);
 DICT_VALUE     *dict_valbyname(unsigned int attr, unsigned int vendor, const char *val);
+const char     *dict_valnamebyattr(unsigned int attr, unsigned int vendor, int value);
 int            dict_vendorbyname(const char *name);
 DICT_VENDOR    *dict_vendorbyvalue(int vendor);
 
index 71bdfed..bbd94d8 100644 (file)
@@ -2301,6 +2301,19 @@ DICT_VALUE *dict_valbyattr(unsigned int attr, unsigned int vendor, int value)
 }
 
 /*
+ *     Associate a value with an attribute and return it.
+ */
+const char *dict_valnamebyattr(unsigned int attr, unsigned int vendor, int value)
+{
+       DICT_VALUE *dv;
+
+       dv = dict_valbyattr(attr, vendor, value);
+       if (!dv) return "";
+
+       return dv->name;
+}
+
+/*
  *     Get a value by its name, keyed off of an attribute.
  */
 DICT_VALUE *dict_valbyname(unsigned int attr, unsigned int vendor, const char *name)