From 5ca8d4181666885f732944eb8a27ad63daf443ee Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 19 May 2010 19:02:25 +0000 Subject: [PATCH] (trunk libT) #2929 "persistent tracker error messages in main window" -- experimental fix --- libtransmission/announcer.c | 3 ++- libtransmission/announcer.h | 3 ++- libtransmission/torrent.c | 37 +++++++++++++++++++++++++++++++------ libtransmission/torrent.h | 1 + 4 files changed, 36 insertions(+), 8 deletions(-) diff --git a/libtransmission/announcer.c b/libtransmission/announcer.c index 924923813..bf239583d 100644 --- a/libtransmission/announcer.c +++ b/libtransmission/announcer.c @@ -581,7 +581,7 @@ getTier( tr_announcer * announcer, int torrentId, int tierId ) **** PUBLISH ***/ -static const tr_tracker_event emptyEvent = { 0, NULL, NULL, 0, 0 }; +static const tr_tracker_event emptyEvent = { 0, NULL, NULL, NULL, 0, 0 }; static void publishMessage( tr_tier * tier, const char * msg, int type ) @@ -592,6 +592,7 @@ publishMessage( tr_tier * tier, const char * msg, int type ) tr_tracker_event event = emptyEvent; event.messageType = type; event.text = msg; + event.tracker = tier->currentTracker ? tier->currentTracker->announce : NULL; tr_publisherPublish( &tiers->publisher, tier, &event ); } } diff --git a/libtransmission/announcer.h b/libtransmission/announcer.h index 15c510223..488940f36 100644 --- a/libtransmission/announcer.h +++ b/libtransmission/announcer.h @@ -43,7 +43,8 @@ typedef struct TrackerEventType messageType; /* for TR_TRACKER_WARNING and TR_TRACKER_ERROR */ - const char * text; + const char * text; + const char * tracker; /* for TR_TRACKER_PEERS */ const uint8_t * compact; diff --git a/libtransmission/torrent.c b/libtransmission/torrent.c index 00b28bd93..89b8355e2 100644 --- a/libtransmission/torrent.c +++ b/libtransmission/torrent.c @@ -347,10 +347,21 @@ tr_torrentSetLocalError( tr_torrent * tor, const char * fmt, ... ) va_start( ap, fmt ); tor->error = TR_STAT_LOCAL_ERROR; + tor->errorTracker[0] = '\0'; evutil_vsnprintf( tor->errorString, sizeof( tor->errorString ), fmt, ap ); va_end( ap ); } +static void +tr_torrentClearError( tr_torrent * tor ) +{ + assert( tr_isTorrent( tor ) ); + + tor->error = TR_STAT_OK; + tor->errorString[0] = '\0'; + tor->errorTracker[0] = '\0'; +} + static void onTrackerResponse( void * tracker UNUSED, void * vevent, @@ -386,21 +397,20 @@ onTrackerResponse( void * tracker UNUSED, case TR_TRACKER_WARNING: tr_torerr( tor, _( "Tracker warning: \"%s\"" ), event->text ); tor->error = TR_STAT_TRACKER_WARNING; + tr_strlcpy( tor->errorTracker, event->tracker, sizeof( tor->errorTracker ) ); tr_strlcpy( tor->errorString, event->text, sizeof( tor->errorString ) ); break; case TR_TRACKER_ERROR: tr_torerr( tor, _( "Tracker error: \"%s\"" ), event->text ); tor->error = TR_STAT_TRACKER_ERROR; + tr_strlcpy( tor->errorTracker, event->tracker, sizeof( tor->errorTracker ) ); tr_strlcpy( tor->errorString, event->text, sizeof( tor->errorString ) ); break; case TR_TRACKER_ERROR_CLEAR: if( tor->error != TR_STAT_LOCAL_ERROR ) - { - tor->error = TR_STAT_OK; - tor->errorString[0] = '\0'; - } + tr_torrentClearError( tor ); break; } } @@ -1363,10 +1373,9 @@ checkAndStartImpl( void * vtor ) { const time_t now = tr_time( ); tor->isRunning = TRUE; - tor->error = TR_STAT_OK; - tor->errorString[0] = '\0'; tor->completeness = tr_cpGetStatus( &tor->completion ); tor->startDate = tor->anyDate = now; + tr_torrentClearError( tor ); tr_torrentResetTransferStats( tor ); tr_announcerTorrentStarted( tor ); @@ -2210,6 +2219,22 @@ tr_torrentSetAnnounceList( tr_torrent * tor, /* cleanup */ tr_bencFree( &metainfo ); + /* if we had a tracker-related error on this torrent, + * and that tracker's been removed, + * then clear the error */ + if( ( tor->error == TR_STAT_TRACKER_WARNING ) + || ( tor->error == TR_STAT_TRACKER_ERROR ) ) + { + tr_bool clear = TRUE; + + for( i=0; clear && ierrorTracker ) ) + clear = FALSE; + + if( clear ) + tr_torrentClearError( tor ); + } + /* tell the announcer to reload this torrent's tracker list */ tr_announcerResetTorrent( tor->session->announcer, tor ); } diff --git a/libtransmission/torrent.h b/libtransmission/torrent.h index dfd61bf1f..9ab21de96 100644 --- a/libtransmission/torrent.h +++ b/libtransmission/torrent.h @@ -141,6 +141,7 @@ struct tr_torrent tr_stat_errtype error; char errorString[128]; + char errorTracker[128]; uint8_t obfuscatedHash[SHA_DIGEST_LENGTH]; -- 2.40.0