-
Per Cederqvist authoredPer Cederqvist authored
text-garb.c 2.52 KiB
/*
* This file contains the functions that deletes old texts.
*
* Author: Per Cederqvist.
*/
#include <time.h>
#include <kom-types.h>
#include "cache.h"
#include "log.h"
#include "internal-services.h"
#include "lyskomd.h"
#include <debug.h>
/*
* Delete old texts.
*
* Return value is TRUE if there is nothing more to do right now,
* FALSE if this function should be called again as soon as the
* server has some time over.
*/
Bool
garb_text(void)
{
static Text_no last_checked = 0;
static time_t last_start = NO_TIME;
static long deleted_texts = 0;
BUGDECL;
Text_stat *text_s;
Misc_info *misc;
u_short nmisc;
double age; /* How many seconds is this text? */
double limit = 24 * 3600;
if ( last_checked == 0 )
{
if ( last_start != NO_TIME
&& difftime(time(NULL), last_start) < GARB_INTERVAL * 60 )
{
return TRUE;
}
log("MSG: garb started.\n");
time( &last_start );
}
last_checked = traverse_text( last_checked );
if ( last_checked == 0 )
{
log("MSG: garb ready. %lu texts deleted.\n", (u_long)deleted_texts);
return FALSE;
}
if ( (text_s = cached_get_text_stat( last_checked )) == NULL )
{
log("ERROR: garb_text(): Can't get text-stat.\n");
return FALSE;
}
age = difftime( time(NULL), text_s->creation_time );
if ( text_s->no_of_marks > 0 || age < 24 * 3600 )
{
return FALSE;
}
for (nmisc = text_s->no_of_misc, misc = text_s->misc_items;
nmisc > 0;
--nmisc, ++misc )
{
switch ( misc->type )
{
case recpt:
if ( cached_conf_exists( misc->datum.recipient ) )
{
limit = (24 * 3600 *
cached_get_garb_nice( misc->datum.recipient ));
if ( age < limit )
return FALSE;
}
break;
case cc_recpt:
if ( cached_conf_exists( misc->datum.cc_recipient ))
{
limit = ( 24 * 3600
* cached_get_garb_nice( misc->datum.cc_recipient ));
if ( age < limit )
return FALSE;
}
break;
case comm_to:
case comm_in:
case footn_to:
case footn_in:
limit = 24 * 3600;
break;
case loc_no:
case rec_time:
case sent_by:
break;
case sent_at:
if ( difftime ( time(NULL), misc->datum.sent_at )
< limit )
{
return FALSE;
}
break;
#ifndef COMPILE_CHECKS
default:
restart_kom("garb_text(): Illegal misc-item.\n");
#endif
}
}
VBUG(("garb_text: deleting %d\n", last_checked));
do_delete_text ( last_checked, text_s );
deleted_texts++;
return FALSE;
}