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

147 lines
3.7 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)
{
2022-05-02 20:20:29 +02:00
case 100:
return F("Continue");
case 101:
return F("Switching Protocols");
2022-05-02 17:22:04 +02:00
case 200:
2022-05-02 20:20:29 +02:00
return F("OK");
case 201:
return F("Created");
case 202:
return F("Accepted");
case 203:
return F("Non-Authoritative Information");
case 204:
return F("No Content");
case 205:
return F("Reset Content");
case 206:
return F("Partial Content");
case 300:
return F("Multiple Choices");
case 301:
return F("Moved Permanently");
case 302:
return F("Found");
case 303:
return F("See Other");
case 304:
return F("Not Modified");
case 305:
return F("Use Proxy");
case 307:
return F("Temporary Redirect");
case 400:
return F("Bad Request");
case 401:
return F("Unauthorized");
case 402:
return F("Payment Required");
2022-05-02 17:22:04 +02:00
case 403:
2022-05-02 20:20:29 +02:00
return F("Forbidden");
2022-05-02 17:22:04 +02:00
case 404:
2022-05-02 20:20:29 +02:00
return F("Not Found");
case 405:
return F("Method Not Allowed");
case 406:
return F("Not Acceptable");
case 407:
return F("Proxy Authentication Required");
case 408:
return F("Request Time-out");
case 409:
return F("Conflict");
case 410:
return F("Gone");
case 411:
return F("Length Required");
case 412:
return F("Precondition Failed");
case 413:
return F("Request Entity Too Large");
case 414:
return F("Request-URI Too Large");
case 415:
return F("Unsupported Media Type");
case 416:
return F("Requested range not satisfiable");
case 417:
return F("Expectation Failed");
2022-05-02 17:22:04 +02:00
case 500:
2022-05-02 20:20:29 +02:00
return F("Internal Server Error");
case 501:
return F("Not Implemented");
case 502:
return F("Bad Gateway");
case 503:
return F("Service Unavailable");
case 504:
return F("Gateway Time-out");
case 505:
return F("HTTP Version not supported");
2022-05-02 17:22:04 +02:00
default:
2022-05-02 20:20:29 +02:00
return F("");
2022-05-02 17:22:04 +02:00
}
}
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
}
}