1
/* $Id: thread.cpp,v 1.10 2004/08/27 15:04:05 terpstra Exp $
3
* thread.cpp - Handle a thread/ command
5
* Copyright (C) 2002 - Wesley W. Terpstra
9
* Authors: 'Wesley W. Terpstra' <wesley@terpstra.ca>
11
* This program is free software; you can redistribute it and/or modify
12
* it under the terms of the GNU General Public License as published by
13
* the Free Software Foundation; version 2.
15
* This program is distributed in the hope that it will be useful,
16
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
* GNU General Public License for more details.
20
* You should have received a copy of the GNU General Public License
21
* along with this program; if not, write to the Free Software
22
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25
#define _XOPEN_SOURCE 500
26
#define _FILE_OFFSET_BITS 64
31
#include "Threading.h"
34
int handle_thread(const Config& cfg, ESort::Reader* db, const string& param)
36
Request req = parse_request(param);
37
cfg.options = req.options;
39
if (!MessageId::is_full(req.options.c_str()) ||
40
req.options.length() != MessageId::full_len)
42
cout << "Status: 200 OK\r\n";
43
cout << "Content-Type: text/html\r\n\r\n";
44
cout << error(_("Bad request"), param,
45
_("The given parameter was not of the correct format. "
46
"A thread request must be formatted like: "
47
"thread/YYYYMMDD.HHMMSS.hashcode.xml"));
51
MessageId id(req.options.c_str());
55
if ((ok = source.load(db, cfg)) != "")
57
cout << "Status: 200 OK\r\n";
58
cout << "Content-Type: text/html\r\n\r\n";
59
cout << error(_("Database thread source pull failure"), ok,
60
_("The specified message does not exist."));
66
if ((ok = thread.load(db, source, spot)) != "" ||
67
(ok = thread.draw_tree(db)) != "")
69
cout << "Status: 200 OK\r\n";
70
cout << "Content-Type: text/html\r\n\r\n";
71
cout << error(_("Database thread tree load failure"), ok,
72
_("Something internal to the database failed. "
73
"Please contact the lurker user mailing list for "
74
"further assistence."));
79
for (Threading::Key j = 0; j < thread.size(); ++j)
81
Summary& sum = thread.getSummary(j);
82
if (!sum.loaded() && (ok = sum.load(db, cfg)) != "")
85
const set<string>& mboxs = sum.mboxs();
86
set<string>::const_iterator i;
87
for (i = mboxs.begin(); i != mboxs.end(); ++i)
93
cout << "Status: 200 OK\r\n";
94
cout << "Content-Type: text/html\r\n\r\n";
95
cout << error(_("Database thread sumary load failure"), ok,
96
_("Something internal to the database failed. "
97
"Please contact the lurker user mailing list for "
98
"further assistence."));
102
Cache cache(cfg, "thread", param, req.ext);
104
cache.o << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
105
<< "<?xml-stylesheet type=\"text/xsl\" href=\"../fmt/thread.xsl\"?>\n"
106
<< "<thread xml:lang=\"" << req.language << "\">\n"
107
<< " " << cfg(req.language) << "\n"
108
<< " <hash>" << subject_hash(source.subject().c_str()) << "</hash>\n";
110
set<string>::const_iterator list;
111
for (list = lists.begin(); list != lists.end(); ++list)
113
Config::Lists::const_iterator desc = cfg.lists.find(*list);
114
if (desc == cfg.lists.end()) continue;
115
cache.o << " " << desc->second(req.language) << "\n";
119
for (Threading::Key i = 0; i < thread.size(); ++i)
122
cache.o << " <row selected=\"true\">\n";
123
else cache.o << " <row>\n";
125
cache.o << " <tree>";
126
thread.draw_tree_row(cache.o, &head, i);
127
cache.o << "</tree>\n " << thread.getSummary(i) << "\n </row>\n";
130
cache.o << "</thread>\n";