]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Add function to check if something is a value utf8 string
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Sun, 17 May 2015 22:47:18 +0000 (18:47 -0400)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Sun, 17 May 2015 22:56:07 +0000 (18:56 -0400)
src/include/libradius.h
src/lib/misc.c

index e28c9c7d4765659471ec73aca6315e28fa32874b..014c92aea08c9a9c0673926f1d0951b60c89ff03 100644 (file)
@@ -716,6 +716,7 @@ size_t              fr_bin2hex(char *hex, uint8_t const *bin, size_t inlen);
 size_t         fr_hex2bin(uint8_t *bin, size_t outlen, char const *hex, size_t inlen);
 uint32_t       fr_strtoul(char const *value, char **end);
 bool           is_whitespace(char const *value);
+bool           is_printable(void const *value, size_t len);
 bool           is_integer(char const *value);
 bool           is_zero(char const *value);
 
index b2892f9b3691942ad4c706572fd596a3036a5bbd..2af61a40ee4f31c353b4c2bf57a4cdb3fe40984e 100644 (file)
@@ -1120,6 +1120,30 @@ bool is_whitespace(char const *value)
        return true;
 }
 
+/** Check whether the string is made up of printable UTF8 chars
+ *
+ * @param value to check.
+ * @param len of value.
+ *
+ * @return
+ *     - true if the string is printable.
+ *     - false if the string contains non printable chars
+ */
+ bool is_printable(void const *value, size_t len)
+ {
+       uint8_t const *p = value;
+       int     clen;
+       size_t  i;
+
+       for (i = 0; i < len; i++) {
+               clen = fr_utf8_char(p);
+               if (clen == 0) return false;
+               i += (size_t)clen;
+               p += clen;
+       }
+       return true;
+ }
+
 /** Check whether the string is all numbers
  *
  * @return true if the entirety of the string is are numebrs, else false.