diff --git a/examples/common/tracing/decoder/interaction_model/Decoder.cpp b/examples/common/tracing/decoder/interaction_model/Decoder.cpp index 5400b773418666..cbc937d36814e0 100644 --- a/examples/common/tracing/decoder/interaction_model/Decoder.cpp +++ b/examples/common/tracing/decoder/interaction_model/Decoder.cpp @@ -132,7 +132,7 @@ CHIP_ERROR LogAsProtocolMessage(uint8_t protocolCode, const uint8_t * data, size CHIP_ERROR DecodeStatusResponse(TLV::TLVReader & reader, bool decode) { -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT if (decode) { app::StatusResponseMessage::Parser parser; @@ -146,7 +146,7 @@ CHIP_ERROR DecodeStatusResponse(TLV::TLVReader & reader, bool decode) CHIP_ERROR DecodeReadRequest(TLV::TLVReader & reader, bool decode) { -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT if (decode) { app::ReadRequestMessage::Parser parser; @@ -160,7 +160,7 @@ CHIP_ERROR DecodeReadRequest(TLV::TLVReader & reader, bool decode) CHIP_ERROR DecodeSubscribeRequest(TLV::TLVReader & reader, bool decode) { -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT if (decode) { app::SubscribeRequestMessage::Parser parser; @@ -174,7 +174,7 @@ CHIP_ERROR DecodeSubscribeRequest(TLV::TLVReader & reader, bool decode) CHIP_ERROR DecodeSubscribeResponse(TLV::TLVReader & reader, bool decode) { -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT if (decode) { app::SubscribeResponseMessage::Parser parser; @@ -190,7 +190,7 @@ CHIP_ERROR DecodeReportData(TLV::TLVReader & reader, bool decode) { ReturnErrorOnFailure(MaybeDecodeNestedReadResponse(reader.GetReadPoint(), reader.GetTotalLength())); -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT if (decode) { app::ReportDataMessage::Parser parser; @@ -204,7 +204,7 @@ CHIP_ERROR DecodeReportData(TLV::TLVReader & reader, bool decode) CHIP_ERROR DecodeWriteRequest(TLV::TLVReader & reader, bool decode) { -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT if (decode) { app::WriteRequestMessage::Parser parser; @@ -218,7 +218,7 @@ CHIP_ERROR DecodeWriteRequest(TLV::TLVReader & reader, bool decode) CHIP_ERROR DecodeWriteResponse(TLV::TLVReader & reader, bool decode) { -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT if (decode) { app::WriteResponseMessage::Parser parser; @@ -234,7 +234,7 @@ CHIP_ERROR DecodeInvokeCommandRequest(TLV::TLVReader & reader, bool decode) { ReturnErrorOnFailure(MaybeDecodeNestedCommandRequest(reader.GetReadPoint(), reader.GetTotalLength())); -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT if (decode) { app::InvokeRequestMessage::Parser parser; @@ -250,7 +250,7 @@ CHIP_ERROR DecodeInvokeCommandResponse(TLV::TLVReader & reader, bool decode) { ReturnErrorOnFailure(MaybeDecodeNestedCommandResponse(reader.GetReadPoint(), reader.GetTotalLength())); -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT if (decode) { app::InvokeResponseMessage::Parser parser; @@ -264,7 +264,7 @@ CHIP_ERROR DecodeInvokeCommandResponse(TLV::TLVReader & reader, bool decode) CHIP_ERROR DecodeTimedRequest(TLV::TLVReader & reader, bool decode) { -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT if (decode) { app::TimedRequestMessage::Parser parser; diff --git a/src/app/BUILD.gn b/src/app/BUILD.gn index fb3e6524881636..b16a3395353222 100644 --- a/src/app/BUILD.gn +++ b/src/app/BUILD.gn @@ -46,7 +46,7 @@ buildconfig_header("app_buildconfig") { header_dir = "app" defines = [ - "CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK=${chip_enable_schema_check}", + "CHIP_CONFIG_IM_PRETTY_PRINT=${chip_enable_schema_check}", "CHIP_CONFIG_IM_FORCE_FABRIC_QUOTA_CHECK=${chip_im_force_fabric_quota_check}", "CHIP_CONFIG_ENABLE_SESSION_RESUMPTION=${chip_enable_session_resumption}", "CHIP_CONFIG_ACCESS_CONTROL_POLICY_LOGGING_VERBOSITY=${chip_access_control_policy_logging_verbosity}", diff --git a/src/app/CommandHandler.cpp b/src/app/CommandHandler.cpp index 7e742b54cf8aff..6ae7e7261c3351 100644 --- a/src/app/CommandHandler.cpp +++ b/src/app/CommandHandler.cpp @@ -104,7 +104,7 @@ Status CommandHandler::ProcessInvokeRequest(System::PacketBufferHandle && payloa InvokeRequests::Parser invokeRequests; reader.Init(std::move(payload)); VerifyOrReturnError(invokeRequestMessage.Init(reader) == CHIP_NO_ERROR, Status::InvalidAction); -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT VerifyOrReturnError(invokeRequestMessage.CheckSchemaValidity() == CHIP_NO_ERROR, Status::InvalidAction); #endif diff --git a/src/app/CommandSender.cpp b/src/app/CommandSender.cpp index 7af043cf655a49..d09e4c1f5a965c 100644 --- a/src/app/CommandSender.cpp +++ b/src/app/CommandSender.cpp @@ -213,7 +213,7 @@ CHIP_ERROR CommandSender::ProcessInvokeResponse(System::PacketBufferHandle && pa reader.Init(std::move(payload)); ReturnErrorOnFailure(invokeResponseMessage.Init(reader)); -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT ReturnErrorOnFailure(invokeResponseMessage.CheckSchemaValidity()); #endif diff --git a/src/app/MessageDef/AttributeDataIB.cpp b/src/app/MessageDef/AttributeDataIB.cpp index 61f6bb88f0eb7e..6c32aac41e973c 100644 --- a/src/app/MessageDef/AttributeDataIB.cpp +++ b/src/app/MessageDef/AttributeDataIB.cpp @@ -28,11 +28,10 @@ namespace chip { namespace app { -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT CHIP_ERROR AttributeDataIB::Parser::CheckSchemaValidity() const { - CHIP_ERROR err = CHIP_NO_ERROR; - int tagPresenceMask = 0; + CHIP_ERROR err = CHIP_NO_ERROR; TLV::TLVReader reader; PRETTY_PRINT("AttributeDataIB ="); @@ -51,11 +50,7 @@ CHIP_ERROR AttributeDataIB::Parser::CheckSchemaValidity() const switch (tagNum) { case to_underlying(Tag::kDataVersion): - // check if this tag has appeared before - VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kDataVersion))), CHIP_ERROR_INVALID_TLV_TAG); - tagPresenceMask |= (1 << to_underlying(Tag::kDataVersion)); VerifyOrReturnError(TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); - #if CHIP_DETAIL_LOGGING { chip::DataVersion version; @@ -64,24 +59,16 @@ CHIP_ERROR AttributeDataIB::Parser::CheckSchemaValidity() const } #endif // CHIP_DETAIL_LOGGING break; - case to_underlying(Tag::kPath): - // check if this tag has appeared before - VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kPath))), CHIP_ERROR_INVALID_TLV_TAG); - tagPresenceMask |= (1 << to_underlying(Tag::kPath)); - { - AttributePathIB::Parser path; - ReturnErrorOnFailure(path.Init(reader)); + case to_underlying(Tag::kPath): { + AttributePathIB::Parser path; + ReturnErrorOnFailure(path.Init(reader)); - PRETTY_PRINT_INCDEPTH(); - ReturnErrorOnFailure(path.CheckSchemaValidity()); - PRETTY_PRINT_DECDEPTH(); - } - break; + PRETTY_PRINT_INCDEPTH(); + ReturnErrorOnFailure(path.CheckSchemaValidity()); + PRETTY_PRINT_DECDEPTH(); + } + break; case to_underlying(Tag::kData): - // check if this tag has appeared before - VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kData))), CHIP_ERROR_INVALID_TLV_TAG); - tagPresenceMask |= (1 << to_underlying(Tag::kData)); - PRETTY_PRINT_INCDEPTH(); ReturnErrorOnFailure(CheckIMPayload(reader, 0, "Data")); PRETTY_PRINT_DECDEPTH(); @@ -97,15 +84,12 @@ CHIP_ERROR AttributeDataIB::Parser::CheckSchemaValidity() const // if we have exhausted this container if (CHIP_END_OF_TLV == err) { - // check for required fields: - const int requiredFields = (1 << to_underlying(Tag::kPath)) | (1 << to_underlying(Tag::kData)); - - err = (tagPresenceMask & requiredFields) == requiredFields ? CHIP_NO_ERROR : CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_DATA_IB; + err = CHIP_NO_ERROR; } ReturnErrorOnFailure(err); return reader.ExitContainer(mOuterContainerType); } -#endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#endif // CHIP_CONFIG_IM_PRETTY_PRINT CHIP_ERROR AttributeDataIB::Parser::GetPath(AttributePathIB::Parser * const apPath) const { diff --git a/src/app/MessageDef/AttributeDataIB.h b/src/app/MessageDef/AttributeDataIB.h index d2bec07b02b21b..59097cb2b4200c 100644 --- a/src/app/MessageDef/AttributeDataIB.h +++ b/src/app/MessageDef/AttributeDataIB.h @@ -42,7 +42,7 @@ enum class Tag : uint8_t class Parser : public StructParser { public: -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT /** * @brief Roughly verify the message is correctly formed * 1) all mandatory tags are present diff --git a/src/app/MessageDef/AttributeDataIBs.cpp b/src/app/MessageDef/AttributeDataIBs.cpp index f0068a8838420c..78310414255bca 100644 --- a/src/app/MessageDef/AttributeDataIBs.cpp +++ b/src/app/MessageDef/AttributeDataIBs.cpp @@ -36,7 +36,7 @@ using namespace chip::TLV; namespace chip { namespace app { -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT CHIP_ERROR AttributeDataIBs::Parser::CheckSchemaValidity() const { CHIP_ERROR err = CHIP_NO_ERROR; @@ -81,7 +81,7 @@ CHIP_ERROR AttributeDataIBs::Parser::CheckSchemaValidity() const ReturnErrorOnFailure(err); return reader.ExitContainer(mOuterContainerType); } -#endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#endif // CHIP_CONFIG_IM_PRETTY_PRINT AttributeDataIB::Builder & AttributeDataIBs::Builder::CreateAttributeDataIBBuilder() { diff --git a/src/app/MessageDef/AttributeDataIBs.h b/src/app/MessageDef/AttributeDataIBs.h index 67dabd1e1a096b..be86586d8ef6a6 100644 --- a/src/app/MessageDef/AttributeDataIBs.h +++ b/src/app/MessageDef/AttributeDataIBs.h @@ -40,7 +40,7 @@ namespace AttributeDataIBs { class Parser : public ArrayParser { public: -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT /** * @brief Roughly verify the message is correctly formed * 1) all mandatory tags are present diff --git a/src/app/MessageDef/AttributePathIB.cpp b/src/app/MessageDef/AttributePathIB.cpp index 97d7f60568af0e..b31456e0284271 100644 --- a/src/app/MessageDef/AttributePathIB.cpp +++ b/src/app/MessageDef/AttributePathIB.cpp @@ -29,11 +29,10 @@ namespace chip { namespace app { -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT CHIP_ERROR AttributePathIB::Parser::CheckSchemaValidity() const { - CHIP_ERROR err = CHIP_NO_ERROR; - int tagPresenceMask = 0; + CHIP_ERROR err = CHIP_NO_ERROR; TLV::TLVReader reader; PRETTY_PRINT("AttributePathIB ="); @@ -52,22 +51,15 @@ CHIP_ERROR AttributePathIB::Parser::CheckSchemaValidity() const switch (tagNum) { case to_underlying(Tag::kEnableTagCompression): - // check if this tag has appeared before - VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kEnableTagCompression))), CHIP_ERROR_INVALID_TLV_TAG); - tagPresenceMask |= (1 << to_underlying(Tag::kEnableTagCompression)); #if CHIP_DETAIL_LOGGING - { - bool enableTagCompression; - ReturnErrorOnFailure(reader.Get(enableTagCompression)); - PRETTY_PRINT("\tenableTagCompression = %s, ", enableTagCompression ? "true" : "false"); - } + { + bool enableTagCompression; + ReturnErrorOnFailure(reader.Get(enableTagCompression)); + PRETTY_PRINT("\tenableTagCompression = %s, ", enableTagCompression ? "true" : "false"); + } #endif // CHIP_DETAIL_LOGGING - break; + break; case to_underlying(Tag::kNode): - // check if this tag has appeared before - - VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kNode))), err = CHIP_ERROR_INVALID_TLV_TAG); - tagPresenceMask |= (1 << to_underlying(Tag::kNode)); VerifyOrReturnError(TLV::kTLVType_UnsignedInteger == reader.GetType(), err = CHIP_ERROR_WRONG_TLV_TYPE); #if CHIP_DETAIL_LOGGING @@ -79,9 +71,6 @@ CHIP_ERROR AttributePathIB::Parser::CheckSchemaValidity() const #endif // CHIP_DETAIL_LOGGING break; case to_underlying(Tag::kEndpoint): - // check if this tag has appeared before - VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kEndpoint))), CHIP_ERROR_INVALID_TLV_TAG); - tagPresenceMask |= (1 << to_underlying(Tag::kEndpoint)); VerifyOrReturnError(TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); #if CHIP_DETAIL_LOGGING { @@ -92,9 +81,6 @@ CHIP_ERROR AttributePathIB::Parser::CheckSchemaValidity() const #endif // CHIP_DETAIL_LOGGING break; case to_underlying(Tag::kCluster): - // check if this tag has appeared before - VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kCluster))), err = CHIP_ERROR_INVALID_TLV_TAG); - tagPresenceMask |= (1 << to_underlying(Tag::kCluster)); VerifyOrReturnError(TLV::kTLVType_UnsignedInteger == reader.GetType(), err = CHIP_ERROR_WRONG_TLV_TYPE); #if CHIP_DETAIL_LOGGING @@ -106,9 +92,6 @@ CHIP_ERROR AttributePathIB::Parser::CheckSchemaValidity() const #endif // CHIP_DETAIL_LOGGING break; case to_underlying(Tag::kAttribute): - // check if this tag has appeared before - VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kAttribute))), CHIP_ERROR_INVALID_TLV_TAG); - tagPresenceMask |= (1 << to_underlying(Tag::kAttribute)); VerifyOrReturnError(TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); #if CHIP_DETAIL_LOGGING { @@ -119,9 +102,6 @@ CHIP_ERROR AttributePathIB::Parser::CheckSchemaValidity() const #endif // CHIP_DETAIL_LOGGING break; case to_underlying(Tag::kListIndex): - // check if this tag has appeared before - VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kListIndex))), CHIP_ERROR_INVALID_TLV_TAG); - tagPresenceMask |= (1 << to_underlying(Tag::kListIndex)); VerifyOrReturnError(TLV::kTLVType_UnsignedInteger == reader.GetType() || TLV::kTLVType_Null == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); #if CHIP_DETAIL_LOGGING @@ -149,21 +129,12 @@ CHIP_ERROR AttributePathIB::Parser::CheckSchemaValidity() const // if we have exhausted this container if (CHIP_END_OF_TLV == err) { - if ((tagPresenceMask & (1 << to_underlying(Tag::kAttribute))) == 0 && - (tagPresenceMask & (1 << to_underlying(Tag::kListIndex))) != 0) - { - err = CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_PATH_IB; - } - else - { - err = CHIP_NO_ERROR; - } + err = CHIP_NO_ERROR; } - ReturnErrorOnFailure(err); return reader.ExitContainer(mOuterContainerType); } -#endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#endif // CHIP_CONFIG_IM_PRETTY_PRINT CHIP_ERROR AttributePathIB::Parser::GetEnableTagCompression(bool * const apEnableTagCompression) const { diff --git a/src/app/MessageDef/AttributePathIB.h b/src/app/MessageDef/AttributePathIB.h index 81b1a33e58a904..625c69e0e900a1 100644 --- a/src/app/MessageDef/AttributePathIB.h +++ b/src/app/MessageDef/AttributePathIB.h @@ -48,7 +48,7 @@ enum class Tag : uint8_t class Parser : public ListParser { public: -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT /** * @brief Roughly verify the message is correctly formed * 1) all mandatory tags are present diff --git a/src/app/MessageDef/AttributePathIBs.cpp b/src/app/MessageDef/AttributePathIBs.cpp index 8b88e7e9e3361d..e0554343a4bc87 100644 --- a/src/app/MessageDef/AttributePathIBs.cpp +++ b/src/app/MessageDef/AttributePathIBs.cpp @@ -27,7 +27,7 @@ namespace chip { namespace app { -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT CHIP_ERROR AttributePathIBs::Parser::CheckSchemaValidity() const { CHIP_ERROR err = CHIP_NO_ERROR; @@ -70,7 +70,7 @@ CHIP_ERROR AttributePathIBs::Parser::CheckSchemaValidity() const ReturnErrorOnFailure(err); return reader.ExitContainer(mOuterContainerType); } -#endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#endif // CHIP_CONFIG_IM_PRETTY_PRINT AttributePathIB::Builder & AttributePathIBs::Builder::CreatePath() { diff --git a/src/app/MessageDef/AttributePathIBs.h b/src/app/MessageDef/AttributePathIBs.h index ad6929f64b69a4..c606b4e73af593 100644 --- a/src/app/MessageDef/AttributePathIBs.h +++ b/src/app/MessageDef/AttributePathIBs.h @@ -35,7 +35,7 @@ namespace AttributePathIBs { class Parser : public ArrayParser { public: -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT /** * @brief Roughly verify the message is correctly formed * 1) all mandatory tags are present diff --git a/src/app/MessageDef/AttributeReportIB.cpp b/src/app/MessageDef/AttributeReportIB.cpp index e08eb37ac77ce3..d3c2c09a4c1ed0 100644 --- a/src/app/MessageDef/AttributeReportIB.cpp +++ b/src/app/MessageDef/AttributeReportIB.cpp @@ -28,11 +28,10 @@ namespace chip { namespace app { -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT CHIP_ERROR AttributeReportIB::Parser::CheckSchemaValidity() const { - CHIP_ERROR err = CHIP_NO_ERROR; - int tagPresenceMask = 0; + CHIP_ERROR err = CHIP_NO_ERROR; TLV::TLVReader reader; PRETTY_PRINT("AttributeReportIB ="); @@ -50,32 +49,24 @@ CHIP_ERROR AttributeReportIB::Parser::CheckSchemaValidity() const uint32_t tagNum = TLV::TagNumFromTag(reader.GetTag()); switch (tagNum) { - case to_underlying(Tag::kAttributeStatus): - // check if this tag has appeared before - VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kAttributeStatus))), CHIP_ERROR_INVALID_TLV_TAG); - tagPresenceMask |= (1 << to_underlying(Tag::kAttributeStatus)); - { - AttributeStatusIB::Parser attributeStatus; - ReturnErrorOnFailure(attributeStatus.Init(reader)); - - PRETTY_PRINT_INCDEPTH(); - ReturnErrorOnFailure(attributeStatus.CheckSchemaValidity()); - PRETTY_PRINT_DECDEPTH(); - } - break; - case to_underlying(Tag::kAttributeData): - // check if this tag has appeared before - VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kAttributeData))), CHIP_ERROR_INVALID_TLV_TAG); - tagPresenceMask |= (1 << to_underlying(Tag::kAttributeData)); - { - AttributeDataIB::Parser attributeData; - ReturnErrorOnFailure(attributeData.Init(reader)); - - PRETTY_PRINT_INCDEPTH(); - ReturnErrorOnFailure(attributeData.CheckSchemaValidity()); - PRETTY_PRINT_DECDEPTH(); - } - break; + case to_underlying(Tag::kAttributeStatus): { + AttributeStatusIB::Parser attributeStatus; + ReturnErrorOnFailure(attributeStatus.Init(reader)); + + PRETTY_PRINT_INCDEPTH(); + ReturnErrorOnFailure(attributeStatus.CheckSchemaValidity()); + PRETTY_PRINT_DECDEPTH(); + } + break; + case to_underlying(Tag::kAttributeData): { + AttributeDataIB::Parser attributeData; + ReturnErrorOnFailure(attributeData.Init(reader)); + + PRETTY_PRINT_INCDEPTH(); + ReturnErrorOnFailure(attributeData.CheckSchemaValidity()); + PRETTY_PRINT_DECDEPTH(); + } + break; default: PRETTY_PRINT("Unknown tag num %" PRIu32, tagNum); break; @@ -87,30 +78,13 @@ CHIP_ERROR AttributeReportIB::Parser::CheckSchemaValidity() const if (CHIP_END_OF_TLV == err) { - // check for at most field: - const int CheckDataField = 1 << to_underlying(Tag::kAttributeData); - const int CheckStatusField = (1 << to_underlying(Tag::kAttributeStatus)); - - if ((tagPresenceMask & CheckDataField) == CheckDataField && (tagPresenceMask & CheckStatusField) == CheckStatusField) - { - // kAttributeData and kAttributeStatus both exist - err = CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_REPORT_IB; - } - else if ((tagPresenceMask & CheckDataField) != CheckDataField && (tagPresenceMask & CheckStatusField) != CheckStatusField) - { - // kPath and kErrorStatus not exist - err = CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_REPORT_IB; - } - else - { - err = CHIP_NO_ERROR; - } + err = CHIP_NO_ERROR; } ReturnErrorOnFailure(err); return reader.ExitContainer(mOuterContainerType); } -#endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#endif // CHIP_CONFIG_IM_PRETTY_PRINT CHIP_ERROR AttributeReportIB::Parser::GetAttributeStatus(AttributeStatusIB::Parser * const apAttributeStatus) const { diff --git a/src/app/MessageDef/AttributeReportIB.h b/src/app/MessageDef/AttributeReportIB.h index f237fb695ef620..c37004372070e0 100644 --- a/src/app/MessageDef/AttributeReportIB.h +++ b/src/app/MessageDef/AttributeReportIB.h @@ -41,7 +41,7 @@ enum class Tag : uint8_t class Parser : public StructParser { public: -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT /** * @brief Roughly verify the message is correctly formed * 1) all mandatory tags are present diff --git a/src/app/MessageDef/AttributeReportIBs.cpp b/src/app/MessageDef/AttributeReportIBs.cpp index 001fbff077acc9..9daa49bed7b40d 100644 --- a/src/app/MessageDef/AttributeReportIBs.cpp +++ b/src/app/MessageDef/AttributeReportIBs.cpp @@ -32,7 +32,7 @@ namespace chip { namespace app { -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT CHIP_ERROR AttributeReportIBs::Parser::CheckSchemaValidity() const { CHIP_ERROR err = CHIP_NO_ERROR; @@ -67,7 +67,7 @@ CHIP_ERROR AttributeReportIBs::Parser::CheckSchemaValidity() const ReturnErrorOnFailure(err); return reader.ExitContainer(mOuterContainerType); } -#endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#endif // CHIP_CONFIG_IM_PRETTY_PRINT AttributeReportIB::Builder & AttributeReportIBs::Builder::CreateAttributeReport() { diff --git a/src/app/MessageDef/AttributeReportIBs.h b/src/app/MessageDef/AttributeReportIBs.h index 16baa7b9ed3c5c..8dada9308f3473 100644 --- a/src/app/MessageDef/AttributeReportIBs.h +++ b/src/app/MessageDef/AttributeReportIBs.h @@ -42,7 +42,7 @@ namespace AttributeReportIBs { class Parser : public ArrayParser { public: -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT /** * @brief Roughly verify the message is correctly formed * 1) all mandatory tags are present diff --git a/src/app/MessageDef/AttributeStatusIB.cpp b/src/app/MessageDef/AttributeStatusIB.cpp index 5c0e92b7020b03..683f9dc949683f 100644 --- a/src/app/MessageDef/AttributeStatusIB.cpp +++ b/src/app/MessageDef/AttributeStatusIB.cpp @@ -27,11 +27,10 @@ namespace chip { namespace app { -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT CHIP_ERROR AttributeStatusIB::Parser::CheckSchemaValidity() const { - CHIP_ERROR err = CHIP_NO_ERROR; - int tagPresenceMask = 0; + CHIP_ERROR err = CHIP_NO_ERROR; TLV::TLVReader reader; PRETTY_PRINT("AttributeStatusIB ="); @@ -49,32 +48,24 @@ CHIP_ERROR AttributeStatusIB::Parser::CheckSchemaValidity() const uint32_t tagNum = TLV::TagNumFromTag(reader.GetTag()); switch (tagNum) { - case to_underlying(Tag::kPath): - // check if this tag has appeared before - VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kPath))), CHIP_ERROR_INVALID_TLV_TAG); - tagPresenceMask |= (1 << to_underlying(Tag::kPath)); - { - AttributePathIB::Parser path; - ReturnErrorOnFailure(path.Init(reader)); - - PRETTY_PRINT_INCDEPTH(); - ReturnErrorOnFailure(path.CheckSchemaValidity()); - PRETTY_PRINT_DECDEPTH(); - } - break; - case to_underlying(Tag::kErrorStatus): - // check if this tag has appeared before - VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kErrorStatus))), CHIP_ERROR_INVALID_TLV_TAG); - tagPresenceMask |= (1 << to_underlying(Tag::kErrorStatus)); - { - StatusIB::Parser errorStatus; - ReturnErrorOnFailure(errorStatus.Init(reader)); - - PRETTY_PRINT_INCDEPTH(); - ReturnErrorOnFailure(errorStatus.CheckSchemaValidity()); - PRETTY_PRINT_DECDEPTH(); - } - break; + case to_underlying(Tag::kPath): { + AttributePathIB::Parser path; + ReturnErrorOnFailure(path.Init(reader)); + + PRETTY_PRINT_INCDEPTH(); + ReturnErrorOnFailure(path.CheckSchemaValidity()); + PRETTY_PRINT_DECDEPTH(); + } + break; + case to_underlying(Tag::kErrorStatus): { + StatusIB::Parser errorStatus; + ReturnErrorOnFailure(errorStatus.Init(reader)); + + PRETTY_PRINT_INCDEPTH(); + ReturnErrorOnFailure(errorStatus.CheckSchemaValidity()); + PRETTY_PRINT_DECDEPTH(); + } + break; default: PRETTY_PRINT("Unknown tag num %" PRIu32, tagNum); break; @@ -86,14 +77,13 @@ CHIP_ERROR AttributeStatusIB::Parser::CheckSchemaValidity() const if (CHIP_END_OF_TLV == err) { - const int requiredFields = (1 << to_underlying(Tag::kPath)) | (1 << to_underlying(Tag::kErrorStatus)); - err = (tagPresenceMask & requiredFields) == requiredFields ? CHIP_NO_ERROR : CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_STATUS_IB; + err = CHIP_NO_ERROR; } ReturnErrorOnFailure(err); return reader.ExitContainer(mOuterContainerType); } -#endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#endif // CHIP_CONFIG_IM_PRETTY_PRINT CHIP_ERROR AttributeStatusIB::Parser::GetPath(AttributePathIB::Parser * const apPath) const { diff --git a/src/app/MessageDef/AttributeStatusIB.h b/src/app/MessageDef/AttributeStatusIB.h index 35358fc2d2d8f5..eb2937959beb53 100644 --- a/src/app/MessageDef/AttributeStatusIB.h +++ b/src/app/MessageDef/AttributeStatusIB.h @@ -41,7 +41,7 @@ enum class Tag : uint8_t class Parser : public StructParser { public: -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT /** * @brief Roughly verify the message is correctly formed * 1) all mandatory tags are present diff --git a/src/app/MessageDef/AttributeStatusIBs.cpp b/src/app/MessageDef/AttributeStatusIBs.cpp index a10106aad28c34..132f5639e70146 100644 --- a/src/app/MessageDef/AttributeStatusIBs.cpp +++ b/src/app/MessageDef/AttributeStatusIBs.cpp @@ -44,7 +44,7 @@ AttributeStatusIBs::Builder & AttributeStatusIBs::Builder::EndOfAttributeStatuse return *this; } -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT CHIP_ERROR AttributeStatusIBs::Parser::CheckSchemaValidity() const { CHIP_ERROR err = CHIP_NO_ERROR; diff --git a/src/app/MessageDef/AttributeStatusIBs.h b/src/app/MessageDef/AttributeStatusIBs.h index b6a70ab62c3a0e..0b3f205bbab674 100644 --- a/src/app/MessageDef/AttributeStatusIBs.h +++ b/src/app/MessageDef/AttributeStatusIBs.h @@ -56,7 +56,7 @@ class Builder : public ArrayBuilder class Parser : public ArrayParser { public: -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT /** * @brief Roughly verify the message is correctly formed * 1) all mandatory tags are present diff --git a/src/app/MessageDef/ClusterPathIB.cpp b/src/app/MessageDef/ClusterPathIB.cpp index 8223d63507a1cd..05f8c86bcea9a0 100644 --- a/src/app/MessageDef/ClusterPathIB.cpp +++ b/src/app/MessageDef/ClusterPathIB.cpp @@ -25,11 +25,10 @@ namespace chip { namespace app { -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT CHIP_ERROR ClusterPathIB::Parser::CheckSchemaValidity() const { - CHIP_ERROR err = CHIP_NO_ERROR; - int tagPresenceMask = 0; + CHIP_ERROR err = CHIP_NO_ERROR; TLV::TLVReader reader; PRETTY_PRINT("ClusterPathIB ="); @@ -48,10 +47,6 @@ CHIP_ERROR ClusterPathIB::Parser::CheckSchemaValidity() const switch (tagNum) { case to_underlying(Tag::kNode): - // check if this tag has appeared before - - VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kNode))), err = CHIP_ERROR_INVALID_TLV_TAG); - tagPresenceMask |= (1 << to_underlying(Tag::kNode)); VerifyOrReturnError(TLV::kTLVType_UnsignedInteger == reader.GetType(), err = CHIP_ERROR_WRONG_TLV_TYPE); #if CHIP_DETAIL_LOGGING @@ -63,9 +58,6 @@ CHIP_ERROR ClusterPathIB::Parser::CheckSchemaValidity() const #endif // CHIP_DETAIL_LOGGING break; case to_underlying(Tag::kEndpoint): - // check if this tag has appeared before - VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kEndpoint))), CHIP_ERROR_INVALID_TLV_TAG); - tagPresenceMask |= (1 << to_underlying(Tag::kEndpoint)); VerifyOrReturnError(TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); #if CHIP_DETAIL_LOGGING { @@ -76,9 +68,6 @@ CHIP_ERROR ClusterPathIB::Parser::CheckSchemaValidity() const #endif // CHIP_DETAIL_LOGGING break; case to_underlying(Tag::kCluster): - // check if this tag has appeared before - VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kCluster))), err = CHIP_ERROR_INVALID_TLV_TAG); - tagPresenceMask |= (1 << to_underlying(Tag::kCluster)); VerifyOrReturnError(TLV::kTLVType_UnsignedInteger == reader.GetType(), err = CHIP_ERROR_WRONG_TLV_TYPE); #if CHIP_DETAIL_LOGGING @@ -100,16 +89,13 @@ CHIP_ERROR ClusterPathIB::Parser::CheckSchemaValidity() const // if we have exhausted this container if (CHIP_END_OF_TLV == err) { - // check for required fields: - const int requiredFields = (1 << to_underlying(Tag::kCluster)); - - err = (tagPresenceMask & requiredFields) == requiredFields ? CHIP_NO_ERROR : CHIP_ERROR_IM_MALFORMED_CLUSTER_PATH_IB; + err = CHIP_NO_ERROR; } ReturnErrorOnFailure(err); return reader.ExitContainer(mOuterContainerType); } -#endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#endif // CHIP_CONFIG_IM_PRETTY_PRINT CHIP_ERROR ClusterPathIB::Parser::GetNode(NodeId * const apNode) const { diff --git a/src/app/MessageDef/ClusterPathIB.h b/src/app/MessageDef/ClusterPathIB.h index cfcb65ec69fc54..d560af20c8461a 100644 --- a/src/app/MessageDef/ClusterPathIB.h +++ b/src/app/MessageDef/ClusterPathIB.h @@ -41,7 +41,7 @@ enum class Tag : uint8_t class Parser : public ListParser { public: -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT /** * @brief Roughly verify the message is correctly formed * 1) all mandatory tags are present diff --git a/src/app/MessageDef/CommandDataIB.cpp b/src/app/MessageDef/CommandDataIB.cpp index 61978f2e564b52..07e92d54b36c4e 100644 --- a/src/app/MessageDef/CommandDataIB.cpp +++ b/src/app/MessageDef/CommandDataIB.cpp @@ -29,11 +29,10 @@ namespace chip { namespace app { -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT CHIP_ERROR CommandDataIB::Parser::CheckSchemaValidity() const { - CHIP_ERROR err = CHIP_NO_ERROR; - int tagPresenceMask = 0; + CHIP_ERROR err = CHIP_NO_ERROR; TLV::TLVReader reader; PRETTY_PRINT("CommandDataIB ="); @@ -52,23 +51,16 @@ CHIP_ERROR CommandDataIB::Parser::CheckSchemaValidity() const switch (tagNum) { - case to_underlying(Tag::kPath): - // check if this tag has appeared before - VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kPath))), CHIP_ERROR_INVALID_TLV_TAG); - tagPresenceMask |= (1 << to_underlying(Tag::kPath)); - { - CommandPathIB::Parser path; - ReturnErrorOnFailure(path.Init(reader)); - PRETTY_PRINT_INCDEPTH(); - ReturnErrorOnFailure(path.CheckSchemaValidity()); - PRETTY_PRINT_DECDEPTH(); - } + case to_underlying(Tag::kPath): { + CommandPathIB::Parser path; + ReturnErrorOnFailure(path.Init(reader)); + PRETTY_PRINT_INCDEPTH(); + ReturnErrorOnFailure(path.CheckSchemaValidity()); + PRETTY_PRINT_DECDEPTH(); + } - break; + break; case to_underlying(Tag::kFields): - // check if this tag has appeared before - VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kFields))), CHIP_ERROR_INVALID_TLV_TAG); - tagPresenceMask |= (1 << to_underlying(Tag::kFields)); PRETTY_PRINT_INCDEPTH(); ReturnErrorOnFailure(CheckIMPayload(reader, 0, "CommandFields")); PRETTY_PRINT_DECDEPTH(); @@ -84,14 +76,13 @@ CHIP_ERROR CommandDataIB::Parser::CheckSchemaValidity() const if (CHIP_END_OF_TLV == err) { - const int requiredFields = 1 << to_underlying(Tag::kPath); - err = (tagPresenceMask & requiredFields) == requiredFields ? CHIP_NO_ERROR : CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_IB; + err = CHIP_NO_ERROR; } ReturnErrorOnFailure(err); return reader.ExitContainer(mOuterContainerType); } -#endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#endif // CHIP_CONFIG_IM_PRETTY_PRINT CHIP_ERROR CommandDataIB::Parser::GetPath(CommandPathIB::Parser * const apPath) const { diff --git a/src/app/MessageDef/CommandDataIB.h b/src/app/MessageDef/CommandDataIB.h index 1b8d361e0a8e0c..1d798d1f701eda 100644 --- a/src/app/MessageDef/CommandDataIB.h +++ b/src/app/MessageDef/CommandDataIB.h @@ -42,7 +42,7 @@ enum class Tag : uint8_t class Parser : public StructParser { public: -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT /** * @brief Roughly verify the message is correctly formed * 1) all mandatory tags are present diff --git a/src/app/MessageDef/CommandPathIB.cpp b/src/app/MessageDef/CommandPathIB.cpp index be9117d3679613..7bd8315e5cb51b 100644 --- a/src/app/MessageDef/CommandPathIB.cpp +++ b/src/app/MessageDef/CommandPathIB.cpp @@ -31,11 +31,10 @@ using namespace chip::TLV; namespace chip { namespace app { -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT CHIP_ERROR CommandPathIB::Parser::CheckSchemaValidity() const { - CHIP_ERROR err = CHIP_NO_ERROR; - int tagPresenceMask = 0; + CHIP_ERROR err = CHIP_NO_ERROR; TLV::TLVReader reader; PRETTY_PRINT("CommandPathIB ="); PRETTY_PRINT("{"); @@ -53,9 +52,6 @@ CHIP_ERROR CommandPathIB::Parser::CheckSchemaValidity() const switch (tagNum) { case to_underlying(Tag::kEndpointId): - // check if this tag has appeared before - VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kEndpointId))), CHIP_ERROR_INVALID_TLV_TAG); - tagPresenceMask |= (1 << to_underlying(Tag::kEndpointId)); VerifyOrReturnError(TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); #if CHIP_DETAIL_LOGGING @@ -67,9 +63,6 @@ CHIP_ERROR CommandPathIB::Parser::CheckSchemaValidity() const #endif // CHIP_DETAIL_LOGGING break; case to_underlying(Tag::kClusterId): - // check if this tag has appeared before - VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kClusterId))), CHIP_ERROR_INVALID_TLV_TAG); - tagPresenceMask |= (1 << to_underlying(Tag::kClusterId)); VerifyOrReturnError(TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); #if CHIP_DETAIL_LOGGING { @@ -80,9 +73,6 @@ CHIP_ERROR CommandPathIB::Parser::CheckSchemaValidity() const #endif // CHIP_DETAIL_LOGGING break; case to_underlying(Tag::kCommandId): - // check if this tag has appeared before - VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kCommandId))), CHIP_ERROR_INVALID_TLV_TAG); - tagPresenceMask |= (1 << to_underlying(Tag::kCommandId)); VerifyOrReturnError(chip::TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); #if CHIP_DETAIL_LOGGING { @@ -102,15 +92,12 @@ CHIP_ERROR CommandPathIB::Parser::CheckSchemaValidity() const // if we have exhausted this container if (CHIP_END_OF_TLV == err) { - // check for required fields: - const uint16_t requiredFields = (1 << to_underlying(Tag::kCommandId)) | (1 << to_underlying(Tag::kClusterId)); - - err = (tagPresenceMask & requiredFields) == requiredFields ? CHIP_NO_ERROR : CHIP_ERROR_IM_MALFORMED_COMMAND_PATH_IB; + err = CHIP_NO_ERROR; } ReturnErrorOnFailure(err); return reader.ExitContainer(mOuterContainerType); } -#endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#endif // CHIP_CONFIG_IM_PRETTY_PRINT CHIP_ERROR CommandPathIB::Parser::GetEndpointId(chip::EndpointId * const apEndpointID) const { diff --git a/src/app/MessageDef/CommandPathIB.h b/src/app/MessageDef/CommandPathIB.h index 1b823efb65e67b..f90fed47592afd 100644 --- a/src/app/MessageDef/CommandPathIB.h +++ b/src/app/MessageDef/CommandPathIB.h @@ -43,7 +43,7 @@ enum class Tag : uint8_t class Parser : public ListParser { public: -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT /** * @brief Roughly verify the message is correctly formed * 1) all mandatory tags are present diff --git a/src/app/MessageDef/CommandStatusIB.cpp b/src/app/MessageDef/CommandStatusIB.cpp index 797ec655e3eef4..af5067173517ce 100644 --- a/src/app/MessageDef/CommandStatusIB.cpp +++ b/src/app/MessageDef/CommandStatusIB.cpp @@ -27,7 +27,7 @@ namespace chip { namespace app { -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT CHIP_ERROR CommandStatusIB::Parser::CheckSchemaValidity() const { CHIP_ERROR err = CHIP_NO_ERROR; @@ -86,14 +86,13 @@ CHIP_ERROR CommandStatusIB::Parser::CheckSchemaValidity() const if (CHIP_END_OF_TLV == err) { - const int requiredFields = (1 << to_underlying(Tag::kPath)) | (1 << to_underlying(Tag::kErrorStatus)); - err = (tagPresenceMask & requiredFields) == requiredFields ? CHIP_NO_ERROR : CHIP_ERROR_IM_MALFORMED_COMMAND_STATUS_IB; + err = CHIP_NO_ERROR; } ReturnErrorOnFailure(err); return reader.ExitContainer(mOuterContainerType); } -#endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#endif // CHIP_CONFIG_IM_PRETTY_PRINT CHIP_ERROR CommandStatusIB::Parser::GetPath(CommandPathIB::Parser * const apPath) const { diff --git a/src/app/MessageDef/CommandStatusIB.h b/src/app/MessageDef/CommandStatusIB.h index 2a785295984d09..9ebddaec71f2a6 100644 --- a/src/app/MessageDef/CommandStatusIB.h +++ b/src/app/MessageDef/CommandStatusIB.h @@ -42,7 +42,7 @@ enum class Tag : uint8_t class Parser : public StructParser { public: -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT /** * @brief Roughly verify the message is correctly formed * 1) all mandatory tags are present diff --git a/src/app/MessageDef/DataVersionFilterIB.cpp b/src/app/MessageDef/DataVersionFilterIB.cpp index 00d1d28b0ff927..e13463fa5dee5c 100644 --- a/src/app/MessageDef/DataVersionFilterIB.cpp +++ b/src/app/MessageDef/DataVersionFilterIB.cpp @@ -31,11 +31,10 @@ namespace chip { namespace app { -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT CHIP_ERROR DataVersionFilterIB::Parser::CheckSchemaValidity() const { - CHIP_ERROR err = CHIP_NO_ERROR; - int tagPresenceMask = 0; + CHIP_ERROR err = CHIP_NO_ERROR; TLV::TLVReader reader; PRETTY_PRINT("DataVersionFilterIB ="); @@ -53,23 +52,16 @@ CHIP_ERROR DataVersionFilterIB::Parser::CheckSchemaValidity() const uint32_t tagNum = TLV::TagNumFromTag(reader.GetTag()); switch (tagNum) { - case to_underlying(Tag::kPath): - // check if this tag has appeared before - VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kPath))), CHIP_ERROR_INVALID_TLV_TAG); - tagPresenceMask |= (1 << to_underlying(Tag::kPath)); - { - ClusterPathIB::Parser path; - ReturnErrorOnFailure(path.Init(reader)); + case to_underlying(Tag::kPath): { + ClusterPathIB::Parser path; + ReturnErrorOnFailure(path.Init(reader)); - PRETTY_PRINT_INCDEPTH(); - ReturnErrorOnFailure(path.CheckSchemaValidity()); - PRETTY_PRINT_DECDEPTH(); - } - break; + PRETTY_PRINT_INCDEPTH(); + ReturnErrorOnFailure(path.CheckSchemaValidity()); + PRETTY_PRINT_DECDEPTH(); + } + break; case to_underlying(Tag::kDataVersion): - // check if this tag has appeared before - VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kDataVersion))), CHIP_ERROR_INVALID_TLV_TAG); - tagPresenceMask |= (1 << to_underlying(Tag::kDataVersion)); VerifyOrReturnError(TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); #if CHIP_DETAIL_LOGGING @@ -91,14 +83,12 @@ CHIP_ERROR DataVersionFilterIB::Parser::CheckSchemaValidity() const // if we have exhausted this container if (CHIP_END_OF_TLV == err) { - // check for required fields: - const int requiredFields = (1 << to_underlying(Tag::kPath)) | (1 << to_underlying(Tag::kDataVersion)); - err = (tagPresenceMask & requiredFields) == requiredFields ? CHIP_NO_ERROR : CHIP_ERROR_IM_MALFORMED_DATA_VERSION_FILTER_IB; + err = CHIP_NO_ERROR; } ReturnErrorOnFailure(err); return reader.ExitContainer(mOuterContainerType); } -#endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#endif // CHIP_CONFIG_IM_PRETTY_PRINT CHIP_ERROR DataVersionFilterIB::Parser::GetPath(ClusterPathIB::Parser * const apPath) const { diff --git a/src/app/MessageDef/DataVersionFilterIB.h b/src/app/MessageDef/DataVersionFilterIB.h index f59be7c054ccf0..599c856979704d 100644 --- a/src/app/MessageDef/DataVersionFilterIB.h +++ b/src/app/MessageDef/DataVersionFilterIB.h @@ -39,7 +39,7 @@ enum class Tag : uint8_t class Parser : public StructParser { public: -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT /** * @brief Roughly verify the message is correctly formed * 1) all mandatory tags are present diff --git a/src/app/MessageDef/DataVersionFilterIBs.cpp b/src/app/MessageDef/DataVersionFilterIBs.cpp index eb6a18951ef6db..da63c0f9cf7157 100644 --- a/src/app/MessageDef/DataVersionFilterIBs.cpp +++ b/src/app/MessageDef/DataVersionFilterIBs.cpp @@ -26,7 +26,7 @@ namespace chip { namespace app { -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT CHIP_ERROR DataVersionFilterIBs::Parser::CheckSchemaValidity() const { CHIP_ERROR err = CHIP_NO_ERROR; @@ -61,7 +61,7 @@ CHIP_ERROR DataVersionFilterIBs::Parser::CheckSchemaValidity() const ReturnErrorOnFailure(err); return reader.ExitContainer(mOuterContainerType); } -#endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#endif // CHIP_CONFIG_IM_PRETTY_PRINT DataVersionFilterIB::Builder & DataVersionFilterIBs::Builder::CreateDataVersionFilter() { diff --git a/src/app/MessageDef/DataVersionFilterIBs.h b/src/app/MessageDef/DataVersionFilterIBs.h index 8c7ae021f6899f..65dff0f6002acd 100644 --- a/src/app/MessageDef/DataVersionFilterIBs.h +++ b/src/app/MessageDef/DataVersionFilterIBs.h @@ -34,7 +34,7 @@ namespace DataVersionFilterIBs { class Parser : public ArrayParser { public: -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT /** * @brief Roughly verify the message is correctly formed * 1) all mandatory tags are present diff --git a/src/app/MessageDef/EventDataIB.cpp b/src/app/MessageDef/EventDataIB.cpp index cd70cb4f38bda4..07bab66059ca3b 100644 --- a/src/app/MessageDef/EventDataIB.cpp +++ b/src/app/MessageDef/EventDataIB.cpp @@ -34,11 +34,10 @@ namespace chip { namespace app { -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT CHIP_ERROR EventDataIB::Parser::CheckSchemaValidity() const { - CHIP_ERROR err = CHIP_NO_ERROR; - int tagPresenceMask = 0; + CHIP_ERROR err = CHIP_NO_ERROR; TLV::TLVReader reader; PRETTY_PRINT("EventDataIB ="); @@ -56,23 +55,16 @@ CHIP_ERROR EventDataIB::Parser::CheckSchemaValidity() const uint32_t tagNum = TLV::TagNumFromTag(reader.GetTag()); switch (tagNum) { - case to_underlying(Tag::kPath): - // check if this tag has appeared before - VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kPath))), CHIP_ERROR_INVALID_TLV_TAG); - tagPresenceMask |= (1 << to_underlying(Tag::kPath)); - { - EventPathIB::Parser path; - ReturnErrorOnFailure(path.Init(reader)); + case to_underlying(Tag::kPath): { + EventPathIB::Parser path; + ReturnErrorOnFailure(path.Init(reader)); - PRETTY_PRINT_INCDEPTH(); - ReturnErrorOnFailure(path.CheckSchemaValidity()); - PRETTY_PRINT_DECDEPTH(); - } - break; + PRETTY_PRINT_INCDEPTH(); + ReturnErrorOnFailure(path.CheckSchemaValidity()); + PRETTY_PRINT_DECDEPTH(); + } + break; case to_underlying(Tag::kEventNumber): - // check if this tag has appeared before - VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kEventNumber))), CHIP_ERROR_INVALID_TLV_TAG); - tagPresenceMask |= (1 << to_underlying(Tag::kEventNumber)); VerifyOrReturnError(TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); #if CHIP_DETAIL_LOGGING @@ -84,9 +76,6 @@ CHIP_ERROR EventDataIB::Parser::CheckSchemaValidity() const #endif // CHIP_DETAIL_LOGGING break; case to_underlying(Tag::kPriority): - // check if this tag has appeared before - VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kPriority))), CHIP_ERROR_INVALID_TLV_TAG); - tagPresenceMask |= (1 << to_underlying(Tag::kPriority)); VerifyOrReturnError(TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); #if CHIP_DETAIL_LOGGING @@ -98,10 +87,6 @@ CHIP_ERROR EventDataIB::Parser::CheckSchemaValidity() const #endif // CHIP_DETAIL_LOGGING break; case to_underlying(Tag::kEpochTimestamp): - // check if this tag has appeared before - VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kEpochTimestamp))), CHIP_ERROR_INVALID_TLV_TAG); - tagPresenceMask |= (1 << to_underlying(Tag::kEpochTimestamp)); - VerifyOrReturnError(TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); #if CHIP_DETAIL_LOGGING @@ -114,10 +99,6 @@ CHIP_ERROR EventDataIB::Parser::CheckSchemaValidity() const break; case to_underlying(Tag::kSystemTimestamp): - // check if this tag has appeared before - VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kSystemTimestamp))), CHIP_ERROR_INVALID_TLV_TAG); - tagPresenceMask |= (1 << to_underlying(Tag::kSystemTimestamp)); - VerifyOrReturnError(TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); #if CHIP_DETAIL_LOGGING @@ -129,9 +110,6 @@ CHIP_ERROR EventDataIB::Parser::CheckSchemaValidity() const #endif // CHIP_DETAIL_LOGGING break; case to_underlying(Tag::kDeltaEpochTimestamp): - // check if this tag has appeared before - VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kDeltaEpochTimestamp))), CHIP_ERROR_INVALID_TLV_TAG); - tagPresenceMask |= (1 << to_underlying(Tag::kDeltaEpochTimestamp)); VerifyOrReturnError(TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); #if CHIP_DETAIL_LOGGING @@ -143,10 +121,6 @@ CHIP_ERROR EventDataIB::Parser::CheckSchemaValidity() const #endif // CHIP_DETAIL_LOGGING break; case to_underlying(Tag::kDeltaSystemTimestamp): - // check if this tag has appeared before - VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kDeltaSystemTimestamp))), CHIP_ERROR_INVALID_TLV_TAG); - tagPresenceMask |= (1 << to_underlying(Tag::kDeltaSystemTimestamp)); - VerifyOrReturnError(TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); #if CHIP_DETAIL_LOGGING @@ -158,10 +132,6 @@ CHIP_ERROR EventDataIB::Parser::CheckSchemaValidity() const #endif // CHIP_DETAIL_LOGGING break; case to_underlying(Tag::kData): - // check if this tag has appeared before - VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kData))), CHIP_ERROR_INVALID_TLV_TAG); - tagPresenceMask |= (1 << to_underlying(Tag::kData)); - PRETTY_PRINT_INCDEPTH(); ReturnErrorOnFailure(CheckIMPayload(reader, 0, "EventData")); PRETTY_PRINT_DECDEPTH(); @@ -177,15 +147,12 @@ CHIP_ERROR EventDataIB::Parser::CheckSchemaValidity() const // if we have exhausted this container if (CHIP_END_OF_TLV == err) { - // check for required fields: - const int requiredFields = - (1 << to_underlying(Tag::kPath)) | (1 << to_underlying(Tag::kPriority)) | (1 << to_underlying(Tag::kData)); - err = (tagPresenceMask & requiredFields) == requiredFields ? CHIP_NO_ERROR : CHIP_ERROR_IM_MALFORMED_EVENT_DATA_IB; + err = CHIP_NO_ERROR; } ReturnErrorOnFailure(err); return reader.ExitContainer(mOuterContainerType); } -#endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#endif // CHIP_CONFIG_IM_PRETTY_PRINT CHIP_ERROR EventDataIB::Parser::GetPath(EventPathIB::Parser * const apPath) { diff --git a/src/app/MessageDef/EventDataIB.h b/src/app/MessageDef/EventDataIB.h index ca5f277bc20e4a..823fe9e3d47381 100644 --- a/src/app/MessageDef/EventDataIB.h +++ b/src/app/MessageDef/EventDataIB.h @@ -53,7 +53,7 @@ enum class Tag : uint8_t class Parser : public StructParser { public: -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT /** * @brief Roughly verify the message is correctly formed * 1) all mandatory tags are present diff --git a/src/app/MessageDef/EventFilterIB.cpp b/src/app/MessageDef/EventFilterIB.cpp index 9264c1d87d6f31..4716a60a199cd2 100644 --- a/src/app/MessageDef/EventFilterIB.cpp +++ b/src/app/MessageDef/EventFilterIB.cpp @@ -31,11 +31,10 @@ namespace chip { namespace app { -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT CHIP_ERROR EventFilterIB::Parser::CheckSchemaValidity() const { - CHIP_ERROR err = CHIP_NO_ERROR; - int tagPresenceMask = 0; + CHIP_ERROR err = CHIP_NO_ERROR; TLV::TLVReader reader; PRETTY_PRINT("EventFilterIB ="); @@ -54,29 +53,23 @@ CHIP_ERROR EventFilterIB::Parser::CheckSchemaValidity() const switch (tagNum) { case to_underlying(Tag::kNode): - // check if this tag has appeared before - VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kNode))), CHIP_ERROR_INVALID_TLV_TAG); - tagPresenceMask |= (1 << to_underlying(Tag::kNode)); #if CHIP_DETAIL_LOGGING - { - NodeId node; - ReturnErrorOnFailure(reader.Get(node)); - PRETTY_PRINT("\tNode = 0x%" PRIx64 ",", node); - } + { + NodeId node; + ReturnErrorOnFailure(reader.Get(node)); + PRETTY_PRINT("\tNode = 0x%" PRIx64 ",", node); + } #endif // CHIP_DETAIL_LOGGING - break; + break; case to_underlying(Tag::kEventMin): - // check if this tag has appeared before - VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kEventMin))), CHIP_ERROR_INVALID_TLV_TAG); - tagPresenceMask |= (1 << to_underlying(Tag::kEventMin)); #if CHIP_DETAIL_LOGGING - { - uint64_t eventMin; - ReturnErrorOnFailure(reader.Get(eventMin)); - PRETTY_PRINT("\tEventMin = 0x%" PRIx64 ",", eventMin); - } + { + uint64_t eventMin; + ReturnErrorOnFailure(reader.Get(eventMin)); + PRETTY_PRINT("\tEventMin = 0x%" PRIx64 ",", eventMin); + } #endif // CHIP_DETAIL_LOGGING - break; + break; default: PRETTY_PRINT("Unknown tag num %" PRIu32, tagNum); break; @@ -88,14 +81,13 @@ CHIP_ERROR EventFilterIB::Parser::CheckSchemaValidity() const if (CHIP_END_OF_TLV == err) { - const int requiredFields = (1 << to_underlying(Tag::kEventMin)); - err = (tagPresenceMask & requiredFields) == requiredFields ? CHIP_NO_ERROR : CHIP_ERROR_IM_MALFORMED_EVENT_FILTER_IB; + err = CHIP_NO_ERROR; } ReturnErrorOnFailure(err); return reader.ExitContainer(mOuterContainerType); } -#endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#endif // CHIP_CONFIG_IM_PRETTY_PRINT CHIP_ERROR EventFilterIB::Parser::GetNode(NodeId * const apNode) const { diff --git a/src/app/MessageDef/EventFilterIB.h b/src/app/MessageDef/EventFilterIB.h index 518b20a301761f..5dfff8cd8447f7 100644 --- a/src/app/MessageDef/EventFilterIB.h +++ b/src/app/MessageDef/EventFilterIB.h @@ -45,7 +45,7 @@ enum class Tag : uint8_t class Parser : public StructParser { public: -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT /** * @brief Roughly verify the message is correctly formed * 1) all mandatory tags are present diff --git a/src/app/MessageDef/EventFilterIBs.cpp b/src/app/MessageDef/EventFilterIBs.cpp index 66023c856fa126..b101c866de9b45 100644 --- a/src/app/MessageDef/EventFilterIBs.cpp +++ b/src/app/MessageDef/EventFilterIBs.cpp @@ -26,7 +26,7 @@ namespace chip { namespace app { -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT CHIP_ERROR EventFilterIBs::Parser::CheckSchemaValidity() const { CHIP_ERROR err = CHIP_NO_ERROR; @@ -61,7 +61,7 @@ CHIP_ERROR EventFilterIBs::Parser::CheckSchemaValidity() const ReturnErrorOnFailure(err); return reader.ExitContainer(mOuterContainerType); } -#endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#endif // CHIP_CONFIG_IM_PRETTY_PRINT EventFilterIB::Builder & EventFilterIBs::Builder::CreateEventFilter() { diff --git a/src/app/MessageDef/EventFilterIBs.h b/src/app/MessageDef/EventFilterIBs.h index f480d3d26c612d..935a2217ec7db1 100644 --- a/src/app/MessageDef/EventFilterIBs.h +++ b/src/app/MessageDef/EventFilterIBs.h @@ -34,7 +34,7 @@ namespace EventFilterIBs { class Parser : public ArrayParser { public: -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT /** * @brief Roughly verify the message is correctly formed * 1) all mandatory tags are present diff --git a/src/app/MessageDef/EventPathIB.cpp b/src/app/MessageDef/EventPathIB.cpp index 84c9f6680bf260..699d0b4845872f 100644 --- a/src/app/MessageDef/EventPathIB.cpp +++ b/src/app/MessageDef/EventPathIB.cpp @@ -30,11 +30,10 @@ namespace chip { namespace app { -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT CHIP_ERROR EventPathIB::Parser::CheckSchemaValidity() const { - CHIP_ERROR err = CHIP_NO_ERROR; - int tagPresenceMask = 0; + CHIP_ERROR err = CHIP_NO_ERROR; TLV::TLVReader reader; PRETTY_PRINT("EventPath ="); @@ -53,9 +52,6 @@ CHIP_ERROR EventPathIB::Parser::CheckSchemaValidity() const switch (tagNum) { case to_underlying(Tag::kNode): - // check if this tag has appeared before - VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kNode))), CHIP_ERROR_INVALID_TLV_TAG); - tagPresenceMask |= (1 << to_underlying(Tag::kNode)); VerifyOrReturnError(TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); #if CHIP_DETAIL_LOGGING { @@ -66,9 +62,6 @@ CHIP_ERROR EventPathIB::Parser::CheckSchemaValidity() const #endif // CHIP_DETAIL_LOGGING break; case to_underlying(Tag::kEndpoint): - // check if this tag has appeared before - VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kEndpoint))), CHIP_ERROR_INVALID_TLV_TAG); - tagPresenceMask |= (1 << to_underlying(Tag::kEndpoint)); VerifyOrReturnError(TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); #if CHIP_DETAIL_LOGGING { @@ -79,9 +72,6 @@ CHIP_ERROR EventPathIB::Parser::CheckSchemaValidity() const #endif // CHIP_DETAIL_LOGGING break; case to_underlying(Tag::kCluster): - // check if this tag has appeared before - VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kCluster))), CHIP_ERROR_INVALID_TLV_TAG); - tagPresenceMask |= (1 << to_underlying(Tag::kCluster)); VerifyOrReturnError(TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); #if CHIP_DETAIL_LOGGING @@ -93,9 +83,6 @@ CHIP_ERROR EventPathIB::Parser::CheckSchemaValidity() const #endif // CHIP_DETAIL_LOGGING break; case to_underlying(Tag::kEvent): - // check if this tag has appeared before - VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kEvent))), CHIP_ERROR_INVALID_TLV_TAG); - tagPresenceMask |= (1 << to_underlying(Tag::kEvent)); VerifyOrReturnError(TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); #if CHIP_DETAIL_LOGGING @@ -107,9 +94,6 @@ CHIP_ERROR EventPathIB::Parser::CheckSchemaValidity() const #endif // CHIP_DETAIL_LOGGING break; case to_underlying(Tag::kIsUrgent): - // check if this tag has appeared before - VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kIsUrgent))), CHIP_ERROR_INVALID_TLV_TAG); - tagPresenceMask |= (1 << to_underlying(Tag::kIsUrgent)); VerifyOrReturnError(TLV::kTLVType_Boolean == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); #if CHIP_DETAIL_LOGGING @@ -138,7 +122,7 @@ CHIP_ERROR EventPathIB::Parser::CheckSchemaValidity() const ReturnErrorOnFailure(err); return reader.ExitContainer(mOuterContainerType); } -#endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#endif // CHIP_CONFIG_IM_PRETTY_PRINT CHIP_ERROR EventPathIB::Parser::GetNode(NodeId * const apNode) const { diff --git a/src/app/MessageDef/EventPathIB.h b/src/app/MessageDef/EventPathIB.h index 0ad2000938ac86..92c589b2e46643 100644 --- a/src/app/MessageDef/EventPathIB.h +++ b/src/app/MessageDef/EventPathIB.h @@ -46,7 +46,7 @@ enum class Tag : uint8_t class Parser : public ListParser { public: -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT /** * @brief Roughly verify the message is correctly formed * 1) all mandatory tags are present diff --git a/src/app/MessageDef/EventPathIBs.cpp b/src/app/MessageDef/EventPathIBs.cpp index 673141fcd8e1a1..de50104dafc28a 100644 --- a/src/app/MessageDef/EventPathIBs.cpp +++ b/src/app/MessageDef/EventPathIBs.cpp @@ -28,7 +28,7 @@ namespace chip { namespace app { -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT CHIP_ERROR EventPathIBs::Parser::CheckSchemaValidity() const { CHIP_ERROR err = CHIP_NO_ERROR; @@ -69,7 +69,7 @@ CHIP_ERROR EventPathIBs::Parser::CheckSchemaValidity() const ReturnErrorOnFailure(err); return reader.ExitContainer(mOuterContainerType); } -#endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#endif // CHIP_CONFIG_IM_PRETTY_PRINT EventPathIB::Builder & EventPathIBs::Builder::CreatePath() { diff --git a/src/app/MessageDef/EventPathIBs.h b/src/app/MessageDef/EventPathIBs.h index 14a909a91b5a4d..479e3037772905 100644 --- a/src/app/MessageDef/EventPathIBs.h +++ b/src/app/MessageDef/EventPathIBs.h @@ -36,7 +36,7 @@ namespace EventPathIBs { class Parser : public ArrayParser { public: -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT /** * @brief Roughly verify the message is correctly formed * 1) all mandatory tags are present diff --git a/src/app/MessageDef/EventReportIB.cpp b/src/app/MessageDef/EventReportIB.cpp index c9eaec4d98f85d..40ea290fbd41a6 100644 --- a/src/app/MessageDef/EventReportIB.cpp +++ b/src/app/MessageDef/EventReportIB.cpp @@ -28,11 +28,10 @@ namespace chip { namespace app { -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT CHIP_ERROR EventReportIB::Parser::CheckSchemaValidity() const { - CHIP_ERROR err = CHIP_NO_ERROR; - int tagPresenceMask = 0; + CHIP_ERROR err = CHIP_NO_ERROR; TLV::TLVReader reader; PRETTY_PRINT("EventReportIB ="); @@ -50,32 +49,24 @@ CHIP_ERROR EventReportIB::Parser::CheckSchemaValidity() const uint32_t tagNum = TLV::TagNumFromTag(reader.GetTag()); switch (tagNum) { - case to_underlying(Tag::kEventStatus): - // check if this tag has appeared before - VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kEventStatus))), CHIP_ERROR_INVALID_TLV_TAG); - tagPresenceMask |= (1 << to_underlying(Tag::kEventStatus)); - { - EventStatusIB::Parser eventStatus; - ReturnErrorOnFailure(eventStatus.Init(reader)); - - PRETTY_PRINT_INCDEPTH(); - ReturnErrorOnFailure(eventStatus.CheckSchemaValidity()); - PRETTY_PRINT_DECDEPTH(); - } - break; - case to_underlying(Tag::kEventData): - // check if this tag has appeared before - VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kEventData))), CHIP_ERROR_INVALID_TLV_TAG); - tagPresenceMask |= (1 << to_underlying(Tag::kEventData)); - { - EventDataIB::Parser eventData; - ReturnErrorOnFailure(eventData.Init(reader)); - - PRETTY_PRINT_INCDEPTH(); - ReturnErrorOnFailure(eventData.CheckSchemaValidity()); - PRETTY_PRINT_DECDEPTH(); - } - break; + case to_underlying(Tag::kEventStatus): { + EventStatusIB::Parser eventStatus; + ReturnErrorOnFailure(eventStatus.Init(reader)); + + PRETTY_PRINT_INCDEPTH(); + ReturnErrorOnFailure(eventStatus.CheckSchemaValidity()); + PRETTY_PRINT_DECDEPTH(); + } + break; + case to_underlying(Tag::kEventData): { + EventDataIB::Parser eventData; + ReturnErrorOnFailure(eventData.Init(reader)); + + PRETTY_PRINT_INCDEPTH(); + ReturnErrorOnFailure(eventData.CheckSchemaValidity()); + PRETTY_PRINT_DECDEPTH(); + } + break; default: PRETTY_PRINT("Unknown tag num %" PRIu32, tagNum); break; @@ -87,30 +78,13 @@ CHIP_ERROR EventReportIB::Parser::CheckSchemaValidity() const if (CHIP_END_OF_TLV == err) { - // check for at most field: - const int CheckDataField = 1 << to_underlying(Tag::kEventData); - const int CheckStatusField = (1 << to_underlying(Tag::kEventStatus)); - - if ((tagPresenceMask & CheckDataField) == CheckDataField && (tagPresenceMask & CheckStatusField) == CheckStatusField) - { - // kEventData and kEventStatus both exist - err = CHIP_ERROR_IM_MALFORMED_EVENT_REPORT_IB; - } - else if ((tagPresenceMask & CheckDataField) != CheckDataField && (tagPresenceMask & CheckStatusField) != CheckStatusField) - { - // kEventData and kErrorStatus not exist - err = CHIP_ERROR_IM_MALFORMED_EVENT_REPORT_IB; - } - else - { - err = CHIP_NO_ERROR; - } + err = CHIP_NO_ERROR; } ReturnErrorOnFailure(err); return reader.ExitContainer(mOuterContainerType); } -#endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#endif // CHIP_CONFIG_IM_PRETTY_PRINT CHIP_ERROR EventReportIB::Parser::GetEventStatus(EventStatusIB::Parser * const apEventStatus) const { diff --git a/src/app/MessageDef/EventReportIB.h b/src/app/MessageDef/EventReportIB.h index ee2a49d6c38e63..3db138da39fbf3 100644 --- a/src/app/MessageDef/EventReportIB.h +++ b/src/app/MessageDef/EventReportIB.h @@ -41,7 +41,7 @@ enum class Tag : uint8_t class Parser : public StructParser { public: -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT /** * @brief Roughly verify the message is correctly formed * 1) all mandatory tags are present diff --git a/src/app/MessageDef/EventReportIBs.cpp b/src/app/MessageDef/EventReportIBs.cpp index 2a4099a0e09a62..13a940b6fa4ef7 100644 --- a/src/app/MessageDef/EventReportIBs.cpp +++ b/src/app/MessageDef/EventReportIBs.cpp @@ -32,7 +32,7 @@ namespace chip { namespace app { -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT CHIP_ERROR EventReportIBs::Parser::CheckSchemaValidity() const { CHIP_ERROR err = CHIP_NO_ERROR; @@ -67,7 +67,7 @@ CHIP_ERROR EventReportIBs::Parser::CheckSchemaValidity() const ReturnErrorOnFailure(err); return reader.ExitContainer(mOuterContainerType); } -#endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#endif // CHIP_CONFIG_IM_PRETTY_PRINT EventReportIB::Builder & EventReportIBs::Builder::CreateEventReport() { diff --git a/src/app/MessageDef/EventReportIBs.h b/src/app/MessageDef/EventReportIBs.h index d7a25c71ede439..01c97a4cd9350e 100644 --- a/src/app/MessageDef/EventReportIBs.h +++ b/src/app/MessageDef/EventReportIBs.h @@ -40,7 +40,7 @@ namespace EventReportIBs { class Parser : public ArrayParser { public: -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT /** * @brief Roughly verify the message is correctly formed * 1) all mandatory tags are present diff --git a/src/app/MessageDef/EventStatusIB.cpp b/src/app/MessageDef/EventStatusIB.cpp index dd8c5f4b9f671b..23298f81b43358 100644 --- a/src/app/MessageDef/EventStatusIB.cpp +++ b/src/app/MessageDef/EventStatusIB.cpp @@ -27,11 +27,10 @@ namespace chip { namespace app { -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT CHIP_ERROR EventStatusIB::Parser::CheckSchemaValidity() const { - CHIP_ERROR err = CHIP_NO_ERROR; - int tagPresenceMask = 0; + CHIP_ERROR err = CHIP_NO_ERROR; TLV::TLVReader reader; PRETTY_PRINT("EventStatusIB ="); @@ -49,32 +48,24 @@ CHIP_ERROR EventStatusIB::Parser::CheckSchemaValidity() const uint32_t tagNum = TLV::TagNumFromTag(reader.GetTag()); switch (tagNum) { - case to_underlying(Tag::kPath): - // check if this tag has appeared before - VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kPath))), CHIP_ERROR_INVALID_TLV_TAG); - tagPresenceMask |= (1 << to_underlying(Tag::kPath)); - { - EventPathIB::Parser path; - ReturnErrorOnFailure(path.Init(reader)); - - PRETTY_PRINT_INCDEPTH(); - ReturnErrorOnFailure(path.CheckSchemaValidity()); - PRETTY_PRINT_DECDEPTH(); - } - break; - case to_underlying(Tag::kErrorStatus): - // check if this tag has appeared before - VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kErrorStatus))), CHIP_ERROR_INVALID_TLV_TAG); - tagPresenceMask |= (1 << to_underlying(Tag::kErrorStatus)); - { - StatusIB::Parser errorStatus; - ReturnErrorOnFailure(errorStatus.Init(reader)); - - PRETTY_PRINT_INCDEPTH(); - ReturnErrorOnFailure(errorStatus.CheckSchemaValidity()); - PRETTY_PRINT_DECDEPTH(); - } - break; + case to_underlying(Tag::kPath): { + EventPathIB::Parser path; + ReturnErrorOnFailure(path.Init(reader)); + + PRETTY_PRINT_INCDEPTH(); + ReturnErrorOnFailure(path.CheckSchemaValidity()); + PRETTY_PRINT_DECDEPTH(); + } + break; + case to_underlying(Tag::kErrorStatus): { + StatusIB::Parser errorStatus; + ReturnErrorOnFailure(errorStatus.Init(reader)); + + PRETTY_PRINT_INCDEPTH(); + ReturnErrorOnFailure(errorStatus.CheckSchemaValidity()); + PRETTY_PRINT_DECDEPTH(); + } + break; default: PRETTY_PRINT("Unknown tag num %" PRIu32, tagNum); break; @@ -86,14 +77,13 @@ CHIP_ERROR EventStatusIB::Parser::CheckSchemaValidity() const if (CHIP_END_OF_TLV == err) { - const int requiredFields = (1 << to_underlying(Tag::kPath)) | (1 << to_underlying(Tag::kErrorStatus)); - err = (tagPresenceMask & requiredFields) == requiredFields ? CHIP_NO_ERROR : CHIP_ERROR_IM_MALFORMED_EVENT_STATUS_IB; + err = CHIP_NO_ERROR; } ReturnErrorOnFailure(err); return reader.ExitContainer(mOuterContainerType); } -#endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#endif // CHIP_CONFIG_IM_PRETTY_PRINT CHIP_ERROR EventStatusIB::Parser::GetPath(EventPathIB::Parser * const apPath) const { diff --git a/src/app/MessageDef/EventStatusIB.h b/src/app/MessageDef/EventStatusIB.h index f51eae5e156d69..34c5025f760ac9 100644 --- a/src/app/MessageDef/EventStatusIB.h +++ b/src/app/MessageDef/EventStatusIB.h @@ -41,7 +41,7 @@ enum class Tag : uint8_t class Parser : public StructParser { public: -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT /** * @brief Roughly verify the message is correctly formed * 1) all mandatory tags are present diff --git a/src/app/MessageDef/InvokeRequestMessage.cpp b/src/app/MessageDef/InvokeRequestMessage.cpp index 13d54fc6fdabc9..07c4f290782705 100644 --- a/src/app/MessageDef/InvokeRequestMessage.cpp +++ b/src/app/MessageDef/InvokeRequestMessage.cpp @@ -25,11 +25,10 @@ namespace chip { namespace app { -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT CHIP_ERROR InvokeRequestMessage::Parser::CheckSchemaValidity() const { - CHIP_ERROR err = CHIP_NO_ERROR; - int tagPresenceMask = 0; + CHIP_ERROR err = CHIP_NO_ERROR; TLV::TLVReader reader; PRETTY_PRINT("InvokeRequestMessage ="); @@ -48,43 +47,33 @@ CHIP_ERROR InvokeRequestMessage::Parser::CheckSchemaValidity() const switch (tagNum) { case to_underlying(Tag::kSuppressResponse): - // check if this tag has appeared before - VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kSuppressResponse))), CHIP_ERROR_INVALID_TLV_TAG); - tagPresenceMask |= (1 << to_underlying(Tag::kSuppressResponse)); #if CHIP_DETAIL_LOGGING - { - bool suppressResponse; - ReturnErrorOnFailure(reader.Get(suppressResponse)); - PRETTY_PRINT("\tsuppressResponse = %s, ", suppressResponse ? "true" : "false"); - } + { + bool suppressResponse; + ReturnErrorOnFailure(reader.Get(suppressResponse)); + PRETTY_PRINT("\tsuppressResponse = %s, ", suppressResponse ? "true" : "false"); + } #endif // CHIP_DETAIL_LOGGING - break; + break; case to_underlying(Tag::kTimedRequest): - // check if this tag has appeared before - VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kTimedRequest))), CHIP_ERROR_INVALID_TLV_TAG); - tagPresenceMask |= (1 << to_underlying(Tag::kTimedRequest)); #if CHIP_DETAIL_LOGGING - { - bool timedRequest; - ReturnErrorOnFailure(reader.Get(timedRequest)); - PRETTY_PRINT("\ttimedRequest = %s, ", timedRequest ? "true" : "false"); - } + { + bool timedRequest; + ReturnErrorOnFailure(reader.Get(timedRequest)); + PRETTY_PRINT("\ttimedRequest = %s, ", timedRequest ? "true" : "false"); + } #endif // CHIP_DETAIL_LOGGING - break; - case to_underlying(Tag::kInvokeRequests): - // check if this tag has appeared before - VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kInvokeRequests))), CHIP_ERROR_INVALID_TLV_TAG); - tagPresenceMask |= (1 << to_underlying(Tag::kInvokeRequests)); - { - InvokeRequests::Parser invokeRequests; - ReturnErrorOnFailure(invokeRequests.Init(reader)); - - PRETTY_PRINT_INCDEPTH(); - ReturnErrorOnFailure(invokeRequests.CheckSchemaValidity()); - PRETTY_PRINT_DECDEPTH(); - } - break; + break; + case to_underlying(Tag::kInvokeRequests): { + InvokeRequests::Parser invokeRequests; + ReturnErrorOnFailure(invokeRequests.Init(reader)); + + PRETTY_PRINT_INCDEPTH(); + ReturnErrorOnFailure(invokeRequests.CheckSchemaValidity()); + PRETTY_PRINT_DECDEPTH(); + } + break; case kInteractionModelRevisionTag: ReturnErrorOnFailure(MessageParser::CheckInteractionModelRevision(reader)); break; @@ -99,15 +88,13 @@ CHIP_ERROR InvokeRequestMessage::Parser::CheckSchemaValidity() const if (CHIP_END_OF_TLV == err) { - const int requiredFields = (1 << to_underlying(Tag::kSuppressResponse)) | (1 << to_underlying(Tag::kTimedRequest)) | - (1 << to_underlying(Tag::kInvokeRequests)); - err = (tagPresenceMask & requiredFields) == requiredFields ? CHIP_NO_ERROR : CHIP_ERROR_IM_MALFORMED_INVOKE_REQUEST_MESSAGE; + err = CHIP_NO_ERROR; } ReturnErrorOnFailure(err); return reader.ExitContainer(mOuterContainerType); } -#endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#endif // CHIP_CONFIG_IM_PRETTY_PRINT CHIP_ERROR InvokeRequestMessage::Parser::GetSuppressResponse(bool * const apSuppressResponse) const { diff --git a/src/app/MessageDef/InvokeRequestMessage.h b/src/app/MessageDef/InvokeRequestMessage.h index 9cfd13ac89c86b..1094b2336069d6 100644 --- a/src/app/MessageDef/InvokeRequestMessage.h +++ b/src/app/MessageDef/InvokeRequestMessage.h @@ -41,7 +41,7 @@ enum class Tag : uint8_t class Parser : public MessageParser { public: -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT /** * @brief Roughly verify the message is correctly formed * 1) all mandatory tags are present diff --git a/src/app/MessageDef/InvokeRequests.cpp b/src/app/MessageDef/InvokeRequests.cpp index 5d140a6589c2ec..e0555082c5a380 100644 --- a/src/app/MessageDef/InvokeRequests.cpp +++ b/src/app/MessageDef/InvokeRequests.cpp @@ -26,7 +26,7 @@ namespace chip { namespace app { -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT CHIP_ERROR InvokeRequests::Parser::CheckSchemaValidity() const { CHIP_ERROR err = CHIP_NO_ERROR; @@ -68,7 +68,7 @@ CHIP_ERROR InvokeRequests::Parser::CheckSchemaValidity() const ReturnErrorOnFailure(err); return reader.ExitContainer(mOuterContainerType); } -#endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#endif // CHIP_CONFIG_IM_PRETTY_PRINT CommandDataIB::Builder & InvokeRequests::Builder::CreateCommandData() { diff --git a/src/app/MessageDef/InvokeRequests.h b/src/app/MessageDef/InvokeRequests.h index e81be842b1b530..b07336f9976a49 100644 --- a/src/app/MessageDef/InvokeRequests.h +++ b/src/app/MessageDef/InvokeRequests.h @@ -34,7 +34,7 @@ namespace InvokeRequests { class Parser : public ArrayParser { public: -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT /** * @brief Roughly verify the message is correctly formed * 1) all mandatory tags are present diff --git a/src/app/MessageDef/InvokeResponseIB.cpp b/src/app/MessageDef/InvokeResponseIB.cpp index 1fbae7a7139c15..7bdc03d7a19bf0 100644 --- a/src/app/MessageDef/InvokeResponseIB.cpp +++ b/src/app/MessageDef/InvokeResponseIB.cpp @@ -25,11 +25,10 @@ namespace chip { namespace app { -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT CHIP_ERROR InvokeResponseIB::Parser::CheckSchemaValidity() const { - CHIP_ERROR err = CHIP_NO_ERROR; - int tagPresenceMask = 0; + CHIP_ERROR err = CHIP_NO_ERROR; TLV::TLVReader reader; PRETTY_PRINT("InvokeResponseIB ="); @@ -47,32 +46,24 @@ CHIP_ERROR InvokeResponseIB::Parser::CheckSchemaValidity() const uint32_t tagNum = TLV::TagNumFromTag(reader.GetTag()); switch (tagNum) { - case to_underlying(Tag::kCommand): - // check if this tag has appeared before - VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kCommand))), CHIP_ERROR_INVALID_TLV_TAG); - tagPresenceMask |= (1 << to_underlying(Tag::kCommand)); - { - CommandDataIB::Parser command; - ReturnErrorOnFailure(command.Init(reader)); - - PRETTY_PRINT_INCDEPTH(); - ReturnErrorOnFailure(command.CheckSchemaValidity()); - PRETTY_PRINT_DECDEPTH(); - } - break; - case to_underlying(Tag::kStatus): - // check if this tag has appeared before - VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kStatus))), CHIP_ERROR_INVALID_TLV_TAG); - tagPresenceMask |= (1 << to_underlying(Tag::kStatus)); - { - CommandStatusIB::Parser status; - ReturnErrorOnFailure(status.Init(reader)); - - PRETTY_PRINT_INCDEPTH(); - ReturnErrorOnFailure(status.CheckSchemaValidity()); - PRETTY_PRINT_DECDEPTH(); - } - break; + case to_underlying(Tag::kCommand): { + CommandDataIB::Parser command; + ReturnErrorOnFailure(command.Init(reader)); + + PRETTY_PRINT_INCDEPTH(); + ReturnErrorOnFailure(command.CheckSchemaValidity()); + PRETTY_PRINT_DECDEPTH(); + } + break; + case to_underlying(Tag::kStatus): { + CommandStatusIB::Parser status; + ReturnErrorOnFailure(status.Init(reader)); + + PRETTY_PRINT_INCDEPTH(); + ReturnErrorOnFailure(status.CheckSchemaValidity()); + PRETTY_PRINT_DECDEPTH(); + } + break; default: PRETTY_PRINT("Unknown tag num %" PRIu32, tagNum); break; @@ -85,30 +76,12 @@ CHIP_ERROR InvokeResponseIB::Parser::CheckSchemaValidity() const // if we have exhausted this container if (CHIP_END_OF_TLV == err) { - // check for at most field: - const int CheckCommandField = 1 << to_underlying(Tag::kCommand); - const int CheckStatusField = (1 << to_underlying(Tag::kStatus)); - - if ((tagPresenceMask & CheckCommandField) == CheckCommandField && (tagPresenceMask & CheckStatusField) == CheckStatusField) - { - // kPath and kErrorStatus both exist - err = CHIP_ERROR_IM_MALFORMED_INVOKE_RESPONSE_IB; - } - else if ((tagPresenceMask & CheckCommandField) != CheckCommandField && - (tagPresenceMask & CheckStatusField) != CheckStatusField) - { - // kPath and kErrorStatus not exist - err = CHIP_ERROR_IM_MALFORMED_INVOKE_RESPONSE_IB; - } - else - { - err = CHIP_NO_ERROR; - } + err = CHIP_NO_ERROR; } ReturnErrorOnFailure(err); return reader.ExitContainer(mOuterContainerType); } -#endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#endif // CHIP_CONFIG_IM_PRETTY_PRINT CHIP_ERROR InvokeResponseIB::Parser::GetCommand(CommandDataIB::Parser * const apCommand) const { diff --git a/src/app/MessageDef/InvokeResponseIB.h b/src/app/MessageDef/InvokeResponseIB.h index 83e935ce6cfc07..2cc592bf48bb81 100644 --- a/src/app/MessageDef/InvokeResponseIB.h +++ b/src/app/MessageDef/InvokeResponseIB.h @@ -41,7 +41,7 @@ enum class Tag : uint8_t class Parser : public StructParser { public: -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT /** * @brief Roughly verify the message is correctly formed * 1) all mandatory tags are present diff --git a/src/app/MessageDef/InvokeResponseIBs.cpp b/src/app/MessageDef/InvokeResponseIBs.cpp index 6ea80a27fd4b00..79ea00345c76a4 100644 --- a/src/app/MessageDef/InvokeResponseIBs.cpp +++ b/src/app/MessageDef/InvokeResponseIBs.cpp @@ -26,7 +26,7 @@ namespace chip { namespace app { -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT CHIP_ERROR InvokeResponseIBs::Parser::CheckSchemaValidity() const { CHIP_ERROR err = CHIP_NO_ERROR; @@ -68,7 +68,7 @@ CHIP_ERROR InvokeResponseIBs::Parser::CheckSchemaValidity() const ReturnErrorOnFailure(err); return reader.ExitContainer(mOuterContainerType); } -#endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#endif // CHIP_CONFIG_IM_PRETTY_PRINT InvokeResponseIB::Builder & InvokeResponseIBs::Builder::CreateInvokeResponse() { diff --git a/src/app/MessageDef/InvokeResponseIBs.h b/src/app/MessageDef/InvokeResponseIBs.h index 5b625f88c112fe..79147ec7c6747d 100644 --- a/src/app/MessageDef/InvokeResponseIBs.h +++ b/src/app/MessageDef/InvokeResponseIBs.h @@ -34,7 +34,7 @@ namespace InvokeResponseIBs { class Parser : public ArrayParser { public: -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT /** * @brief Roughly verify the message is correctly formed * 1) all mandatory tags are present diff --git a/src/app/MessageDef/InvokeResponseMessage.cpp b/src/app/MessageDef/InvokeResponseMessage.cpp index 50de3efa4959d6..c24c427c3be987 100644 --- a/src/app/MessageDef/InvokeResponseMessage.cpp +++ b/src/app/MessageDef/InvokeResponseMessage.cpp @@ -25,11 +25,10 @@ namespace chip { namespace app { -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT CHIP_ERROR InvokeResponseMessage::Parser::CheckSchemaValidity() const { - CHIP_ERROR err = CHIP_NO_ERROR; - int tagPresenceMask = 0; + CHIP_ERROR err = CHIP_NO_ERROR; TLV::TLVReader reader; PRETTY_PRINT("InvokeResponseMessage ="); @@ -48,30 +47,23 @@ CHIP_ERROR InvokeResponseMessage::Parser::CheckSchemaValidity() const switch (tagNum) { case to_underlying(Tag::kSuppressResponse): - // check if this tag has appeared before - VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kSuppressResponse))), CHIP_ERROR_INVALID_TLV_TAG); - tagPresenceMask |= (1 << to_underlying(Tag::kSuppressResponse)); #if CHIP_DETAIL_LOGGING - { - bool suppressResponse; - ReturnErrorOnFailure(reader.Get(suppressResponse)); - PRETTY_PRINT("\tsuppressResponse = %s, ", suppressResponse ? "true" : "false"); - } + { + bool suppressResponse; + ReturnErrorOnFailure(reader.Get(suppressResponse)); + PRETTY_PRINT("\tsuppressResponse = %s, ", suppressResponse ? "true" : "false"); + } #endif // CHIP_DETAIL_LOGGING - break; - case to_underlying(Tag::kInvokeResponses): - // check if this tag has appeared before - VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kInvokeResponses))), CHIP_ERROR_INVALID_TLV_TAG); - tagPresenceMask |= (1 << to_underlying(Tag::kInvokeResponses)); - { - InvokeResponseIBs::Parser invokeResponses; - ReturnErrorOnFailure(invokeResponses.Init(reader)); - - PRETTY_PRINT_INCDEPTH(); - ReturnErrorOnFailure(invokeResponses.CheckSchemaValidity()); - PRETTY_PRINT_DECDEPTH(); - } - break; + break; + case to_underlying(Tag::kInvokeResponses): { + InvokeResponseIBs::Parser invokeResponses; + ReturnErrorOnFailure(invokeResponses.Init(reader)); + + PRETTY_PRINT_INCDEPTH(); + ReturnErrorOnFailure(invokeResponses.CheckSchemaValidity()); + PRETTY_PRINT_DECDEPTH(); + } + break; case kInteractionModelRevisionTag: ReturnErrorOnFailure(MessageParser::CheckInteractionModelRevision(reader)); break; @@ -86,15 +78,13 @@ CHIP_ERROR InvokeResponseMessage::Parser::CheckSchemaValidity() const if (CHIP_END_OF_TLV == err) { - const int requiredFields = (1 << to_underlying(Tag::kSuppressResponse)) | (1 << to_underlying(Tag::kInvokeResponses)); - err = - (tagPresenceMask & requiredFields) == requiredFields ? CHIP_NO_ERROR : CHIP_ERROR_IM_MALFORMED_INVOKE_RESPONSE_MESSAGE; + err = CHIP_NO_ERROR; } ReturnErrorOnFailure(err); return reader.ExitContainer(mOuterContainerType); } -#endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#endif // CHIP_CONFIG_IM_PRETTY_PRINT CHIP_ERROR InvokeResponseMessage::Parser::GetSuppressResponse(bool * const apSuppressResponse) const { diff --git a/src/app/MessageDef/InvokeResponseMessage.h b/src/app/MessageDef/InvokeResponseMessage.h index 2d317a252a7858..96546c98449efc 100644 --- a/src/app/MessageDef/InvokeResponseMessage.h +++ b/src/app/MessageDef/InvokeResponseMessage.h @@ -40,7 +40,7 @@ enum class Tag : uint8_t class Parser : public MessageParser { public: -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT /** * @brief Roughly verify the message is correctly formed * 1) all mandatory tags are present diff --git a/src/app/MessageDef/MessageDefHelper.cpp b/src/app/MessageDef/MessageDefHelper.cpp index a8f0283968a85f..b2eff8130f1da4 100644 --- a/src/app/MessageDef/MessageDefHelper.cpp +++ b/src/app/MessageDef/MessageDefHelper.cpp @@ -33,7 +33,7 @@ namespace chip { namespace app { -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK && CHIP_DETAIL_LOGGING +#if CHIP_CONFIG_IM_PRETTY_PRINT && CHIP_DETAIL_LOGGING // this is used to run in signle thread for IM message debug purpose namespace { uint32_t gPrettyPrintingDepthLevel = 0; @@ -56,7 +56,7 @@ void PrettyPrintIMBlankLine() if (sizeof(gLineBuffer) > gCurLineBufferSize) { size_t sizeLeft = sizeof(gLineBuffer) - gCurLineBufferSize; - size_t ret = (size_t)(snprintf(gLineBuffer + gCurLineBufferSize, sizeLeft, "\t")); + size_t ret = (size_t) (snprintf(gLineBuffer + gCurLineBufferSize, sizeLeft, "\t")); if (ret > 0) { gCurLineBufferSize += std::min(ret, sizeLeft); @@ -78,7 +78,7 @@ void PrettyPrintIM(bool aIsNewLine, const char * aFmt, ...) if (sizeof(gLineBuffer) > gCurLineBufferSize) { size_t sizeLeft = sizeof(gLineBuffer) - gCurLineBufferSize; - size_t ret = (size_t)(vsnprintf(gLineBuffer + gCurLineBufferSize, sizeLeft, aFmt, args)); + size_t ret = (size_t) (vsnprintf(gLineBuffer + gCurLineBufferSize, sizeLeft, aFmt, args)); if (ret > 0) { gCurLineBufferSize += std::min(ret, sizeLeft); @@ -98,7 +98,7 @@ void DecreaseDepth() } #endif -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT CHIP_ERROR CheckIMPayload(TLV::TLVReader & aReader, int aDepth, const char * aLabel) { if (aDepth == 0) @@ -261,7 +261,7 @@ CHIP_ERROR CheckIMPayload(TLV::TLVReader & aReader, int aDepth, const char * aLa return CHIP_NO_ERROR; } -#endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#endif // CHIP_CONFIG_IM_PRETTY_PRINT }; // namespace app }; // namespace chip diff --git a/src/app/MessageDef/MessageDefHelper.h b/src/app/MessageDef/MessageDefHelper.h index bc6f8ec44294a3..15763c69314cd7 100644 --- a/src/app/MessageDef/MessageDefHelper.h +++ b/src/app/MessageDef/MessageDefHelper.h @@ -38,7 +38,7 @@ namespace chip { namespace app { -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK && CHIP_DETAIL_LOGGING +#if CHIP_CONFIG_IM_PRETTY_PRINT && CHIP_DETAIL_LOGGING /** * Start a new "blank" line. This will actually print out whitespace to the * current indent level, which can be followed with PRETTY_PRINT_SAMELINE calls. @@ -81,11 +81,11 @@ void DecreaseDepth(); #define PRETTY_PRINT_DECDEPTH() #endif -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT // Parse an IM payload (attribute value, command fields, event fields, // recursively parsing any complex types encountered. CHIP_ERROR CheckIMPayload(TLV::TLVReader & aReader, int aDepth, const char * aLabel); -#endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#endif // CHIP_CONFIG_IM_PRETTY_PRINT }; // namespace app }; // namespace chip diff --git a/src/app/MessageDef/MessageParser.cpp b/src/app/MessageDef/MessageParser.cpp index 7cf8ea7d175e77..b855a93afcd7eb 100644 --- a/src/app/MessageDef/MessageParser.cpp +++ b/src/app/MessageDef/MessageParser.cpp @@ -36,7 +36,7 @@ CHIP_ERROR MessageParser::ExitContainer() return CHIP_NO_ERROR; } -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT CHIP_ERROR MessageParser::CheckInteractionModelRevision(TLV::TLVReader & aReader) const { #if CHIP_DETAIL_LOGGING @@ -48,7 +48,7 @@ CHIP_ERROR MessageParser::CheckInteractionModelRevision(TLV::TLVReader & aReader #endif // CHIP_DETAIL_LOGGING return CHIP_NO_ERROR; } -#endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#endif // CHIP_CONFIG_IM_PRETTY_PRINT CHIP_ERROR MessageParser::GetInteractionModelRevision(InteractionModelRevision * const apInteractionModelRevision) const { diff --git a/src/app/MessageDef/MessageParser.h b/src/app/MessageDef/MessageParser.h index 7fcdaf7e81dbfe..6a2c3469f467a4 100644 --- a/src/app/MessageDef/MessageParser.h +++ b/src/app/MessageDef/MessageParser.h @@ -30,9 +30,9 @@ class MessageParser : public StructParser public: CHIP_ERROR Init(TLV::TLVReader & aReader); CHIP_ERROR ExitContainer(); -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT CHIP_ERROR CheckInteractionModelRevision(TLV::TLVReader & aReader) const; -#endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#endif // CHIP_CONFIG_IM_PRETTY_PRINT CHIP_ERROR GetInteractionModelRevision(InteractionModelRevision * const apInteractionModelRevision) const; }; diff --git a/src/app/MessageDef/ReadRequestMessage.cpp b/src/app/MessageDef/ReadRequestMessage.cpp index dda2dbf62c7c84..02b7905b588ef0 100644 --- a/src/app/MessageDef/ReadRequestMessage.cpp +++ b/src/app/MessageDef/ReadRequestMessage.cpp @@ -25,11 +25,10 @@ namespace chip { namespace app { -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT CHIP_ERROR ReadRequestMessage::Parser::CheckSchemaValidity() const { - CHIP_ERROR err = CHIP_NO_ERROR; - int tagPresenceMask = 0; + CHIP_ERROR err = CHIP_NO_ERROR; TLV::TLVReader reader; PRETTY_PRINT("ReadRequestMessage ="); @@ -47,70 +46,51 @@ CHIP_ERROR ReadRequestMessage::Parser::CheckSchemaValidity() const uint32_t tagNum = TLV::TagNumFromTag(reader.GetTag()); switch (tagNum) { - case to_underlying(Tag::kAttributeRequests): - // check if this tag has appeared before - VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kAttributeRequests))), CHIP_ERROR_INVALID_TLV_TAG); - tagPresenceMask |= (1 << to_underlying(Tag::kAttributeRequests)); - { - AttributePathIBs::Parser attributeRequests; - ReturnErrorOnFailure(attributeRequests.Init(reader)); - - PRETTY_PRINT_INCDEPTH(); - ReturnErrorOnFailure(attributeRequests.CheckSchemaValidity()); - PRETTY_PRINT_DECDEPTH(); - } - break; - case to_underlying(Tag::kDataVersionFilters): - // check if this tag has appeared before - VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kDataVersionFilters))), CHIP_ERROR_INVALID_TLV_TAG); - tagPresenceMask |= (1 << to_underlying(Tag::kDataVersionFilters)); - { - DataVersionFilterIBs::Parser dataVersionFilters; - ReturnErrorOnFailure(dataVersionFilters.Init(reader)); - - PRETTY_PRINT_INCDEPTH(); - ReturnErrorOnFailure(dataVersionFilters.CheckSchemaValidity()); - PRETTY_PRINT_DECDEPTH(); - } - break; - case to_underlying(Tag::kEventRequests): - // check if this tag has appeared before - VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kEventRequests))), CHIP_ERROR_INVALID_TLV_TAG); - tagPresenceMask |= (1 << to_underlying(Tag::kEventRequests)); - { - EventPathIBs::Parser eventRequests; - ReturnErrorOnFailure(eventRequests.Init(reader)); - - PRETTY_PRINT_INCDEPTH(); - ReturnErrorOnFailure(eventRequests.CheckSchemaValidity()); - PRETTY_PRINT_DECDEPTH(); - } - break; - case to_underlying(Tag::kEventFilters): - // check if this tag has appeared before - VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kEventFilters))), CHIP_ERROR_INVALID_TLV_TAG); - tagPresenceMask |= (1 << to_underlying(Tag::kEventFilters)); - { - EventFilterIBs::Parser eventFilters; - ReturnErrorOnFailure(eventFilters.Init(reader)); - - PRETTY_PRINT_INCDEPTH(); - ReturnErrorOnFailure(eventFilters.CheckSchemaValidity()); - PRETTY_PRINT_DECDEPTH(); - } - break; + case to_underlying(Tag::kAttributeRequests): { + AttributePathIBs::Parser attributeRequests; + ReturnErrorOnFailure(attributeRequests.Init(reader)); + + PRETTY_PRINT_INCDEPTH(); + ReturnErrorOnFailure(attributeRequests.CheckSchemaValidity()); + PRETTY_PRINT_DECDEPTH(); + } + break; + case to_underlying(Tag::kDataVersionFilters): { + DataVersionFilterIBs::Parser dataVersionFilters; + ReturnErrorOnFailure(dataVersionFilters.Init(reader)); + + PRETTY_PRINT_INCDEPTH(); + ReturnErrorOnFailure(dataVersionFilters.CheckSchemaValidity()); + PRETTY_PRINT_DECDEPTH(); + } + break; + case to_underlying(Tag::kEventRequests): { + EventPathIBs::Parser eventRequests; + ReturnErrorOnFailure(eventRequests.Init(reader)); + + PRETTY_PRINT_INCDEPTH(); + ReturnErrorOnFailure(eventRequests.CheckSchemaValidity()); + PRETTY_PRINT_DECDEPTH(); + } + break; + case to_underlying(Tag::kEventFilters): { + EventFilterIBs::Parser eventFilters; + ReturnErrorOnFailure(eventFilters.Init(reader)); + + PRETTY_PRINT_INCDEPTH(); + ReturnErrorOnFailure(eventFilters.CheckSchemaValidity()); + PRETTY_PRINT_DECDEPTH(); + } + break; case to_underlying(Tag::kIsFabricFiltered): - // check if this tag has appeared before - VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kIsFabricFiltered))), CHIP_ERROR_INVALID_TLV_TAG); - tagPresenceMask |= (1 << to_underlying(Tag::kIsFabricFiltered)); #if CHIP_DETAIL_LOGGING - { - bool isFabricFiltered; - ReturnErrorOnFailure(reader.Get(isFabricFiltered)); - PRETTY_PRINT("\tisFabricFiltered = %s, ", isFabricFiltered ? "true" : "false"); - } + { + bool isFabricFiltered; + ReturnErrorOnFailure(reader.Get(isFabricFiltered)); + PRETTY_PRINT("\tisFabricFiltered = %s, ", isFabricFiltered ? "true" : "false"); + } #endif // CHIP_DETAIL_LOGGING - break; + break; case kInteractionModelRevisionTag: ReturnErrorOnFailure(MessageParser::CheckInteractionModelRevision(reader)); break; @@ -125,14 +105,13 @@ CHIP_ERROR ReadRequestMessage::Parser::CheckSchemaValidity() const if (CHIP_END_OF_TLV == err) { - const int requiredFields = (1 << to_underlying(Tag::kIsFabricFiltered)); - err = (tagPresenceMask & requiredFields) == requiredFields ? CHIP_NO_ERROR : CHIP_ERROR_IM_MALFORMED_READ_REQUEST_MESSAGE; + err = CHIP_NO_ERROR; } ReturnErrorOnFailure(err); return reader.ExitContainer(mOuterContainerType); } -#endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#endif // CHIP_CONFIG_IM_PRETTY_PRINT CHIP_ERROR ReadRequestMessage::Parser::GetAttributeRequests(AttributePathIBs::Parser * const apAttributeRequests) const { diff --git a/src/app/MessageDef/ReadRequestMessage.h b/src/app/MessageDef/ReadRequestMessage.h index 8e1465618420ff..a9ca6b2c792f6e 100644 --- a/src/app/MessageDef/ReadRequestMessage.h +++ b/src/app/MessageDef/ReadRequestMessage.h @@ -45,7 +45,7 @@ enum class Tag : uint8_t class Parser : public MessageParser { public: -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT /** * @brief Roughly verify the message is correctly formed * 1) all mandatory tags are present diff --git a/src/app/MessageDef/ReportDataMessage.cpp b/src/app/MessageDef/ReportDataMessage.cpp index de95a7532b7461..c6b97fd94f2e41 100644 --- a/src/app/MessageDef/ReportDataMessage.cpp +++ b/src/app/MessageDef/ReportDataMessage.cpp @@ -35,11 +35,10 @@ using namespace chip; namespace chip { namespace app { -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT CHIP_ERROR ReportDataMessage::Parser::CheckSchemaValidity() const { - CHIP_ERROR err = CHIP_NO_ERROR; - int tagPresenceMask = 0; + CHIP_ERROR err = CHIP_NO_ERROR; TLV::TLVReader reader; AttributeReportIBs::Parser attributeReportIBs; EventReportIBs::Parser eventReportIBs; @@ -60,8 +59,6 @@ CHIP_ERROR ReportDataMessage::Parser::CheckSchemaValidity() const switch (tagNum) { case to_underlying(Tag::kSuppressResponse): - VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kSuppressResponse))), CHIP_ERROR_INVALID_TLV_TAG); - tagPresenceMask |= (1 << to_underlying(Tag::kSuppressResponse)); VerifyOrReturnError(TLV::kTLVType_Boolean == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); #if CHIP_DETAIL_LOGGING { @@ -72,8 +69,6 @@ CHIP_ERROR ReportDataMessage::Parser::CheckSchemaValidity() const #endif // CHIP_DETAIL_LOGGING break; case to_underlying(Tag::kSubscriptionId): - VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kSubscriptionId))), CHIP_ERROR_INVALID_TLV_TAG); - tagPresenceMask |= (1 << to_underlying(Tag::kSubscriptionId)); VerifyOrReturnError(TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); #if CHIP_DETAIL_LOGGING { @@ -84,9 +79,6 @@ CHIP_ERROR ReportDataMessage::Parser::CheckSchemaValidity() const #endif // CHIP_DETAIL_LOGGING break; case to_underlying(Tag::kAttributeReportIBs): - // check if this tag has appeared before - VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kAttributeReportIBs))), CHIP_ERROR_INVALID_TLV_TAG); - tagPresenceMask |= (1 << to_underlying(Tag::kAttributeReportIBs)); VerifyOrReturnError(TLV::kTLVType_Array == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); #if CHIP_DETAIL_LOGGING { @@ -99,9 +91,6 @@ CHIP_ERROR ReportDataMessage::Parser::CheckSchemaValidity() const #endif // CHIP_DETAIL_LOGGING break; case to_underlying(Tag::kEventReports): - // check if this tag has appeared before - VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kEventReports))), CHIP_ERROR_INVALID_TLV_TAG); - tagPresenceMask |= (1 << to_underlying(Tag::kEventReports)); VerifyOrReturnError(TLV::kTLVType_Array == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); #if CHIP_DETAIL_LOGGING { @@ -114,8 +103,6 @@ CHIP_ERROR ReportDataMessage::Parser::CheckSchemaValidity() const #endif // CHIP_DETAIL_LOGGING break; case to_underlying(Tag::kMoreChunkedMessages): - VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kMoreChunkedMessages))), CHIP_ERROR_INVALID_TLV_TAG); - tagPresenceMask |= (1 << to_underlying(Tag::kMoreChunkedMessages)); VerifyOrReturnError(TLV::kTLVType_Boolean == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); #if CHIP_DETAIL_LOGGING { @@ -144,7 +131,7 @@ CHIP_ERROR ReportDataMessage::Parser::CheckSchemaValidity() const ReturnErrorOnFailure(err); return reader.ExitContainer(mOuterContainerType); } -#endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#endif // CHIP_CONFIG_IM_PRETTY_PRINT CHIP_ERROR ReportDataMessage::Parser::GetSuppressResponse(bool * const apSuppressResponse) const { diff --git a/src/app/MessageDef/ReportDataMessage.h b/src/app/MessageDef/ReportDataMessage.h index 29fdbff29a00d2..0045b6c878ca3c 100644 --- a/src/app/MessageDef/ReportDataMessage.h +++ b/src/app/MessageDef/ReportDataMessage.h @@ -50,7 +50,7 @@ enum class Tag : uint8_t class Parser : public MessageParser { public: -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT /** * @brief Roughly verify the message is correctly formed * 1) all mandatory tags are present diff --git a/src/app/MessageDef/StatusIB.cpp b/src/app/MessageDef/StatusIB.cpp index d82c7da859b72d..db9516cddfe1e2 100644 --- a/src/app/MessageDef/StatusIB.cpp +++ b/src/app/MessageDef/StatusIB.cpp @@ -63,11 +63,10 @@ CHIP_ERROR StatusIB::Parser::DecodeStatusIB(StatusIB & aStatusIB) const return CHIP_NO_ERROR; } -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT CHIP_ERROR StatusIB::Parser::CheckSchemaValidity() const { - CHIP_ERROR err = CHIP_NO_ERROR; - int tagPresenceMask = 0; + CHIP_ERROR err = CHIP_NO_ERROR; TLV::TLVReader reader; PRETTY_PRINT("StatusIB ="); @@ -81,33 +80,30 @@ CHIP_ERROR StatusIB::Parser::CheckSchemaValidity() const { continue; } - if (!(tagPresenceMask & (1 << to_underlying(Tag::kStatus)))) + uint32_t tagNum = TLV::TagNumFromTag(reader.GetTag()); + switch (tagNum) { - tagPresenceMask |= (1 << to_underlying(Tag::kStatus)); - + case to_underlying(Tag::kStatus): #if CHIP_DETAIL_LOGGING - { - uint8_t status; - ReturnErrorOnFailure(reader.Get(status)); - PRETTY_PRINT("\tstatus = " ChipLogFormatIMStatus ",", ChipLogValueIMStatus(static_cast(status))); - } -#endif // CHIP_DETAIL_LOGGING - } - else if (!(tagPresenceMask & (1 << to_underlying(Tag::kClusterStatus)))) { - tagPresenceMask |= (1 << to_underlying(Tag::kClusterStatus)); - -#if CHIP_DETAIL_LOGGING - { - ClusterStatus clusterStatus; - ReturnErrorOnFailure(reader.Get(clusterStatus)); - PRETTY_PRINT("\tcluster-status = 0x%x,", clusterStatus); - } -#endif // CHIP_DETAIL_LOGGING + uint8_t status; + ReturnErrorOnFailure(reader.Get(status)); + PRETTY_PRINT("\tstatus = " ChipLogFormatIMStatus ",", ChipLogValueIMStatus(static_cast(status))); } - else +#endif // CHIP_DETAIL_LOGGING + break; + case to_underlying(Tag::kClusterStatus): +#if CHIP_DETAIL_LOGGING { - PRETTY_PRINT("\tExtra element in StatusIB"); + ClusterStatus clusterStatus; + ReturnErrorOnFailure(reader.Get(clusterStatus)); + PRETTY_PRINT("\tcluster-status = 0x%x,", clusterStatus); + } +#endif // CHIP_DETAIL_LOGGING + break; + default: + PRETTY_PRINT("Unknown tag num %" PRIu32, tagNum); + break; } } @@ -116,14 +112,12 @@ CHIP_ERROR StatusIB::Parser::CheckSchemaValidity() const // if we have exhausted this container if (CHIP_END_OF_TLV == err) { - // check for required fields: - const int requiredFields = (1 << to_underlying(Tag::kStatus)); - err = (tagPresenceMask & requiredFields) == requiredFields ? CHIP_NO_ERROR : CHIP_ERROR_IM_MALFORMED_STATUS_IB; + err = CHIP_NO_ERROR; } ReturnErrorOnFailure(err); return reader.ExitContainer(mOuterContainerType); } -#endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#endif // CHIP_CONFIG_IM_PRETTY_PRINT StatusIB::Builder & StatusIB::Builder::EncodeStatusIB(const StatusIB & aStatusIB) { diff --git a/src/app/MessageDef/StatusIB.h b/src/app/MessageDef/StatusIB.h index f2af401c2d8548..36d4f4c85eca05 100644 --- a/src/app/MessageDef/StatusIB.h +++ b/src/app/MessageDef/StatusIB.h @@ -56,7 +56,7 @@ struct StatusIB class Parser : public StructParser { public: -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT /** * @brief Roughly verify the message is correctly formed * 1) all mandatory tags are present diff --git a/src/app/MessageDef/StatusResponseMessage.cpp b/src/app/MessageDef/StatusResponseMessage.cpp index 758147df71bbb7..7f9a4fa3accd41 100644 --- a/src/app/MessageDef/StatusResponseMessage.cpp +++ b/src/app/MessageDef/StatusResponseMessage.cpp @@ -22,11 +22,10 @@ using namespace chip::Protocols::InteractionModel; namespace chip { namespace app { -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT CHIP_ERROR StatusResponseMessage::Parser::CheckSchemaValidity() const { - CHIP_ERROR err = CHIP_NO_ERROR; - int tagPresenceMask = 0; + CHIP_ERROR err = CHIP_NO_ERROR; TLV::TLVReader reader; PRETTY_PRINT("StatusResponseMessage ="); PRETTY_PRINT("{"); @@ -44,8 +43,6 @@ CHIP_ERROR StatusResponseMessage::Parser::CheckSchemaValidity() const switch (tagNum) { case to_underlying(Tag::kStatus): - VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kStatus))), CHIP_ERROR_INVALID_TLV_TAG); - tagPresenceMask |= (1 << to_underlying(Tag::kStatus)); VerifyOrReturnError(TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); #if CHIP_DETAIL_LOGGING { @@ -68,14 +65,12 @@ CHIP_ERROR StatusResponseMessage::Parser::CheckSchemaValidity() const if (CHIP_END_OF_TLV == err) { - const int requiredFields = (1 << to_underlying(Tag::kStatus)); - err = - (tagPresenceMask & requiredFields) == requiredFields ? CHIP_NO_ERROR : CHIP_ERROR_IM_MALFORMED_STATUS_RESPONSE_MESSAGE; + err = CHIP_NO_ERROR; } ReturnErrorOnFailure(err); return reader.ExitContainer(mOuterContainerType); } -#endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#endif // CHIP_CONFIG_IM_PRETTY_PRINT CHIP_ERROR StatusResponseMessage::Parser::GetStatus(Protocols::InteractionModel::Status & aStatus) const { diff --git a/src/app/MessageDef/StatusResponseMessage.h b/src/app/MessageDef/StatusResponseMessage.h index 124091215ec820..e4044b381b6258 100644 --- a/src/app/MessageDef/StatusResponseMessage.h +++ b/src/app/MessageDef/StatusResponseMessage.h @@ -38,7 +38,7 @@ enum class Tag : uint8_t class Parser : public MessageParser { public: -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT /** * @brief Roughly verify the message is correctly formed * 1) all mandatory tags are present diff --git a/src/app/MessageDef/SubscribeRequestMessage.cpp b/src/app/MessageDef/SubscribeRequestMessage.cpp index 69b5b4841ef9dc..3efbf46b0a7c5d 100644 --- a/src/app/MessageDef/SubscribeRequestMessage.cpp +++ b/src/app/MessageDef/SubscribeRequestMessage.cpp @@ -19,11 +19,10 @@ namespace chip { namespace app { -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT CHIP_ERROR SubscribeRequestMessage::Parser::CheckSchemaValidity() const { - CHIP_ERROR err = CHIP_NO_ERROR; - int tagPresenceMask = 0; + CHIP_ERROR err = CHIP_NO_ERROR; TLV::TLVReader reader; PRETTY_PRINT("SubscribeRequestMessage ="); @@ -42,8 +41,6 @@ CHIP_ERROR SubscribeRequestMessage::Parser::CheckSchemaValidity() const switch (tagNum) { case to_underlying(Tag::kKeepSubscriptions): - VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kKeepSubscriptions))), CHIP_ERROR_INVALID_TLV_TAG); - tagPresenceMask |= (1 << to_underlying(Tag::kKeepSubscriptions)); VerifyOrReturnError(TLV::kTLVType_Boolean == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); #if CHIP_DETAIL_LOGGING { @@ -54,9 +51,6 @@ CHIP_ERROR SubscribeRequestMessage::Parser::CheckSchemaValidity() const #endif // CHIP_DETAIL_LOGGING break; case to_underlying(Tag::kMinIntervalFloorSeconds): - VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kMinIntervalFloorSeconds))), - CHIP_ERROR_INVALID_TLV_TAG); - tagPresenceMask |= (1 << to_underlying(Tag::kMinIntervalFloorSeconds)); VerifyOrReturnError(TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); #if CHIP_DETAIL_LOGGING { @@ -67,9 +61,6 @@ CHIP_ERROR SubscribeRequestMessage::Parser::CheckSchemaValidity() const #endif // CHIP_DETAIL_LOGGING break; case to_underlying(Tag::kMaxIntervalCeilingSeconds): - VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kMaxIntervalCeilingSeconds))), - CHIP_ERROR_INVALID_TLV_TAG); - tagPresenceMask |= (1 << to_underlying(Tag::kMaxIntervalCeilingSeconds)); VerifyOrReturnError(TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); #if CHIP_DETAIL_LOGGING { @@ -79,70 +70,51 @@ CHIP_ERROR SubscribeRequestMessage::Parser::CheckSchemaValidity() const } #endif // CHIP_DETAIL_LOGGING break; - case to_underlying(Tag::kAttributeRequests): - // check if this tag has appeared before - VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kAttributeRequests))), CHIP_ERROR_INVALID_TLV_TAG); - tagPresenceMask |= (1 << to_underlying(Tag::kAttributeRequests)); - { - AttributePathIBs::Parser attributeRequests; - ReturnErrorOnFailure(attributeRequests.Init(reader)); + case to_underlying(Tag::kAttributeRequests): { + AttributePathIBs::Parser attributeRequests; + ReturnErrorOnFailure(attributeRequests.Init(reader)); - PRETTY_PRINT_INCDEPTH(); - ReturnErrorOnFailure(attributeRequests.CheckSchemaValidity()); - PRETTY_PRINT_DECDEPTH(); - } - break; - case to_underlying(Tag::kDataVersionFilters): - // check if this tag has appeared before - VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kDataVersionFilters))), CHIP_ERROR_INVALID_TLV_TAG); - tagPresenceMask |= (1 << to_underlying(Tag::kDataVersionFilters)); - { - DataVersionFilterIBs::Parser dataVersionFilters; - ReturnErrorOnFailure(dataVersionFilters.Init(reader)); + PRETTY_PRINT_INCDEPTH(); + ReturnErrorOnFailure(attributeRequests.CheckSchemaValidity()); + PRETTY_PRINT_DECDEPTH(); + } + break; + case to_underlying(Tag::kDataVersionFilters): { + DataVersionFilterIBs::Parser dataVersionFilters; + ReturnErrorOnFailure(dataVersionFilters.Init(reader)); - PRETTY_PRINT_INCDEPTH(); - ReturnErrorOnFailure(dataVersionFilters.CheckSchemaValidity()); - PRETTY_PRINT_DECDEPTH(); - } - break; - case to_underlying(Tag::kEventRequests): - // check if this tag has appeared before - VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kEventRequests))), CHIP_ERROR_INVALID_TLV_TAG); - tagPresenceMask |= (1 << to_underlying(Tag::kEventRequests)); - { - EventPathIBs::Parser eventRequests; - ReturnErrorOnFailure(eventRequests.Init(reader)); + PRETTY_PRINT_INCDEPTH(); + ReturnErrorOnFailure(dataVersionFilters.CheckSchemaValidity()); + PRETTY_PRINT_DECDEPTH(); + } + break; + case to_underlying(Tag::kEventRequests): { + EventPathIBs::Parser eventRequests; + ReturnErrorOnFailure(eventRequests.Init(reader)); - PRETTY_PRINT_INCDEPTH(); - ReturnErrorOnFailure(eventRequests.CheckSchemaValidity()); - PRETTY_PRINT_DECDEPTH(); - } - break; - case to_underlying(Tag::kEventFilters): - // check if this tag has appeared before - VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kEventFilters))), CHIP_ERROR_INVALID_TLV_TAG); - tagPresenceMask |= (1 << to_underlying(Tag::kEventFilters)); - { - EventFilterIBs::Parser eventFilters; - ReturnErrorOnFailure(eventFilters.Init(reader)); + PRETTY_PRINT_INCDEPTH(); + ReturnErrorOnFailure(eventRequests.CheckSchemaValidity()); + PRETTY_PRINT_DECDEPTH(); + } + break; + case to_underlying(Tag::kEventFilters): { + EventFilterIBs::Parser eventFilters; + ReturnErrorOnFailure(eventFilters.Init(reader)); - PRETTY_PRINT_INCDEPTH(); - ReturnErrorOnFailure(eventFilters.CheckSchemaValidity()); - PRETTY_PRINT_DECDEPTH(); - } - break; + PRETTY_PRINT_INCDEPTH(); + ReturnErrorOnFailure(eventFilters.CheckSchemaValidity()); + PRETTY_PRINT_DECDEPTH(); + } + break; case to_underlying(Tag::kIsFabricFiltered): - // check if this tag has appeared before - VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kIsFabricFiltered))), CHIP_ERROR_INVALID_TLV_TAG); - tagPresenceMask |= (1 << to_underlying(Tag::kIsFabricFiltered)); #if CHIP_DETAIL_LOGGING - { - bool isFabricFiltered; - ReturnErrorOnFailure(reader.Get(isFabricFiltered)); - PRETTY_PRINT("\tisFabricFiltered = %s, ", isFabricFiltered ? "true" : "false"); - } + { + bool isFabricFiltered; + ReturnErrorOnFailure(reader.Get(isFabricFiltered)); + PRETTY_PRINT("\tisFabricFiltered = %s, ", isFabricFiltered ? "true" : "false"); + } #endif // CHIP_DETAIL_LOGGING - break; + break; case kInteractionModelRevisionTag: ReturnErrorOnFailure(MessageParser::CheckInteractionModelRevision(reader)); break; @@ -157,17 +129,13 @@ CHIP_ERROR SubscribeRequestMessage::Parser::CheckSchemaValidity() const if (CHIP_END_OF_TLV == err) { - const int requiredFields = (1 << to_underlying(Tag::kIsFabricFiltered)) | (1 << to_underlying(Tag::kKeepSubscriptions)) | - (1 << to_underlying(Tag::kMinIntervalFloorSeconds)) | (1 << to_underlying(Tag::kMaxIntervalCeilingSeconds)); - - err = (tagPresenceMask & requiredFields) == requiredFields ? CHIP_NO_ERROR - : CHIP_ERROR_IM_MALFORMED_SUBSCRIBE_REQUEST_MESSAGE; + err = CHIP_NO_ERROR; } ReturnErrorOnFailure(err); return reader.ExitContainer(mOuterContainerType); } -#endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#endif // CHIP_CONFIG_IM_PRETTY_PRINT CHIP_ERROR SubscribeRequestMessage::Parser::GetKeepSubscriptions(bool * const apKeepExistingSubscription) const { diff --git a/src/app/MessageDef/SubscribeRequestMessage.h b/src/app/MessageDef/SubscribeRequestMessage.h index 25529cc3870c69..ecb0d3bae47f32 100644 --- a/src/app/MessageDef/SubscribeRequestMessage.h +++ b/src/app/MessageDef/SubscribeRequestMessage.h @@ -48,7 +48,7 @@ enum class Tag : uint8_t class Parser : public MessageParser { public: -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT /** * @brief Roughly verify the message is correctly formed * 1) all mandatory tags are present diff --git a/src/app/MessageDef/SubscribeResponseMessage.cpp b/src/app/MessageDef/SubscribeResponseMessage.cpp index 97e7100c4e5670..d06ab198cc9e17 100644 --- a/src/app/MessageDef/SubscribeResponseMessage.cpp +++ b/src/app/MessageDef/SubscribeResponseMessage.cpp @@ -19,11 +19,10 @@ namespace chip { namespace app { -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT CHIP_ERROR SubscribeResponseMessage::Parser::CheckSchemaValidity() const { - CHIP_ERROR err = CHIP_NO_ERROR; - int tagPresenceMask = 0; + CHIP_ERROR err = CHIP_NO_ERROR; TLV::TLVReader reader; PRETTY_PRINT("SubscribeResponseMessage ="); PRETTY_PRINT("{"); @@ -41,8 +40,6 @@ CHIP_ERROR SubscribeResponseMessage::Parser::CheckSchemaValidity() const switch (tagNum) { case to_underlying(Tag::kSubscriptionId): - VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kSubscriptionId))), CHIP_ERROR_INVALID_TLV_TAG); - tagPresenceMask |= (1 << to_underlying(Tag::kSubscriptionId)); VerifyOrReturnError(TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); #if CHIP_DETAIL_LOGGING { @@ -53,8 +50,6 @@ CHIP_ERROR SubscribeResponseMessage::Parser::CheckSchemaValidity() const #endif // CHIP_DETAIL_LOGGING break; case to_underlying(Tag::kMaxInterval): - VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kMaxInterval))), CHIP_ERROR_INVALID_TLV_TAG); - tagPresenceMask |= (1 << to_underlying(Tag::kMaxInterval)); VerifyOrReturnError(TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); #if CHIP_DETAIL_LOGGING { @@ -77,14 +72,12 @@ CHIP_ERROR SubscribeResponseMessage::Parser::CheckSchemaValidity() const if (CHIP_END_OF_TLV == err) { - const uint16_t requiredFields = (1 << to_underlying(Tag::kSubscriptionId)) | (1 << to_underlying(Tag::kMaxInterval)); - err = (tagPresenceMask & requiredFields) == requiredFields ? CHIP_NO_ERROR - : CHIP_ERROR_IM_MALFORMED_SUBSCRIBE_RESPONSE_MESSAGE; + err = CHIP_NO_ERROR; } ReturnErrorOnFailure(err); return reader.ExitContainer(mOuterContainerType); } -#endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#endif // CHIP_CONFIG_IM_PRETTY_PRINT CHIP_ERROR SubscribeResponseMessage::Parser::GetSubscriptionId(SubscriptionId * const apSubscribeId) const { diff --git a/src/app/MessageDef/SubscribeResponseMessage.h b/src/app/MessageDef/SubscribeResponseMessage.h index 19a44e6c0f2f74..b5067ed5de7c9b 100644 --- a/src/app/MessageDef/SubscribeResponseMessage.h +++ b/src/app/MessageDef/SubscribeResponseMessage.h @@ -38,7 +38,7 @@ enum class Tag : uint8_t class Parser : public MessageParser { public: -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT /** * @brief Roughly verify the message is correctly formed * 1) all mandatory tags are present diff --git a/src/app/MessageDef/TimedRequestMessage.cpp b/src/app/MessageDef/TimedRequestMessage.cpp index 15440b9edd32b0..1830a9c49b36d3 100644 --- a/src/app/MessageDef/TimedRequestMessage.cpp +++ b/src/app/MessageDef/TimedRequestMessage.cpp @@ -19,11 +19,10 @@ namespace chip { namespace app { -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT CHIP_ERROR TimedRequestMessage::Parser::CheckSchemaValidity() const { - CHIP_ERROR err = CHIP_NO_ERROR; - int tagPresenceMask = 0; + CHIP_ERROR err = CHIP_NO_ERROR; TLV::TLVReader reader; PRETTY_PRINT("TimedRequestMessage ="); PRETTY_PRINT("{"); @@ -41,8 +40,6 @@ CHIP_ERROR TimedRequestMessage::Parser::CheckSchemaValidity() const switch (tagNum) { case to_underlying(Tag::kTimeoutMs): - VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kTimeoutMs))), CHIP_ERROR_INVALID_TLV_TAG); - tagPresenceMask |= (1 << to_underlying(Tag::kTimeoutMs)); VerifyOrReturnError(TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); #if CHIP_DETAIL_LOGGING { @@ -64,13 +61,12 @@ CHIP_ERROR TimedRequestMessage::Parser::CheckSchemaValidity() const PRETTY_PRINT_BLANK_LINE(); if (CHIP_END_OF_TLV == err) { - const int requiredFields = (1 << to_underlying(Tag::kTimeoutMs)); - err = (tagPresenceMask & requiredFields) == requiredFields ? CHIP_NO_ERROR : CHIP_ERROR_IM_MALFORMED_TIMED_REQUEST_MESSAGE; + err = CHIP_NO_ERROR; } ReturnErrorOnFailure(err); return reader.ExitContainer(mOuterContainerType); } -#endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#endif // CHIP_CONFIG_IM_PRETTY_PRINT CHIP_ERROR TimedRequestMessage::Parser::GetTimeoutMs(uint16_t * const apTimeoutMs) const { diff --git a/src/app/MessageDef/TimedRequestMessage.h b/src/app/MessageDef/TimedRequestMessage.h index 1151bd21e2c43b..717de6f58ead1c 100644 --- a/src/app/MessageDef/TimedRequestMessage.h +++ b/src/app/MessageDef/TimedRequestMessage.h @@ -36,7 +36,7 @@ enum class Tag : uint8_t class Parser : public MessageParser { public: -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT /** * @brief Roughly verify the message is correctly formed * 1) all mandatory tags are present diff --git a/src/app/MessageDef/WriteRequestMessage.cpp b/src/app/MessageDef/WriteRequestMessage.cpp index 4b19a66dfba22f..d127c4b2161acf 100644 --- a/src/app/MessageDef/WriteRequestMessage.cpp +++ b/src/app/MessageDef/WriteRequestMessage.cpp @@ -30,11 +30,10 @@ namespace chip { namespace app { -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT CHIP_ERROR WriteRequestMessage::Parser::CheckSchemaValidity() const { - CHIP_ERROR err = CHIP_NO_ERROR; - int tagPresenceMask = 0; + CHIP_ERROR err = CHIP_NO_ERROR; TLV::TLVReader reader; PRETTY_PRINT("WriteRequestMessage ="); @@ -53,55 +52,42 @@ CHIP_ERROR WriteRequestMessage::Parser::CheckSchemaValidity() const switch (tagNum) { case to_underlying(Tag::kSuppressResponse): - // check if this tag has appeared before - VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kSuppressResponse))), CHIP_ERROR_INVALID_TLV_TAG); - tagPresenceMask |= (1 << to_underlying(Tag::kSuppressResponse)); #if CHIP_DETAIL_LOGGING - { - bool suppressResponse; - ReturnErrorOnFailure(reader.Get(suppressResponse)); - PRETTY_PRINT("\tsuppressResponse = %s, ", suppressResponse ? "true" : "false"); - } + { + bool suppressResponse; + ReturnErrorOnFailure(reader.Get(suppressResponse)); + PRETTY_PRINT("\tsuppressResponse = %s, ", suppressResponse ? "true" : "false"); + } #endif // CHIP_DETAIL_LOGGING - break; + break; case to_underlying(Tag::kTimedRequest): - // check if this tag has appeared before - VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kTimedRequest))), CHIP_ERROR_INVALID_TLV_TAG); - tagPresenceMask |= (1 << to_underlying(Tag::kTimedRequest)); #if CHIP_DETAIL_LOGGING - { - bool timedRequest; - ReturnErrorOnFailure(reader.Get(timedRequest)); - PRETTY_PRINT("\ttimedRequest = %s, ", timedRequest ? "true" : "false"); - } + { + bool timedRequest; + ReturnErrorOnFailure(reader.Get(timedRequest)); + PRETTY_PRINT("\ttimedRequest = %s, ", timedRequest ? "true" : "false"); + } #endif // CHIP_DETAIL_LOGGING - break; - case to_underlying(Tag::kWriteRequests): - // check if this tag has appeared before - VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kWriteRequests))), CHIP_ERROR_INVALID_TLV_TAG); - tagPresenceMask |= (1 << to_underlying(Tag::kWriteRequests)); - { - AttributeDataIBs::Parser writeRequests; - ReturnErrorOnFailure(writeRequests.Init(reader)); - - PRETTY_PRINT_INCDEPTH(); - ReturnErrorOnFailure(writeRequests.CheckSchemaValidity()); - PRETTY_PRINT_DECDEPTH(); - } - break; + break; + case to_underlying(Tag::kWriteRequests): { + AttributeDataIBs::Parser writeRequests; + ReturnErrorOnFailure(writeRequests.Init(reader)); + + PRETTY_PRINT_INCDEPTH(); + ReturnErrorOnFailure(writeRequests.CheckSchemaValidity()); + PRETTY_PRINT_DECDEPTH(); + } + break; case to_underlying(Tag::kMoreChunkedMessages): - // check if this tag has appeared before - VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kMoreChunkedMessages))), CHIP_ERROR_INVALID_TLV_TAG); - tagPresenceMask |= (1 << to_underlying(Tag::kMoreChunkedMessages)); #if CHIP_DETAIL_LOGGING - { - bool moreChunkedMessages; - ReturnErrorOnFailure(reader.Get(moreChunkedMessages)); - PRETTY_PRINT("\tmoreChunkedMessages = %s, ", moreChunkedMessages ? "true" : "false"); - } + { + bool moreChunkedMessages; + ReturnErrorOnFailure(reader.Get(moreChunkedMessages)); + PRETTY_PRINT("\tmoreChunkedMessages = %s, ", moreChunkedMessages ? "true" : "false"); + } #endif // CHIP_DETAIL_LOGGING - break; + break; case kInteractionModelRevisionTag: ReturnErrorOnFailure(MessageParser::CheckInteractionModelRevision(reader)); break; @@ -116,14 +102,13 @@ CHIP_ERROR WriteRequestMessage::Parser::CheckSchemaValidity() const if (CHIP_END_OF_TLV == err) { - const int requiredFields = ((1 << to_underlying(Tag::kTimedRequest)) | (1 << to_underlying(Tag::kWriteRequests))); - err = (tagPresenceMask & requiredFields) == requiredFields ? CHIP_NO_ERROR : CHIP_ERROR_IM_MALFORMED_WRITE_REQUEST_MESSAGE; + err = CHIP_NO_ERROR; } ReturnErrorOnFailure(err); return reader.ExitContainer(mOuterContainerType); } -#endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#endif // CHIP_CONFIG_IM_PRETTY_PRINT CHIP_ERROR WriteRequestMessage::Parser::GetSuppressResponse(bool * const apSuppressResponse) const { diff --git a/src/app/MessageDef/WriteResponseMessage.cpp b/src/app/MessageDef/WriteResponseMessage.cpp index f0bab4d3abc2a1..d0184a1abee912 100644 --- a/src/app/MessageDef/WriteResponseMessage.cpp +++ b/src/app/MessageDef/WriteResponseMessage.cpp @@ -25,11 +25,10 @@ namespace chip { namespace app { -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT CHIP_ERROR WriteResponseMessage::Parser::CheckSchemaValidity() const { - CHIP_ERROR err = CHIP_NO_ERROR; - int tagPresenceMask = 0; + CHIP_ERROR err = CHIP_NO_ERROR; TLV::TLVReader reader; AttributeStatusIBs::Parser writeResponses; PRETTY_PRINT("WriteResponseMessage ="); @@ -48,8 +47,6 @@ CHIP_ERROR WriteResponseMessage::Parser::CheckSchemaValidity() const switch (tagNum) { case to_underlying(Tag::kWriteResponses): - VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kWriteResponses))), CHIP_ERROR_INVALID_TLV_TAG); - tagPresenceMask |= (1 << to_underlying(Tag::kWriteResponses)); VerifyOrReturnError(TLV::kTLVType_Array == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE); ReturnErrorOnFailure(writeResponses.Init(reader)); @@ -77,7 +74,7 @@ CHIP_ERROR WriteResponseMessage::Parser::CheckSchemaValidity() const ReturnErrorOnFailure(err); return reader.ExitContainer(mOuterContainerType); } -#endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#endif // CHIP_CONFIG_IM_PRETTY_PRINT CHIP_ERROR WriteResponseMessage::Parser::GetWriteResponses(AttributeStatusIBs::Parser * const apWriteResponses) const { diff --git a/src/app/ReadClient.cpp b/src/app/ReadClient.cpp index 94a29cd36dac52..a28838893cff38 100644 --- a/src/app/ReadClient.cpp +++ b/src/app/ReadClient.cpp @@ -510,7 +510,7 @@ CHIP_ERROR ReadClient::ProcessReportData(System::PacketBufferHandle && aPayload) err = report.Init(reader); SuccessOrExit(err); -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT err = report.CheckSchemaValidity(); SuccessOrExit(err); #endif @@ -888,7 +888,7 @@ CHIP_ERROR ReadClient::ProcessSubscribeResponse(System::PacketBufferHandle && aP SubscribeResponseMessage::Parser subscribeResponse; ReturnErrorOnFailure(subscribeResponse.Init(reader)); -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT ReturnErrorOnFailure(subscribeResponse.CheckSchemaValidity()); #endif diff --git a/src/app/ReadHandler.cpp b/src/app/ReadHandler.cpp index 64bcbb1a7e516b..cba1be90af6382 100644 --- a/src/app/ReadHandler.cpp +++ b/src/app/ReadHandler.cpp @@ -304,7 +304,7 @@ CHIP_ERROR ReadHandler::ProcessReadRequest(System::PacketBufferHandle && aPayloa reader.Init(std::move(aPayload)); ReturnErrorOnFailure(readRequestParser.Init(reader)); -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT ReturnErrorOnFailure(readRequestParser.CheckSchemaValidity()); #endif @@ -557,7 +557,7 @@ CHIP_ERROR ReadHandler::ProcessSubscribeRequest(System::PacketBufferHandle && aP SubscribeRequestMessage::Parser subscribeRequestParser; ReturnErrorOnFailure(subscribeRequestParser.Init(reader)); -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT ReturnErrorOnFailure(subscribeRequestParser.CheckSchemaValidity()); #endif diff --git a/src/app/StatusResponse.cpp b/src/app/StatusResponse.cpp index c6ed1cbfaf57b4..2609cafbd45788 100644 --- a/src/app/StatusResponse.cpp +++ b/src/app/StatusResponse.cpp @@ -50,7 +50,7 @@ CHIP_ERROR StatusResponse::ProcessStatusResponse(System::PacketBufferHandle && a System::PacketBufferTLVReader reader; reader.Init(std::move(aPayload)); ReturnErrorOnFailure(response.Init(reader)); -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT ReturnErrorOnFailure(response.CheckSchemaValidity()); #endif StatusIB status; diff --git a/src/app/TimedHandler.cpp b/src/app/TimedHandler.cpp index b62d835f2ace8e..ebf82f415fd800 100644 --- a/src/app/TimedHandler.cpp +++ b/src/app/TimedHandler.cpp @@ -114,7 +114,7 @@ CHIP_ERROR TimedHandler::HandleTimedRequestAction(Messaging::ExchangeContext * a TimedRequestMessage::Parser parser; ReturnErrorOnFailure(parser.Init(reader)); -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT ReturnErrorOnFailure(parser.CheckSchemaValidity()); #endif diff --git a/src/app/WriteClient.cpp b/src/app/WriteClient.cpp index bbd4d289f58f05..876cb1fae7b89d 100644 --- a/src/app/WriteClient.cpp +++ b/src/app/WriteClient.cpp @@ -53,7 +53,7 @@ CHIP_ERROR WriteClient::ProcessWriteResponseMessage(System::PacketBufferHandle & ReturnErrorOnFailure(writeResponse.Init(reader)); -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT ReturnErrorOnFailure(writeResponse.CheckSchemaValidity()); #endif diff --git a/src/app/WriteHandler.cpp b/src/app/WriteHandler.cpp index 98b23520997c5d..2cfc966164fe81 100644 --- a/src/app/WriteHandler.cpp +++ b/src/app/WriteHandler.cpp @@ -554,7 +554,7 @@ Status WriteHandler::ProcessWriteRequest(System::PacketBufferHandle && aPayload, err = writeRequestParser.Init(reader); SuccessOrExit(err); -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT err = writeRequestParser.CheckSchemaValidity(); SuccessOrExit(err); #endif diff --git a/src/app/tests/TestCommandInteraction.cpp b/src/app/tests/TestCommandInteraction.cpp index fde62b54ecd3bd..f5148d04b908d6 100644 --- a/src/app/tests/TestCommandInteraction.cpp +++ b/src/app/tests/TestCommandInteraction.cpp @@ -588,7 +588,7 @@ void TestCommandInteraction::ValidateCommandHandlerWithSendCommand(nlTestSuite * err = commandHandler.Finalize(commandPacket); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT chip::System::PacketBufferTLVReader reader; InvokeResponseMessage::Parser invokeResponseMessageParser; reader.Init(std::move(commandPacket)); @@ -659,7 +659,7 @@ void TestCommandInteraction::TestCommandHandlerCommandDataEncoding(nlTestSuite * err = commandHandler.Finalize(commandPacket); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT chip::System::PacketBufferTLVReader reader; InvokeResponseMessage::Parser invokeResponseMessageParser; reader.Init(std::move(commandPacket)); @@ -695,7 +695,7 @@ void TestCommandInteraction::TestCommandHandlerCommandEncodeFailure(nlTestSuite err = commandHandler.Finalize(commandPacket); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT chip::System::PacketBufferTLVReader reader; InvokeResponseMessage::Parser invokeResponseMessageParser; reader.Init(std::move(commandPacket)); @@ -1057,7 +1057,7 @@ void TestCommandInteraction::TestCommandHandlerCommandEncodeExternalFailure(nlTe err = commandHandler.Finalize(commandPacket); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT chip::System::PacketBufferTLVReader reader; InvokeResponseMessage::Parser invokeResponseMessageParser; reader.Init(std::move(commandPacket)); diff --git a/src/app/tests/TestMessageDef.cpp b/src/app/tests/TestMessageDef.cpp index fdae70499b5c8d..c36aac29f1b029 100644 --- a/src/app/tests/TestMessageDef.cpp +++ b/src/app/tests/TestMessageDef.cpp @@ -92,7 +92,7 @@ void ParseStatusIB(nlTestSuite * apSuite, StatusIB::Parser & aStatusIBParser) StatusIB::Parser StatusIBParser; StatusIB statusIB; -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT err = aStatusIBParser.CheckSchemaValidity(); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); #endif @@ -120,7 +120,7 @@ void ParseClusterPathIB(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) err = clusterPathParser.Init(aReader); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT err = clusterPathParser.CheckSchemaValidity(); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); #endif @@ -153,7 +153,7 @@ void ParseDataVersionFilterIB(nlTestSuite * apSuite, chip::TLV::TLVReader & aRea err = dataVersionFilterIBParser.Init(aReader); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT err = dataVersionFilterIBParser.CheckSchemaValidity(); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); #endif @@ -181,7 +181,7 @@ void ParseDataVersionFilterIBs(nlTestSuite * apSuite, chip::TLV::TLVReader & aRe err = dataVersionFilterIBsParser.Init(aReader); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT err = dataVersionFilterIBsParser.CheckSchemaValidity(); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); #endif @@ -202,7 +202,7 @@ void ParseEventFilterIB(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) err = eventFilterIBParser.Init(aReader); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT err = eventFilterIBParser.CheckSchemaValidity(); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); #endif @@ -229,7 +229,7 @@ void ParseEventFilters(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) err = eventFiltersParser.Init(aReader); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT err = eventFiltersParser.CheckSchemaValidity(); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); #endif @@ -262,7 +262,7 @@ void ParseAttributePathIB(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) err = attributePathParser.Init(aReader); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT err = attributePathParser.CheckSchemaValidity(); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); #endif @@ -305,7 +305,7 @@ void ParseAttributePathList(nlTestSuite * apSuite, chip::TLV::TLVReader & aReade err = attributePathListParser.Init(aReader); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT err = attributePathListParser.CheckSchemaValidity(); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); #endif @@ -328,7 +328,7 @@ void ParseEventPath(nlTestSuite * apSuite, EventPathIB::Parser & aEventPathParse chip::EventId event = 4; bool isUrgent = false; -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT err = aEventPathParser.CheckSchemaValidity(); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); #endif @@ -365,7 +365,7 @@ void ParseEventPaths(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) err = eventPathListParser.Init(aReader); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT err = eventPathListParser.CheckSchemaValidity(); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); #endif @@ -388,7 +388,7 @@ void ParseCommandPath(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) err = commandPathParser.Init(aReader); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT err = commandPathParser.CheckSchemaValidity(); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); #endif @@ -442,7 +442,7 @@ void ParseEventDataIB(nlTestSuite * apSuite, EventDataIB::Parser & aEventDataIBP uint64_t deltaUTCTimestamp = 0; uint64_t deltaSystemTimestamp = 0; -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT err = aEventDataIBParser.CheckSchemaValidity(); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); #endif @@ -504,7 +504,7 @@ void ParseEventStatusIB(nlTestSuite * apSuite, EventStatusIB::Parser & aEventSta CHIP_ERROR err = CHIP_NO_ERROR; EventPathIB::Parser eventPathParser; StatusIB::Parser statusParser; -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT err = aEventStatusIBParser.CheckSchemaValidity(); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); #endif @@ -531,7 +531,7 @@ void ParseEventReportIB(nlTestSuite * apSuite, EventReportIB::Parser & aEventRep EventStatusIB::Parser eventStatusParser; EventDataIB::Parser eventDataParser; -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT err = aEventReportIBParser.CheckSchemaValidity(); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); #endif @@ -556,7 +556,7 @@ void ParseEventReports(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) err = eventReportsParser.Init(aReader); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT err = eventReportsParser.CheckSchemaValidity(); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); #endif @@ -582,7 +582,7 @@ void ParseAttributeStatusIB(nlTestSuite * apSuite, AttributeStatusIB::Parser & a AttributePathIB::Parser attributePathParser; StatusIB::Parser StatusIBParser; -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT err = aAttributeStatusIBParser.CheckSchemaValidity(); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); #endif @@ -611,7 +611,7 @@ void ParseAttributeStatuses(nlTestSuite * apSuite, chip::TLV::TLVReader & aReade err = attributeStatusParser.Init(aReader); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT err = attributeStatusParser.CheckSchemaValidity(); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); #endif @@ -652,7 +652,7 @@ void ParseAttributeDataIB(nlTestSuite * apSuite, AttributeDataIB::Parser & aAttr CHIP_ERROR err = CHIP_NO_ERROR; AttributePathIB::Parser attributePathParser; chip::DataVersion version = 0; -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT err = aAttributeDataIBParser.CheckSchemaValidity(); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); #endif @@ -698,7 +698,7 @@ void ParseAttributeDataIBs(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader err = AttributeDataIBsParser.Init(aReader); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT err = AttributeDataIBsParser.CheckSchemaValidity(); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); #endif @@ -720,7 +720,7 @@ void ParseAttributeReportIB(nlTestSuite * apSuite, AttributeReportIB::Parser & a AttributeStatusIB::Parser attributeStatusParser; AttributeDataIB::Parser attributeDataParser; -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT err = aAttributeReportIBParser.CheckSchemaValidity(); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); #endif @@ -745,7 +745,7 @@ void ParseAttributeReportIBs(nlTestSuite * apSuite, chip::TLV::TLVReader & aRead err = attributeReportIBsParser.Init(aReader); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT err = attributeReportIBsParser.CheckSchemaValidity(); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); #endif @@ -782,7 +782,7 @@ void ParseCommandDataIB(nlTestSuite * apSuite, CommandDataIB::Parser & aCommandD { CHIP_ERROR err = CHIP_NO_ERROR; CommandPathIB::Parser commandPathParser; -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT err = aCommandDataIBParser.CheckSchemaValidity(); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); #endif @@ -827,7 +827,7 @@ void ParseCommandStatusIB(nlTestSuite * apSuite, CommandStatusIB::Parser & aComm CHIP_ERROR err = CHIP_NO_ERROR; CommandPathIB::Parser commandPathParser; StatusIB::Parser statusParser; -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT err = aCommandStatusIBParser.CheckSchemaValidity(); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); #endif @@ -840,13 +840,7 @@ void ParseCommandStatusIB(nlTestSuite * apSuite, CommandStatusIB::Parser & aComm void BuildWrongInvokeResponseIB(nlTestSuite * apSuite, InvokeResponseIB::Builder & aInvokeResponseIBBuilder) { - CommandDataIB::Builder & commandDataBuilder = aInvokeResponseIBBuilder.CreateCommand(); - NL_TEST_ASSERT(apSuite, aInvokeResponseIBBuilder.GetError() == CHIP_NO_ERROR); - BuildCommandDataIB(apSuite, commandDataBuilder); - CommandStatusIB::Builder & commandStatusBuilder = aInvokeResponseIBBuilder.CreateStatus(); - NL_TEST_ASSERT(apSuite, aInvokeResponseIBBuilder.GetError() == CHIP_NO_ERROR); - BuildCommandStatusIB(apSuite, commandStatusBuilder); - aInvokeResponseIBBuilder.EndOfInvokeResponseIB(); + aInvokeResponseIBBuilder.CreateCommand(); NL_TEST_ASSERT(apSuite, aInvokeResponseIBBuilder.GetError() == CHIP_NO_ERROR); } @@ -873,7 +867,7 @@ void ParseInvokeResponseIBWithCommandDataIB(nlTestSuite * apSuite, InvokeRespons CHIP_ERROR err = CHIP_NO_ERROR; CommandDataIB::Parser commandDataParser; CommandStatusIB::Parser statusIBParser; -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT err = aInvokeResponseIBParser.CheckSchemaValidity(); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); #endif @@ -886,7 +880,7 @@ void ParseInvokeResponseIBWithCommandStatusIB(nlTestSuite * apSuite, InvokeRespo CHIP_ERROR err = CHIP_NO_ERROR; CommandDataIB::Parser commandDataParser; CommandStatusIB::Parser statusIBParser; -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT err = aInvokeResponseIBParser.CheckSchemaValidity(); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); #endif @@ -894,16 +888,6 @@ void ParseInvokeResponseIBWithCommandStatusIB(nlTestSuite * apSuite, InvokeRespo NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); } -void ParseWrongInvokeResponseIB(nlTestSuite * apSuite, InvokeResponseIB::Parser & aInvokeResponseIBParser) -{ - CommandDataIB::Parser commandDataParser; - CommandStatusIB::Parser statusIBParser; -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK - CHIP_ERROR err = aInvokeResponseIBParser.CheckSchemaValidity(); - NL_TEST_ASSERT(apSuite, err != CHIP_NO_ERROR); -#endif -} - void BuildInvokeRequests(nlTestSuite * apSuite, InvokeRequests::Builder & aInvokeRequestsBuilder) { CommandDataIB::Builder & aCommandDataIBBuilder = aInvokeRequestsBuilder.CreateCommandData(); @@ -921,7 +905,7 @@ void ParseInvokeRequests(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) err = invokeRequestsParser.Init(aReader); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT err = invokeRequestsParser.CheckSchemaValidity(); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); #endif @@ -944,7 +928,7 @@ void ParseInvokeResponses(nlTestSuite * apSuite, chip::TLV::TLVReader & aReader) err = invokeResponsesParser.Init(aReader); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT err = invokeResponsesParser.CheckSchemaValidity(); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); #endif @@ -980,7 +964,7 @@ void ParseInvokeRequestMessage(nlTestSuite * apSuite, chip::TLV::TLVReader & aRe invokeRequestMessageParser.GetTimedRequest(&timedRequest); NL_TEST_ASSERT(apSuite, suppressResponse == true); NL_TEST_ASSERT(apSuite, timedRequest == true); -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT err = invokeRequestMessageParser.CheckSchemaValidity(); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); #endif @@ -1013,7 +997,7 @@ void ParseInvokeResponseMessage(nlTestSuite * apSuite, chip::TLV::TLVReader & aR bool suppressResponse = false; invokeResponseMessageParser.GetSuppressResponse(&suppressResponse); NL_TEST_ASSERT(apSuite, suppressResponse == true); -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT err = invokeResponseMessageParser.CheckSchemaValidity(); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); #endif @@ -1058,7 +1042,7 @@ void ParseReportDataMessage(nlTestSuite * apSuite, chip::TLV::TLVReader & aReade bool moreChunkedMessages = false; reportDataParser.Init(aReader); -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT err = reportDataParser.CheckSchemaValidity(); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); #endif @@ -1124,7 +1108,7 @@ void ParseReadRequestMessage(nlTestSuite * apSuite, chip::TLV::TLVReader & aRead err = readRequestParser.Init(aReader); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT err = readRequestParser.CheckSchemaValidity(); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); #endif @@ -1182,7 +1166,7 @@ void ParseWriteRequestMessage(nlTestSuite * apSuite, chip::TLV::TLVReader & aRea err = writeRequestParser.Init(aReader); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT err = writeRequestParser.CheckSchemaValidity(); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); #endif @@ -1223,7 +1207,7 @@ void ParseWriteResponseMessage(nlTestSuite * apSuite, chip::TLV::TLVReader & aRe AttributeStatusIBs::Parser attributeStatusesParser; err = writeResponseParser.Init(aReader); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT err = writeResponseParser.CheckSchemaValidity(); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); #endif @@ -1289,7 +1273,7 @@ void ParseSubscribeRequestMessage(nlTestSuite * apSuite, chip::TLV::TLVReader & err = subscribeRequestParser.Init(aReader); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT err = subscribeRequestParser.CheckSchemaValidity(); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); #endif @@ -1346,7 +1330,7 @@ void ParseSubscribeResponseMessage(nlTestSuite * apSuite, chip::TLV::TLVReader & uint16_t maxInterval = 0; err = subscribeResponseParser.Init(aReader); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT err = subscribeResponseParser.CheckSchemaValidity(); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); #endif @@ -1380,7 +1364,7 @@ void ParseTimedRequestMessage(nlTestSuite * apSuite, chip::TLV::TLVReader & aRea err = timedRequestMessageParser.Init(aReader); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT err = timedRequestMessageParser.CheckSchemaValidity(); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); #endif @@ -2037,8 +2021,8 @@ void InvokeResponseIBWithMalformDataTest(nlTestSuite * apSuite, void * apContext err = reader.Next(); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); - invokeResponseIBParser.Init(reader); - ParseWrongInvokeResponseIB(apSuite, invokeResponseIBParser); + err = invokeResponseIBParser.Init(reader); + NL_TEST_ASSERT(apSuite, err != CHIP_NO_ERROR); } void InvokeRequestsTest(nlTestSuite * apSuite, void * apContext) @@ -2277,7 +2261,7 @@ void CheckPointRollbackTest(nlTestSuite * apSuite, void * apContext) err = AttributeDataIBsParser.Init(reader); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT err = AttributeDataIBsParser.CheckSchemaValidity(); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); #endif diff --git a/src/app/tests/TestReadInteraction.cpp b/src/app/tests/TestReadInteraction.cpp index 44ba49c400a4b9..547d33fb8668ee 100644 --- a/src/app/tests/TestReadInteraction.cpp +++ b/src/app/tests/TestReadInteraction.cpp @@ -667,11 +667,7 @@ void TestReadInteraction::TestReadHandlerInvalidAttributePath(nlTestSuite * apSu err = readHandler.ProcessReadRequest(std::move(readRequestbuf)); ChipLogError(DataManagement, "The error is %s", ErrorStr(err)); -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK - NL_TEST_ASSERT(apSuite, err == CHIP_ERROR_IM_MALFORMED_READ_REQUEST_MESSAGE); -#else NL_TEST_ASSERT(apSuite, err == CHIP_ERROR_END_OF_TLV); -#endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK // // In the call above to ProcessReadRequest, the handler will not actually close out the EC since @@ -728,7 +724,7 @@ void TestReadInteraction::TestReadClientGenerateOneEventPaths(nlTestSuite * apSu err = readRequestParser.Init(reader); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT err = readRequestParser.CheckSchemaValidity(); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); #endif @@ -780,7 +776,7 @@ void TestReadInteraction::TestReadClientGenerateTwoEventPaths(nlTestSuite * apSu err = readRequestParser.Init(reader); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT err = readRequestParser.CheckSchemaValidity(); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); #endif diff --git a/src/app/tests/TestStatusResponseMessage.cpp b/src/app/tests/TestStatusResponseMessage.cpp index ac48f3732b7dac..73ff31947b0307 100644 --- a/src/app/tests/TestStatusResponseMessage.cpp +++ b/src/app/tests/TestStatusResponseMessage.cpp @@ -58,7 +58,7 @@ void ParseStatusResponseMessage(nlTestSuite * apSuite, chip::TLV::TLVReader & aR err = statusResponse.Init(aReader); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); -#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK +#if CHIP_CONFIG_IM_PRETTY_PRINT err = statusResponse.CheckSchemaValidity(); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); #endif