X-Git-Url: http://ftp.carnet.hr/carnet-debian/scm?a=blobdiff_plain;f=src%2Fos_maild%2Fmail_list.c;h=7e782b2efd454c0649c975a0e8c52abbf7ed3ff5;hb=3f728675941dc69d4e544d3a880a56240a6e394a;hp=1e70a9ed7ab9af5d741bb8d20937da58bce6a718;hpb=301048b51990573e58a30dc4a5bb4ec285cad554;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 1e70a9e..7e782b2 --- a/src/os_maild/mail_list.c +++ b/src/os_maild/mail_list.c @@ -1,5 +1,3 @@ -/* @(#) $Id$ */ - /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * @@ -9,7 +7,6 @@ * 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 */