2 #include "EventLogger.h"
4 static struct Event *first_event = NULL, *last_event = NULL;
6 struct Event *createEvent(struct ClientSocket *client, struct UserNode *user, struct ChanNode *chan, char *command, char **args, int argc, int flags) {
7 struct Event *event = malloc(sizeof(*event));
10 perror("malloc() failed");
13 event->client = client;
16 event->event_time = time(0);
17 event->command = strdup(command);
18 char arguments[MAXLEN];
21 for(i = 0; i < argc; i++)
22 argpos += sprintf(arguments + argpos, "%s ", args[i]);
23 arguments[(argpos ? argpos-1 : 0)] = '\0';
24 event->arguments = strdup(arguments);
28 last_event->next = event;
37 void logEvent(struct Event *event) {
41 static void destroyEvent(struct Event *event) {
42 if(event == first_event)
43 first_event = event->next;
44 if(event == last_event) {
46 for(last = first_event; last; last = last->next)
47 if(last->next == NULL) break;
51 free(event->arguments);
55 void destroyEvents() {
57 while(first_event && now - first_event->event_time >= 60) {
58 destroyEvent(first_event);