mirror of
https://github.com/liquidraver/ZephCore.git
synced 2026-09-02 02:08:25 +00:00
Add .gitattributes rules so .c/.h/.cpp/.hpp are always stored as LF (prevents EOL drift from editors with autocrlf-true defaults), and renormalize the 30 source files that had drifted to CRLF in the index. Pure mechanical change — `git diff --ignore-cr-at-eol` is empty. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
73 lines
2.2 KiB
C++
73 lines
2.2 KiB
C++
/*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
* RegionMap - Region-based flood filtering for repeaters
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <mesh/Packet.h>
|
|
#include "TransportKeyStore.h"
|
|
#include <cstdint>
|
|
#include <string.h>
|
|
|
|
#ifndef MAX_REGION_ENTRIES
|
|
#ifdef CONFIG_ZEPHCORE_MAX_REGION_ENTRIES
|
|
#define MAX_REGION_ENTRIES CONFIG_ZEPHCORE_MAX_REGION_ENTRIES
|
|
#else
|
|
#define MAX_REGION_ENTRIES 32
|
|
#endif
|
|
#endif
|
|
|
|
#define REGION_DENY_FLOOD 0x01
|
|
#define REGION_DENY_DIRECT 0x02 // reserved for future
|
|
|
|
struct RegionEntry {
|
|
uint16_t id;
|
|
uint16_t parent;
|
|
uint8_t flags;
|
|
char name[31];
|
|
|
|
bool isWildcard() const { return id == 0; }
|
|
};
|
|
|
|
class RegionMap {
|
|
TransportKeyStore* _store;
|
|
uint16_t next_id;
|
|
uint16_t home_id;
|
|
uint16_t default_id;
|
|
uint16_t num_regions;
|
|
RegionEntry regions[MAX_REGION_ENTRIES];
|
|
RegionEntry wildcard;
|
|
|
|
void printChildRegions(int indent, const RegionEntry* parent, char* buf, int& pos, int max_len) const;
|
|
|
|
public:
|
|
RegionMap(TransportKeyStore& store);
|
|
|
|
static bool is_name_char(uint8_t c);
|
|
|
|
bool load(const char* path = nullptr);
|
|
bool save(const char* path = nullptr);
|
|
|
|
RegionEntry* putRegion(const char* name, uint16_t parent_id, uint16_t id = 0);
|
|
RegionEntry* findMatch(mesh::Packet* packet, uint8_t mask);
|
|
RegionEntry& getWildcard() { return wildcard; }
|
|
RegionEntry* findByName(const char* name);
|
|
RegionEntry* findByNamePrefix(const char* prefix);
|
|
RegionEntry* findById(uint16_t id);
|
|
RegionEntry* getHomeRegion(); // NOTE: can be NULL
|
|
void setHomeRegion(const RegionEntry* home);
|
|
RegionEntry* getDefaultRegion(); // NOTE: can be NULL
|
|
void setDefaultRegion(const RegionEntry* def);
|
|
bool removeRegion(const RegionEntry& region);
|
|
bool clear();
|
|
void resetFrom(const RegionMap& src) { num_regions = 0; next_id = src.next_id; }
|
|
int getCount() const { return num_regions; }
|
|
const RegionEntry* getByIdx(int i) const { return ®ions[i]; }
|
|
const RegionEntry* getRoot() const { return &wildcard; }
|
|
int exportNamesTo(char* dest, int max_len, uint8_t mask, bool invert = false);
|
|
int getTransportKeysFor(const RegionEntry& src, TransportKey dest[], int max_num);
|
|
|
|
size_t exportTo(char* dest, size_t max_len) const;
|
|
};
|