diff options
Diffstat (limited to 'ot_http.c')
-rw-r--r-- | ot_http.c | 35 |
1 files changed, 18 insertions, 17 deletions
@@ -28,10 +28,6 @@ | |||
28 | #include "ot_accesslist.h" | 28 | #include "ot_accesslist.h" |
29 | #include "ot_sync.h" | 29 | #include "ot_sync.h" |
30 | 30 | ||
31 | #ifndef WANT_TRACKER_SYNC | ||
32 | #define add_peer_to_torrent(A,B,C) add_peer_to_torrent(A,B) | ||
33 | #endif | ||
34 | |||
35 | #define OT_MAXMULTISCRAPE_COUNT 64 | 31 | #define OT_MAXMULTISCRAPE_COUNT 64 |
36 | static ot_hash multiscrape_buf[OT_MAXMULTISCRAPE_COUNT]; | 32 | static ot_hash multiscrape_buf[OT_MAXMULTISCRAPE_COUNT]; |
37 | extern char *g_redirecturl; | 33 | extern char *g_redirecturl; |
@@ -103,7 +99,7 @@ ssize_t http_issue_error( const int64 client_socket, int code ) { | |||
103 | #ifdef _DEBUG_HTTPERROR | 99 | #ifdef _DEBUG_HTTPERROR |
104 | fprintf( stderr, "DEBUG: invalid request was: %s\n", debug_request ); | 100 | fprintf( stderr, "DEBUG: invalid request was: %s\n", debug_request ); |
105 | #endif | 101 | #endif |
106 | stats_issue_event( EVENT_FAILED, 1, code ); | 102 | stats_issue_event( EVENT_FAILED, FLAG_TCP, code ); |
107 | http_senddata( client_socket, static_outbuf, reply_size); | 103 | http_senddata( client_socket, static_outbuf, reply_size); |
108 | return -2; | 104 | return -2; |
109 | } | 105 | } |
@@ -169,7 +165,7 @@ ssize_t http_sendiovecdata( const int64 client_socket, int iovec_entries, struct | |||
169 | return 0; | 165 | return 0; |
170 | } | 166 | } |
171 | 167 | ||
172 | #ifdef WANT_TRACKER_SYNC | 168 | #ifdef WANT_SYNC_BATCH |
173 | static ssize_t http_handle_sync( const int64 client_socket, char *data ) { | 169 | static ssize_t http_handle_sync( const int64 client_socket, char *data ) { |
174 | struct http_data* h = io_getcookie( client_socket ); | 170 | struct http_data* h = io_getcookie( client_socket ); |
175 | size_t len; | 171 | size_t len; |
@@ -193,7 +189,7 @@ static ssize_t http_handle_sync( const int64 client_socket, char *data ) { | |||
193 | if( ( len = scan_urlencoded_query( &c, data = c, SCAN_SEARCHPATH_VALUE ) ) < 10 ) HTTPERROR_400_PARAM; | 189 | if( ( len = scan_urlencoded_query( &c, data = c, SCAN_SEARCHPATH_VALUE ) ) < 10 ) HTTPERROR_400_PARAM; |
194 | if( add_changeset_to_tracker( (uint8_t*)data, len ) ) HTTPERROR_400_PARAM; | 190 | if( add_changeset_to_tracker( (uint8_t*)data, len ) ) HTTPERROR_400_PARAM; |
195 | if( mode == SYNC_OUT ) { | 191 | if( mode == SYNC_OUT ) { |
196 | stats_issue_event( EVENT_SYNC_IN, 1, 0 ); | 192 | stats_issue_event( EVENT_SYNC_IN, FLAG_TCP, 0 ); |
197 | mode = SYNC_IN; | 193 | mode = SYNC_IN; |
198 | } | 194 | } |
199 | break; | 195 | break; |
@@ -203,7 +199,7 @@ static ssize_t http_handle_sync( const int64 client_socket, char *data ) { | |||
203 | if( mode == SYNC_OUT ) { | 199 | if( mode == SYNC_OUT ) { |
204 | /* Pass this task to the worker thread */ | 200 | /* Pass this task to the worker thread */ |
205 | h->flag |= STRUCT_HTTP_FLAG_WAITINGFORTASK; | 201 | h->flag |= STRUCT_HTTP_FLAG_WAITINGFORTASK; |
206 | stats_issue_event( EVENT_SYNC_OUT_REQUEST, 1, 0 ); | 202 | stats_issue_event( EVENT_SYNC_OUT_REQUEST, FLAG_TCP, 0 ); |
207 | sync_deliver( client_socket ); | 203 | sync_deliver( client_socket ); |
208 | io_dontwantread( client_socket ); | 204 | io_dontwantread( client_socket ); |
209 | return -2; | 205 | return -2; |
@@ -216,7 +212,6 @@ static ssize_t http_handle_sync( const int64 client_socket, char *data ) { | |||
216 | #endif | 212 | #endif |
217 | 213 | ||
218 | static ssize_t http_handle_stats( const int64 client_socket, char *data, char *d, size_t l ) { | 214 | static ssize_t http_handle_stats( const int64 client_socket, char *data, char *d, size_t l ) { |
219 | struct http_data* h = io_getcookie( client_socket ); | ||
220 | char *c = data; | 215 | char *c = data; |
221 | int mode = TASK_STATS_PEERS, scanon = 1, format = 0; | 216 | int mode = TASK_STATS_PEERS, scanon = 1, format = 0; |
222 | 217 | ||
@@ -284,7 +279,11 @@ static ssize_t http_handle_stats( const int64 client_socket, char *data, char *d | |||
284 | } | 279 | } |
285 | } | 280 | } |
286 | 281 | ||
282 | /* Touch variable */ | ||
283 | d=d; | ||
284 | #ifdef WANT_FULLSCRAPE | ||
287 | if( mode == TASK_STATS_TPB ) { | 285 | if( mode == TASK_STATS_TPB ) { |
286 | struct http_data* h = io_getcookie( client_socket ); | ||
288 | tai6464 t; | 287 | tai6464 t; |
289 | #ifdef WANT_COMPRESSION_GZIP | 288 | #ifdef WANT_COMPRESSION_GZIP |
290 | d[l-1] = 0; | 289 | d[l-1] = 0; |
@@ -292,9 +291,6 @@ static ssize_t http_handle_stats( const int64 client_socket, char *data, char *d | |||
292 | h->flag |= STRUCT_HTTP_FLAG_GZIP; | 291 | h->flag |= STRUCT_HTTP_FLAG_GZIP; |
293 | format |= TASK_FLAG_GZIP; | 292 | format |= TASK_FLAG_GZIP; |
294 | } | 293 | } |
295 | #else | ||
296 | /* Touch variable */ | ||
297 | d=d; | ||
298 | #endif | 294 | #endif |
299 | /* Pass this task to the worker thread */ | 295 | /* Pass this task to the worker thread */ |
300 | h->flag |= STRUCT_HTTP_FLAG_WAITINGFORTASK; | 296 | h->flag |= STRUCT_HTTP_FLAG_WAITINGFORTASK; |
@@ -305,12 +301,14 @@ static ssize_t http_handle_stats( const int64 client_socket, char *data, char *d | |||
305 | io_dontwantread( client_socket ); | 301 | io_dontwantread( client_socket ); |
306 | return -2; | 302 | return -2; |
307 | } | 303 | } |
304 | #endif | ||
308 | 305 | ||
309 | /* default format for now */ | 306 | /* default format for now */ |
310 | if( !( l = return_stats_for_tracker( static_outbuf + SUCCESS_HTTP_HEADER_LENGTH, mode, 0 ) ) ) HTTPERROR_500; | 307 | if( !( l = return_stats_for_tracker( static_outbuf + SUCCESS_HTTP_HEADER_LENGTH, mode, 0 ) ) ) HTTPERROR_500; |
311 | return l; | 308 | return l; |
312 | } | 309 | } |
313 | 310 | ||
311 | #ifdef WANT_FULLSCRAPE | ||
314 | static ssize_t http_handle_fullscrape( const int64 client_socket, char *d, size_t l ) { | 312 | static ssize_t http_handle_fullscrape( const int64 client_socket, char *d, size_t l ) { |
315 | struct http_data* h = io_getcookie( client_socket ); | 313 | struct http_data* h = io_getcookie( client_socket ); |
316 | int format = 0; | 314 | int format = 0; |
@@ -341,6 +339,7 @@ write( 2, debug_request, l ); | |||
341 | io_dontwantread( client_socket ); | 339 | io_dontwantread( client_socket ); |
342 | return -2; | 340 | return -2; |
343 | } | 341 | } |
342 | #endif | ||
344 | 343 | ||
345 | static ssize_t http_handle_scrape( const int64 client_socket, char *data ) { | 344 | static ssize_t http_handle_scrape( const int64 client_socket, char *data ) { |
346 | int scanon = 1, numwant = 0; | 345 | int scanon = 1, numwant = 0; |
@@ -387,7 +386,7 @@ UTORRENT1600_WORKAROUND: | |||
387 | 386 | ||
388 | /* Enough for http header + whole scrape string */ | 387 | /* Enough for http header + whole scrape string */ |
389 | if( !( l = return_tcp_scrape_for_torrent( multiscrape_buf, numwant, SUCCESS_HTTP_HEADER_LENGTH + static_outbuf ) ) ) HTTPERROR_500; | 388 | if( !( l = return_tcp_scrape_for_torrent( multiscrape_buf, numwant, SUCCESS_HTTP_HEADER_LENGTH + static_outbuf ) ) ) HTTPERROR_500; |
390 | stats_issue_event( EVENT_SCRAPE, 1, l ); | 389 | stats_issue_event( EVENT_SCRAPE, FLAG_TCP, l ); |
391 | return l; | 390 | return l; |
392 | } | 391 | } |
393 | 392 | ||
@@ -486,12 +485,12 @@ static ssize_t http_handle_announce( const int64 client_socket, char *data ) { | |||
486 | return sprintf( static_outbuf + SUCCESS_HTTP_HEADER_LENGTH, "d14:failure reason81:Your client forgot to send your torrent's info_hash. Please upgrade your client.e" ); | 485 | return sprintf( static_outbuf + SUCCESS_HTTP_HEADER_LENGTH, "d14:failure reason81:Your client forgot to send your torrent's info_hash. Please upgrade your client.e" ); |
487 | 486 | ||
488 | if( OT_FLAG( &peer ) & PEER_FLAG_STOPPED ) | 487 | if( OT_FLAG( &peer ) & PEER_FLAG_STOPPED ) |
489 | len = remove_peer_from_torrent( hash, &peer, SUCCESS_HTTP_HEADER_LENGTH + static_outbuf, 1 ); | 488 | len = remove_peer_from_torrent( hash, &peer, SUCCESS_HTTP_HEADER_LENGTH + static_outbuf, FLAG_TCP ); |
490 | else { | 489 | else { |
491 | torrent = add_peer_to_torrent( hash, &peer, 0 ); | 490 | torrent = add_peer_to_torrent( hash, &peer WANT_SYNC_PARAM( 0 ) ); |
492 | if( !torrent || !( len = return_peers_for_torrent( hash, numwant, SUCCESS_HTTP_HEADER_LENGTH + static_outbuf, 1 ) ) ) HTTPERROR_500; | 491 | if( !torrent || !( len = return_peers_for_torrent( hash, numwant, SUCCESS_HTTP_HEADER_LENGTH + static_outbuf, 1 ) ) ) HTTPERROR_500; |
493 | } | 492 | } |
494 | stats_issue_event( EVENT_ANNOUNCE, 1, len); | 493 | stats_issue_event( EVENT_ANNOUNCE, FLAG_TCP, len); |
495 | return len; | 494 | return len; |
496 | } | 495 | } |
497 | 496 | ||
@@ -529,14 +528,16 @@ ssize_t http_handle_request( const int64 client_socket, char *data, size_t recv_ | |||
529 | /* This is the hardcore match for announce*/ | 528 | /* This is the hardcore match for announce*/ |
530 | if( ( *data == 'a' ) || ( *data == '?' ) ) | 529 | if( ( *data == 'a' ) || ( *data == '?' ) ) |
531 | reply_size = http_handle_announce( client_socket, c ); | 530 | reply_size = http_handle_announce( client_socket, c ); |
531 | #ifdef WANT_FULLSCRAPE | ||
532 | else if( !byte_diff( data, 12, "scrape HTTP/" ) ) | 532 | else if( !byte_diff( data, 12, "scrape HTTP/" ) ) |
533 | reply_size = http_handle_fullscrape( client_socket, recv_header, recv_length ); | 533 | reply_size = http_handle_fullscrape( client_socket, recv_header, recv_length ); |
534 | #endif | ||
534 | /* This is the hardcore match for scrape */ | 535 | /* This is the hardcore match for scrape */ |
535 | else if( !byte_diff( data, 2, "sc" ) ) | 536 | else if( !byte_diff( data, 2, "sc" ) ) |
536 | reply_size = http_handle_scrape( client_socket, c ); | 537 | reply_size = http_handle_scrape( client_socket, c ); |
537 | /* All the rest is matched the standard way */ | 538 | /* All the rest is matched the standard way */ |
538 | else switch( len ) { | 539 | else switch( len ) { |
539 | #ifdef WANT_TRACKER_SYNC | 540 | #ifdef WANT_SYNC_BATCH |
540 | case 4: /* sync ? */ | 541 | case 4: /* sync ? */ |
541 | if( byte_diff( data, 4, "sync") ) HTTPERROR_404; | 542 | if( byte_diff( data, 4, "sync") ) HTTPERROR_404; |
542 | reply_size = http_handle_sync( client_socket, c ); | 543 | reply_size = http_handle_sync( client_socket, c ); |