From 8f7de730ccd5d36fc3f743497a8d5a971fa6b71b Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Mon, 27 Aug 2007 09:24:22 +0000 Subject: [PATCH] - Added some more torrent_handle checking to be sure we don't use invalid ones --- src/bittorrent.cpp | 79 ++++++++++++++++++++++++++-------------------- 1 file changed, 45 insertions(+), 34 deletions(-) diff --git a/src/bittorrent.cpp b/src/bittorrent.cpp index 88556204c..5d6c41f95 100644 --- a/src/bittorrent.cpp +++ b/src/bittorrent.cpp @@ -998,14 +998,17 @@ void bittorrent::readAlerts() { while (a.get()) { if (torrent_finished_alert* p = dynamic_cast(a.get())) { QTorrentHandle h(p->handle); - QString hash = h.hash(); - qDebug("Received finished alert for %s", h.name().toUtf8().data()); - setFinishedTorrent(hash); - emit finishedTorrent(h); + if(h.is_valid()){ + QString hash = h.hash(); + qDebug("Received finished alert for %s", h.name().toUtf8().data()); + setFinishedTorrent(hash); + emit finishedTorrent(h); + } } else if (file_error_alert* p = dynamic_cast(a.get())) { QTorrentHandle h(p->handle); - emit fullDiskError(h); + if(h.is_valid()) + emit fullDiskError(h); } else if (dynamic_cast(a.get())) { // Level: fatal @@ -1014,32 +1017,36 @@ void bittorrent::readAlerts() { else if (tracker_alert* p = dynamic_cast(a.get())) { // Level: fatal QTorrentHandle h(p->handle); - QString hash = h.hash(); - QList > errors = trackersErrors.value(hash, QList >()); - if(errors.size() > 5) - errors.removeAt(0); - errors << QPair(QTime::currentTime().toString("hh:mm:ss"), QString::fromUtf8(a->msg().c_str())); - trackersErrors[hash] = errors; - // Authentication - if(p->status_code == 401) { - emit trackerAuthenticationRequired(h); + if(h.is_valid()){ + QString hash = h.hash(); + QList > errors = trackersErrors.value(hash, QList >()); + if(errors.size() > 5) + errors.removeAt(0); + errors << QPair(QTime::currentTime().toString("hh:mm:ss"), QString::fromUtf8(a->msg().c_str())); + trackersErrors[hash] = errors; + // Authentication + if(p->status_code == 401) { + emit trackerAuthenticationRequired(h); + } } } else if (torrent_paused_alert* p = dynamic_cast(a.get())) { QTorrentHandle h(p->handle); - QString hash = h.hash(); - qDebug("Received torrent_paused_alert for %s", hash.toUtf8().data()); - if(!pausedTorrents.contains(hash)) { - if(h.is_valid() && h.is_paused()) { - pausedTorrents << hash; - if(reloadingTorrents.indexOf(hash) != -1) { - reloadTorrent(h); + if(h.is_valid()){ + QString hash = h.hash(); + qDebug("Received torrent_paused_alert for %s", hash.toUtf8().data()); + if(!pausedTorrents.contains(hash)) { + if(h.is_valid() && h.is_paused()) { + pausedTorrents << hash; + if(reloadingTorrents.indexOf(hash) != -1) { + reloadTorrent(h); + } + }else{ + qDebug("Not adding torrent no pausedList, it is invalid or resumed"); } }else{ - qDebug("Not adding torrent no pausedList, it is invalid or resumed"); + qDebug("Received alert for already paused torrent"); } - }else{ - qDebug("Received alert for already paused torrent"); } } else if (peer_blocked_alert* p = dynamic_cast(a.get())) { @@ -1047,23 +1054,27 @@ void bittorrent::readAlerts() { } else if (fastresume_rejected_alert* p = dynamic_cast(a.get())) { QTorrentHandle h(p->handle); - qDebug("/!\\ Fast resume failed for %s, reason: %s", h.name().toUtf8().data(), p->msg().c_str()); - emit fastResumeDataRejected(QString::fromUtf8(p->handle.name().c_str())); + if(h.is_valid()){ + qDebug("/!\\ Fast resume failed for %s, reason: %s", h.name().toUtf8().data(), p->msg().c_str()); + emit fastResumeDataRejected(h.name()); + } } else if (url_seed_alert* p = dynamic_cast(a.get())) { emit urlSeedProblem(QString::fromUtf8(p->url.c_str()), QString::fromUtf8(p->msg().c_str())); } else if (torrent_checked_alert* p = dynamic_cast(a.get())) { QTorrentHandle h(p->handle); - QString hash = h.hash(); - qDebug("%s have just finished checking", hash.toUtf8().data()); - int index = torrentsToPauseAfterChecking.indexOf(hash); - if(index != -1) { - // Pause torrent - pauseTorrent(hash); - qDebug("%s was paused after checking", hash.toUtf8().data()); + if(h.is_valid()){ + QString hash = h.hash(); + qDebug("%s have just finished checking", hash.toUtf8().data()); + int index = torrentsToPauseAfterChecking.indexOf(hash); + if(index != -1) { + // Pause torrent + pauseTorrent(hash); + qDebug("%s was paused after checking", hash.toUtf8().data()); + } + emit torrentFinishedChecking(hash); } - emit torrentFinishedChecking(hash); } a = s->pop_alert(); }