#include "report_list.h" #include #include void report_list_init(report_list_t *list) { INIT_LIST_HEAD(list); } report_list_cell_t *report_list_add(report_list_t *list, int seq, msg_usr_t *attack) { report_list_cell_t *cell; cell = malloc(sizeof(report_list_cell_t)); if (!cell) { fprintf(stderr, "unable to alloc enough memory for report list cell, skipping\n"); return NULL; } cell->seq = seq; cell->info = *attack; cell->processed = 0; INIT_LIST_HEAD(&cell->list); list_add_tail(&cell->list, list); return cell; } report_list_cell_t *report_list_find(report_list_t *list, u_int32_t addr, int include_processed) { struct list_head *entry; __list_for_each(entry, list) { report_list_cell_t *cell; cell = list_entry(entry, report_list_cell_t, list); if (cell->info.s_addr == addr && include_processed || !cell->processed) { return cell; } } return NULL; } report_list_cell_t *report_list_find_seq(report_list_t *list, int seq) { struct list_head *entry; __list_for_each(entry, list) { report_list_cell_t *cell; cell = list_entry(entry, report_list_cell_t, list); if (cell->seq == seq) { return cell; } } return NULL; } void report_list_remove(report_list_cell_t *cell) { list_del(&cell->list); free(cell); } void report_list_clear_processed(report_list_t *list) { report_list_cell_t *cell, *n; list_for_each_entry_safe(cell, n, list, list) { if (cell->processed) { report_list_remove(cell); } } } void report_list_print(report_list_t *list) { struct list_head *entry; printf("* report list {\n"); __list_for_each(entry, list) { report_list_cell_t *cell; cell = list_entry(entry, report_list_cell_t, list); printf("%d,\n", cell->seq); } printf("} report list *\n"); }