1 /* @(#) $Id: ./src/analysisd/eventinfo_list.c, 2011/09/08 dcid Exp $
4 /* Copyright (C) 2009 Trend Micro Inc.
7 * This program is a free software; you can redistribute it
8 * and/or modify it under the terms of the GNU General Public
9 * License (version 2) as published by the FSF - Free Software
12 * License details at the LICENSE file included with OSSEC or
13 * online at: http://www.ossec.net/en/licensing.html
18 #include "eventinfo.h"
25 int _memorymaxsize = 0;
29 /* Create the Event List */
30 void OS_CreateEventList(int maxsize)
34 _memorymaxsize = maxsize;
38 debug1("%s: OS_CreateEventList completed.", ARGV0);
42 /* Get the last event -- or first node */
43 EventNode *OS_GetLastEvent()
45 EventNode *eventnode_pt = eventnode;
50 /* Add an event to the list -- always to the begining */
51 void OS_AddEvent(Eventinfo *lf)
53 EventNode *tmp_node = eventnode;
58 new_node = (EventNode *)calloc(1,sizeof(EventNode));
62 ErrorExit(MEM_ERROR,ARGV0);
65 /* Always adding to the beginning of the list
66 * The new node will become the first node and
67 * new_node->next will be the previous first node
69 new_node->next = tmp_node;
70 new_node->prev = NULL;
71 tmp_node->prev = new_node;
75 /* Adding the event to the node */
80 /* Need to remove the last nodes */
81 if(_memoryused > _memorymaxsize)
86 /* Remove at least the last 10 events
87 * or the events that will not match anymore
88 * (higher than max frequency)
90 while((i < 10)||((lf->time - lastnode->event->time) > _max_freq))
93 lastnode = lastnode->prev;
94 lastnode->next = NULL;
97 Free_Eventinfo(oldlast->event);
108 /* Adding first node */
109 eventnode = (EventNode *)calloc(1,sizeof(EventNode));
110 if(eventnode == NULL)
112 ErrorExit(MEM_ERROR,ARGV0);
115 eventnode->prev = NULL;
116 eventnode->next = NULL;
117 eventnode->event = lf;
119 lastnode = eventnode;