blob: cec4cd5270df80e44e3529f7f47b52a3da223b23 (
plain)
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
|
/***************************************************************************
* Copyright (C) 2004 by Paulo Moura Guedes *
* moura@kdewebdev.org *
* *
* 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; either version 2 of the License, or *
* (at your option) any later version. *
* *
* 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., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
#include "linkstatus.h"
#include "../parser/node.h"
#include "../ui/treeview.h"
#include <klocale.h>
#include <kcharsets.h>
#include <tqdom.h>
LinktqStatus::~LinktqStatus()
{
//kdDebug(23100) << "|";
for(uint i = 0; i != tqchildren_nodes_.size(); ++i)
{
if(tqchildren_nodes_[i])
{
delete tqchildren_nodes_[i];
tqchildren_nodes_[i] = 0;
}
}
tqchildren_nodes_.clear();
if(isRedirection())
{
if(redirection_)
{
delete redirection_;
redirection_ = 0;
}
}
}
void LinktqStatus::reset()
{
depth_ = -1;
external_domain_depth_ = -1;
is_root_ = false;
error_occurred_ = false;
is_redirection_ = false;
checked_ = false;
only_check_header_ = true;
malformed_ = false;
Q_ASSERT(!node_);
has_base_URI_ = false;
label_ = "";
absolute_url_ = "";
doc_html_ = "";
http_header_ = HttpResponseHeader();
error_ = "";
for(uint i = 0; i != tqchildren_nodes_.size(); ++i)
{
if(tqchildren_nodes_[i])
{
delete tqchildren_nodes_[i];
tqchildren_nodes_[i] = 0;
}
}
tqchildren_nodes_.clear();
if(isRedirection())
{
if(redirection_)
{
delete redirection_;
redirection_ = 0;
}
}
Q_ASSERT(!tqparent_);
base_URI_ = "";
}
TQString const LinktqStatus::toString() const
{
TQString aux;
if(!is_root_)
{
Q_ASSERT(tqparent_);
aux += i18n( "Parent: %1" ).tqarg( tqparent()->absoluteUrl().prettyURL() ) + "\n";
}
Q_ASSERT(!original_url_.isNull());
aux += i18n( "URL: %1" ).tqarg( absoluteUrl().prettyURL() ) + "\n";
aux += i18n( "Original URL: %1" ).tqarg( originalUrl() ) + "\n";
if(node())
aux += i18n( "Node: %1" ).tqarg( node()->content() ) + "\n";
return aux;
}
LinktqStatus* LinktqStatus::lastRedirection(LinktqStatus* ls)
{
if(ls->isRedirection())
if(ls->redirection())
return lastRedirection(ls->redirection());
else
return ls;
else
return ls;
}
void LinktqStatus::loadNode()
{
Q_ASSERT(node_);
setOriginalUrl(node_->url());
setLabel(node_->linkLabel());
if(malformed())
{
setErrorOccurred(true);
setError(i18n( "Malformed" ));
settqStatus(LinktqStatus::MALFORMED);
kdDebug(23100) << "Malformed:" << endl;
kdDebug(23100) << "Node: " << node()->content() << endl;
//kdDebug(23100) << toString() << endl; // probable segfault
}
}
bool LinktqStatus::malformed() const // don't inline please (#include "node.h")
{
return (malformed_ || node_->malformed());
}
void LinktqStatus::setChildrenNodes(vector<Node*> const& nodes) // don't inline please (#include "node.h")
{
tqchildren_nodes_.reserve(nodes.size());
tqchildren_nodes_ = nodes;
}
void LinktqStatus::setMalformed(bool flag)
{
malformed_ = flag;
if(flag)
{
setErrorOccurred(true);
setError(i18n( "Malformed" ));
settqStatus(LinktqStatus::MALFORMED);
kdDebug(23100) << "Malformed!" << endl;
kdDebug(23100) << node()->content() << endl;
//kdDebug(23100) << toString() << endl; // probable segfault
}
else if(error() == i18n( "Malformed" ))
{
setErrorOccurred(false);
setError("");
settqStatus(LinktqStatus::UNDETERMINED);
}
}
void LinktqStatus::save(TQDomElement& element) const
{
TQDomElement child_element = element.ownerDocument().createElement("link");
// <url>
TQDomElement tmp_1 = element.ownerDocument().createElement("url");
tmp_1.appendChild(element.ownerDocument().createTextNode(absoluteUrl().prettyURL()));
child_element.appendChild(tmp_1);
// <status>
tmp_1 = element.ownerDocument().createElement("status");
tmp_1.setAttribute("broken",
ResultView::displayableWithtqStatus(this, ResultView::bad) ?
"true" : "false");
tmp_1.appendChild(element.ownerDocument().createTextNode(statusText()));
child_element.appendChild(tmp_1);
// <label>
tmp_1 = element.ownerDocument().createElement("label");
tmp_1.appendChild(element.ownerDocument().createTextNode(KCharsets::resolveEntities(label())));
child_element.appendChild(tmp_1);
// <referers>
tmp_1 = element.ownerDocument().createElement("referrers");
for(TQValueVector<KURL>::const_iterator it = referrers_.begin(); it != referrers_.end(); ++it)
{
TQDomElement tmp_2 = element.ownerDocument().createElement("url");
tmp_2.appendChild(element.ownerDocument().createTextNode(it->prettyURL()));
tmp_1.appendChild(tmp_2);
}
Q_ASSERT(!referrers_.isEmpty());
child_element.appendChild(tmp_1);
element.appendChild(child_element);
}
|