diff options
Diffstat (limited to 'opentracker.c')
| -rw-r--r-- | opentracker.c | 43 |
1 files changed, 37 insertions, 6 deletions
diff --git a/opentracker.c b/opentracker.c index df46f8d..2020b43 100644 --- a/opentracker.c +++ b/opentracker.c | |||
| @@ -71,6 +71,29 @@ int header_complete(struct http_data* r) { | |||
| 71 | return 0; | 71 | return 0; |
| 72 | } | 72 | } |
| 73 | 73 | ||
| 74 | void sendmallocdata( int64 s, struct http_data *h, char * buffer, size_t size ) { | ||
| 75 | tai6464 t; | ||
| 76 | char *header; | ||
| 77 | size_t header_size; | ||
| 78 | |||
| 79 | if( !h ) { free( buffer); return; } | ||
| 80 | array_reset(&h->r); | ||
| 81 | |||
| 82 | header = malloc( SUCCESS_HTTP_HEADER_LENGTH ); | ||
| 83 | if( !header ) { free( buffer ); return; } | ||
| 84 | |||
| 85 | header_size = sprintf( header, "HTTP/1.0 200 OK\r\nContent-Type: text/plain\r\nContent-Length: %zd\r\n\r\n", size ); | ||
| 86 | |||
| 87 | iob_reset( &h->batch ); | ||
| 88 | iob_addbuf_free( &h->batch, header, header_size ); | ||
| 89 | iob_addbuf_free( &h->batch, buffer, size ); | ||
| 90 | |||
| 91 | // writeable sockets just have a tcp timeout | ||
| 92 | taia_uint(&t,0); io_timeout( s, t ); | ||
| 93 | io_dontwantread( s ); | ||
| 94 | io_wantwrite( s ); | ||
| 95 | } | ||
| 96 | |||
| 74 | /* whoever sends data is not interested in its input-array */ | 97 | /* whoever sends data is not interested in its input-array */ |
| 75 | void senddata(int64 s, struct http_data* h, char *buffer, size_t size ) { | 98 | void senddata(int64 s, struct http_data* h, char *buffer, size_t size ) { |
| 76 | size_t written_size; | 99 | size_t written_size; |
| @@ -84,7 +107,6 @@ void senddata(int64 s, struct http_data* h, char *buffer, size_t size ) { | |||
| 84 | #endif | 107 | #endif |
| 85 | free(h); io_close( s ); | 108 | free(h); io_close( s ); |
| 86 | } else { | 109 | } else { |
| 87 | /* here we would take a copy of the buffer and remember it */ | ||
| 88 | char * outbuf = malloc( size - written_size ); | 110 | char * outbuf = malloc( size - written_size ); |
| 89 | tai6464 t; | 111 | tai6464 t; |
| 90 | 112 | ||
| @@ -103,6 +125,8 @@ void senddata(int64 s, struct http_data* h, char *buffer, size_t size ) { | |||
| 103 | 125 | ||
| 104 | // writeable sockets just have a tcp timeout | 126 | // writeable sockets just have a tcp timeout |
| 105 | taia_uint(&t,0); io_timeout( s, t ); | 127 | taia_uint(&t,0); io_timeout( s, t ); |
| 128 | io_dontwantread( s ); | ||
| 129 | io_wantwrite( s ); | ||
| 106 | } | 130 | } |
| 107 | } | 131 | } |
| 108 | 132 | ||
| @@ -221,13 +245,20 @@ e400_param: | |||
| 221 | } | 245 | } |
| 222 | } | 246 | } |
| 223 | 247 | ||
| 224 | /* Scanned whole query string, wo */ | 248 | /* Scanned whole query string, no hash means full scrape... you might want to limit that */ |
| 225 | if( !hash ) | 249 | if( !hash ) { |
| 226 | return httperror(s,h,"400 Invalid Request","This server only serves specific scrapes."); | 250 | char * reply; |
| 251 | |||
| 252 | reply_size = return_fullscrape_for_tracker( &reply ); | ||
| 253 | if( reply_size ) | ||
| 254 | return sendmallocdata( s, h, reply, reply_size ); | ||
| 227 | 255 | ||
| 228 | /* Enough for http header + whole scrape string */ | ||
| 229 | if( ( reply_size = return_scrape_for_torrent( hash, SUCCESS_HTTP_HEADER_LENGTH + static_scratch ) ) <= 0 ) | ||
| 230 | goto e500; | 256 | goto e500; |
| 257 | } else { | ||
| 258 | /* Enough for http header + whole scrape string */ | ||
| 259 | if( ( reply_size = return_scrape_for_torrent( hash, SUCCESS_HTTP_HEADER_LENGTH + static_scratch ) ) <= 0 ) | ||
| 260 | goto e500; | ||
| 261 | } | ||
| 231 | break; | 262 | break; |
| 232 | case 8: | 263 | case 8: |
| 233 | if( byte_diff(data,8,"announce")) | 264 | if( byte_diff(data,8,"announce")) |
