Skip to content

Commit 04651f9

Browse files
committed
Reworked data manipulators and other cleanup
1 parent 20f0b6a commit 04651f9

19 files changed

+469
-571
lines changed

examples/network-manager-app/linux/args.gni

+2
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,6 @@ chip_project_config_include_dirs = [
2222
]
2323

2424
chip_config_network_layer_ble = false
25+
26+
# This enables AccessRestrictionList (ARL) support used by the NIM sample app
2527
chip_enable_access_restrictions = true

examples/platform/linux/AppMain.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
#include "CommissionableInit.h"
105105

106106
#if CHIP_CONFIG_USE_ACCESS_RESTRICTIONS
107-
#include "ExampleAccessRestriction.h"
107+
#include "ExampleAccessRestrictionProvider.h"
108108
#include <app/server/DefaultArlStorage.h>
109109
#endif
110110

@@ -602,12 +602,12 @@ void ChipLinuxAppMainLoop(AppMainLoopImplementation * impl)
602602
#if CHIP_CONFIG_USE_ACCESS_RESTRICTIONS
603603
if (LinuxDeviceOptions::GetInstance().accessRestrictionEntries.HasValue())
604604
{
605-
initParams.accessRestriction = new ExampleAccessRestriction();
606-
initParams.arlStorage = new app::DefaultArlStorage();
607-
for (const auto & entry : LinuxDeviceOptions::GetInstance().accessRestrictionEntries.Value())
608-
{
609-
VerifyOrDie(AccessRestriction::CreateCommissioningEntry(entry) == CHIP_NO_ERROR);
610-
}
605+
auto exampleAccessRestrictionProvider = new ExampleAccessRestrictionProvider();
606+
exampleAccessRestrictionProvider->SetCommissioningEntries(
607+
LinuxDeviceOptions::GetInstance().accessRestrictionEntries.Value());
608+
609+
initParams.accessRestrictionProvider = exampleAccessRestrictionProvider;
610+
initParams.arlStorage = new app::DefaultArlStorage();
611611
}
612612
#endif
613613

examples/platform/linux/ExampleAccessRestriction.h examples/platform/linux/ExampleAccessRestrictionProvider.h

+5-6
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,25 @@
2222

2323
#pragma once
2424

25-
#include <access/AccessRestriction.h>
25+
#include <access/AccessRestrictionProvider.h>
2626
#include <app-common/zap-generated/cluster-objects.h>
2727
#include <app/EventLogging.h>
2828

