simplify
This commit is contained in:
parent
1f2cb6e021
commit
265e0562f8
5 changed files with 55 additions and 62 deletions
|
@ -25,8 +25,7 @@ namespace fw
|
|||
#ifdef ESP8266
|
||||
firewall_rule_t rule;
|
||||
uint8_t total_space_needed = 0;
|
||||
total_space_needed += sizeof(rule.source);
|
||||
total_space_needed += sizeof(rule.destination);
|
||||
total_space_needed += sizeof(rule.ip);
|
||||
total_space_needed += sizeof(rule.port_from);
|
||||
total_space_needed += sizeof(rule.port_to);
|
||||
total_space_needed += sizeof(rule.target);
|
||||
|
@ -87,26 +86,20 @@ namespace fw
|
|||
sprintf(rulename, "fwRule%i", key);
|
||||
|
||||
this->memory.begin(rulename, true);
|
||||
strncpy(rule_ptr->source, this->memory.getString("source", "0.0.0.0").c_str(), sizeof(rule_ptr->source));
|
||||
strncpy(rule_ptr->destination, this->memory.getString("destination", "0.0.0.0").c_str(), sizeof(rule_ptr->source));
|
||||
rule_ptr->port_from = this->memory.getUChar("port_from", 0);
|
||||
rule_ptr->port_to = this->memory.getUChar("port_to", 0);
|
||||
rule_ptr->protocol = static_cast<firewall_protocol_t>(this->memory.getUChar("protocol", PROTOCOL_ALL));
|
||||
rule_ptr->target = static_cast<firewall_target_t>(this->memory.getUChar("target", TARGET_REJECT));
|
||||
strncpy(rule_ptr->source, this->memory.getString(firewall_fields[IP], "0.0.0.0").c_str(), sizeof(rule_ptr->source));
|
||||
rule_ptr->port_from = this->memory.getUChar(firewall_fields[PORT_FROM], 0);
|
||||
rule_ptr->port_to = this->memory.getUChar(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_REJECT));
|
||||
this->memory.end();
|
||||
|
||||
#elif defined(ESP8266)
|
||||
uint16_t eespom_position = eeprom_rule_position(key);
|
||||
const char source[IPV4ADDRESS_LENGTH] = "";
|
||||
const char destination[IPV4ADDRESS_LENGTH] = "";
|
||||
|
||||
EEPROM.get(eespom_position, source);
|
||||
strncpy(rule_ptr->source, source, sizeof(rule_ptr->source));
|
||||
eespom_position += sizeof(rule_ptr->source);
|
||||
|
||||
EEPROM.get(eespom_position, destination);
|
||||
strncpy(rule_ptr->destination, destination, sizeof(rule_ptr->destination));
|
||||
eespom_position += sizeof(rule_ptr->destination);
|
||||
strncpy(rule_ptr->ip, source, sizeof(rule_ptr->ip));
|
||||
eespom_position += sizeof(rule_ptr->ip);
|
||||
|
||||
rule_ptr->port_from = EEPROM.read(eespom_position);
|
||||
eespom_position += sizeof(rule_ptr->port_from);
|
||||
|
@ -141,21 +134,18 @@ namespace fw
|
|||
sprintf(rulename, "fwRule%i", rule_ptr->key);
|
||||
|
||||
this->memory.begin(rulename, false);
|
||||
this->memory.putString("source", rule_ptr->source);
|
||||
this->memory.putString("destination", rule_ptr->destination);
|
||||
this->memory.putUChar("port_from", rule_ptr->port_from);
|
||||
this->memory.putUChar("port_to", rule_ptr->port_to);
|
||||
this->memory.putUChar("protocol", rule_ptr->protocol);
|
||||
this->memory.putUChar("target", rule_ptr->target);
|
||||
this->memory.putString(firewall_fields[IP], rule_ptr->ip);
|
||||
this->memory.putUChar(firewall_fields[PORT_FROM], rule_ptr->port_from);
|
||||
this->memory.putUChar(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();
|
||||
#elif defined(ESP8266)
|
||||
uint16_t eespom_position = eeprom_rule_position(rule_ptr->key);
|
||||
|
||||
EEPROM.put(eespom_position, rule_ptr->source);
|
||||
eespom_position += sizeof(rule_ptr->source);
|
||||
EEPROM.put(eespom_position, rule_ptr->destination);
|
||||
eespom_position += sizeof(rule_ptr->destination);
|
||||
EEPROM.put(eespom_position, rule_ptr->ip);
|
||||
eespom_position += sizeof(rule_ptr->ip);
|
||||
EEPROM.put(eespom_position, rule_ptr->port_from);
|
||||
eespom_position += sizeof(rule_ptr->port_from);
|
||||
EEPROM.put(eespom_position, rule_ptr->port_to);
|
||||
|
|
Reference in a new issue