1 /* @(#) $Id: eventinfo_list.c,v 1.7 2009/06/24 17:06:22 dcid Exp $ */
3 /* Copyright (C) 2009 Trend Micro Inc.
6 * This program is a free software; you can redistribute it
7 * and/or modify it under the terms of the GNU General Public
8 * License (version 3) as published by the FSF - Free Software
11 * License details at the LICENSE file included with OSSEC or
12 * online at: http://www.ossec.net/en/licensing.html
17 #include "eventinfo.h"
24 int _memorymaxsize = 0;
28 /* Create the Event List */
29 void OS_CreateEventList(int maxsize)
33 _memorymaxsize = maxsize;
37 debug1("%s: OS_CreateEventList completed.", ARGV0);
41 /* Get the last event -- or first node */
42 EventNode *OS_GetLastEvent()
44 EventNode *eventnode_pt = eventnode;
49 /* Add an event to the list -- always to the begining */
50 void OS_AddEvent(Eventinfo *lf)
52 EventNode *tmp_node = eventnode;
57 new_node = (EventNode *)calloc(1,sizeof(EventNode));
61 ErrorExit(MEM_ERROR,ARGV0);
64 /* Always adding to the beginning of the list
65 * The new node will become the first node and
66 * new_node->next will be the previous first node
68 new_node->next = tmp_node;
69 new_node->prev = NULL;
70 tmp_node->prev = new_node;
74 /* Adding the event to the node */
79 /* Need to remove the last nodes */
80 if(_memoryused > _memorymaxsize)
85 /* Remove at least the last 10 events
86 * or the events that will not match anymore
87 * (higher than max frequency)
89 while((i < 10)||((lf->time - lastnode->event->time) > _max_freq))
92 lastnode = lastnode->prev;
93 lastnode->next = NULL;
96 Free_Eventinfo(oldlast->event);
107 /* Adding first node */
108 eventnode = (EventNode *)calloc(1,sizeof(EventNode));
109 if(eventnode == NULL)
111 ErrorExit(MEM_ERROR,ARGV0);
114 eventnode->prev = NULL;
115 eventnode->next = NULL;
116 eventnode->event = lf;
118 lastnode = eventnode;