Added character string helper to test for printable. Added to WP checks.

This commit is contained in:
skarg
2010-12-02 19:33:22 +00:00
parent f26997a367
commit e850469da8
3 changed files with 43 additions and 0 deletions
+5
View File
@@ -177,6 +177,11 @@ bool WPValidateString(
(characterstring_length(&pValue->type.Character_String) ==
0)) {
*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->
type.Character_String) >= iMaxLen) {
*pErrorClass = ERROR_CLASS_RESOURCES;
+2
View File
@@ -151,6 +151,8 @@ extern "C" {
BACNET_CHARACTER_STRING * char_string);
size_t characterstring_capacity(
BACNET_CHARACTER_STRING * char_string);
bool characterstring_printable(
BACNET_CHARACTER_STRING * char_string);
/* returns false if the string exceeds capacity
initialize by using length=0 */
+36
View File
@@ -454,6 +454,42 @@ uint8_t characterstring_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
initialize by using value=NULL */
bool octetstring_init(