File: thread.cpp

package info (click to toggle)
lurker 2.1-7
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 1,800 kB
  • ctags: 1,088
  • sloc: cpp: 10,527; sh: 1,348; xml: 1,278; perl: 206; makefile: 198
file content (98 lines) | stat: -rw-r--r-- 2,477 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*  $Id: thread.cpp,v 1.9 2006/02/19 01:17:22 terpstra Exp $
 *  
 *  thread.cpp - Cleanup after a thread/ command
 *  
 *  Copyright (C) 2002 - Wesley W. Terpstra
 *  
 *  License: GPL
 *  
 *  Authors: 'Wesley W. Terpstra' <wesley@terpstra.ca>
 *  
 *    This program is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation; version 2.
 *    
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *    
 *    You should have received a copy of the GNU General Public License
 *    along with this program; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#define _FILE_OFFSET_BITS 64

#include "PTable.h"
#include <Keys.h>

#include <iostream>

using namespace std;

bool PTable::test_thread(KSI ks)
{
	const string::size_type skip = sizeof("thread");
	return MessageId::is_full(ks->first.c_str() + skip);

}
void PTable::calc_thread(KSI ks)
{
	/* Threads depend on thread data!
	 *
	 * ... but also include:
	 *   host info (from config file)
	 *
	 * Policy:
	 *   kill if obsolete due to above
	 *   kill if older than a fixed time
	 *   kill if no recent accesses
	 */
	
	if (!test_thread(ks))
	{
		if (verbose)
			cout << ks->first << ": not a lurker file." << endl;
		return;
	}
	
	MessageId id(ks->first.c_str() + 7);
	
	if (ks->second.mtime <= cfg.modified)
	{	// die - it's older than the config file
		ks->second.kill = true;
		if (verbose)
			cout << ks->first << ": older than config file." << endl;
		return;
	}
	
	if (now - ks->second.mtime >= modifiedLimit)
	{
		ks->second.kill = true;
		if (verbose)
			cout << ks->first << ": expired due to maximum age." << endl;
		return;
	}
	
	if (now - ks->second.atime >= accessedLimit)
	{
		ks->second.kill = true;
		if (verbose)
			cout << ks->first << ": expired due to no access." << endl;
		return;
	}
	
	Summary& sum = summaries[id];
	string tid(subject_hash(sum.subject.c_str()));
	if (threads.find(tid) != threads.end())
	{	// die - the thread changed
		ks->second.kill = true;
		if (verbose)
			cout << ks->first << ": thread modified." << endl;
		return;
	}
	
	if (verbose)
		cout << ks->first << ": not expired" << endl;
}