From 3cf4f4445a5848a73133ba1c7c66162f3ccdf463 Mon Sep 17 00:00:00 2001 From: Florian Hoss Date: Mon, 2 May 2022 20:49:18 +0200 Subject: [PATCH] simplify --- ESPFirewall/lib/Firewall/src/API.cpp | 12 ++++++------ ESPFirewall/lib/Firewall/src/API.hpp | 5 ----- ESPFirewall/lib/Firewall/src/Utils.hpp | 9 ++++----- 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/ESPFirewall/lib/Firewall/src/API.cpp b/ESPFirewall/lib/Firewall/src/API.cpp index aae8084..9209823 100644 --- a/ESPFirewall/lib/Firewall/src/API.cpp +++ b/ESPFirewall/lib/Firewall/src/API.cpp @@ -187,12 +187,12 @@ namespace fw return false; else { - return this->server->hasArg("source") || - this->server->hasArg("destination") || - this->server->hasArg("protocol") || - this->server->hasArg("port_from") || - this->server->hasArg("port_to") || - this->server->hasArg("target"); + for (uint8_t i = 0; i < firewall_fields_amount; i++) + { + if (!this->server->hasArg(firewall_fields[i])) + return false; + } + return true; } } diff --git a/ESPFirewall/lib/Firewall/src/API.hpp b/ESPFirewall/lib/Firewall/src/API.hpp index 4ef9c82..e60404e 100644 --- a/ESPFirewall/lib/Firewall/src/API.hpp +++ b/ESPFirewall/lib/Firewall/src/API.hpp @@ -54,11 +54,6 @@ namespace fw uint16_t server_port; void handle_client(); String get_url_base(); - 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); public: API(const char *cert, const char *key, const char *username, const char *password, const String ip, const uint16_t port); diff --git a/ESPFirewall/lib/Firewall/src/Utils.hpp b/ESPFirewall/lib/Firewall/src/Utils.hpp index 2aa156e..ec19025 100644 --- a/ESPFirewall/lib/Firewall/src/Utils.hpp +++ b/ESPFirewall/lib/Firewall/src/Utils.hpp @@ -39,16 +39,15 @@ namespace fw uint8_t key; char source[IPV4ADDRESS_LENGTH]; char destination[IPV4ADDRESS_LENGTH]; - uint16_t port_from; // port is max 65565 - uint16_t port_to; + uint32_t port_from; // port can be max 65565 + uint32_t port_to; // range of uint16_t: 0 to 65535 firewall_protocol_t protocol; firewall_target_t target; struct firewall_rules *next; } firewall_rule_t; - const byte numChars = 12; - const char firewall_fields[][numChars] = { - "key", + static const uint8_t firewall_fields_amount = 6; + const char firewall_fields[firewall_fields_amount][12] = { "source", "destination", "port_from",