Skip to content

Commit

Permalink
Remove the necessary eleemnt check in im schema check
Browse files Browse the repository at this point in the history
  • Loading branch information
yunhanw-google committed Aug 18, 2022
1 parent 866e7ee commit a3f93b2
Show file tree
Hide file tree
Showing 88 changed files with 535 additions and 932 deletions.
20 changes: 10 additions & 10 deletions examples/common/tracing/decoder/interaction_model/Decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/app/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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}",
Expand Down
2 changes: 1 addition & 1 deletion src/app/CommandHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/app/CommandSender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
40 changes: 12 additions & 28 deletions src/app/MessageDef/AttributeDataIB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 =");
Expand All @@ -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;
Expand All @@ -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();
Expand All @@ -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
{
Expand Down
2 changes: 1 addition & 1 deletion src/app/MessageDef/AttributeDataIB.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/app/MessageDef/AttributeDataIBs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
{
Expand Down
2 changes: 1 addition & 1 deletion src/app/MessageDef/AttributeDataIBs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
49 changes: 10 additions & 39 deletions src/app/MessageDef/AttributePathIB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 =");
Expand All @@ -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
Expand All @@ -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
{
Expand All @@ -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
Expand All @@ -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
{
Expand All @@ -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
Expand Down Expand Up @@ -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
{
Expand Down
2 changes: 1 addition & 1 deletion src/app/MessageDef/AttributePathIB.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/app/MessageDef/AttributePathIBs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
{
Expand Down
2 changes: 1 addition & 1 deletion src/app/MessageDef/AttributePathIBs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit a3f93b2

Please sign in to comment.