diff options
Diffstat (limited to 'opentracker.c')
-rw-r--r-- | opentracker.c | 47 |
1 files changed, 38 insertions, 9 deletions
diff --git a/opentracker.c b/opentracker.c index 06be4fa..59b561b 100644 --- a/opentracker.c +++ b/opentracker.c | |||
@@ -284,6 +284,7 @@ static void httpresponse( const int64 s, char *data _DEBUG_HTTPERROR_PARAM( size | |||
284 | ot_torrent *torrent; | 284 | ot_torrent *torrent; |
285 | ot_hash *hash = NULL; | 285 | ot_hash *hash = NULL; |
286 | int numwant, tmp, scanon, mode; | 286 | int numwant, tmp, scanon, mode; |
287 | ot_tasktype format = TASK_FULLSCRAPE; | ||
287 | unsigned short port = htons(6881); | 288 | unsigned short port = htons(6881); |
288 | ssize_t len; | 289 | ssize_t len; |
289 | size_t reply_size = 0, reply_off; | 290 | size_t reply_size = 0, reply_off; |
@@ -359,7 +360,7 @@ LOG_TO_STDERR( "sync: %d.%d.%d.%d\n", h->ip[0], h->ip[1], h->ip[2], h->ip[3] ); | |||
359 | if( !byte_diff( data, 2, "sc" ) ) goto SCRAPE_WORKAROUND; | 360 | if( !byte_diff( data, 2, "sc" ) ) goto SCRAPE_WORKAROUND; |
360 | if( byte_diff(data,5,"stats")) HTTPERROR_404; | 361 | if( byte_diff(data,5,"stats")) HTTPERROR_404; |
361 | scanon = 1; | 362 | scanon = 1; |
362 | mode = STATS_PEERS; | 363 | mode = TASK_STATS_PEERS; |
363 | 364 | ||
364 | while( scanon ) { | 365 | while( scanon ) { |
365 | switch( scan_urlencoded_query( &c, data = c, SCAN_SEARCHPATH_PARAM ) ) { | 366 | switch( scan_urlencoded_query( &c, data = c, SCAN_SEARCHPATH_PARAM ) ) { |
@@ -373,24 +374,52 @@ LOG_TO_STDERR( "sync: %d.%d.%d.%d\n", h->ip[0], h->ip[1], h->ip[2], h->ip[3] ); | |||
373 | } | 374 | } |
374 | if( scan_urlencoded_query( &c, data = c, SCAN_SEARCHPATH_VALUE ) != 4 ) HTTPERROR_400_PARAM; | 375 | if( scan_urlencoded_query( &c, data = c, SCAN_SEARCHPATH_VALUE ) != 4 ) HTTPERROR_400_PARAM; |
375 | if( !byte_diff(data,4,"peer")) | 376 | if( !byte_diff(data,4,"peer")) |
376 | mode = STATS_PEERS; | 377 | mode = TASK_STATS_PEERS; |
377 | else if( !byte_diff(data,4,"conn")) | 378 | else if( !byte_diff(data,4,"conn")) |
378 | mode = STATS_CONNS; | 379 | mode = TASK_STATS_CONNS; |
379 | else if( !byte_diff(data,4,"top5")) | 380 | else if( !byte_diff(data,4,"top5")) |
380 | mode = STATS_TOP5; | 381 | mode = TASK_STATS_TOP5; |
381 | else if( !byte_diff(data,4,"fscr")) | 382 | else if( !byte_diff(data,4,"fscr")) |
382 | mode = STATS_FULLSCRAPE; | 383 | mode = TASK_STATS_FULLSCRAPE; |
383 | else if( !byte_diff(data,4,"tcp4")) | 384 | else if( !byte_diff(data,4,"tcp4")) |
384 | mode = STATS_TCP; | 385 | mode = TASK_STATS_TCP; |
385 | else if( !byte_diff(data,4,"udp4")) | 386 | else if( !byte_diff(data,4,"udp4")) |
386 | mode = STATS_UDP; | 387 | mode = TASK_STATS_UDP; |
387 | else if( !byte_diff(data,4,"s24s")) | 388 | else if( !byte_diff(data,4,"s24s")) |
388 | mode = STATS_SLASH24S; | 389 | mode = TASK_STATS_SLASH24S; |
390 | else if( !byte_diff(data,4,"tpbs")) | ||
391 | mode = TASK_STATS_TPB; | ||
389 | else | 392 | else |
390 | HTTPERROR_400_PARAM; | 393 | HTTPERROR_400_PARAM; |
394 | break; | ||
395 | case 6: | ||
396 | if( byte_diff(data,6,"format")) { | ||
397 | scan_urlencoded_skipvalue( &c ); | ||
398 | continue; | ||
399 | } | ||
400 | if( scan_urlencoded_query( &c, data = c, SCAN_SEARCHPATH_VALUE ) != 3 ) HTTPERROR_400_PARAM; | ||
401 | if( !byte_diff(data,3,"bin")) | ||
402 | format = TASK_FULLSCRAPE_TPB_BINARY; | ||
403 | else if( !byte_diff(data,3,"ben")) | ||
404 | format = TASK_FULLSCRAPE; | ||
405 | else if( !byte_diff(data,3,"url")) | ||
406 | format = TASK_FULLSCRAPE_TPB_URLENCODED; | ||
407 | else if( !byte_diff(data,3,"txt")) | ||
408 | format = TASK_FULLSCRAPE_TPB_ASCII; | ||
409 | else | ||
410 | HTTPERROR_400_PARAM; | ||
411 | break; | ||
391 | } | 412 | } |
392 | } | 413 | } |
393 | 414 | ||
415 | if( mode == TASK_STATS_TPB ) { | ||
416 | /* Pass this task to the worker thread */ | ||
417 | h->flag |= STRUCT_HTTP_FLAG_WAITINGFORTASK; | ||
418 | fullscrape_deliver( s, format ); | ||
419 | io_dontwantread( s ); | ||
420 | return; | ||
421 | } | ||
422 | |||
394 | // default format for now | 423 | // default format for now |
395 | if( !( reply_size = return_stats_for_tracker( static_outbuf + SUCCESS_HTTP_HEADER_LENGTH, mode, 0 ) ) ) HTTPERROR_500; | 424 | if( !( reply_size = return_stats_for_tracker( static_outbuf + SUCCESS_HTTP_HEADER_LENGTH, mode, 0 ) ) ) HTTPERROR_500; |
396 | break; | 425 | break; |
@@ -410,7 +439,7 @@ write( 2, debug_request, l ); | |||
410 | #endif | 439 | #endif |
411 | /* Pass this task to the worker thread */ | 440 | /* Pass this task to the worker thread */ |
412 | h->flag |= STRUCT_HTTP_FLAG_WAITINGFORTASK; | 441 | h->flag |= STRUCT_HTTP_FLAG_WAITINGFORTASK; |
413 | fullscrape_deliver( s ); | 442 | fullscrape_deliver( s, TASK_FULLSCRAPE ); |
414 | io_dontwantread( s ); | 443 | io_dontwantread( s ); |
415 | return; | 444 | return; |
416 | } | 445 | } |