From 9ecda70764eeae4d8690cf44a1bc1da90311a239 Mon Sep 17 00:00:00 2001 From: Florian Hoss Date: Fri, 29 Jul 2022 10:36:46 +0200 Subject: [PATCH] Compile for the correct device --- src/{esp32 => }/Utils.cpp | 0 src/{esp32 => }/Utils.hpp | 0 src/esp32/API.cpp | 2 + src/esp32/API.hpp | 2 +- src/esp32/Firewall.cpp | 2 + src/esp32/Firewall.hpp | 2 +- src/esp32/Storage.cpp | 2 + src/esp32/Storage.hpp | 2 +- src/esp8266/API.cpp | 2 + src/esp8266/API.hpp | 2 +- src/esp8266/Firewall.cpp | 2 + src/esp8266/Firewall.hpp | 2 +- src/esp8266/Storage.cpp | 2 + src/esp8266/Storage.hpp | 2 +- src/esp8266/Utils.cpp | 58 ------------------------- src/esp8266/Utils.hpp | 90 --------------------------------------- 16 files changed, 18 insertions(+), 154 deletions(-) rename src/{esp32 => }/Utils.cpp (100%) rename src/{esp32 => }/Utils.hpp (100%) delete mode 100644 src/esp8266/Utils.cpp delete mode 100644 src/esp8266/Utils.hpp diff --git a/src/esp32/Utils.cpp b/src/Utils.cpp similarity index 100% rename from src/esp32/Utils.cpp rename to src/Utils.cpp diff --git a/src/esp32/Utils.hpp b/src/Utils.hpp similarity index 100% rename from src/esp32/Utils.hpp rename to src/Utils.hpp diff --git a/src/esp32/API.cpp b/src/esp32/API.cpp index 6d9c734..24b61af 100644 --- a/src/esp32/API.cpp +++ b/src/esp32/API.cpp @@ -1,3 +1,4 @@ +#ifdef ESP32 #include "API.hpp" namespace fw @@ -283,3 +284,4 @@ namespace fw return serialized_string; } } +#endif diff --git a/src/esp32/API.hpp b/src/esp32/API.hpp index bd5cd78..eb6f9d4 100644 --- a/src/esp32/API.hpp +++ b/src/esp32/API.hpp @@ -4,7 +4,7 @@ #include "WebServer.h" #include "uri/UriBraces.h" #include "Firewall.hpp" -#include "Utils.hpp" +#include "../Utils.hpp" namespace fw { diff --git a/src/esp32/Firewall.cpp b/src/esp32/Firewall.cpp index f94012c..4fac93f 100644 --- a/src/esp32/Firewall.cpp +++ b/src/esp32/Firewall.cpp @@ -1,3 +1,4 @@ +#ifdef ESP32 #include "Firewall.hpp" namespace fw @@ -179,3 +180,4 @@ namespace fw return false; } } +#endif diff --git a/src/esp32/Firewall.hpp b/src/esp32/Firewall.hpp index 091e9e3..c6aa93d 100644 --- a/src/esp32/Firewall.hpp +++ b/src/esp32/Firewall.hpp @@ -1,7 +1,7 @@ #ifndef ESP32_FIREWALL_HPP #define ESP32_FIREWALL_HPP -#include "Utils.hpp" +#include "../Utils.hpp" #include "Storage.hpp" #include "WiFiClient.h" #include "lwip/netif.h" diff --git a/src/esp32/Storage.cpp b/src/esp32/Storage.cpp index d9d44ee..dfbaf6b 100644 --- a/src/esp32/Storage.cpp +++ b/src/esp32/Storage.cpp @@ -1,3 +1,4 @@ +#ifdef ESP32 #include "Storage.hpp" namespace fw @@ -68,3 +69,4 @@ namespace fw this->memory.end(); } } +#endif diff --git a/src/esp32/Storage.hpp b/src/esp32/Storage.hpp index 2cf4414..85bea3f 100644 --- a/src/esp32/Storage.hpp +++ b/src/esp32/Storage.hpp @@ -2,7 +2,7 @@ #define ESP32_STORAGE_HPP #include "Preferences.h" -#include "Utils.hpp" +#include "../Utils.hpp" namespace fw { diff --git a/src/esp8266/API.cpp b/src/esp8266/API.cpp index 13a1558..2e69b31 100644 --- a/src/esp8266/API.cpp +++ b/src/esp8266/API.cpp @@ -1,3 +1,4 @@ +#ifdef ESP8266 #include "API.hpp" namespace fw @@ -285,3 +286,4 @@ namespace fw return serialized_string; } } +#endif diff --git a/src/esp8266/API.hpp b/src/esp8266/API.hpp index d5bcc5a..da1e94d 100644 --- a/src/esp8266/API.hpp +++ b/src/esp8266/API.hpp @@ -4,7 +4,7 @@ #include "ESP8266WebServerSecure.h" #include "uri/UriBraces.h" #include "Firewall.hpp" -#include "Utils.hpp" +#include "../Utils.hpp" namespace fw { diff --git a/src/esp8266/Firewall.cpp b/src/esp8266/Firewall.cpp index f94012c..2cbdae1 100644 --- a/src/esp8266/Firewall.cpp +++ b/src/esp8266/Firewall.cpp @@ -1,3 +1,4 @@ +#ifdef ESP8266 #include "Firewall.hpp" namespace fw @@ -179,3 +180,4 @@ namespace fw return false; } } +#endif diff --git a/src/esp8266/Firewall.hpp b/src/esp8266/Firewall.hpp index bcff05d..6117ef2 100644 --- a/src/esp8266/Firewall.hpp +++ b/src/esp8266/Firewall.hpp @@ -1,7 +1,7 @@ #ifndef ESP8266_FIREWALL_HPP #define ESP8266_FIREWALL_HPP -#include "Utils.hpp" +#include "../Utils.hpp" #include "Storage.hpp" #include "WiFiClient.h" #include "lwip/netif.h" diff --git a/src/esp8266/Storage.cpp b/src/esp8266/Storage.cpp index 9299a28..5e7c318 100644 --- a/src/esp8266/Storage.cpp +++ b/src/esp8266/Storage.cpp @@ -1,3 +1,4 @@ +#ifdef ESP8266 #include "Storage.hpp" namespace fw @@ -72,3 +73,4 @@ namespace fw EEPROM.commit(); } } +#endif diff --git a/src/esp8266/Storage.hpp b/src/esp8266/Storage.hpp index d9a3747..aee758c 100644 --- a/src/esp8266/Storage.hpp +++ b/src/esp8266/Storage.hpp @@ -2,7 +2,7 @@ #define ESP8266_STORAGE_HPP #include "EEPROM.h" -#include "Utils.hpp" +#include "../Utils.hpp" namespace fw { diff --git a/src/esp8266/Utils.cpp b/src/esp8266/Utils.cpp deleted file mode 100644 index c2a5137..0000000 --- a/src/esp8266/Utils.cpp +++ /dev/null @@ -1,58 +0,0 @@ -#include "Utils.hpp" - -namespace fw -{ - String protocol_to_string(firewall_protocol_t &protocol) - { - switch (protocol) - { - case PROTOCOL_TCP: - return "TCP"; - case PROTOCOL_UDP: - return "UDP"; - default: - return "ALL"; - } - } - - firewall_protocol_t string_to_protocol(String &protocol) - { - if (protocol.equals("TCP")) - return PROTOCOL_TCP; - else if (protocol.equals("UDP")) - return PROTOCOL_UDP; - else - return PROTOCOL_ALL; - } - - String target_to_string(firewall_target_t &target) - { - switch (target) - { - case TARGET_DROP: - return "DROP"; - default: - return "ACCEPT"; - } - } - - firewall_target_t string_to_target(String &target) - { - if (target.equals("DROP")) - return TARGET_DROP; - else - return TARGET_ACCEPT; - } - - void endless_loop() - { - Serial.printf("Something went wrong. Running endless loop until fixed..."); - while (true) - delay(500); - } - - bool is_in_range(const uint16_t number, const uint16_t lower, const uint16_t upper) - { - return lower <= number && number <= upper; - } -} diff --git a/src/esp8266/Utils.hpp b/src/esp8266/Utils.hpp deleted file mode 100644 index ffe0970..0000000 --- a/src/esp8266/Utils.hpp +++ /dev/null @@ -1,90 +0,0 @@ -#ifndef UTILS_HPP -#define UTILS_HPP - -#include "Arduino.h" -#include "WString.h" - -namespace fw -{ - typedef enum firewall_targets : uint8_t - { - TARGET_DROP = 1, - TARGET_ACCEPT = 2, - } firewall_target_t; - - typedef enum firewall_protocols : uint8_t - { - PROTOCOL_TCP = 6, - PROTOCOL_UDP = 17, - PROTOCOL_ALL = 255, - } firewall_protocol_t; - - typedef enum ok : uint8_t - { - SUCCESS = 0, - ERROR = 1, - NO_ACTION = 2, - } ok_t; - - typedef enum auth : uint8_t - { - AUTHENTICATED = 0, - DENIED = 1, - } auth_t; - - static const uint8_t IPV4ADDRESS_LENGTH = 16; - typedef struct firewall_rules - { - uint8_t key; - char ip[IPV4ADDRESS_LENGTH]; - uint16_t port_from; - uint16_t port_to; - firewall_protocol_t protocol; - firewall_target_t target; - struct firewall_rules *next; - } firewall_rule_t; - - typedef struct my_packet - { - char ip[IPV4ADDRESS_LENGTH]; - firewall_protocol_t protocol; - uint16_t port; - } my_packet_t; - - static const uint8_t firewall_fields_amount = 6; - const char firewall_fields[firewall_fields_amount][10] = {"key", "ip", "port_from", "port_to", "protocol", "target"}; - typedef enum firewall_fields : uint8_t - { - KEY, - IP, - PORT_FROM, - PORT_TO, - PROTOCOL, - TARGET, - } firewall_fields_t; - - static const uint8_t CREDENTIALS_LENGTH = 32; - typedef struct credentials - { - char password[CREDENTIALS_LENGTH]; - char username[CREDENTIALS_LENGTH]; - } credential_t; - - typedef struct api_endpoints - { - char uri[60]; - char method[7]; - char description[30]; - struct api_endpoints *next; - } api_endpoint_t; - - String protocol_to_string(firewall_protocol_t &protocol); - firewall_protocol_t string_to_protocol(String &protocol); - String target_to_string(firewall_target_t &target); - firewall_target_t string_to_target(String &target); - String response_code_to_string(const uint16_t response_code); - void endless_loop(); - bool is_in_range(const uint16_t number, const uint16_t lower, const uint16_t upper); -} - -#endif