2929
namespace chip {
3030
namespace Access {
3131

32-
class ExampleAccessRestriction : public AccessRestriction
32+
class ExampleAccessRestrictionProvider : public AccessRestrictionProvider
3333
{
3434
public:
35-
ExampleAccessRestriction() : AccessRestriction() {}
35+
ExampleAccessRestrictionProvider() : AccessRestrictionProvider() {}
3636

37-
~ExampleAccessRestriction() {}
37+
~ExampleAccessRestrictionProvider() {}
3838

3939
protected:
4040
CHIP_ERROR DoRequestFabricRestrictionReview(const FabricIndex fabricIndex, uint64_t token, const std::vector<Entry> & arl)
4141
{
4242
// this example simply removes all restrictions and will generate AccessRestrictionEntryChanged events
43-
while (Access::GetAccessControl().GetAccessRestriction()->DeleteEntry(0, fabricIndex) == CHIP_NO_ERROR)
44-
;
43+
Access::GetAccessControl().GetAccessRestrictionProvider()->SetEntries(fabricIndex, std::vector<Entry>{});
4544

4645
chip::app::Clusters::AccessControl::Events::FabricRestrictionReviewUpdate::Type event{ .fabricIndex = fabricIndex };
4746
EventNumber eventNumber;

examples/platform/linux/Options.cpp

+8-9
Original file line numberDiff line numberDiff line change
@@ -338,30 +338,29 @@ const char * sDeviceOptionHelp =
338338
"\n";
339339

340340
#if CHIP_CONFIG_USE_ACCESS_RESTRICTIONS
341-
bool ParseAccessRestrictionEntriesFromJson(const char * jsonString,
342-
std::vector<Platform::SharedPtr<AccessRestriction::Entry>> & entries)
341+
bool ParseAccessRestrictionEntriesFromJson(const char * jsonString, std::vector<AccessRestrictionProvider::Entry> & entries)
343342
{
344343
Json::Value root;
345344
Json::Reader reader;
346345
VerifyOrReturnValue(reader.parse(jsonString, root), false);
347346

348347
for (Json::Value::const_iterator eIt = root.begin(); eIt != root.end(); eIt++)
349348
{
350-
auto entry = MakeShared<AccessRestriction::Entry>();
349+
AccessRestrictionProvider::Entry entry;
351350

352-
entry->endpointNumber = static_cast<EndpointId>((*eIt)["endpoint"].asUInt());
353-
entry->clusterId = static_cast<ClusterId>((*eIt)["cluster"].asUInt());
351+
entry.endpointNumber = static_cast<EndpointId>((*eIt)["endpoint"].asUInt());
352+
entry.clusterId = static_cast<ClusterId>((*eIt)["cluster"].asUInt());
354353

355354
Json::Value restrictions = (*eIt)["restrictions"];
356355
for (Json::Value::const_iterator rIt = restrictions.begin(); rIt != restrictions.end(); rIt++)
357356
{
358-
AccessRestriction::Restriction restriction;
359-
restriction.restrictionType = static_cast<AccessRestriction::Type>((*rIt)["type"].asInt());
357+
AccessRestrictionProvider::Restriction restriction;
358+
restriction.restrictionType = static_cast<AccessRestrictionProvider::Type>((*rIt)["type"].asInt());
360359
if ((*rIt).isMember("id"))
361360
{
362361
restriction.id.SetValue((*rIt)["id"].asUInt());
363362
}
364-
entry->restrictions.push_back(restriction);
363+
entry.restrictions.push_back(restriction);
365364
}
366365

367366
entries.push_back(entry);
@@ -582,7 +581,7 @@ bool HandleOption(const char * aProgram, OptionSet * aOptions, int aIdentifier,
582581

583582
#if CHIP_CONFIG_USE_ACCESS_RESTRICTIONS
584583
case kDeviceOption_UseAccessRestrictions: {
585-
std::vector<Platform::SharedPtr<AccessRestriction::Entry>> accessRestrictionEntries;
584+
std::vector<AccessRestrictionProvider::Entry> accessRestrictionEntries;
586585
retval = ParseAccessRestrictionEntriesFromJson(aValue, accessRestrictionEntries);
587586
if (retval)
588587
{

examples/platform/linux/Options.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
#include <testing/CustomCSRResponse.h>
4141

4242
#if CHIP_CONFIG_USE_ACCESS_RESTRICTIONS
43-
#include <access/AccessRestriction.h>
43+
#include <access/AccessRestrictionProvider.h>
4444
#endif
4545

4646
struct LinuxDeviceOptions
@@ -88,7 +88,7 @@ struct LinuxDeviceOptions
8888
int32_t subscriptionResumptionRetryIntervalSec = -1;
8989
#endif
9090
#if CHIP_CONFIG_USE_ACCESS_RESTRICTIONS
91-
chip::Optional<std::vector<chip::Platform::SharedPtr<chip::Access::AccessRestriction::Entry>>> accessRestrictionEntries;
91+
chip::Optional<std::vector<chip::Access::AccessRestrictionProvider::Entry>> accessRestrictionEntries;
9292
#endif
9393
static LinuxDeviceOptions & GetInstance();
9494
};

src/access/AccessControl.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ void AccessControl::RemoveEntryListener(EntryListener & listener)
326326
bool AccessControl::IsAccessRestrictionListSupported() const
327327
{
328328
#if CHIP_CONFIG_USE_ACCESS_RESTRICTIONS
329-
return mAccessRestriction != nullptr;
329+
return mAccessRestrictionProvider != nullptr;
330330
#else
331331
return false;
332332
#endif
@@ -357,9 +357,9 @@ CHIP_ERROR AccessControl::Check(const SubjectDescriptor & subjectDescriptor, con
357357
}
358358

359359
#if CHIP_CONFIG_USE_ACCESS_RESTRICTIONS
360-
if (mAccessRestriction != nullptr)
360+
if (mAccessRestrictionProvider != nullptr)
361361
{
362-
CHIP_ERROR result = mAccessRestriction->Check(subjectDescriptor, requestPath);
362+
CHIP_ERROR result = mAccessRestrictionProvider->Check(subjectDescriptor, requestPath);
363363
if (result != CHIP_NO_ERROR)
364364
{
365365
ChipLogProgress(DataManagement, "AccessControl: %s",

src/access/AccessControl.h

+8-5
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include <access/AccessConfig.h>
2222

2323
#if CHIP_CONFIG_USE_ACCESS_RESTRICTIONS
24-
#include "AccessRestriction.h"
24+
#include "AccessRestrictionProvider.h"
2525
#endif
2626

2727
#include "Privilege.h"
@@ -635,9 +635,12 @@ class AccessControl
635635

636636
#if CHIP_CONFIG_USE_ACCESS_RESTRICTIONS
637637
// Set an optional AcceessRestriction object for MNGD feature.
638-
void SetAccessRestriction(AccessRestriction * accessRestriction) { mAccessRestriction = accessRestriction; }
638+
void SetAccessRestrictionProvider(AccessRestrictionProvider * accessRestrictionProvider)
639+
{
640+
mAccessRestrictionProvider = accessRestrictionProvider;
641+
}
639642

640-
AccessRestriction * GetAccessRestriction() { return mAccessRestriction; }
643+
AccessRestrictionProvider * GetAccessRestrictionProvider() { return mAccessRestrictionProvider; }
641644
#endif
642645

643646
/**
@@ -651,7 +654,7 @@ class AccessControl
651654
* Check whether access (by a subject descriptor, to a request path,
652655
* requiring a privilege) should be allowed or denied.
653656
*
654-
* If an AccessRestriction object is set, it will be checked for additional access restrictions.
657+
* If an AccessRestrictionProvider object is set, it will be checked for additional access restrictions.
655658
*
656659
* @retval #CHIP_ERROR_ACCESS_DENIED if denied.
657660
* @retval other errors should also be treated as denied.
@@ -679,7 +682,7 @@ class AccessControl
679682
EntryListener * mEntryListener = nullptr;
680683

681684
#if CHIP_CONFIG_USE_ACCESS_RESTRICTIONS
682-
AccessRestriction * mAccessRestriction;
685+
AccessRestrictionProvider * mAccessRestrictionProvider;
683686
#endif
684687
};
685688

0 commit comments

Comments
 (0)