#ifndef ESP32_API_HPP #define ESP32_API_HPP #ifdef ESP32 #include "WebServer.h" #elif defined(ESP8266) #include "ESP8266WebServerSecure.h" #endif #include "uri/UriRegex.h" #include "Firewall.hpp" #include "Utils.hpp" namespace fw { class API { public: API(Firewall *, const char *cert, const char *key, const char *username, const char *password, const String ip, const uint16_t port = 8080); ~API(); void handle_client(); private: #ifdef ESP32 WebServer *server; #elif defined(ESP8266) BearSSL::ESP8266WebServerSecure *server; BearSSL::ServerSessions *serverCache; #endif Firewall *firewall; credential_t credentials; api_endpoint_t *endpoint_head = NULL; String api_ip = "0.0.0.0"; uint16_t api_port; String json_response_type = "application/json; charset=utf-8"; String log = "[API]"; String get_url_base(); ok_t setup_auth(const char *username, const char *password); auth_t check_auth(); void setup_routing(const char *cert, const char *key); void add_endpoint_to_list(const String uri, const char *method, const char *description); void not_found_handler(); void get_endpoint_list_handler(); void get_firewall_rule_handler(); void get_firewall_rules_handler(); void post_firewall_handler(); void delete_firewall_handler(); bool request_has_all_firewall_parameter(); String json_new_attribute(String key, String value, bool last = false); String json_new_attribute(String key, uint32_t value, bool last = false); void json_generic_response(String serialized_string, const uint16_t response_code); void json_array_response(String serialized_string, const uint16_t response_code); void json_message_response(String message, const uint16_t response_code); String construct_json_firewall_rule(firewall_rule_t *rule_ptr); String construct_json_firewall(); String construct_json_api_endpoint(api_endpoint_t *api_ptr); String construct_json_api(); }; } #endif