Skip to content

Commit

Permalink
Code clarity updates
Browse files Browse the repository at this point in the history
  • Loading branch information
andreilitvin committed Jan 31, 2025
1 parent d36e731 commit 61d7ac7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 17 deletions.
20 changes: 4 additions & 16 deletions src/app/WriteHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* limitations under the License.
*/

#include "app/ConcreteAttributePath.h"
#include <app/AppConfig.h>
#include <app/AttributeAccessInterfaceRegistry.h>
#include <app/AttributeValueDecoder.h>
Expand Down Expand Up @@ -759,7 +760,7 @@ void WriteHandler::MoveToState(const State aTargetState)
}

DataModel::ActionReturnStatus WriteHandler::CheckWriteAllowed(const Access::SubjectDescriptor & aSubject,
const ConcreteDataAttributePath & aPath)
const ConcreteAttributePath & aPath)
{
// TODO: ordering is to check writability/existence BEFORE ACL and this seems wrong, however
// existing unit tests (TC_AcessChecker.py) validate that we get UnsupportedWrite instead of UnsupportedAccess
Expand All @@ -786,21 +787,8 @@ DataModel::ActionReturnStatus WriteHandler::CheckWriteAllowed(const Access::Subj
bool checkAcl = true;
if (mLastSuccessfullyWrittenPath.has_value())
{
// NOTE: explicit cast/check only for attribute path and nothing else.
//
// Specifically we DO NOT use `operator==` because `aPath` is a
// DATA path (contains a list index) and we do not want
// mLastSuccessfullyWrittenPath to be auto-cast to a
// data path with a empty list and fail the compare.
//
// This inline endpoint/cluster/attribute compare results in
// smaller code as well.
if ((aPath.mEndpointId == mLastSuccessfullyWrittenPath->mEndpointId) &&
(aPath.mClusterId == mLastSuccessfullyWrittenPath->mClusterId) &&
(aPath.mAttributeId == mLastSuccessfullyWrittenPath->mAttributeId))
{
checkAcl = false;
}
// only validate ACL if path has changed
checkAcl = (aPath != mLastSuccessfullyWrittenPath);
}

if (checkAcl)
Expand Down
2 changes: 1 addition & 1 deletion src/app/WriteHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ class WriteHandler : public Messaging::ExchangeDelegate
///
/// Returns a success status if all is ok, failure otherwise.
DataModel::ActionReturnStatus CheckWriteAllowed(const Access::SubjectDescriptor & aSubject,
const ConcreteDataAttributePath & aPath);
const ConcreteAttributePath & aPath);

// Write the given data to the given path
CHIP_ERROR WriteClusterData(const Access::SubjectDescriptor & aSubject, const ConcreteDataAttributePath & aPath,
Expand Down

0 comments on commit 61d7ac7

Please sign in to comment.