cleanup API
This commit is contained in:
parent
3e664dd408
commit
d08a0599a6
2 changed files with 38 additions and 41 deletions
|
@ -8,14 +8,18 @@
|
|||
#endif
|
||||
|
||||
#include "uri/UriRegex.h"
|
||||
|
||||
#include "Rules.hpp"
|
||||
#include "Firewall.hpp"
|
||||
#include "Utils.hpp"
|
||||
|
||||
namespace fw
|
||||
{
|
||||
class API : public Rules
|
||||
class API
|
||||
{
|
||||
public:
|
||||
API(Firewall *, const char *cert, const char *key, const char *username, const char *password, const uint16_t port = 8080);
|
||||
~API();
|
||||
void handle_client();
|
||||
|
||||
private:
|
||||
#ifdef ESP32
|
||||
WebServer *server;
|
||||
|
@ -23,41 +27,36 @@ namespace fw
|
|||
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 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_api_endpoint(const String uri, const char *method, const char *description);
|
||||
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();
|
||||
void not_found_handler();
|
||||
void api_endpoints_handler();
|
||||
|
||||
bool request_has_firewall_parameter();
|
||||
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_message_response(String message, const uint16_t response_code);
|
||||
String construct_json_firewall_rule(firewall_rule_t *);
|
||||
|
||||
String construct_json_firewall_rule(firewall_rule_t *rule_ptr);
|
||||
String construct_json_firewall();
|
||||
String construct_json_api_endpoint(api_endpoint_t *);
|
||||
String construct_json_api_endpoint(api_endpoint_t *api_ptr);
|
||||
String construct_json_api();
|
||||
String construct_json_begin(const uint16_t response_code);
|
||||
|
||||
protected:
|
||||
String server_ip;
|
||||
uint16_t server_port;
|
||||
void handle_client();
|
||||
String get_url_base();
|
||||
|
||||
public:
|
||||
API(const char *cert, const char *key, const char *username, const char *password, const String ip, const uint16_t port);
|
||||
~API();
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue