From e0bbfbff4cfe35930f987be7dd9d72ffcf652c4a Mon Sep 17 00:00:00 2001 From: Arran Cudbard-Bell Date: Sun, 17 May 2015 18:47:18 -0400 Subject: [PATCH] Add function to check if something is a value utf8 string --- src/include/libradius.h | 1 + src/lib/misc.c | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/include/libradius.h b/src/include/libradius.h index e28c9c7d476..014c92aea08 100644 --- a/src/include/libradius.h +++ b/src/include/libradius.h @@ -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); diff --git a/src/lib/misc.c b/src/lib/misc.c index b2892f9b369..2af61a40ee4 100644 --- a/src/lib/misc.c +++ b/src/lib/misc.c @@ -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. -- 2.47.3