Fixes from clang / scan-build
[freeradius.git] / src / lib / print.c
index 5fcdef9..2c14c22 100644 (file)
@@ -35,7 +35,7 @@ RCSID("$Id$")
  *     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;
 
@@ -127,9 +127,9 @@ static int utf8_char(uint8_t *str)
  *     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;
 
@@ -144,7 +144,7 @@ void librad_safeprint(char *in, size_t inlen, char *out, size_t outlen)
                 *      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 '\\':
@@ -176,7 +176,7 @@ void librad_safeprint(char *in, size_t inlen, char *out, size_t outlen)
                        continue;
                }
 
-               utf8 = utf8_char((uint8_t *)str);
+               utf8 = fr_utf8_char(str);
                if (!utf8) {
                        snprintf(out, outlen, "\\%03o", *str);
                        out  += 4;
@@ -217,13 +217,13 @@ int vp_prints_value(char * out, size_t outlen, VALUE_PAIR *vp, int delimitst)
                        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, "\"");
 
@@ -233,7 +233,7 @@ int vp_prints_value(char * out, size_t outlen, VALUE_PAIR *vp, int delimitst)
 
                        } else {
                                /* Non-tagged attribute: no delimiter */
-                               librad_safeprint(vp->vp_strvalue,
+                               fr_print_string(vp->vp_strvalue,
                                                 vp->length, buf, sizeof(buf));
                        }
                        a = buf;
@@ -241,7 +241,7 @@ int vp_prints_value(char * out, size_t outlen, VALUE_PAIR *vp, int delimitst)
                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 {
@@ -252,7 +252,7 @@ int vp_prints_value(char * out, size_t outlen, VALUE_PAIR *vp, int delimitst)
                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 {
@@ -272,6 +272,10 @@ int vp_prints_value(char * out, size_t outlen, VALUE_PAIR *vp, int delimitst)
                        }
                        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));
@@ -329,6 +333,15 @@ int vp_prints_value(char * out, size_t outlen, VALUE_PAIR *vp, int delimitst)
                        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;
@@ -372,14 +385,12 @@ static const char *vp_tokens[] = {
   "<`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;
                
@@ -420,10 +431,9 @@ int vp_prints(char *out, size_t outlen, VALUE_PAIR *vp)
        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;