#include "libradius.h"
#include "missing.h"
+/*
+ * There are very few vendors, and they're looked up only when we
+ * read the dictionaries. So it's OK to have a singly linked
+ * list here.
+ */
static DICT_VENDOR *dictionary_vendors = NULL;
static rbtree_t *attributes_byname = NULL;
return -1;
}
- if (strlen(name) > (sizeof(vval->vendorname) -1)) {
+ if (strlen(name) > (sizeof(vval->name) -1)) {
librad_log("dict_addvendor: vendor name too long");
return -1;
}
librad_log("dict_addvendor: out of memory");
return -1;
}
- strcpy(vval->vendorname, name);
+ strcpy(vval->name, name);
vval->vendorpec = value;
/* Insert at front. */
/*
* Process the ATTRIBUTE command
*/
-static int process_attribute(const char* fn, const int line, const int block_vendor, const char* data) {
+static int process_attribute(const char* fn, const int line,
+ const int block_vendor, const char* data)
+{
int vendor;
char namestr[256];
char valstr[256];
s += 5;
}
- vendor = dict_vendorname(s);
+ vendor = dict_vendorbyname(s);
if (!vendor) {
librad_log( "dict_init: %s[%d]: unknown vendor %s",
fn, line, optstr);
/*
* Process the VALUE command
*/
-static int process_value(const char* fn, const int line, const char* data) {
+static int process_value(const char* fn, const int line, const char* data)
+{
char namestr[256];
char valstr[256];
char attrstr[256];
/*
* Process the VENDOR command
*/
-static int process_vendor(const char* fn, const int line, const char* data) {
+static int process_vendor(const char* fn, const int line, const char* data)
+{
char valstr[256];
char attrstr[256];
int value;
/*
* Initialize the dictionary.
*/
-static int my_dict_init(const char *dir, const char *fn, const char *src_file, int src_line)
+static int my_dict_init(const char *dir, const char *fn,
+ const char *src_file, int src_line)
{
FILE *fp;
char dirtmp[256];
return -1;
}
- vendor = dict_vendorname(optstr);
+ vendor = dict_vendorbyname(optstr);
if (!vendor) {
librad_log(
"dict_init: %s[%d]: unknown vendor %s",
return -1;
}
- vendor = dict_vendorname(optstr);
+ vendor = dict_vendorbyname(optstr);
if (!vendor) {
librad_log(
"dict_init: %s[%d]: unknown vendor %s",
/*
* Get the vendor PEC based on the vendor name
*/
-int dict_vendorname(const char *name)
+int dict_vendorbyname(const char *name)
{
DICT_VENDOR *v;
* Find the vendor, if any.
*/
for (v = dictionary_vendors; v; v = v->next) {
- if (strcasecmp(name, v->vendorname) == 0) {
+ if (strcasecmp(name, v->name) == 0) {
return v->vendorpec;
}
}
return 0;
}
+
+/*
+ * Return the vendor struct based on the PEC.
+ */
+DICT_VENDOR *dict_vendorbyvalue(int vendor)
+{
+ DICT_VENDOR *v;
+
+ /*
+ * Find the vendor, if any.
+ */
+ for (v = dictionary_vendors; v; v = v->next) {
+ if (vendor == v->vendorpec) {
+ return v;
+ }
+ }
+
+ return NULL;
+
+}
} else if (VENDOR(attr) == 0) {
sprintf(vp->name, "Attr-%u", attr);
} else {
- sprintf(vp->name, "Vendor-%u-Attr-%u",
- VENDOR(attr), attr & 0xffff);
+ DICT_VENDOR *v;
+
+ v = dict_vendorbyvalue(VENDOR(attr));
+ if (v) {
+ sprintf(vp->name, "%s-Attr-%u",
+ v->name, attr & 0xffff);
+ } else {
+ sprintf(vp->name, "Vendor-%u-Attr-%u",
+ VENDOR(attr), attr & 0xffff);
+ }
}
switch (vp->type) {
case PW_TYPE_INTEGER:
memcpy(buffer, attribute, p - attribute);
buffer[p - attribute] = '\0';
- vendor = dict_vendorname(buffer);
+ vendor = dict_vendorbyname(buffer);
if (vendor == 0) goto error;
p += 6;