diff options
author | Luke Howard <lukeh@padl.com> | 2011-11-14 18:54:44 +1100 |
---|---|---|
committer | Luke Howard <lukeh@padl.com> | 2011-11-14 18:54:44 +1100 |
commit | d9ae6534eed05639403584b7b2733ec36c08f1a4 (patch) | |
tree | 7ad5914e36f7d12db73b06973dbd2ee3b7b872e4 /lib/avp.c | |
parent | f780ff204e39420aabf94a7fab4e2c37790b658f (diff) |
add rs_attr_display_name/rs_attr_parse_name
Diffstat (limited to 'lib/avp.c')
-rw-r--r-- | lib/avp.c | 74 |
1 files changed, 74 insertions, 0 deletions
@@ -447,6 +447,79 @@ rs_attr_find (const char *name, return RSE_OK; } +int +rs_attr_display_name (unsigned int attr, + unsigned int vendor, + char *buffer, + size_t bufsize, + int canonical) +{ + const DICT_ATTR *da = NULL; + DICT_ATTR da2; + int err; + + if (!canonical) { + da = nr_dict_attr_byvalue (attr, vendor); + } + if (da == NULL) { + err = nr_dict_attr_2struct(&da2, attr, vendor, + buffer, bufsize); + if (err < 0) + return -err; + } else { + snprintf(buffer, bufsize, "%s", da->name); + } + + return RSE_OK; +} + +int +rs_attr_parse_name (const char *name, + unsigned int *attr, + unsigned int *vendor) +{ + const DICT_ATTR *da; + + if (strncmp(name, "Attr-", 5) == 0) { + char *s = (char *)&name[5]; + unsigned int tmp; + + tmp = strtoul(s, &s, 10); + if (*s == '.') { + s++; + + switch (tmp) { + case PW_VENDOR_SPECIFIC: + *vendor = strtoul(s, &s, 10); + if (*s != '.') + return RSE_ATTR_BAD_NAME; + + s++; + + *attr = strtoul(s, &s, 10); + if (*s != '\0') + return RSE_ATTR_BAD_NAME; + + break; + default: + return RSE_ATTR_BAD_NAME; + } + } else { + *attr = tmp; + *vendor = 0; + } + } else { + da = nr_dict_attr_byname (name); + if (da == NULL) + return RSE_ATTR_UNKNOWN; + + *attr = da->attr; + *vendor = da->vendor; + } + + return RSE_OK; +} + size_t rs_avp_display_value (rs_const_avp *vp, char *buffer, @@ -454,3 +527,4 @@ rs_avp_display_value (rs_const_avp *vp, { return nr_vp_snprintf_value (buffer, buflen, vp); } + |