diff --git a/src/common/inc/string_utilities.h b/src/common/inc/string_utilities.h index b6b238ff..404aec3e 100644 --- a/src/common/inc/string_utilities.h +++ b/src/common/inc/string_utilities.h @@ -40,6 +40,19 @@ StringUtils_copyStringMax(char* dest, int maxBufferSize, const char* str1); LIB61850_INTERNAL char* StringUtils_copyStringToBuffer(const char* string, char* buffer); +/** + * \brief Copy string to buffer and replace characters + * + * NOTE: str should be a 0 terminated string. The terminating 0 is also copied. + * + * \param str the source string to copy + * \param buffer the destination buffer + * \param oldChar the character that has to be replaced while copying + * \param newChar the replacement character + */ +LIB61850_INTERNAL char* +StringUtils_copyStringToBufferAndReplace(const char* str, char* buffer, char oldChar, char newChar); + LIB61850_INTERNAL char* StringUtils_copySubString(char* startPos, char* endPos); diff --git a/src/common/string_utilities.c b/src/common/string_utilities.c index abf9a04c..2f659e6f 100644 --- a/src/common/string_utilities.c +++ b/src/common/string_utilities.c @@ -1,7 +1,7 @@ /* * string_utilities.c * - * Copyright 2013 Michael Zillgith + * Copyright 2013-2023 Michael Zillgith * * This file is part of libIEC61850. * @@ -65,6 +65,27 @@ StringUtils_copyStringToBuffer(const char* string, char* buffer) return buffer; } +char* +StringUtils_copyStringToBufferAndReplace(const char* str, char* buffer, char oldChar, char newChar) +{ + int i = 0; + + while (true) + { + if (str[i] == oldChar) + buffer[i] = newChar; + else + buffer[i] = str[i]; + + if (str[i] == 0) + break; + + i++; + } + + return buffer; +} + char* StringUtils_createStringFromBuffer(const uint8_t* buf, int size) diff --git a/src/iec61850/server/mms_mapping/mms_mapping.c b/src/iec61850/server/mms_mapping/mms_mapping.c index 1d4d86c1..27471a58 100644 --- a/src/iec61850/server/mms_mapping/mms_mapping.c +++ b/src/iec61850/server/mms_mapping/mms_mapping.c @@ -3497,7 +3497,7 @@ mmsListObjectsAccessHandler(void* parameter, MmsGetNameListType listType, MmsDom StringUtils_createStringFromBufferInBuffer(str, (uint8_t*) (doStart + 1), doEnd - doStart); - subObjectName = StringUtils_copyStringToBuffer(doEnd + 2, subObjectBuf); + subObjectName = StringUtils_copyStringToBufferAndReplace(doEnd + 2, subObjectBuf, '$', '.'); } } } @@ -3564,7 +3564,7 @@ mmsListObjectsAccessHandler(void* parameter, MmsGetNameListType listType, MmsDom StringUtils_createStringFromBufferInBuffer(str, (uint8_t*) (doStart + 1), doEnd - doStart); - subObjectName = StringUtils_copyStringToBuffer(doEnd + 2, subObjectBuf); + subObjectName = StringUtils_copyStringToBufferAndReplace(doEnd + 2, subObjectBuf, '$', '.'); } if (fc == IEC61850_FC_SP) {