Changeset 6185 for branches/1.2x
- Timestamp:
- Jun 13, 2008, 9:25:25 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/1.2x/cli/transmissioncli.c
r6177 r6185 31 31 32 32 #include <libtransmission/transmission.h> 33 #include <libtransmission/bencode.h> 33 34 #include <libtransmission/makemeta.h> 34 35 #include <libtransmission/metainfo.h> /* tr_metainfoFree */ 35 36 #include <libtransmission/utils.h> /* tr_wait */ 36 37 #include <libtransmission/web.h> /* tr_webRun */ 37 38 38 39 /* macro to shut up "unused parameter" warnings */ … … 100 101 } 101 102 103 static int 104 is_rfc2396_alnum( char ch ) 105 { 106 return ( '0' <= ch && ch <= '9' ) 107 || ( 'A' <= ch && ch <= 'Z' ) 108 || ( 'a' <= ch && ch <= 'z' ); 109 } 110 111 static void 112 escape( char * out, const uint8_t * in, int in_len ) /* rfc2396 */ 113 { 114 const uint8_t *end = in + in_len; 115 while( in != end ) 116 if( is_rfc2396_alnum(*in) ) 117 *out++ = (char) *in++; 118 else 119 out += snprintf( out, 4, "%%%02X", (unsigned int)*in++ ); 120 *out = '\0'; 121 } 122 102 123 #define LINEWIDTH 80 103 124 … … 108 129 { 109 130 system( finishCall ); 131 } 132 133 static int leftToScrape = 0; 134 135 static void 136 scrapeDoneFunc( struct tr_handle * session UNUSED, 137 long response_code, 138 const void * response, 139 size_t response_byte_count, 140 void * host ) 141 { 142 tr_benc top, *files; 143 144 if( !tr_bencLoad( response, response_byte_count, &top, NULL ) 145 && tr_bencDictFindDict( &top, "files", &files ) 146 && files->val.l.count >= 2 ) 147 { 148 int64_t complete=-1, incomplete=-1, downloaded=-1; 149 tr_benc * hash = &files->val.l.vals[1]; 150 tr_bencDictFindInt( hash, "complete", &complete ); 151 tr_bencDictFindInt( hash, "incomplete", &incomplete ); 152 tr_bencDictFindInt( hash, "downloaded", &downloaded ); 153 printf( "%4d seeders, %4d leechers, %5d downloads at %s\n", 154 (int)complete, (int)incomplete, (int)downloaded, (char*)host ); 155 tr_bencFree( &top ); 156 } 157 else 158 printf( "unable to parse response (http code %lu) at %s", response_code, (char*)host ); 159 160 --leftToScrape; 110 161 } 111 162 … … 184 235 ctor = tr_ctorNew( h ); 185 236 tr_ctorSetMetainfoFromFile( ctor, torrentPath ); 186 tr_ctorSetPaused( ctor, TR_FORCE, 0);237 tr_ctorSetPaused( ctor, TR_FORCE, showScrape ); 187 238 tr_ctorSetDestination( ctor, TR_FORCE, savePath ); 239 240 if( showScrape ) 241 { 242 tr_info info; 243 244 if( !tr_torrentParse( h, ctor, &info ) ) 245 { 246 int i; 247 const time_t start = time( NULL ); 248 for( i=0; i<info.trackerCount; ++i ) 249 { 250 if( info.trackers[i].scrape ) 251 { 252 const char * scrape = info.trackers[i].scrape; 253 char escaped[SHA_DIGEST_LENGTH*3 + 1]; 254 char url[2048], *host; 255 escape( escaped, info.hash, SHA_DIGEST_LENGTH ); 256 snprintf( url, sizeof(url), "%s%cinfo_hash=%s", 257 scrape, 258 strchr(scrape,'?')?'&':'?', 259 escaped ); 260 tr_httpParseURL( scrape, -1, &host, NULL, NULL ); 261 ++leftToScrape; 262 tr_webRun( h, url, scrapeDoneFunc, host ); 263 } 264 } 265 266 fprintf( stderr, "scraping %d trackers:\n", leftToScrape ); 267 268 while( leftToScrape>0 && ((time(NULL)-start)<20) ) 269 tr_wait( 250 ); 270 } 271 goto cleanup; 272 } 273 188 274 189 275 if( showInfo ) … … 241 327 tr_close( h ); 242 328 return EXIT_FAILURE; 243 }244 245 if( showScrape )246 {247 const struct tr_stat * stats;248 const uint64_t start = tr_date( );249 printf( "Scraping, Please wait...\n" );250 251 do252 {253 stats = tr_torrentStat( tor );254 if( !stats || tr_date() - start > 20000 )255 {256 printf( "Scrape failed.\n" );257 goto cleanup;258 }259 tr_wait( 2000 );260 }261 while( stats->completedFromTracker == -1 || stats->leechers == -1 || stats->seeders == -1 );262 263 printf( "%d seeder(s), %d leecher(s), %d download(s).\n",264 stats->seeders, stats->leechers, stats->completedFromTracker );265 266 goto cleanup;267 329 } 268 330
Note: See TracChangeset
for help on using the changeset viewer.