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

75 lines
1.6 KiB
C++
Raw Normal View History

2022-04-21 15:16:54 +02:00
#include "Utils.hpp"
2022-04-24 00:13:20 +02:00
namespace fw
2022-04-21 15:16:54 +02:00
{
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";
}
}
2022-04-23 23:50:46 +02:00
firewall_protocol_t string_to_protocol(String &protocol)
2022-04-21 15:16:54 +02:00
{
2022-04-23 23:50:46 +02:00
if (protocol.equals("TCP"))
2022-04-22 22:40:01 +02:00
return PROTOCOL_TCP;
2022-04-23 23:50:46 +02:00
else if (protocol.equals("UDP"))
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";
}
}
2022-04-23 23:50:46 +02:00
firewall_target_t string_to_target(String &target)
2022-04-21 15:16:54 +02:00
{
2022-04-23 23:50:46 +02:00
if (target.equals("REJECT"))
2022-04-22 22:40:01 +02:00
return TARGET_REJECT;
2022-04-23 23:50:46 +02:00
else if (target.equals("DROP"))
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
}
2022-05-02 17:22:04 +02:00
String response_code_to_string(const uint16_t response_code)
{
switch (response_code)
{
case 200:
return "success";
case 403:
return "unauthorized";
case 404:
return "not found";
case 500:
return "server error";
default:
return "unknown error";
}
}
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
}
}