Transfer data
This commit is contained in:
parent
cac6d98908
commit
c43dd6121a
27 changed files with 3237 additions and 0 deletions
70
src/esp32/Storage.cpp
Normal file
70
src/esp32/Storage.cpp
Normal file
|
@ -0,0 +1,70 @@
|
|||
#include "Storage.hpp"
|
||||
|
||||
namespace fw
|
||||
{
|
||||
Storage::Storage()
|
||||
{
|
||||
}
|
||||
|
||||
Storage::~Storage()
|
||||
{
|
||||
}
|
||||
|
||||
uint8_t Storage::retrieve_amount_of_rules()
|
||||
{
|
||||
this->memory.begin("settings", true);
|
||||
const uint8_t amount_of_rules = memory.getUChar("amount_of_rules", 0);
|
||||
this->memory.end();
|
||||
|
||||
return amount_of_rules;
|
||||
}
|
||||
|
||||
void Storage::store_amount_of_rules(const uint8_t new_amount)
|
||||
{
|
||||
this->memory.begin("settings", false);
|
||||
this->memory.putUChar("amount_of_rules", new_amount);
|
||||
this->memory.end();
|
||||
}
|
||||
|
||||
firewall_rule_t *Storage::retrieve_firewall_rule(const uint8_t key)
|
||||
{
|
||||
firewall_rule_t *rule_ptr = (firewall_rule_t *)malloc(sizeof(firewall_rule_t));
|
||||
rule_ptr->key = key;
|
||||
char rulename[10]; // fwRule99\n
|
||||
sprintf(rulename, "fwRule%i", key);
|
||||
|
||||
this->memory.begin(rulename, true);
|
||||
strncpy(rule_ptr->ip, this->memory.getString(firewall_fields[IP], "0.0.0.0").c_str(), sizeof(rule_ptr->ip));
|
||||
rule_ptr->port_from = this->memory.getUShort(firewall_fields[PORT_FROM], 0);
|
||||
rule_ptr->port_to = this->memory.getUShort(firewall_fields[PORT_TO], 0);
|
||||
rule_ptr->protocol = static_cast<firewall_protocol_t>(this->memory.getUChar(firewall_fields[PROTOCOL], PROTOCOL_ALL));
|
||||
rule_ptr->target = static_cast<firewall_target_t>(this->memory.getUChar(firewall_fields[TARGET], TARGET_ACCEPT));
|
||||
this->memory.end();
|
||||
return rule_ptr;
|
||||
}
|
||||
|
||||
void Storage::store_all_firewall_rules(firewall_rule_t *rule_head)
|
||||
{
|
||||
firewall_rule_t *temp = rule_head;
|
||||
while (temp != NULL)
|
||||
{
|
||||
store_firewall_rule(temp);
|
||||
temp = temp->next;
|
||||
}
|
||||
}
|
||||
|
||||
void Storage::store_firewall_rule(firewall_rule_t *rule_ptr)
|
||||
{
|
||||
char rulename[10]; // fwRule99\n
|
||||
sprintf(rulename, "fwRule%i", rule_ptr->key);
|
||||
|
||||
this->memory.begin(rulename, false);
|
||||
this->memory.putString(firewall_fields[IP], rule_ptr->ip);
|
||||
this->memory.putUShort(firewall_fields[PORT_FROM], rule_ptr->port_from);
|
||||
this->memory.putUShort(firewall_fields[PORT_TO], rule_ptr->port_to);
|
||||
this->memory.putUChar(firewall_fields[PROTOCOL], rule_ptr->protocol);
|
||||
this->memory.putUChar(firewall_fields[TARGET], rule_ptr->target);
|
||||
|
||||
this->memory.end();
|
||||
}
|
||||
}
|
Reference in a new issue