* Note that we don't care about the length of the input string,
* because '\0' is an invalid UTF-8 character.
*/
-static int utf8_char(uint8_t *str)
+int fr_utf8_char(const uint8_t *str)
{
if (*str < 0x20) return 0;
* has to be larger than the input string by at least 5 bytes.
* If not, the output is silently truncated...
*/
-void librad_safeprint(char *in, size_t inlen, char *out, size_t outlen)
+void fr_print_string(const char *in, size_t inlen, char *out, size_t outlen)
{
- uint8_t *str = (uint8_t *)in;
+ const uint8_t *str = (const uint8_t *) in;
int sp = 0;
int utf8 = 0;
* Some clients send strings with an off-by-one
* length (confused with strings in C).
*/
- if ((inlen == 0) && (*str == 0)) break;
+ if ((inlen == 1) && (*str == 0)) break;
switch (*str) {
case '\\':
continue;
}
- utf8 = utf8_char((uint8_t *)str);
+ utf8 = fr_utf8_char(str);
if (!utf8) {
snprintf(out, outlen, "\\%03o", *str);
out += 4;
if ((delimitst == 1) && vp->flags.has_tag) {
/* Tagged attribute: print delimter and ignore tag */
buf[0] = '"';
- librad_safeprint(vp->vp_strvalue,
+ fr_print_string(vp->vp_strvalue,
vp->length, buf + 1, sizeof(buf) - 2);
strcat(buf, "\"");
} else if (delimitst == 1) {
/* Non-tagged attribute: print delimter */
buf[0] = '"';
- librad_safeprint(vp->vp_strvalue,
+ fr_print_string(vp->vp_strvalue,
vp->length, buf + 1, sizeof(buf) - 2);
strcat(buf, "\"");
} else {
/* Non-tagged attribute: no delimiter */
- librad_safeprint(vp->vp_strvalue,
+ fr_print_string(vp->vp_strvalue,
vp->length, buf, sizeof(buf));
}
a = buf;
case PW_TYPE_INTEGER:
if ( vp->flags.has_tag ) {
/* Attribute value has a tag, need to ignore it */
- if ((v = dict_valbyattr(vp->attribute, (vp->vp_integer & 0xffffff)))
+ if ((v = dict_valbyattr(vp->attribute, vp->vendor, (vp->vp_integer & 0xffffff)))
!= NULL)
a = v->name;
else {
case PW_TYPE_BYTE:
case PW_TYPE_SHORT:
/* Normal, non-tagged attribute */
- if ((v = dict_valbyattr(vp->attribute, vp->vp_integer))
+ if ((v = dict_valbyattr(vp->attribute, vp->vendor, vp->vp_integer))
!= NULL)
a = v->name;
else {
}
if (len > 0) a = buf;
break;
+ case PW_TYPE_SIGNED: /* Damned code for 1 WiMAX attribute */
+ snprintf(buf, sizeof(buf), "%d", vp->vp_signed);
+ a = buf;
+ break;
case PW_TYPE_IPADDR:
a = inet_ntop(AF_INET, &(vp->vp_ipaddr),
buf, sizeof(buf));
a = buf;
break;
+ case PW_TYPE_TLV:
+ if (outlen <= (2 * (vp->length + 1))) return 0;
+
+ strcpy(buf, "0x");
+
+ fr_bin2hex(vp->vp_tlv, buf + 2, vp->length);
+ a = buf;
+ break;
+
default:
a = "UNKNOWN-TYPE";
break;
"<`STRING`>"
};
-const char *vp_print_name(char *buffer, size_t bufsize, int attr)
+const char *vp_print_name(char *buffer, size_t bufsize, int attr, int vendor)
{
- int vendor;
size_t len = 0;
if (!buffer) return NULL;
- vendor = VENDOR(attr);
if (vendor) {
DICT_VENDOR *v;
if (!vp) return 0;
name = vp->name;
- len = 0;
if (!name || !*name) {
- if (!vp_print_name(namebuf, sizeof(namebuf), vp->attribute)) {
+ if (!vp_print_name(namebuf, sizeof(namebuf), vp->attribute, vp->attribute)) {
return 0;
}
name = namebuf;