From 6cc816beb982823501855336cd00ec520e23b723 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Mon, 24 Apr 2023 10:15:24 -0400 Subject: [PATCH] Log payloads for read/subscribe even if we reject them. (#26188) Right now we only log read/subscribe payloads when we are actaully handling the read/subscribe. But that means when they are rejected it's hard to tell what might have caused them to get rejected. This just moves the logging to much earlier in the processing. --- src/app/InteractionModelEngine.cpp | 7 +++++++ src/app/ReadHandler.cpp | 14 ++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/app/InteractionModelEngine.cpp b/src/app/InteractionModelEngine.cpp index 08f3266f522b1d..2a5dd2f3216932 100644 --- a/src/app/InteractionModelEngine.cpp +++ b/src/app/InteractionModelEngine.cpp @@ -441,6 +441,10 @@ Protocols::InteractionModel::Status InteractionModelEngine::OnReadInitialRequest SubscribeRequestMessage::Parser subscribeRequestParser; VerifyOrReturnError(subscribeRequestParser.Init(reader) == CHIP_NO_ERROR, Status::InvalidAction); +#if CHIP_CONFIG_IM_PRETTY_PRINT + subscribeRequestParser.PrettyPrint(); +#endif + VerifyOrReturnError(subscribeRequestParser.GetKeepSubscriptions(&keepExistingSubscriptions) == CHIP_NO_ERROR, Status::InvalidAction); if (!keepExistingSubscriptions) @@ -538,6 +542,9 @@ Protocols::InteractionModel::Status InteractionModelEngine::OnReadInitialRequest ReadRequestMessage::Parser readRequestParser; VerifyOrReturnError(readRequestParser.Init(reader) == CHIP_NO_ERROR, Status::InvalidAction); +#if CHIP_CONFIG_IM_PRETTY_PRINT + readRequestParser.PrettyPrint(); +#endif { size_t requestedAttributePathCount = 0; size_t requestedEventPathCount = 0; diff --git a/src/app/ReadHandler.cpp b/src/app/ReadHandler.cpp index 5dc2ce668fec09..ef594e3badd163 100644 --- a/src/app/ReadHandler.cpp +++ b/src/app/ReadHandler.cpp @@ -394,9 +394,10 @@ CHIP_ERROR ReadHandler::ProcessReadRequest(System::PacketBufferHandle && aPayloa reader.Init(std::move(aPayload)); ReturnErrorOnFailure(readRequestParser.Init(reader)); -#if CHIP_CONFIG_IM_PRETTY_PRINT - readRequestParser.PrettyPrint(); -#endif + + // No need to pretty-print here. We pretty-print read requests in the read + // case of InteractionModelEngine::OnReadInitialRequest, so we do it even if + // we reject a read request. err = readRequestParser.GetAttributeRequests(&attributePathListParser); if (err == CHIP_END_OF_TLV) @@ -647,9 +648,10 @@ CHIP_ERROR ReadHandler::ProcessSubscribeRequest(System::PacketBufferHandle && aP SubscribeRequestMessage::Parser subscribeRequestParser; ReturnErrorOnFailure(subscribeRequestParser.Init(reader)); -#if CHIP_CONFIG_IM_PRETTY_PRINT - subscribeRequestParser.PrettyPrint(); -#endif + + // No need to pretty-print here. We pretty-print subscribe requests in the + // subscribe case of InteractionModelEngine::OnReadInitialRequest, so we do + // it even if we reject a subscribe request. AttributePathIBs::Parser attributePathListParser; CHIP_ERROR err = subscribeRequestParser.GetAttributeRequests(&attributePathListParser);