From c86be9feb4e912c4583fc7dfbc5f17e22c7af908 Mon Sep 17 00:00:00 2001 From: Florian Hoss Date: Wed, 20 Apr 2022 19:58:15 +0200 Subject: [PATCH] move helper functions to types --- .../arduino/lib/Firewall/FirewallTypes.h | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/SourceCode/arduino/lib/Firewall/FirewallTypes.h b/SourceCode/arduino/lib/Firewall/FirewallTypes.h index d89cc01..56a4b61 100644 --- a/SourceCode/arduino/lib/Firewall/FirewallTypes.h +++ b/SourceCode/arduino/lib/Firewall/FirewallTypes.h @@ -29,4 +29,50 @@ typedef struct firewall_rule struct firewall_rule *next; } firewall_rule_t; +String protocol_to_string(firewall_protocol_t &protocol) +{ + switch (protocol) + { + case FW_TCP: + return "TCP"; + case FW_UDP: + return "UDP"; + default: + return "ALL"; + } +} + +firewall_protocol_t string_to_protocol(std::string &protocol) +{ + if (protocol.compare("TCP") == 0) + return FW_TCP; + else if (protocol.compare("UDP") == 0) + return FW_UDP; + else + return FW_ALL; +} + +String target_to_string(firewall_target_t &target) +{ + switch (target) + { + case FW_REJECT: + return "REJECT"; + case FW_DROP: + return "DROP"; + default: + return "ACCEPT"; + } +} + +firewall_target_t string_to_target(std::string &target) +{ + if (target.compare("REJECT") == 0) + return FW_REJECT; + else if (target.compare("DROP") == 0) + return FW_DROP; + else + return FW_ACCEPT; +} + #endif