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
14 #include "headers/debug_op.h"
16 #include "mail_list.h"
17 #include "error_messages/error_messages.h"
19 static MailNode *n_node;
20 static MailNode *lastnode;
22 static int _memoryused = 0;
23 static int _memorymaxsize = 0;
26 /* Create the Mail List */
27 void OS_CreateMailList(int maxsize)
31 _memorymaxsize = maxsize;
38 MailNode *OS_CheckLastMail()
43 /* Get the last Mail -- or first node */
44 MailNode *OS_PopLastMail()
49 if (lastnode == NULL) {
55 lastnode = lastnode->prev;
61 void FreeMailMsg(MailMsg *ml)
79 void FreeMail(MailNode *ml)
84 if (ml->mail->subject) {
85 free(ml->mail->subject);
97 /* Add an email to the list -- always to the beginning */
98 void OS_AddMailtoList(MailMsg *ml)
100 MailNode *tmp_node = n_node;
104 new_node = (MailNode *)calloc(1, sizeof(MailNode));
106 if (new_node == NULL) {
107 ErrorExit(MEM_ERROR, ARGV0, errno, strerror(errno));
110 /* Always add to the beginning of the list
111 * The new node will become the first node and
112 * new_node->next will be the previous first node
114 new_node->next = tmp_node;
115 new_node->prev = NULL;
116 tmp_node->prev = new_node;
120 /* Add the event to the node */
125 /* Need to remove the last node */
126 if (_memoryused > _memorymaxsize) {
130 lastnode = lastnode->prev;
141 n_node = (MailNode *)calloc(1, sizeof(MailNode));
142 if (n_node == NULL) {
143 ErrorExit(MEM_ERROR, ARGV0, errno, strerror(errno));