1 /* Copyright (C) 2009 Trend Micro Inc.
4 * This program is a free software; you can redistribute it
5 * and/or modify it under the terms of the GNU General Public
6 * License (version 2) as published by the FSF - Free Software
11 #include "eventinfo.h"
15 static EventNode *eventnode;
16 static EventNode *lastnode;
18 static int _memoryused = 0;
19 static int _memorymaxsize = 0;
23 /* Create the Event List */
24 void OS_CreateEventList(int maxsize)
27 _memorymaxsize = maxsize;
30 debug1("%s: OS_CreateEventList completed.", ARGV0);
34 /* Get the last event -- or first node */
35 EventNode *OS_GetLastEvent()
37 EventNode *eventnode_pt = eventnode;
39 return (eventnode_pt);
42 /* Add an event to the list -- always to the beginning */
43 void OS_AddEvent(Eventinfo *lf)
45 EventNode *tmp_node = eventnode;
49 new_node = (EventNode *)calloc(1, sizeof(EventNode));
51 if (new_node == NULL) {
52 ErrorExit(MEM_ERROR, ARGV0, errno, strerror(errno));
55 /* Always add to the beginning of the list
56 * The new node will become the first node and
57 * new_node->next will be the previous first node
59 new_node->next = tmp_node;
60 new_node->prev = NULL;
61 tmp_node->prev = new_node;
65 /* Add the event to the node */
70 /* Need to remove the last nodes */
71 if (_memoryused > _memorymaxsize) {
75 /* Remove at least the last 10 events
76 * or the events that will not match anymore
77 * (higher than max frequency)
79 while ((i < 10) || ((lf->time - lastnode->event->time) > _max_freq)) {
81 lastnode = lastnode->prev;
82 lastnode->next = NULL;
85 Free_Eventinfo(oldlast->event);
96 eventnode = (EventNode *)calloc(1, sizeof(EventNode));
97 if (eventnode == NULL) {
98 ErrorExit(MEM_ERROR, ARGV0, errno, strerror(errno));
101 eventnode->prev = NULL;
102 eventnode->next = NULL;
103 eventnode->event = lf;
105 lastnode = eventnode;