Skip to content

Commit

Permalink
[nxp fromtree] [DiagnosticLogs] When the size of the logs for the tar…
Browse files Browse the repository at this point in the history
…get intent is 0, the server returns Exhausted instead of NoLogs (project-chip#32205)

(cherry picked from commit d2ed79c)
  • Loading branch information
vivien-apple authored and dinabenamar committed Mar 22, 2024
1 parent 7c12adc commit 9b03d2a
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ void DiagnosticLogsServer::HandleLogRequestForResponsePayload(CommandHandler * c
Optional<uint64_t> timeStamp;
Optional<uint64_t> timeSinceBoot;

auto size = delegate->GetSizeForIntent(intent);
VerifyOrReturn(size != 0, AddResponse(commandObj, path, StatusEnum::kNoLogs));

auto err = delegate->GetLogForIntent(intent, logContent, timeStamp, timeSinceBoot);
VerifyOrReturn(CHIP_ERROR_NOT_FOUND != err, AddResponse(commandObj, path, StatusEnum::kNoLogs));
VerifyOrReturn(CHIP_NO_ERROR == err, AddResponse(commandObj, path, StatusEnum::kDenied));
Expand All @@ -136,10 +139,13 @@ void DiagnosticLogsServer::HandleLogRequestForBdx(CommandHandler * commandObj, c
auto * delegate = GetDiagnosticLogsProviderDelegate(path.mEndpointId);
VerifyOrReturn(nullptr != delegate, AddResponse(commandObj, path, StatusEnum::kNoLogs));

auto size = delegate->GetSizeForIntent(intent);
// In the case where the size is 0 sets the Status field of the RetrieveLogsResponse to NoLogs and do not start a BDX session.
VerifyOrReturn(size != 0, HandleLogRequestForResponsePayload(commandObj, path, intent, StatusEnum::kNoLogs));

// In the case where the Node is able to fit the entirety of the requested logs within the LogContent field, the Status field of
// the RetrieveLogsResponse SHALL be set to Exhausted and a BDX session SHALL NOT be initiated.
VerifyOrReturn(delegate->GetSizeForIntent(intent) > kMaxLogContentSize,
HandleLogRequestForResponsePayload(commandObj, path, intent, StatusEnum::kExhausted));
VerifyOrReturn(size > kMaxLogContentSize, HandleLogRequestForResponsePayload(commandObj, path, intent, StatusEnum::kExhausted));

// If the RequestedProtocol is set to BDX and either the Node does not support BDX or it is not possible for the Node
// to establish a BDX session, then the Node SHALL utilize the LogContent field of the RetrieveLogsResponse command
Expand Down

0 comments on commit 9b03d2a

Please sign in to comment.