~ubuntu-branches/ubuntu/breezy/lurker/breezy

« back to all changes in this revision

Viewing changes to render/thread.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Meurer
  • Date: 2004-09-26 16:27:51 UTC
  • Revision ID: james.westby@ubuntu.com-20040926162751-z1ohcjltv7ojtg6z
Tags: upstream-1.2
ImportĀ upstreamĀ versionĀ 1.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*  $Id: thread.cpp,v 1.10 2004/08/27 15:04:05 terpstra Exp $
 
2
 *  
 
3
 *  thread.cpp - Handle a thread/ command
 
4
 *  
 
5
 *  Copyright (C) 2002 - Wesley W. Terpstra
 
6
 *  
 
7
 *  License: GPL
 
8
 *  
 
9
 *  Authors: 'Wesley W. Terpstra' <wesley@terpstra.ca>
 
10
 *  
 
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.
 
14
 *    
 
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.
 
19
 *    
 
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
 
23
 */
 
24
 
 
25
#define _XOPEN_SOURCE 500
 
26
#define _FILE_OFFSET_BITS 64
 
27
 
 
28
#include <Keys.h>
 
29
 
 
30
#include "commands.h"
 
31
#include "Threading.h"
 
32
#include "Cache.h"
 
33
 
 
34
int handle_thread(const Config& cfg, ESort::Reader* db, const string& param)
 
35
{
 
36
        Request req = parse_request(param);
 
37
        cfg.options = req.options;
 
38
        
 
39
        if (!MessageId::is_full(req.options.c_str()) ||
 
40
            req.options.length() != MessageId::full_len)
 
41
        {
 
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"));
 
48
                return 1;
 
49
        }
 
50
        
 
51
        MessageId id(req.options.c_str());
 
52
        string ok;
 
53
        
 
54
        Summary source(id);
 
55
        if ((ok = source.load(db, cfg)) != "")
 
56
        {
 
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."));
 
61
                return 1;
 
62
        }
 
63
        
 
64
        Threading::Key spot;
 
65
        Threading thread;
 
66
        if ((ok = thread.load(db, source, spot)) != "" ||
 
67
            (ok = thread.draw_tree(db)) != "")
 
68
        {
 
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."));
 
75
                return 1;
 
76
        }
 
77
        
 
78
        set<string> lists;
 
79
        for (Threading::Key j = 0; j < thread.size(); ++j)
 
80
        {
 
81
                Summary& sum = thread.getSummary(j);
 
82
                if (!sum.loaded() && (ok = sum.load(db, cfg)) != "")
 
83
                        break;
 
84
                
 
85
                const set<string>& mboxs = sum.mboxs();
 
86
                set<string>::const_iterator i;
 
87
                for (i = mboxs.begin(); i != mboxs.end(); ++i)
 
88
                        lists.insert(*i);
 
89
        }
 
90
        
 
91
        if (ok != "")
 
92
        {
 
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."));
 
99
                return 1;
 
100
        }
 
101
        
 
102
        Cache cache(cfg, "thread", param, req.ext);
 
103
        
 
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";
 
109
        
 
110
        set<string>::const_iterator list;
 
111
        for (list = lists.begin(); list != lists.end(); ++list)
 
112
        {
 
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";
 
116
        }
 
117
        
 
118
        int head = -1;
 
119
        for (Threading::Key i = 0; i < thread.size(); ++i)
 
120
        {
 
121
                if (i == spot)
 
122
                        cache.o << " <row selected=\"true\">\n";
 
123
                else    cache.o << " <row>\n";
 
124
                
 
125
                cache.o << "  <tree>";
 
126
                thread.draw_tree_row(cache.o, &head, i);
 
127
                cache.o << "</tree>\n  " << thread.getSummary(i) << "\n </row>\n";
 
128
        }
 
129
        
 
130
        cache.o << "</thread>\n";
 
131
        
 
132
        return 0;
 
133
}