This repository has been archived on 2024-10-30. You can view files and clone it, but cannot push or open issues or pull requests.
esp-firewall/ESPFirewall/lib/Firewall/src/Utils.cpp

58 lines
1.3 KiB
C++
Raw Normal View History

2022-04-21 15:16:54 +02:00
#include "Utils.hpp"
namespace firewall
{
String protocol_to_string(firewall_protocol_t &protocol)
{
switch (protocol)
{
2022-04-22 22:40:01 +02:00
case PROTOCOL_TCP:
2022-04-21 15:16:54 +02:00
return "TCP";
2022-04-22 22:40:01 +02:00
case PROTOCOL_UDP:
2022-04-21 15:16:54 +02:00
return "UDP";
default:
return "ALL";
}
}
firewall_protocol_t string_to_protocol(std::string &protocol)
{
if (protocol.compare("TCP") == 0)
2022-04-22 22:40:01 +02:00
return PROTOCOL_TCP;
2022-04-21 15:16:54 +02:00
else if (protocol.compare("UDP") == 0)
2022-04-22 22:40:01 +02:00
return PROTOCOL_UDP;
2022-04-21 15:16:54 +02:00
else
2022-04-22 22:40:01 +02:00
return PROTOCOL_ALL;
2022-04-21 15:16:54 +02:00
}
String target_to_string(firewall_target_t &target)
{
switch (target)
{
2022-04-22 22:40:01 +02:00
case TARGET_REJECT:
2022-04-21 15:16:54 +02:00
return "REJECT";
2022-04-22 22:40:01 +02:00
case TARGET_DROP:
2022-04-21 15:16:54 +02:00
return "DROP";
default:
return "ACCEPT";
}
}
firewall_target_t string_to_target(std::string &target)
{
if (target.compare("REJECT") == 0)
2022-04-22 22:40:01 +02:00
return TARGET_REJECT;
2022-04-21 15:16:54 +02:00
else if (target.compare("DROP") == 0)
2022-04-22 22:40:01 +02:00
return TARGET_DROP;
2022-04-21 15:16:54 +02:00
else
2022-04-22 22:40:01 +02:00
return TARGET_ACCEPT;
2022-04-21 15:16:54 +02:00
}
void endless_loop()
{
2022-04-23 23:36:44 +02:00
Serial.printf("Something went wrong. Running endless loop until fixed...");
2022-04-21 15:16:54 +02:00
while (true)
2022-04-23 23:36:44 +02:00
delay(500);
2022-04-21 15:16:54 +02:00
}
}