Skip to content

Commit 751d0dd

Browse files
Repurpose the checkSchemaValidity to PrettyPrint only (project-chip#21987)
--Remove the necessary elemnt check in im pretty print --Rename CheckSchemaValidity to PrettyPrint --Don't process the returned error for prettyPrint in IM client/server code
1 parent 6221fe1 commit 751d0dd

File tree

93 files changed

+732
-1641
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+732
-1641
lines changed

config/esp32/components/chip/CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ if (CONFIG_BUILD_CHIP_TESTS)
119119
chip_gn_arg_bool("chip_build_tests" "true")
120120
endif()
121121

122-
if (CONFIG_CHIP_ENABLE_SCHEMA_CHECK)
123-
chip_gn_arg_bool("chip_enable_schema_check" "true")
122+
if (CONFIG_IM_PRETTY_PRINT)
123+
chip_gn_arg_bool("enable_im_pretty_print" "true")
124124
endif()
125125

126126
if (NOT CONFIG_USE_MINIMAL_MDNS)

config/esp32/components/chip/Kconfig

+3-4
Original file line numberDiff line numberDiff line change
@@ -787,12 +787,11 @@ menu "CHIP Device Layer"
787787
for the debug level events are disabled.
788788

789789

790-
config CHIP_ENABLE_SCHEMA_CHECK
791-
bool "Enable Schema Check"
790+
config CHIP_CONFIG_IM_PRETTY_PRINT
791+
bool "Enable IM Pretty Print"
792792
default y
793793
help
794-
If enabled, it checks incoming messages are following the expected schema,
795-
and incoming message payloads are logged in detail.
794+
If enabled, incoming message payloads are logged in detail.
796795
To see detailed logging please set default log level to Debug.
797796
(Component config --> Log output --> Default log verbosity --> Debug)
798797

examples/common/tracing/decoder/interaction_model/Decoder.cpp

+20-20
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,12 @@ CHIP_ERROR LogAsProtocolMessage(uint8_t protocolCode, const uint8_t * data, size
132132

133133
CHIP_ERROR DecodeStatusResponse(TLV::TLVReader & reader, bool decode)
134134
{
135-
#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK
135+
#if CHIP_CONFIG_IM_PRETTY_PRINT
136136
if (decode)
137137
{
138138
app::StatusResponseMessage::Parser parser;
139139
ReturnErrorOnFailure(parser.Init(reader));
140-
return parser.CheckSchemaValidity();
140+
parser.PrettyPrint();
141141
}
142142
#endif
143143

@@ -146,12 +146,12 @@ CHIP_ERROR DecodeStatusResponse(TLV::TLVReader & reader, bool decode)
146146

147147
CHIP_ERROR DecodeReadRequest(TLV::TLVReader & reader, bool decode)
148148
{
149-
#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK
149+
#if CHIP_CONFIG_IM_PRETTY_PRINT
150150
if (decode)
151151
{
152152
app::ReadRequestMessage::Parser parser;
153153
ReturnErrorOnFailure(parser.Init(reader));
154-
return parser.CheckSchemaValidity();
154+
return parser.PrettyPrint();
155155
}
156156
#endif
157157

@@ -160,12 +160,12 @@ CHIP_ERROR DecodeReadRequest(TLV::TLVReader & reader, bool decode)
160160

161161
CHIP_ERROR DecodeSubscribeRequest(TLV::TLVReader & reader, bool decode)
162162
{
163-
#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK
163+
#if CHIP_CONFIG_IM_PRETTY_PRINT
164164
if (decode)
165165
{
166166
app::SubscribeRequestMessage::Parser parser;
167167
ReturnErrorOnFailure(parser.Init(reader));
168-
return parser.CheckSchemaValidity();
168+
return parser.PrettyPrint();
169169
}
170170
#endif
171171

@@ -174,12 +174,12 @@ CHIP_ERROR DecodeSubscribeRequest(TLV::TLVReader & reader, bool decode)
174174

175175
CHIP_ERROR DecodeSubscribeResponse(TLV::TLVReader & reader, bool decode)
176176
{
177-
#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK
177+
#if CHIP_CONFIG_IM_PRETTY_PRINT
178178
if (decode)
179179
{
180180
app::SubscribeResponseMessage::Parser parser;
181181
ReturnErrorOnFailure(parser.Init(reader));
182-
return parser.CheckSchemaValidity();
182+
parser.PrettyPrint();
183183
}
184184
#endif
185185

@@ -190,12 +190,12 @@ CHIP_ERROR DecodeReportData(TLV::TLVReader & reader, bool decode)
190190
{
191191
ReturnErrorOnFailure(MaybeDecodeNestedReadResponse(reader.GetReadPoint(), reader.GetTotalLength()));
192192

193-
#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK
193+
#if CHIP_CONFIG_IM_PRETTY_PRINT
194194
if (decode)
195195
{
196196
app::ReportDataMessage::Parser parser;
197197
ReturnErrorOnFailure(parser.Init(reader));
198-
return parser.CheckSchemaValidity();
198+
parser.PrettyPrint();
199199
}
200200
#endif
201201

@@ -204,12 +204,12 @@ CHIP_ERROR DecodeReportData(TLV::TLVReader & reader, bool decode)
204204

205205
CHIP_ERROR DecodeWriteRequest(TLV::TLVReader & reader, bool decode)
206206
{
207-
#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK
207+
#if CHIP_CONFIG_IM_PRETTY_PRINT
208208
if (decode)
209209
{
210210
app::WriteRequestMessage::Parser parser;
211211
ReturnErrorOnFailure(parser.Init(reader));
212-
return parser.CheckSchemaValidity();
212+
return parser.PrettyPrint();
213213
}
214214
#endif
215215

@@ -218,12 +218,12 @@ CHIP_ERROR DecodeWriteRequest(TLV::TLVReader & reader, bool decode)
218218

219219
CHIP_ERROR DecodeWriteResponse(TLV::TLVReader & reader, bool decode)
220220
{
221-
#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK
221+
#if CHIP_CONFIG_IM_PRETTY_PRINT
222222
if (decode)
223223
{
224224
app::WriteResponseMessage::Parser parser;
225225
ReturnErrorOnFailure(parser.Init(reader));
226-
return parser.CheckSchemaValidity();
226+
return parser.PrettyPrint();
227227
}
228228
#endif
229229

@@ -234,12 +234,12 @@ CHIP_ERROR DecodeInvokeCommandRequest(TLV::TLVReader & reader, bool decode)
234234
{
235235
ReturnErrorOnFailure(MaybeDecodeNestedCommandRequest(reader.GetReadPoint(), reader.GetTotalLength()));
236236

237-
#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK
237+
#if CHIP_CONFIG_IM_PRETTY_PRINT
238238
if (decode)
239239
{
240240
app::InvokeRequestMessage::Parser parser;
241241
ReturnErrorOnFailure(parser.Init(reader));
242-
return parser.CheckSchemaValidity();
242+
return parser.PrettyPrint();
243243
}
244244
#endif
245245

@@ -250,12 +250,12 @@ CHIP_ERROR DecodeInvokeCommandResponse(TLV::TLVReader & reader, bool decode)
250250
{
251251
ReturnErrorOnFailure(MaybeDecodeNestedCommandResponse(reader.GetReadPoint(), reader.GetTotalLength()));
252252

253-
#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK
253+
#if CHIP_CONFIG_IM_PRETTY_PRINT
254254
if (decode)
255255
{
256256
app::InvokeResponseMessage::Parser parser;
257257
ReturnErrorOnFailure(parser.Init(reader));
258-
return parser.CheckSchemaValidity();
258+
parser.PrettyPrint();
259259
}
260260
#endif
261261

@@ -264,12 +264,12 @@ CHIP_ERROR DecodeInvokeCommandResponse(TLV::TLVReader & reader, bool decode)
264264

265265
CHIP_ERROR DecodeTimedRequest(TLV::TLVReader & reader, bool decode)
266266
{
267-
#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK
267+
#if CHIP_CONFIG_IM_PRETTY_PRINT
268268
if (decode)
269269
{
270270
app::TimedRequestMessage::Parser parser;
271271
ReturnErrorOnFailure(parser.Init(reader));
272-
return parser.CheckSchemaValidity();
272+
parser.PrettyPrint();
273273
}
274274
#endif
275275

src/app/BUILD.gn

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import("common_flags.gni")
2020

2121
declare_args() {
2222
# Enable strict schema checks.
23-
chip_enable_schema_check =
23+
enable_im_pretty_print =
2424
is_debug && (current_os == "linux" || current_os == "mac" ||
2525
current_os == "ios" || current_os == "android")
2626

@@ -46,7 +46,7 @@ buildconfig_header("app_buildconfig") {
4646
header_dir = "app"
4747

4848
defines = [
49-
"CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK=${chip_enable_schema_check}",
49+
"CHIP_CONFIG_IM_PRETTY_PRINT=${enable_im_pretty_print}",
5050
"CHIP_CONFIG_IM_FORCE_FABRIC_QUOTA_CHECK=${chip_im_force_fabric_quota_check}",
5151
"CHIP_CONFIG_ENABLE_SESSION_RESUMPTION=${chip_enable_session_resumption}",
5252
"CHIP_CONFIG_ACCESS_CONTROL_POLICY_LOGGING_VERBOSITY=${chip_access_control_policy_logging_verbosity}",

src/app/CommandHandler.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ Status CommandHandler::ProcessInvokeRequest(System::PacketBufferHandle && payloa
104104
InvokeRequests::Parser invokeRequests;
105105
reader.Init(std::move(payload));
106106
VerifyOrReturnError(invokeRequestMessage.Init(reader) == CHIP_NO_ERROR, Status::InvalidAction);
107-
#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK
108-
VerifyOrReturnError(invokeRequestMessage.CheckSchemaValidity() == CHIP_NO_ERROR, Status::InvalidAction);
107+
#if CHIP_CONFIG_IM_PRETTY_PRINT
108+
invokeRequestMessage.PrettyPrint();
109109
#endif
110110

111111
VerifyOrReturnError(invokeRequestMessage.GetSuppressResponse(&mSuppressResponse) == CHIP_NO_ERROR, Status::InvalidAction);

src/app/CommandSender.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,8 @@ CHIP_ERROR CommandSender::ProcessInvokeResponse(System::PacketBufferHandle && pa
213213
reader.Init(std::move(payload));
214214
ReturnErrorOnFailure(invokeResponseMessage.Init(reader));
215215

216-
#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK
217-
ReturnErrorOnFailure(invokeResponseMessage.CheckSchemaValidity());
216+
#if CHIP_CONFIG_IM_PRETTY_PRINT
217+
invokeResponseMessage.PrettyPrint();
218218
#endif
219219

220220
ReturnErrorOnFailure(invokeResponseMessage.GetSuppressResponse(&suppressResponse));

src/app/MessageDef/AttributeDataIB.cpp

+13-29
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,10 @@
2828

2929
namespace chip {
3030
namespace app {
31-
#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK
32-
CHIP_ERROR AttributeDataIB::Parser::CheckSchemaValidity() const
31+
#if CHIP_CONFIG_IM_PRETTY_PRINT
32+
CHIP_ERROR AttributeDataIB::Parser::PrettyPrint() const
3333
{
34-
CHIP_ERROR err = CHIP_NO_ERROR;
35-
int tagPresenceMask = 0;
34+
CHIP_ERROR err = CHIP_NO_ERROR;
3635
TLV::TLVReader reader;
3736

3837
PRETTY_PRINT("AttributeDataIB =");
@@ -51,11 +50,7 @@ CHIP_ERROR AttributeDataIB::Parser::CheckSchemaValidity() const
5150
switch (tagNum)
5251
{
5352
case to_underlying(Tag::kDataVersion):
54-
// check if this tag has appeared before
55-
VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kDataVersion))), CHIP_ERROR_INVALID_TLV_TAG);
56-
tagPresenceMask |= (1 << to_underlying(Tag::kDataVersion));
5753
VerifyOrReturnError(TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE);
58-
5954
#if CHIP_DETAIL_LOGGING
6055
{
6156
chip::DataVersion version;
@@ -64,24 +59,16 @@ CHIP_ERROR AttributeDataIB::Parser::CheckSchemaValidity() const
6459
}
6560
#endif // CHIP_DETAIL_LOGGING
6661
break;
67-
case to_underlying(Tag::kPath):
68-
// check if this tag has appeared before
69-
VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kPath))), CHIP_ERROR_INVALID_TLV_TAG);
70-
tagPresenceMask |= (1 << to_underlying(Tag::kPath));
71-
{
72-
AttributePathIB::Parser path;
73-
ReturnErrorOnFailure(path.Init(reader));
62+
case to_underlying(Tag::kPath): {
63+
AttributePathIB::Parser path;
64+
ReturnErrorOnFailure(path.Init(reader));
7465

75-
PRETTY_PRINT_INCDEPTH();
76-
ReturnErrorOnFailure(path.CheckSchemaValidity());
77-
PRETTY_PRINT_DECDEPTH();
78-
}
79-
break;
66+
PRETTY_PRINT_INCDEPTH();
67+
ReturnErrorOnFailure(path.PrettyPrint());
68+
PRETTY_PRINT_DECDEPTH();
69+
}
70+
break;
8071
case to_underlying(Tag::kData):
81-
// check if this tag has appeared before
82-
VerifyOrReturnError(!(tagPresenceMask & (1 << to_underlying(Tag::kData))), CHIP_ERROR_INVALID_TLV_TAG);
83-
tagPresenceMask |= (1 << to_underlying(Tag::kData));
84-
8572
PRETTY_PRINT_INCDEPTH();
8673
ReturnErrorOnFailure(CheckIMPayload(reader, 0, "Data"));
8774
PRETTY_PRINT_DECDEPTH();
@@ -97,15 +84,12 @@ CHIP_ERROR AttributeDataIB::Parser::CheckSchemaValidity() const
9784
// if we have exhausted this container
9885
if (CHIP_END_OF_TLV == err)
9986
{
100-
// check for required fields:
101-
const int requiredFields = (1 << to_underlying(Tag::kPath)) | (1 << to_underlying(Tag::kData));
102-
103-
err = (tagPresenceMask & requiredFields) == requiredFields ? CHIP_NO_ERROR : CHIP_ERROR_IM_MALFORMED_ATTRIBUTE_DATA_IB;
87+
err = CHIP_NO_ERROR;
10488
}
10589
ReturnErrorOnFailure(err);
10690
return reader.ExitContainer(mOuterContainerType);
10791
}
108-
#endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK
92+
#endif // CHIP_CONFIG_IM_PRETTY_PRINT
10993

11094
CHIP_ERROR AttributeDataIB::Parser::GetPath(AttributePathIB::Parser * const apPath) const
11195
{

src/app/MessageDef/AttributeDataIB.h

+3-17
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,9 @@ enum class Tag : uint8_t
4242
class Parser : public StructParser
4343
{
4444
public:
45-
#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK
46-
/**
47-
* @brief Roughly verify the message is correctly formed
48-
* 1) all mandatory tags are present
49-
* 2) all elements have expected data type
50-
* 3) any tag can only appear once
51-
* 4) At the top level of the structure, unknown tags are ignored for forward compatibility
52-
* @note The main use of this function is to print out what we're
53-
* receiving during protocol development and debugging.
54-
* The encoding rule has changed in IM encoding spec so this
55-
* check is only "roughly" conformant now.
56-
*
57-
* @return #CHIP_NO_ERROR on success
58-
*/
59-
CHIP_ERROR CheckSchemaValidity() const;
60-
#endif
61-
45+
#if CHIP_CONFIG_IM_PRETTY_PRINT
46+
CHIP_ERROR PrettyPrint() const;
47+
#endif // CHIP_CONFIG_IM_PRETTY_PRINT
6248
/**
6349
* @brief Get the DataVersion.
6450
*

src/app/MessageDef/AttributeDataIBs.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ using namespace chip::TLV;
3636

3737
namespace chip {
3838
namespace app {
39-
#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK
40-
CHIP_ERROR AttributeDataIBs::Parser::CheckSchemaValidity() const
39+
#if CHIP_CONFIG_IM_PRETTY_PRINT
40+
CHIP_ERROR AttributeDataIBs::Parser::PrettyPrint() const
4141
{
4242
CHIP_ERROR err = CHIP_NO_ERROR;
4343
size_t numDataElement = 0;
@@ -59,7 +59,7 @@ CHIP_ERROR AttributeDataIBs::Parser::CheckSchemaValidity() const
5959
ReturnErrorOnFailure(data.Init(reader));
6060

6161
PRETTY_PRINT_INCDEPTH();
62-
ReturnErrorOnFailure(data.CheckSchemaValidity());
62+
ReturnErrorOnFailure(data.PrettyPrint());
6363
PRETTY_PRINT_DECDEPTH();
6464
}
6565

@@ -81,7 +81,7 @@ CHIP_ERROR AttributeDataIBs::Parser::CheckSchemaValidity() const
8181
ReturnErrorOnFailure(err);
8282
return reader.ExitContainer(mOuterContainerType);
8383
}
84-
#endif // CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK
84+
#endif // CHIP_CONFIG_IM_PRETTY_PRINT
8585

8686
AttributeDataIB::Builder & AttributeDataIBs::Builder::CreateAttributeDataIBBuilder()
8787
{

src/app/MessageDef/AttributeDataIBs.h

+3-16
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,9 @@ namespace AttributeDataIBs {
4040
class Parser : public ArrayParser
4141
{
4242
public:
43-
#if CHIP_CONFIG_IM_ENABLE_SCHEMA_CHECK
44-
/**
45-
* @brief Roughly verify the message is correctly formed
46-
* 1) all mandatory tags are present
47-
* 2) all elements have expected data type
48-
* 3) any tag can only appear once
49-
* 4) At the top level of the structure, unknown tags are ignored for forward compatibility
50-
* @note The main use of this function is to print out what we're
51-
* receiving during protocol development and debugging.
52-
* The encoding rule has changed in IM encoding spec so this
53-
* check is only "roughly" conformant now.
54-
*
55-
* @return #CHIP_NO_ERROR on success
56-
*/
57-
CHIP_ERROR CheckSchemaValidity() const;
58-
#endif
43+
#if CHIP_CONFIG_IM_PRETTY_PRINT
44+
CHIP_ERROR PrettyPrint() const;
45+
#endif // CHIP_CONFIG_IM_PRETTY_PRINT
5946
};
6047

6148
class Builder : public ArrayBuilder

0 commit comments

Comments
 (0)