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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
|
/* $Id: list.cpp 1649 2009-10-19 14:35:01Z terpstra $
*
* list.cpp - Handle a list/ 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 <iostream>
#include <cerrno>
#include <cassert>
#include <ctime>
#include <map>
#include <vector>
#include <MessageId.h>
#include <XmlEscape.h>
#include <Keys.h>
#include <esort.h>
#include "commands.h"
#include "Cache.h"
#include "Summary.h"
using namespace std;
#define NUM_TOPICS 20
#define NUM_DAYS 14
// nested types break g++ 2.95
struct NewTopic
{
bool pushed;
Summary newest;
vector<int> days;
};
static time_t now;
int load_topic(const Config& cfg, ESort::Reader* db, const string& hash, NewTopic& t)
{
string prefix = LU_KEYWORD LU_KEYWORD_THREAD + hash + '\0';
auto_ptr<ESort::Walker> dayWalker(db->seek(
prefix, "\xFF\xFF\xFF\xFF",
ESort::Backward));
// set it up for num days
t.days.resize(NUM_DAYS, 0);
t.pushed = false;
while (dayWalker->advance() != -1)
{ // check corrupt
if (dayWalker->key.length() != prefix.length() + 8) break;
MessageId id(dayWalker->key.c_str() + prefix.length(), 8);
// this is the newest if none has been set
if (!t.newest.loaded())
{
Summary sum(id);
string ok = sum.load(db, cfg);
if (ok != "")
error(_("Database list pull failure"), ok,
_("Something internal to the database failed. "
"Please contact the lurker user mailing list for "
"further assistence."));
if (!sum.deleted()) t.newest = sum;
}
int daygap = (now - id.timestamp()) / (60*60*24);
if (daygap >= NUM_DAYS)
{
if (t.newest.loaded()) break;
}
else
++t.days[daygap];
}
return 0;
}
int handle_list(const Config& cfg, ESort::Reader* db, const string& param)
{
Request req = parse_request(param);
cfg.options = req.options;
const Config::Lists::const_iterator li = cfg.lists.find(req.options);
// Identical error message if it's missing or not allowed (security)
if (li == cfg.lists.end() || !li->second.allowed)
error(_("No such list"), req.options,
_("The specified mailing list is not available in this "
"archive. Perhaps you misspelled it or went to the "
"wrong server?"));
const List& list = li->second;
// Right! Everything the user did is ok.
map<string, NewTopic> topics;
vector<string> order;
auto_ptr<ESort::Walker> topicFinder(db->seek(
LU_NEW_TOPICS + list.mbox + '\0',
"\xFF\xFF\xFF\xFF",
ESort::Backward));
string::size_type skip = 1 + list.mbox.length() + 1;
now = time(0);
while (order.size() < NUM_TOPICS && topicFinder->advance() != -1)
{ // check corrupt
if (topicFinder->key.length() != skip + 4 + 8) break;
const unsigned char* tss =
reinterpret_cast<const unsigned char*>
(topicFinder->key.c_str() + skip);
time_t when = (time_t)tss[0] << 24 |
(time_t)tss[1] << 16 |
(time_t)tss[2] << 8 |
(time_t)tss[3];
string hash(topicFinder->key, skip + 4, 8);
// not already loaded?
if (topics.find(hash) == topics.end() &&
load_topic(cfg, db, hash, topics[hash]) != 0)
return 1;
// Is this point in time the first (non-deleted) hit?
NewTopic& t = topics[hash];
if (t.newest.loaded() && // does the thread have any hits?
t.newest.id().timestamp() == when &&
!t.pushed)
{
t.pushed = true;
order.push_back(hash);
}
}
Cache cache(cfg, "list", param, req.ext);
cache.o << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
<< "<?xml-stylesheet type=\"text/xsl\" href=\"../ui/list.xsl\"?>\n"
<< "<list xml:lang=\"" << req.language << "\">\n"
<< " <mode>" << req.ext << "</mode>\n"
<< " " << cfg(req.language) << "\n"
<< " " << list(req.language) << "\n";
for (vector<string>::iterator i = order.begin(); i != order.end(); ++i)
{
cache.o << " <row>\n";
NewTopic& t = topics[*i];
vector<int>::iterator j;
cache.o << " <title>" << xmlEscape << skipSubjectStart(t.newest.subject().c_str()) << "</title>\n"
<< " ";
for (j = t.days.begin(); j != t.days.end(); ++j)
cache.o << "<day>" << *j << "</day>";
cache.o << "\n";
cache.o << " " << t.newest << "\n";
cache.o << " </row>\n";
}
cache.o << "</list>\n";
return 0;
}
|