Removed code duplication from rules.c

Signed-off-by: Janos SUTO <sj@acts.hu>
This commit is contained in:
Janos SUTO 2018-11-03 15:02:54 +01:00
parent 6e47f50ffd
commit d97e653e8c

View File

@ -10,22 +10,31 @@
#include "rules.h" #include "rules.h"
void reset_rule_condition(struct rule_cond *rule_cond){
memset(rule_cond->domain, 0, SMALLBUFSIZE);
memset(rule_cond->from, 0, SMALLBUFSIZE);
memset(rule_cond->to, 0, SMALLBUFSIZE);
memset(rule_cond->subject, 0, SMALLBUFSIZE);
memset(rule_cond->body, 0, SMALLBUFSIZE);
memset(rule_cond->_size, 0, SMALLBUFSIZE);
memset(rule_cond->attachment_name, 0, SMALLBUFSIZE);
memset(rule_cond->attachment_type, 0, SMALLBUFSIZE);
memset(rule_cond->_attachment_size, 0, SMALLBUFSIZE);
rule_cond->size = 0;
rule_cond->attachment_size = 0;
rule_cond->spam = 0;
rule_cond->days = 0;
rule_cond->folder_id = 0;
}
void load_rules(struct session_data *sdata, struct node *xhash[], char *table){ void load_rules(struct session_data *sdata, struct node *xhash[], char *table){
char s[SMALLBUFSIZE]; char s[SMALLBUFSIZE];
struct rule_cond rule_cond; struct rule_cond rule_cond;
struct sql sql; struct sql sql;
memset(rule_cond.domain, 0, SMALLBUFSIZE); reset_rule_condition(&rule_cond);
memset(rule_cond.from, 0, SMALLBUFSIZE);
memset(rule_cond.to, 0, SMALLBUFSIZE);
memset(rule_cond.subject, 0, SMALLBUFSIZE);
memset(rule_cond.body, 0, SMALLBUFSIZE);
memset(rule_cond._size, 0, SMALLBUFSIZE);
memset(rule_cond.attachment_name, 0, SMALLBUFSIZE);
memset(rule_cond.attachment_type, 0, SMALLBUFSIZE);
memset(rule_cond._attachment_size, 0, SMALLBUFSIZE);
rule_cond.size = rule_cond.attachment_size = rule_cond.spam = rule_cond.days = rule_cond.folder_id = 0;
snprintf(s, sizeof(s)-1, "SELECT `domain`, `from`, `to`, `subject`, `body`, `_size`, `size`, `attachment_name`, `attachment_type`, `_attachment_size`, `attachment_size`, `spam`, `days`, `folder_id` FROM `%s`", table); snprintf(s, sizeof(s)-1, "SELECT `domain`, `from`, `to`, `subject`, `body`, `_size`, `size`, `attachment_name`, `attachment_type`, `_attachment_size`, `attachment_size`, `spam`, `days`, `folder_id` FROM `%s`", table);
@ -58,18 +67,7 @@ void load_rules(struct session_data *sdata, struct node *xhash[], char *table){
while(p_fetch_results(&sql) == OK){ while(p_fetch_results(&sql) == OK){
append_rule(xhash, &rule_cond); append_rule(xhash, &rule_cond);
reset_rule_condition(&rule_cond);
memset(rule_cond.domain, 0, SMALLBUFSIZE);
memset(rule_cond.from, 0, SMALLBUFSIZE);
memset(rule_cond.to, 0, SMALLBUFSIZE);
memset(rule_cond.subject, 0, SMALLBUFSIZE);
memset(rule_cond.body, 0, SMALLBUFSIZE);
memset(rule_cond._size, 0, SMALLBUFSIZE);
memset(rule_cond.attachment_name, 0, SMALLBUFSIZE);
memset(rule_cond.attachment_type, 0, SMALLBUFSIZE);
memset(rule_cond._attachment_size, 0, SMALLBUFSIZE);
rule_cond.size = rule_cond.attachment_size = rule_cond.spam = rule_cond.days = rule_cond.folder_id = 0;
} }
p_free_results(&sql); p_free_results(&sql);