mirror of
https://github.com/meshcore-dev/MeshCore.git
synced 2026-04-20 22:13:47 +00:00
refactor ClientACL and CommonCLI, add ClientACL::clear()
This commit is contained in:
parent
3c27132914
commit
6336bd5b72
9 changed files with 25 additions and 9 deletions
|
|
@ -12,6 +12,7 @@ static File openWrite(FILESYSTEM* _fs, const char* filename) {
|
|||
}
|
||||
|
||||
void ClientACL::load(FILESYSTEM* _fs) {
|
||||
_fs = fs;
|
||||
num_clients = 0;
|
||||
if (_fs->exists("/s_contacts")) {
|
||||
#if defined(RP2040_PLATFORM)
|
||||
|
|
@ -50,7 +51,8 @@ void ClientACL::load(FILESYSTEM* _fs) {
|
|||
}
|
||||
}
|
||||
|
||||
void ClientACL::save(FILESYSTEM* _fs, bool (*filter)(ClientInfo*)) {
|
||||
void ClientACL::save(FILESYSTEM* fs, bool (*filter)(ClientInfo*)) {
|
||||
_fs = fs;
|
||||
File file = openWrite(_fs, "/s_contacts");
|
||||
if (file) {
|
||||
uint8_t unused[2];
|
||||
|
|
@ -74,6 +76,16 @@ void ClientACL::save(FILESYSTEM* _fs, bool (*filter)(ClientInfo*)) {
|
|||
}
|
||||
}
|
||||
|
||||
bool ClientACL::clear() {
|
||||
if (!_fs) return false; // no filesystem, nothing to clear
|
||||
if (_fs->exists("/s_contacts")) {
|
||||
_fs->remove("/s_contacts");
|
||||
}
|
||||
memset(clients, 0, sizeof(clients));
|
||||
num_clients = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
ClientInfo* ClientACL::getClient(const uint8_t* pubkey, int key_len) {
|
||||
for (int i = 0; i < num_clients; i++) {
|
||||
if (memcmp(pubkey, clients[i].id.pub_key, key_len) == 0) return &clients[i]; // already known
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue