56 lines
2 KiB
C++
56 lines
2 KiB
C++
#include "esp32Storage.hpp"
|
|
|
|
namespace firewall
|
|
{
|
|
Storage::Storage()
|
|
{
|
|
}
|
|
|
|
Storage::~Storage()
|
|
{
|
|
}
|
|
|
|
uint8_t Storage::retrieve_amount_of_firewall_rules()
|
|
{
|
|
uint8_t amount_of_rules;
|
|
this->preferences.begin("settings", false);
|
|
amount_of_rules = preferences.getUChar("amount_of_rules", 0);
|
|
this->preferences.end();
|
|
return amount_of_rules;
|
|
}
|
|
|
|
void Storage::store_amount_of_firewall_rules(const uint8_t new_amount)
|
|
{
|
|
this->preferences.begin("settings", false);
|
|
this->preferences.putUChar("amount_of_rules", new_amount);
|
|
this->preferences.end();
|
|
}
|
|
|
|
firewall_rule_t *Storage::retrieve_firewall_rule(const uint8_t key)
|
|
{
|
|
char rulename[12];
|
|
firewall_rule_t *rule_ptr = (firewall_rule_t *)malloc(sizeof(firewall_rule_t));
|
|
sprintf(rulename, "fw_rule_%i", key);
|
|
this->preferences.begin(rulename, false);
|
|
rule_ptr->key = key;
|
|
strcpy(rule_ptr->source, this->preferences.getString("source").c_str());
|
|
strcpy(rule_ptr->destination, this->preferences.getString("destination").c_str());
|
|
rule_ptr->protocol = static_cast<firewall_protocol_t>(this->preferences.getUChar("protocol"));
|
|
rule_ptr->target = static_cast<firewall_target_t>(this->preferences.getUChar("target"));
|
|
this->preferences.end();
|
|
return rule_ptr;
|
|
}
|
|
|
|
void Storage::store_firewall_rule(const uint8_t &new_amount, firewall_rule_t *rule_ptr)
|
|
{
|
|
this->store_amount_of_firewall_rules(new_amount);
|
|
char rulename[12];
|
|
sprintf(rulename, "fw_rule_%i", rule_ptr->key);
|
|
this->preferences.begin(rulename, false);
|
|
this->preferences.putString("source", rule_ptr->source);
|
|
this->preferences.putString("destination", rule_ptr->destination);
|
|
this->preferences.putUChar("protocol", rule_ptr->protocol);
|
|
this->preferences.putUChar("target", rule_ptr->target);
|
|
this->preferences.end();
|
|
}
|
|
}
|