Added ability to disable UTF8 validation for character strings.

This commit is contained in:
Steve Karg
2020-01-04 12:15:44 -06:00
parent f721350b3f
commit 6c52e5ce2e
+26 -8
View File
@@ -44,6 +44,9 @@
#endif #endif
/** @file bacstr.c Manipulate Bit/Char/Octet Strings */ /** @file bacstr.c Manipulate Bit/Char/Octet Strings */
#ifndef BACNET_STRING_UTF8_VALIDATION
#define BACNET_STRING_UTF8_VALIDATION 1
#endif
void bitstring_init(BACNET_BIT_STRING *bit_string) void bitstring_init(BACNET_BIT_STRING *bit_string)
{ {
@@ -527,6 +530,7 @@ bool characterstring_printable(BACNET_CHARACTER_STRING *char_string)
return status; return status;
} }
#if BACNET_STRING_UTF8_VALIDATION
/* Basic UTF-8 manipulation routines /* Basic UTF-8 manipulation routines
by Jeff Bezanson by Jeff Bezanson
placed in the public domain Fall 2005 */ placed in the public domain Fall 2005 */
@@ -628,6 +632,14 @@ bool utf8_isvalid(const char *str, size_t length)
return true; return true;
} }
#else
bool utf8_isvalid(const char *str, size_t length)
{
(void)str;
(void)length;
return true;
}
#endif
bool characterstring_valid(BACNET_CHARACTER_STRING *char_string) bool characterstring_valid(BACNET_CHARACTER_STRING *char_string)
{ {
@@ -855,7 +867,7 @@ bool octetstring_value_same(
#include <time.h> #include <time.h>
#include "ctest.h" #include "ctest.h"
void testBitString(Test *pTest) static void testBitString(Test *pTest)
{ {
uint8_t bit = 0; uint8_t bit = 0;
int max_bit; int max_bit;
@@ -917,7 +929,7 @@ void testBitString(Test *pTest)
} }
} }
void testCharacterString(Test *pTest) static void testCharacterString(Test *pTest)
{ {
BACNET_CHARACTER_STRING bacnet_string; BACNET_CHARACTER_STRING bacnet_string;
char *value = "Joshua,Mary,Anna,Christopher"; char *value = "Joshua,Mary,Anna,Christopher";
@@ -971,7 +983,7 @@ void testCharacterString(Test *pTest)
} }
} }
void testOctetString(Test *pTest) static void testOctetString(Test *pTest)
{ {
BACNET_OCTET_STRING bacnet_string; BACNET_OCTET_STRING bacnet_string;
uint8_t *value = NULL; uint8_t *value = NULL;
@@ -1030,20 +1042,26 @@ void testOctetString(Test *pTest)
} }
} }
#ifdef TEST_BACSTR void testBACnetStrings(Test *pTest)
int main(void)
{ {
Test *pTest;
bool rc; bool rc;
pTest = ct_create("BACnet Strings", NULL); /* add individual tests */
/* individual tests */
rc = ct_addTestFunction(pTest, testBitString); rc = ct_addTestFunction(pTest, testBitString);
assert(rc); assert(rc);
rc = ct_addTestFunction(pTest, testCharacterString); rc = ct_addTestFunction(pTest, testCharacterString);
assert(rc); assert(rc);
rc = ct_addTestFunction(pTest, testOctetString); rc = ct_addTestFunction(pTest, testOctetString);
assert(rc); assert(rc);
}
#ifdef TEST_BACSTR
int main(void)
{
Test *pTest;
pTest = ct_create("BACnet Strings", NULL);
testBACnetStrings(pTest);
/* configure output */ /* configure output */
ct_setStream(pTest, stdout); ct_setStream(pTest, stdout);
ct_run(pTest); ct_run(pTest);