Skip to content

Commit 8c5fc8e

Browse files
committed
Refactor RFConfiguration by removing whitelist and blacklist functionality
1 parent fd986c9 commit 8c5fc8e

File tree

4 files changed

+8
-181
lines changed

4 files changed

+8
-181
lines changed

main/commonRF.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ int currentReceiver = ACTIVE_NONE;
4343
extern void enableActiveReceiver();
4444
extern void disableCurrentReceiver();
4545

46+
// Note: this is currently just a simple wrapper used to make everything work.
47+
// It prevents introducing external dependencies on newly added C++ structures,
48+
// and acts as a first approach to mask the concrete implementations (rf, rf2,
49+
// pilight, etc.). Later this can be extended or replaced by more complete driver
50+
// abstractions without changing the rest of the system.
4651
class ZCommonRFWrapper : public RFReceiver {
4752
public:
4853
ZCommonRFWrapper() : RFReceiver() {}

main/gatewayRF.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ void RFtoX() {
207207

208208
mySwitch.resetAvailable();
209209

210-
if (MQTTvalue != 0 && !isAduplicateSignal(MQTTvalue) && !iRFConfig.inBlackList(MQTTvalue) && iRFConfig.inWhiteList(MQTTvalue)) { // conditions to avoid duplications of RF -->MQTT
210+
if (MQTTvalue != 0 && !isAduplicateSignal(MQTTvalue)) { // conditions to avoid duplications of RF -->MQTT
211211
# if defined(ZmqttDiscovery) && defined(RF_on_HAS_as_DeviceTrigger)
212212
if (SYSConfig.discovery)
213213
announceGatewayTriggerTypeToHASS(MQTTvalue);

main/rf/RFConfiguration.cpp

Lines changed: 2 additions & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,12 @@ extern rtl_433_ESP rtl_433;
88
#endif
99

1010
// Constructor
11-
RFConfiguration::RFConfiguration(RFReceiver& receiver) : iRFReceiver(receiver), whiteList(nullptr), whiteListSize(0), blackList(nullptr), blackListSize(0) {
11+
RFConfiguration::RFConfiguration(RFReceiver& receiver) : iRFReceiver(receiver) {
1212
reInit();
1313
}
1414

1515
// Destructor
1616
RFConfiguration::~RFConfiguration() {
17-
delete[] whiteList;
18-
delete[] blackList;
1917
}
2018

2119
// Getters and Setters
@@ -51,35 +49,6 @@ void RFConfiguration::setActiveReceiver(int receiver) {
5149
activeReceiver = receiver;
5250
}
5351

54-
bool RFConfiguration::isWhitelistIgnored() const {
55-
return ignoreWhitelist;
56-
}
57-
58-
void RFConfiguration::setIgnoreWhitelist(bool ignore) {
59-
ignoreWhitelist = ignore;
60-
}
61-
62-
bool RFConfiguration::isBlacklistIgnored() const {
63-
return ignoreBlacklist;
64-
}
65-
66-
void RFConfiguration::setIgnoreBlacklist(bool ignore) {
67-
ignoreBlacklist = ignore;
68-
}
69-
70-
// Utility methods
71-
void RFConfiguration::clearWhiteList() {
72-
delete[] whiteList;
73-
whiteList = nullptr;
74-
whiteListSize = 0;
75-
}
76-
77-
void RFConfiguration::clearBlackList() {
78-
delete[] blackList;
79-
blackList = nullptr;
80-
blackListSize = 0;
81-
}
82-
8352
/**
8453
* @brief Initializes the RFConfiguration with default values.
8554
*
@@ -96,10 +65,6 @@ void RFConfiguration::reInit() {
9665
activeReceiver = ACTIVE_RECEIVER;
9766
rssiThreshold = 0;
9867
newOokThreshold = 0;
99-
ignoreWhitelist = false;
100-
ignoreBlacklist = false;
101-
clearWhiteList();
102-
clearBlackList();
10368
}
10469

10570
/**
@@ -272,14 +237,7 @@ void RFConfiguration::loadFromMessage(JsonObject& RFdata) {
272237
*/
273238
void RFConfiguration::fromJson(JsonObject& RFdata) {
274239
bool success = false;
275-
if (RFdata.containsKey("white-list")) {
276-
success = commandSetWhiteorBlackList(RFdata, true);
277-
Log.notice(F("RF white-list updated" CR));
278-
}
279-
if (RFdata.containsKey("black-list")) {
280-
success = commandSetWhiteorBlackList(RFdata, false);
281-
Log.notice(F("RF black-list updated" CR));
282-
}
240+
283241
if (RFdata.containsKey("frequency") && validFrequency(RFdata["frequency"])) {
284242
Config_update(RFdata, "frequency", frequency);
285243
Log.notice(F("RF Receive mhz: %F" CR), frequency);
@@ -344,66 +302,11 @@ void RFConfiguration::toJson(JsonObject& RFdata) {
344302
RFdata["rssithreshold"] = rssiThreshold;
345303
RFdata["ookthreshold"] = newOokThreshold;
346304
RFdata["active"] = activeReceiver;
347-
RFdata["ignoreWhitelist"] = ignoreWhitelist;
348-
RFdata["ignoreBlacklist"] = ignoreBlacklist;
349305

350306
// Add white-list vector to the JSON object
351307
JsonArray whiteListArray = RFdata.createNestedArray("white-list");
352-
for (size_t i = 0; i < whiteListSize; ++i) {
353-
whiteListArray.add(whiteList[i]);
354-
}
355308
// Add black-list vector to the JSON object
356309
JsonArray blackListArray = RFdata.createNestedArray("black-list");
357-
for (size_t i = 0; i < blackListSize; ++i) {
358-
blackListArray.add(blackList[i]);
359-
}
360-
}
361-
362-
/**
363-
* @brief Checks if a given MQTT value is present in the blacklist.
364-
*
365-
* This function determines whether the specified MQTT value is included
366-
* in the blacklist defined in the If the `ignoreBlacklist`
367-
* flag in RFConfiguration is set to true, the function will always return false,
368-
* effectively bypassing the blacklist check.
369-
*
370-
* @param MQTTvalue The MQTT value to check against the blacklist.
371-
* @return true if the MQTT value is in the blacklist and the blacklist
372-
* check is not ignored; false otherwise.
373-
*/
374-
bool RFConfiguration::inBlackList(uint64_t MQTTvalue) {
375-
if (ignoreBlacklist) {
376-
return false;
377-
}
378-
for (size_t i = 0; i < blackListSize; ++i) {
379-
if (blackList[i] == MQTTvalue) {
380-
return true;
381-
}
382-
}
383-
return false;
384-
}
385-
386-
/**
387-
* @brief Checks if a given MQTT value is in the whitelist.
388-
*
389-
* This function determines whether the specified MQTT value is present
390-
* in the whitelist. If the whitelist is disabled (via the `ignoreWhitelist`
391-
* flag) or is empty, the function will always return true.
392-
*
393-
* @param MQTTvalue The MQTT value to check against the whitelist.
394-
* @return true if the whitelist is disabled, empty, or the value is found in the whitelist.
395-
* @return false if the value is not in the whitelist.
396-
*/
397-
bool RFConfiguration::inWhiteList(uint64_t MQTTvalue) {
398-
if (ignoreWhitelist || whiteListSize == 0) {
399-
return true;
400-
}
401-
for (size_t i = 0; i < whiteListSize; ++i) {
402-
if (whiteList[i] == MQTTvalue) {
403-
return true;
404-
}
405-
}
406-
return false;
407310
}
408311

409312
/**
@@ -427,48 +330,3 @@ bool RFConfiguration::validFrequency(float mhz) {
427330
return true;
428331
return false;
429332
}
430-
431-
/**
432-
* @brief Updates the white or black list of RF devices.
433-
*
434-
* This function updates the white or black list of RF devices based on the provided JSON object.
435-
* It iterates through the list of devices and creates or updates them in the system.
436-
*
437-
* @param RFdata The JSON object containing the RF data.
438-
* @param isWhite A boolean indicating whether to update the white list (true) or black list (false).
439-
* @return true if the update was successful, false otherwise.
440-
*/
441-
bool RFConfiguration::commandSetWhiteorBlackList(JsonObject& RFdata, bool isWhite) {
442-
Log.trace(F("RF update WorB" CR));
443-
const char* jsonKey = isWhite ? "white-list" : "black-list";
444-
445-
int size = RFdata[jsonKey].size();
446-
if (size == 0)
447-
return false;
448-
449-
if (isWhite) {
450-
clearWhiteList();
451-
} else {
452-
clearBlackList();
453-
}
454-
455-
for (int i = 0; i < size; i++) {
456-
const char* value = RFdata[jsonKey][i];
457-
if (value != NULL) {
458-
uint64_t MQTTvalue = strtoull(value, NULL, 10);
459-
if (isWhite) {
460-
whiteList = (uint64_t*)realloc(whiteList, (whiteListSize + 1) * sizeof(uint64_t));
461-
whiteList[whiteListSize++] = MQTTvalue;
462-
Log.trace(F("[RF] White list updated with value: %s" CR), value);
463-
} else {
464-
blackList = (uint64_t*)realloc(blackList, (blackListSize + 1) * sizeof(uint64_t));
465-
blackList[blackListSize++] = MQTTvalue;
466-
Log.trace(F("[RF] Black list updated with value: %s" CR), value);
467-
}
468-
} else {
469-
Log.error(F("[RF] Error updating WorB: NULL value" CR));
470-
return false;
471-
}
472-
}
473-
return true;
474-
}

main/rf/RFConfiguration.h

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,6 @@ class RFConfiguration {
2424
int getActiveReceiver() const;
2525
void setActiveReceiver(int receiver);
2626

27-
bool isWhitelistIgnored() const;
28-
void setIgnoreWhitelist(bool ignore);
29-
30-
bool isBlacklistIgnored() const;
31-
void setIgnoreBlacklist(bool ignore);
32-
33-
// Utility methods
34-
void clearWhiteList();
35-
void clearBlackList();
36-
3727
/**
3828
* Initializes the structure with default values.
3929
*
@@ -103,24 +93,6 @@ class RFConfiguration {
10393
*/
10494
void toJson(JsonObject& RFdata);
10595

106-
/**
107-
* Checks if a given MQTT value is present in the blacklist.
108-
*
109-
* @param MQTTvalue The MQTT value to check against the blacklist.
110-
* @return true if the MQTT value is in the blacklist and the blacklist
111-
* check is not ignored; false otherwise.
112-
*/
113-
bool inBlackList(uint64_t MQTTvalue);
114-
115-
/**
116-
* Checks if a given MQTT value is in the whitelist.
117-
*
118-
* @param MQTTvalue The MQTT value to check against the whitelist.
119-
* @return true if the whitelist is disabled, empty, or the value is found in the whitelist.
120-
* @return false if the value is not in the whitelist.
121-
*/
122-
bool inWhiteList(uint64_t MQTTvalue);
123-
12496
/**
12597
* @brief Validates if the given frequency is within the acceptable ranges for the CC1101 module.
12698
*
@@ -141,14 +113,6 @@ class RFConfiguration {
141113
int rssiThreshold;
142114
int newOokThreshold;
143115
int activeReceiver;
144-
bool ignoreWhitelist;
145-
bool ignoreBlacklist;
146-
uint64_t* whiteList;
147-
size_t whiteListSize;
148-
uint64_t* blackList;
149-
size_t blackListSize;
150-
151-
bool commandSetWhiteorBlackList(JsonObject& RFdata, bool isWhite);
152116
};
153117

154118
#endif // RFCONFIG_H

0 commit comments

Comments
 (0)