]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
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:15:53 +0000 (09:15 -0500)
This is simpler than having duplicate code throughout the
source.

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

index b81205c63c8291de5bf2a453d4b4172192ea0c24..e7d183796584f14787aa50cdcf97b844d2874a96 100644 (file)
@@ -262,6 +262,7 @@ DICT_ATTR   *dict_attrbyvalue(unsigned int attr);
 DICT_ATTR      *dict_attrbyname(const char *attr);
 DICT_VALUE     *dict_valbyattr(unsigned int attr, int val);
 DICT_VALUE     *dict_valbyname(unsigned int attr, const char *val);
+const char     *dict_valnamebyattr(unsigned int attr, int value);
 int            dict_vendorbyname(const char *name);
 DICT_VENDOR    *dict_vendorbyvalue(int vendor);
 
index d61efd084d09f930d6d67a7526aafab5edb909b7..439f80ff9a9b2f88d0f20b5e7ae270b9ef58d0ee 100644 (file)
@@ -1838,6 +1838,34 @@ DICT_VALUE *dict_valbyattr(unsigned int attr, int value)
        return fr_hash_table_finddata(values_byvalue, &dval);
 }
 
+/*
+ *     Associate a value with an attribute and return it.
+ */
+const char *dict_valnamebyattr(unsigned int attr, int value)
+{
+       DICT_VALUE dval, *dv;
+
+       /*
+        *      First, look up aliases.
+        */
+       dval.attr = attr;
+       dval.name[0] = '\0';
+
+       /*
+        *      Look up the attribute alias target, and use
+        *      the correct attribute number if found.
+        */
+       dv = fr_hash_table_finddata(values_byname, &dval);
+       if (dv) dval.attr = dv->value;
+
+       dval.value = value;
+
+       dv = fr_hash_table_finddata(values_byvalue, &dval);
+       if (!dv) return "";
+
+       return dv->name;
+}
+
 /*
  *     Get a value by its name, keyed off of an attribute.
  */