summaryrefslogtreecommitdiff
path: root/rbutil/rbutilqt/base/httpget.cpp
diff options
context:
space:
mode:
authorDominik Riebeling <Dominik.Riebeling@gmail.com>2009-03-21 23:18:57 +0000
committerDominik Riebeling <Dominik.Riebeling@gmail.com>2009-03-21 23:18:57 +0000
commit6a76ebbab10594f425edbd26e1fa35b0e37a61e5 (patch)
tree102bc8ef2af55e240731e422f34748842304e637 /rbutil/rbutilqt/base/httpget.cpp
parente8f25d91e8d89b3acc96aad3a81b684ea71443a8 (diff)
downloadrockbox-6a76ebbab10594f425edbd26e1fa35b0e37a61e5.tar.gz
rockbox-6a76ebbab10594f425edbd26e1fa35b0e37a61e5.zip
Cleanup HttpGet debugging output: make it somewhat more silent and streamline the messages in general.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@20438 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'rbutil/rbutilqt/base/httpget.cpp')
-rw-r--r--rbutil/rbutilqt/base/httpget.cpp55
1 files changed, 25 insertions, 30 deletions
diff --git a/rbutil/rbutilqt/base/httpget.cpp b/rbutil/rbutilqt/base/httpget.cpp
index 5aabc5b29c..4db4ec384e 100644
--- a/rbutil/rbutilqt/base/httpget.cpp
+++ b/rbutil/rbutilqt/base/httpget.cpp
@@ -54,7 +54,7 @@ HttpGet::HttpGet(QObject *parent)
54 connect(&http, SIGNAL(dataReadProgress(int, int)), this, SIGNAL(dataReadProgress(int, int))); 54 connect(&http, SIGNAL(dataReadProgress(int, int)), this, SIGNAL(dataReadProgress(int, int)));
55 connect(&http, SIGNAL(requestFinished(int, bool)), this, SLOT(httpFinished(int, bool))); 55 connect(&http, SIGNAL(requestFinished(int, bool)), this, SLOT(httpFinished(int, bool)));
56 connect(&http, SIGNAL(responseHeaderReceived(const QHttpResponseHeader&)), this, SLOT(httpResponseHeader(const QHttpResponseHeader&))); 56 connect(&http, SIGNAL(responseHeaderReceived(const QHttpResponseHeader&)), this, SLOT(httpResponseHeader(const QHttpResponseHeader&)));
57 connect(&http, SIGNAL(stateChanged(int)), this, SLOT(httpState(int))); 57// connect(&http, SIGNAL(stateChanged(int)), this, SLOT(httpState(int)));
58 connect(&http, SIGNAL(requestStarted(int)), this, SLOT(httpStarted(int))); 58 connect(&http, SIGNAL(requestStarted(int)), this, SLOT(httpStarted(int)));
59 59
60 connect(&http, SIGNAL(readyRead(const QHttpResponseHeader&)), this, SLOT(httpResponseHeader(const QHttpResponseHeader&))); 60 connect(&http, SIGNAL(readyRead(const QHttpResponseHeader&)), this, SLOT(httpResponseHeader(const QHttpResponseHeader&)));
@@ -69,7 +69,6 @@ void HttpGet::setCache(const QDir& d)
69 m_cachedir = d; 69 m_cachedir = d;
70 bool result; 70 bool result;
71 result = initializeCache(d); 71 result = initializeCache(d);
72 qDebug() << "[HTTP]"<< __func__ << "(QDir)" << d.absolutePath() << result;
73 m_usecache = result; 72 m_usecache = result;
74} 73}
75 74
@@ -79,7 +78,6 @@ void HttpGet::setCache(const QDir& d)
79 */ 78 */
80void HttpGet::setCache(bool c) 79void HttpGet::setCache(bool c)
81{ 80{
82 qDebug() << "[HTTP]" << __func__ << "(bool) =" << c;
83 m_usecache = c; 81 m_usecache = c;
84 // make sure cache is initialized 82 // make sure cache is initialized
85 if(c) 83 if(c)
@@ -126,7 +124,6 @@ QHttp::Error HttpGet::error()
126 124
127void HttpGet::setProxy(const QUrl &proxy) 125void HttpGet::setProxy(const QUrl &proxy)
128{ 126{
129 qDebug() << "[HTTP]" << __func__ << "(QUrl)" << proxy.toString();
130 m_proxy = proxy; 127 m_proxy = proxy;
131 http.setProxy(m_proxy.host(), m_proxy.port(), m_proxy.userName(), m_proxy.password()); 128 http.setProxy(m_proxy.host(), m_proxy.port(), m_proxy.userName(), m_proxy.password());
132} 129}
@@ -134,7 +131,6 @@ void HttpGet::setProxy(const QUrl &proxy)
134 131
135void HttpGet::setProxy(bool enable) 132void HttpGet::setProxy(bool enable)
136{ 133{
137 qDebug() << "[HTTP]" << __func__ << "(bool)" << enable;
138 if(enable) 134 if(enable)
139 http.setProxy(m_proxy.host(), m_proxy.port(), m_proxy.userName(), m_proxy.password()); 135 http.setProxy(m_proxy.host(), m_proxy.port(), m_proxy.userName(), m_proxy.password());
140 else 136 else
@@ -146,12 +142,12 @@ void HttpGet::setFile(QFile *file)
146{ 142{
147 outputFile = file; 143 outputFile = file;
148 outputToBuffer = false; 144 outputToBuffer = false;
149 qDebug() << "[HTTP]" << __func__ << "(QFile*)" << outputFile->fileName();
150} 145}
151 146
152 147
153void HttpGet::abort() 148void HttpGet::abort()
154{ 149{
150 qDebug() << "[HTTP] Aborting requests, pending:" << http.hasPendingRequests();
155 http.abort(); 151 http.abort();
156 if(!outputToBuffer) 152 if(!outputToBuffer)
157 outputFile->close(); 153 outputFile->close();
@@ -179,8 +175,7 @@ bool HttpGet::getFile(const QUrl &url)
179 if(!outputToBuffer) { 175 if(!outputToBuffer) {
180 if (!outputFile->open(QIODevice::ReadWrite)) { 176 if (!outputFile->open(QIODevice::ReadWrite)) {
181 qDebug() << "[HTTP] Error: Cannot open " << qPrintable(outputFile->fileName()) 177 qDebug() << "[HTTP] Error: Cannot open " << qPrintable(outputFile->fileName())
182 << " for writing: " << qPrintable(outputFile->errorString()) 178 << " for writing: " << qPrintable(outputFile->errorString());
183 << endl;
184 return false; 179 return false;
185 } 180 }
186 } 181 }
@@ -189,7 +184,7 @@ bool HttpGet::getFile(const QUrl &url)
189 // returned in case the object is reused. 184 // returned in case the object is reused.
190 dataBuffer.clear(); 185 dataBuffer.clear();
191 } 186 }
192 qDebug() << "[HTTP] downloading" << url.toEncoded(); 187 qDebug() << "[HTTP] GET URI" << url.toEncoded();
193 // create request 188 // create request
194 http.setHost(url.host(), url.port(80)); 189 http.setHost(url.host(), url.port(80));
195 // construct query (if any) 190 // construct query (if any)
@@ -218,6 +213,7 @@ bool HttpGet::getFile(const QUrl &url)
218 connect(this, SIGNAL(headerFinished()), this, SLOT(getFileFinish())); 213 connect(this, SIGNAL(headerFinished()), this, SLOT(getFileFinish()));
219 m_header.setRequest("HEAD", m_path + m_query); 214 m_header.setRequest("HEAD", m_path + m_query);
220 headRequest = http.request(m_header); 215 headRequest = http.request(m_header);
216 qDebug() << "[HTTP] HEAD scheduled: " << headRequest;
221 } 217 }
222 218
223 return true; 219 return true;
@@ -229,18 +225,17 @@ void HttpGet::getFileFinish()
229 m_cachefile = m_cachedir.absolutePath() + "/rbutil-cache/" + m_hash; 225 m_cachefile = m_cachedir.absolutePath() + "/rbutil-cache/" + m_hash;
230 if(m_usecache) { 226 if(m_usecache) {
231 // check if the file is present in cache 227 // check if the file is present in cache
232 qDebug() << "[HTTP] cache ENABLED";
233 QFileInfo cachefile = QFileInfo(m_cachefile); 228 QFileInfo cachefile = QFileInfo(m_cachefile);
234 if(cachefile.isReadable() 229 if(cachefile.isReadable()
235 && cachefile.size() > 0 230 && cachefile.size() > 0
236 && cachefile.lastModified() > m_serverTimestamp) { 231 && cachefile.lastModified() > m_serverTimestamp) {
237 232
238 qDebug() << "[HTTP] cached file found:" << m_cachefile; 233 qDebug() << "[HTTP] Cache: up-to-date file found:" << m_cachefile;
239 234
240 getRequest = -1; 235 getRequest = -1;
241 QFile c(m_cachefile); 236 QFile c(m_cachefile);
242 if(!outputToBuffer) { 237 if(!outputToBuffer) {
243 qDebug() << "[HTTP] copying cache file to output" << outputFile->fileName(); 238 qDebug() << "[HTTP] Cache: copying file to output" << outputFile->fileName();
244 c.open(QIODevice::ReadOnly); 239 c.open(QIODevice::ReadOnly);
245 outputFile->open(QIODevice::ReadWrite); 240 outputFile->open(QIODevice::ReadWrite);
246 outputFile->write(c.readAll()); 241 outputFile->write(c.readAll());
@@ -248,7 +243,7 @@ void HttpGet::getFileFinish()
248 c.close(); 243 c.close();
249 } 244 }
250 else { 245 else {
251 qDebug() << "[HTTP] reading cache file into buffer"; 246 qDebug() << "[HTTP] Cache: reading file into buffer";
252 c.open(QIODevice::ReadOnly); 247 c.open(QIODevice::ReadOnly);
253 dataBuffer = c.readAll(); 248 dataBuffer = c.readAll();
254 c.close(); 249 c.close();
@@ -260,11 +255,8 @@ void HttpGet::getFileFinish()
260 } 255 }
261 else { 256 else {
262 if(cachefile.isReadable()) 257 if(cachefile.isReadable())
263 qDebug() << "[HTTP] file in cache timestamp:" << cachefile.lastModified(); 258 qDebug() << "[HTTP] Cache: outdated, timestamp:" << cachefile.lastModified();
264 else 259 qDebug() << "[HTTP] Cache: caching as" << m_cachefile;
265 qDebug() << "[HTTP] file not in cache.";
266 qDebug() << "[HTTP] server file timestamp:" << m_serverTimestamp;
267 qDebug() << "[HTTP] downloading file to" << m_cachefile;
268 // unlink old cache file 260 // unlink old cache file
269 if(cachefile.isReadable()) 261 if(cachefile.isReadable())
270 QFile(m_cachefile).remove(); 262 QFile(m_cachefile).remove();
@@ -285,7 +277,7 @@ void HttpGet::getFileFinish()
285 << qPrintable(outputFile->fileName()); 277 << qPrintable(outputFile->fileName());
286 getRequest = http.request(m_header, 0, outputFile); 278 getRequest = http.request(m_header, 0, outputFile);
287 } 279 }
288 qDebug() << "[HTTP] GET request scheduled, id:" << getRequest; 280 qDebug() << "[HTTP] GET scheduled: " << getRequest;
289 281
290 return; 282 return;
291} 283}
@@ -294,7 +286,7 @@ void HttpGet::getFileFinish()
294void HttpGet::httpDone(bool error) 286void HttpGet::httpDone(bool error)
295{ 287{
296 if (error) { 288 if (error) {
297 qDebug() << "[HTTP] Error: " << qPrintable(http.errorString()) << httpResponse(); 289 qDebug() << "[HTTP] Error:" << qPrintable(http.errorString()) << httpResponse();
298 } 290 }
299 if(!outputToBuffer) 291 if(!outputToBuffer)
300 outputFile->close(); 292 outputFile->close();
@@ -322,14 +314,12 @@ void HttpGet::httpDone(bool error)
322 314
323void HttpGet::httpFinished(int id, bool error) 315void HttpGet::httpFinished(int id, bool error)
324{ 316{
325 qDebug() << "[HTTP]" << __func__ << "(int, bool) =" << id << error; 317 qDebug() << "[HTTP] Request finished:" << id << "Error:" << error
318 << "pending requests:" << http.hasPendingRequests();
326 if(id == getRequest) { 319 if(id == getRequest) {
327 dataBuffer = http.readAll(); 320 dataBuffer = http.readAll();
328
329 emit requestFinished(id, error); 321 emit requestFinished(id, error);
330 } 322 }
331 qDebug() << "[HTTP] hasPendingRequests =" << http.hasPendingRequests();
332
333 323
334 if(id == headRequest) { 324 if(id == headRequest) {
335 QHttpResponseHeader h = http.lastResponse(); 325 QHttpResponseHeader h = http.lastResponse();
@@ -354,7 +344,7 @@ void HttpGet::httpFinished(int id, bool error)
354 // RFC 822 344 // RFC 822
355 else 345 else
356 m_serverTimestamp = QDateTime::fromString(date, "dd MMM yyyy hh:mm:ss"); 346 m_serverTimestamp = QDateTime::fromString(date, "dd MMM yyyy hh:mm:ss");
357 qDebug() << "[HTTP] Header Request Date:" << date << ", parsed:" << m_serverTimestamp; 347 qDebug() << "[HTTP] HEAD finished, server date:" << date << ", parsed:" << m_serverTimestamp;
358 emit headerFinished(); 348 emit headerFinished();
359 return; 349 return;
360 } 350 }
@@ -364,8 +354,8 @@ void HttpGet::httpFinished(int id, bool error)
364 354
365void HttpGet::httpStarted(int id) 355void HttpGet::httpStarted(int id)
366{ 356{
367 qDebug() << "[HTTP]" << __func__ << "(int) =" << id; 357 qDebug() << "[HTTP] Request started: " << id << "Header req:"
368 qDebug() << "headRequest" << headRequest << "getRequest" << getRequest; 358 << headRequest << "Get req:" << getRequest;
369} 359}
370 360
371 361
@@ -381,7 +371,7 @@ void HttpGet::httpResponseHeader(const QHttpResponseHeader &resp)
381 // this download 371 // this download
382 m_response = resp.statusCode(); 372 m_response = resp.statusCode();
383 if(m_response != 200) { 373 if(m_response != 200) {
384 qDebug() << "[HTTP] response error =" << m_response << resp.reasonPhrase(); 374 // abort old request first.
385 http.abort(); 375 http.abort();
386 } 376 }
387 // 301 -- moved permanently 377 // 301 -- moved permanently
@@ -394,6 +384,11 @@ void HttpGet::httpResponseHeader(const QHttpResponseHeader &resp)
394 qDebug() << "[HTTP] response =" << m_response << "- following"; 384 qDebug() << "[HTTP] response =" << m_response << "- following";
395 getFile(resp.value("location") + m_query); 385 getFile(resp.value("location") + m_query);
396 } 386 }
387 else if(m_response != 200) {
388 // all other errors are fatal.
389 qDebug() << "[HTTP] Response error:" << m_response << resp.reasonPhrase();
390 }
391
397} 392}
398 393
399 394
@@ -408,7 +403,7 @@ void HttpGet::httpState(int state)
408 QString s[] = {"Unconnected", "HostLookup", "Connecting", "Sending", 403 QString s[] = {"Unconnected", "HostLookup", "Connecting", "Sending",
409 "Reading", "Connected", "Closing"}; 404 "Reading", "Connected", "Closing"};
410 if(state <= 6) 405 if(state <= 6)
411 qDebug() << "[HTTP]" << __func__ << "() = " << s[state]; 406 qDebug() << "[HTTP] State:" << s[state];
412 else qDebug() << "[HTTP]" << __func__ << "() = " << state; 407 else qDebug() << "[HTTP] State:" << state;
413} 408}
414 409