Added character string helper to test for printable. Added to WP checks.
This commit is contained in:
@@ -177,6 +177,11 @@ bool WPValidateString(
|
|||||||
(characterstring_length(&pValue->type.Character_String) ==
|
(characterstring_length(&pValue->type.Character_String) ==
|
||||||
0)) {
|
0)) {
|
||||||
*pErrorCode = ERROR_CODE_VALUE_OUT_OF_RANGE;
|
*pErrorCode = ERROR_CODE_VALUE_OUT_OF_RANGE;
|
||||||
|
} else if ((bEmptyAllowed == false) &&
|
||||||
|
(!characterstring_printable(
|
||||||
|
&pValue->type.Character_String))) {
|
||||||
|
/* assumption: non-empty also means must be "printable" */
|
||||||
|
*pErrorCode = ERROR_CODE_VALUE_OUT_OF_RANGE;
|
||||||
} else if (characterstring_length(&pValue->
|
} else if (characterstring_length(&pValue->
|
||||||
type.Character_String) >= iMaxLen) {
|
type.Character_String) >= iMaxLen) {
|
||||||
*pErrorClass = ERROR_CLASS_RESOURCES;
|
*pErrorClass = ERROR_CLASS_RESOURCES;
|
||||||
|
|||||||
@@ -151,6 +151,8 @@ extern "C" {
|
|||||||
BACNET_CHARACTER_STRING * char_string);
|
BACNET_CHARACTER_STRING * char_string);
|
||||||
size_t characterstring_capacity(
|
size_t characterstring_capacity(
|
||||||
BACNET_CHARACTER_STRING * char_string);
|
BACNET_CHARACTER_STRING * char_string);
|
||||||
|
bool characterstring_printable(
|
||||||
|
BACNET_CHARACTER_STRING * char_string);
|
||||||
|
|
||||||
/* returns false if the string exceeds capacity
|
/* returns false if the string exceeds capacity
|
||||||
initialize by using length=0 */
|
initialize by using length=0 */
|
||||||
|
|||||||
@@ -454,6 +454,42 @@ uint8_t characterstring_encoding(
|
|||||||
return encoding;
|
return encoding;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* returns true if string is printable */
|
||||||
|
/* used to assist in the requirement that
|
||||||
|
"The set of characters used in the Object_Name shall be
|
||||||
|
restricted to printable characters." */
|
||||||
|
/* printable character: a character that represents a printable
|
||||||
|
symbol as opposed to a device control character. These
|
||||||
|
include, but are not limited to, upper- and lowercase letters,
|
||||||
|
punctuation marks, and mathematical symbols. The exact set
|
||||||
|
depends upon the character set being used. In ANSI X3.4 the
|
||||||
|
printable characters are represented by single octets in the range
|
||||||
|
X'20' - X'7E'.*/
|
||||||
|
bool characterstring_printable(
|
||||||
|
BACNET_CHARACTER_STRING * char_string)
|
||||||
|
{
|
||||||
|
bool status = false; /* return value */
|
||||||
|
size_t i; /* counter */
|
||||||
|
|
||||||
|
if (char_string) {
|
||||||
|
if (char_string->encoding == CHARACTER_ANSI_X34) {
|
||||||
|
status = true;
|
||||||
|
for (i = 0; i < MAX_CHARACTER_STRING_BYTES; i++) {
|
||||||
|
if (i < char_string->length) {
|
||||||
|
if ((char_string->value[i] < 0x20) ||
|
||||||
|
(char_string->value[i] > 0x7E)) {
|
||||||
|
status = false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
/* returns false if the string exceeds capacity
|
/* returns false if the string exceeds capacity
|
||||||
initialize by using value=NULL */
|
initialize by using value=NULL */
|
||||||
bool octetstring_init(
|
bool octetstring_init(
|
||||||
|
|||||||
Reference in New Issue
Block a user