diff --git a/ESPFirewall/lib/Firewall/src/esp32Storage.cpp b/ESPFirewall/lib/Firewall/src/esp32Storage.cpp index 7516f86..bacaffe 100644 --- a/ESPFirewall/lib/Firewall/src/esp32Storage.cpp +++ b/ESPFirewall/lib/Firewall/src/esp32Storage.cpp @@ -4,8 +4,10 @@ namespace fw { Storage::Storage() { +#ifdef ESP32 if (this->mount_spiffs() == ERROR) endless_loop(); +#endif } Storage::~Storage() @@ -14,19 +16,24 @@ namespace fw ok_t Storage::mount_spiffs() { +#ifdef ESP32 if (!SPIFFS.begin(false)) { if (!SPIFFS.begin(true)) { - log_e("SPIFFS cannot be mounted"); + Serial.println("SPIFFS cannot be mounted"); return ERROR; }; } return SUCCESS; +#elif defined(ESP8266) + return NO_ACTION; +#endif } uint8_t Storage::retrieve_settings_value(const char *key) { +#ifdef ESP32 uint8_t amount_of_rules; this->memory.begin("settings", true); @@ -34,17 +41,23 @@ namespace fw this->memory.end(); return amount_of_rules; +#elif defined(ESP8266) + return 0; +#endif } void Storage::store_settings_value(const char *key, const uint8_t new_amount) { +#ifdef ESP32 this->memory.begin("settings", false); this->memory.putUChar(key, new_amount); this->memory.end(); +#endif } firewall_rule_t *Storage::retrieve_firewall_rule(const uint8_t key) { +#ifdef ESP32 firewall_rule_t *rule_ptr = (firewall_rule_t *)malloc(sizeof(firewall_rule_t)); rule_ptr->key = key; @@ -59,20 +72,26 @@ namespace fw this->memory.end(); return rule_ptr; +#elif defined(ESP8266) + return NULL; +#endif } void Storage::store_all_firewall_rules(firewall_rule_t *head) { +#ifdef ESP32 firewall_rule_t *temp = head; while (temp != NULL) { store_firewall_rule(temp); temp = temp->next; } +#endif } void Storage::store_firewall_rule(firewall_rule_t *rule_ptr) { +#ifdef ESP32 char rulename[9]; // fwRule99\n sprintf(rulename, "fwRule%i", rule_ptr->key); @@ -82,6 +101,7 @@ namespace fw this->memory.putUChar("protocol", rule_ptr->protocol); this->memory.putUChar("target", rule_ptr->target); this->memory.end(); +#endif } // httpsserver::SSLCert *Storage::retrieve_certificate() diff --git a/ESPFirewall/lib/Firewall/src/esp32Storage.hpp b/ESPFirewall/lib/Firewall/src/esp32Storage.hpp index 0aa9d66..13f07a4 100644 --- a/ESPFirewall/lib/Firewall/src/esp32Storage.hpp +++ b/ESPFirewall/lib/Firewall/src/esp32Storage.hpp @@ -1,8 +1,11 @@ #ifndef ESP32_STORAGE_HPP #define ESP32_STORAGE_HPP +#ifdef ESP32 #include "Preferences.h" #include "SPIFFS.h" +#endif + #include "Utils.hpp" namespace fw @@ -10,7 +13,9 @@ namespace fw class Storage { private: +#ifdef ESP32 Preferences memory; +#endif ok_t mount_spiffs(); protected: