Commit b2b3129c authored by Per Cederqvist's avatar Per Cederqvist
Browse files

(day_to_sec): New constant.

(default_save): New constant.
(saved_by_aux): New static helper function.
(saved_by_recipient): Ditto.
(saved_by_comment): Ditto.
(saved): Ditto.
(garb_text): Use the saved() function to simplify code.
parent 49a03919
/*
* $Id: text-garb.c,v 0.49 2003/07/31 23:02:38 ceder Exp $
* $Id: text-garb.c,v 0.50 2003/08/11 09:38:52 ceder Exp $
* Copyright (C) 1991-1995, 1997-2002 Lysator Academic Computer Association.
*
* This file is part of the LysKOM server.
......@@ -107,97 +107,105 @@ static Text_no last_checked = 0;
static struct timeval garb_timer;
static Bool garb_timer_running = FALSE;
/*
* 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.
*/
static const double day_to_sec = 24 * 3600;
static const double default_save = 1.0 * 24 * 3600;
static Bool
garb_text(void)
saved_by_aux(Text_stat *text_s)
{
static long deleted_texts = 0;
unsigned short naux;
for (naux = 0; naux < text_s->aux_item_list.length; ++naux)
if (text_s->aux_item_list.items[naux].flags.dont_garb)
return TRUE;
Text_stat *text_s;
return FALSE;
}
static Bool
saved_by_recipient(Text_stat *text_s,
double age)
{
unsigned short nmisc;
Misc_info *misc;
u_short nmisc, naux;
double age; /* How many seconds is this text? */
double limit = 24 * 3600;
double limit;
Bool in_rec_group = FALSE;
if (param.garb_enable == FALSE)
return TRUE;
for (nmisc = text_s->no_of_misc, misc = text_s->misc_items;
nmisc > 0;
--nmisc, ++misc)
{
switch (misc->type)
{
case recpt:
case cc_recpt:
case bcc_recpt:
in_rec_group = TRUE;
if (cached_conf_exists(misc->datum.recipient))
{
limit = (day_to_sec
* cached_get_garb_nice(misc->datum.recipient));
if (age < limit)
return TRUE;
}
if ( last_checked == 0 )
kom_log("MSG: garb started.\n");
break;
tell_cache_garb_text(1);
last_checked = traverse_text( last_checked );
case comm_to:
case comm_in:
case footn_to:
case footn_in:
in_rec_group = FALSE;
break;
case loc_no:
case rec_time:
case sent_by:
break;
case sent_at:
if (in_rec_group
&& ldifftime(current_time.tv_sec, misc->datum.sent_at) < limit)
{
return TRUE;
}
break;
if ( last_checked == 0 )
{
kom_log("MSG: garb ready. %lu texts deleted.\n",
(u_long)deleted_texts);
tell_cache_garb_text(0);
#ifdef DEBUG_CALLS
async_garb_ended(deleted_texts);
#ifndef COMPILE_CHECKS
default:
#endif
deleted_texts = 0;
return TRUE;
}
if ( (text_s = cached_get_text_stat( last_checked )) == NULL )
{
kom_log("ERROR: garb_text(): Can't get text-stat.\n");
tell_cache_garb_text(0);
return FALSE;
case unknown_info:
restart_kom("saved_by_recipient(): Illegal misc-item.\n");
}
}
age = ldifftime(current_time.tv_sec, text_s->creation_time);
if ( text_s->no_of_marks > 0 || age < 24 * 3600 )
{
tell_cache_garb_text(0);
return FALSE;
}
return FALSE;
}
for (naux = 0; naux < text_s->aux_item_list.length; ++naux)
{
if (text_s->aux_item_list.items[naux].flags.dont_garb)
{
tell_cache_garb_text(0);
return FALSE;
}
}
static Bool
saved_by_comment(Text_stat *text_s)
{
unsigned short nmisc;
Misc_info *misc;
Bool in_comm_group = FALSE;
for (nmisc = text_s->no_of_misc, misc = text_s->misc_items;
nmisc > 0;
--nmisc, ++misc )
--nmisc, ++misc)
{
switch ( misc->type )
switch (misc->type)
{
case recpt:
case cc_recpt:
case bcc_recpt:
if (cached_conf_exists(misc->datum.recipient ))
{
limit = (24 * 3600.0
* cached_get_garb_nice(misc->datum.recipient));
if (age < limit)
{
tell_cache_garb_text(0);
return FALSE;
}
}
in_comm_group = FALSE;
break;
case comm_to:
case comm_in:
case footn_to:
case footn_in:
limit = 24 * 3600;
in_comm_group = TRUE;
break;
case loc_no:
......@@ -206,25 +214,99 @@ garb_text(void)
break;
case sent_at:
if (ldifftime(current_time.tv_sec, misc->datum.sent_at) < limit)
if (in_comm_group && ldifftime(current_time.tv_sec,
misc->datum.sent_at) < default_save)
{
tell_cache_garb_text(0);
return FALSE;
return TRUE;
}
break;
#ifndef COMPILE_CHECKS
default:
#endif
case unknown_info:
restart_kom("garb_text(): Illegal misc-item.\n");
restart_kom("saved_by_recipient(): Illegal misc-item.\n");
}
}
VBUG(("garb_text: deleting %lu\n", last_checked));
do_delete_text ( last_checked, text_s );
deleted_texts++;
return FALSE;
}
static Bool
saved(Text_no text_no,
Text_stat *text_s)
{
double age;
if (text_s->no_of_marks > 0)
return TRUE;
age = ldifftime(current_time.tv_sec, text_s->creation_time);
if (age < default_save)
return TRUE;
if (saved_by_aux(text_s))
return TRUE;
if (saved_by_recipient(text_s, age))
return TRUE;
if (saved_by_comment(text_s))
return TRUE;
return FALSE;
}
/*
* 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.
*/
static Bool
garb_text(void)
{
static long deleted_texts = 0;
Text_stat *text_s;
if (param.garb_enable == FALSE)
return TRUE;
if (last_checked == 0)
kom_log("MSG: garb started.\n");
tell_cache_garb_text(1);
last_checked = traverse_text( last_checked );
if (last_checked == 0)
{
kom_log("MSG: garb ready. %lu texts deleted.\n",
(unsigned long)deleted_texts);
tell_cache_garb_text(0);
#ifdef DEBUG_CALLS
async_garb_ended(deleted_texts);
#endif
deleted_texts = 0;
return TRUE;
}
if ((text_s = cached_get_text_stat(last_checked)) == NULL)
{
kom_log("ERROR: garb_text(): Can't get text-stat.\n");
tell_cache_garb_text(0);
return FALSE;
}
if (!saved(last_checked, text_s))
{
VBUG(("garb_text: deleting %lu\n", last_checked));
do_delete_text(last_checked, text_s);
deleted_texts++;
}
tell_cache_garb_text(0);
return FALSE;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment