X-Git-Url: http://ftp.carnet.hr/pub/carnet-debian/scm?a=blobdiff_plain;f=src%2Fos_maild%2Fmail_list.c;h=7e782b2efd454c0649c975a0e8c52abbf7ed3ff5;hb=3f728675941dc69d4e544d3a880a56240a6e394a;hp=7537428364f18578c1d8897659031557e0b3f1f6;hpb=914feba5d54f979cd5d7e69c349c3d01f630042a;p=ossec-hids.git diff --git a/src/os_maild/mail_list.c b/src/os_maild/mail_list.c old mode 100755 new mode 100644 index 7537428..7e782b2 --- a/src/os_maild/mail_list.c +++ b/src/os_maild/mail_list.c @@ -1,15 +1,12 @@ -/* @(#) $Id: mail_list.c,v 1.6 2009/06/24 17:06:30 dcid Exp $ */ - /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ - #include #include #include @@ -17,14 +14,13 @@ #include "headers/debug_op.h" #include "maild.h" #include "mail_list.h" - #include "error_messages/error_messages.h" -MailNode *n_node; -MailNode *lastnode; +static MailNode *n_node; +static MailNode *lastnode; -int _memoryused = 0; -int _memorymaxsize = 0; +static int _memoryused = 0; +static int _memorymaxsize = 0; /* Create the Mail List */ @@ -33,134 +29,127 @@ void OS_CreateMailList(int maxsize) n_node = NULL; _memorymaxsize = maxsize; - _memoryused = 0; - + return; } -/* check last mail */ +/* Check last mail */ MailNode *OS_CheckLastMail() { - return(lastnode); + return (lastnode); } /* Get the last Mail -- or first node */ MailNode *OS_PopLastMail() { - MailNode *oldlast; oldlast = lastnode; - - if(lastnode == NULL) - { + if (lastnode == NULL) { n_node = NULL; - return(NULL); + return (NULL); } - + _memoryused--; - lastnode = lastnode->prev; /* Remove the last */ - return(oldlast); + return (oldlast); } - void FreeMailMsg(MailMsg *ml) { - if(ml == NULL) + if (ml == NULL) { return; - - if(ml->subject) + } + + if (ml->subject) { free(ml->subject); - - if(ml->body) + } + + if (ml->body) { free(ml->body); - - free(ml); -} + } + free(ml); +} /* Free mail node */ void FreeMail(MailNode *ml) { - if(ml == NULL) + if (ml == NULL) { return; - if(ml->mail->subject) + } + if (ml->mail->subject) { free(ml->mail->subject); - - if(ml->mail->body) + } + + if (ml->mail->body) { free(ml->mail->body); + } - free(ml->mail); + free(ml->mail); free(ml); } -/* Add an email to the list -- always to the begining */ +/* Add an email to the list -- always to the beginning */ void OS_AddMailtoList(MailMsg *ml) { MailNode *tmp_node = n_node; - - if(tmp_node) - { + + if (tmp_node) { MailNode *new_node; - new_node = (MailNode *)calloc(1,sizeof(MailNode)); - - if(new_node == NULL) - { - ErrorExit(MEM_ERROR,ARGV0); + new_node = (MailNode *)calloc(1, sizeof(MailNode)); + + if (new_node == NULL) { + ErrorExit(MEM_ERROR, ARGV0, errno, strerror(errno)); } - /* Always adding to the beginning of the list + /* Always add to the beginning of the list * The new node will become the first node and * new_node->next will be the previous first node */ new_node->next = tmp_node; new_node->prev = NULL; tmp_node->prev = new_node; - + n_node = new_node; - /* Adding the event to the node */ + /* Add the event to the node */ new_node->mail = ml; _memoryused++; - + /* Need to remove the last node */ - if(_memoryused > _memorymaxsize) - { + if (_memoryused > _memorymaxsize) { MailNode *oldlast; oldlast = lastnode; lastnode = lastnode->prev; - - /* free last node */ + + /* Free last node */ FreeMail(oldlast); - + _memoryused--; } } - - else - { - /* Adding first node */ - n_node = (MailNode *)calloc(1,sizeof(MailNode)); - if(n_node == NULL) - { - ErrorExit(MEM_ERROR,ARGV0); + + else { + /* Add first node */ + n_node = (MailNode *)calloc(1, sizeof(MailNode)); + if (n_node == NULL) { + ErrorExit(MEM_ERROR, ARGV0, errno, strerror(errno)); } n_node->prev = NULL; n_node->next = NULL; n_node->mail = ml; - - lastnode = n_node; + + lastnode = n_node; } return; } -/* EOF */