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
2022-04-22 22:40:01 +02:00

57 lines
1.3 KiB
C++

#include "Utils.hpp"
namespace firewall
{
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(std::string &protocol)
{
if (protocol.compare("TCP") == 0)
return PROTOCOL_TCP;
else if (protocol.compare("UDP") == 0)
return PROTOCOL_UDP;
else
return PROTOCOL_ALL;
}
String target_to_string(firewall_target_t &target)
{
switch (target)
{
case TARGET_REJECT:
return "REJECT";
case TARGET_DROP:
return "DROP";
default:
return "ACCEPT";
}
}
firewall_target_t string_to_target(std::string &target)
{
if (target.compare("REJECT") == 0)
return TARGET_REJECT;
else if (target.compare("DROP") == 0)
return TARGET_DROP;
else
return TARGET_ACCEPT;
}
void endless_loop()
{
log_e("Something went wrong. Running endless loop until fixed...");
while (true)
sleep(500);
}
}