diff options
author | erdgeist <> | 2006-12-19 18:01:28 +0000 |
---|---|---|
committer | erdgeist <> | 2006-12-19 18:01:28 +0000 |
commit | c87389f92987fac73aabd5798fe10fd44d42cf4e (patch) | |
tree | 549baf2f7a7cf9f6efab289aaeeae06195cf82ec | |
parent | f406961fe0dc2945b2eaeaefac5e9fd7d087fde8 (diff) |
Now every answer goes in one buffer
-rw-r--r-- | opentracker.c | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/opentracker.c b/opentracker.c index 342acf7..0ff0100 100644 --- a/opentracker.c +++ b/opentracker.c | |||
@@ -70,7 +70,6 @@ void httperror(struct http_data* h,const char* title,const char* message) | |||
70 | } | 70 | } |
71 | 71 | ||
72 | // bestimmten http parameter auslesen und adresse zurueckgeben | 72 | // bestimmten http parameter auslesen und adresse zurueckgeben |
73 | |||
74 | const char* http_header(struct http_data* r,const char* h) | 73 | const char* http_header(struct http_data* r,const char* h) |
75 | { | 74 | { |
76 | long i; | 75 | long i; |
@@ -160,10 +159,10 @@ e400: | |||
160 | goto bailout; | 159 | goto bailout; |
161 | } | 160 | } |
162 | 161 | ||
163 | // Enough for whole scrape string | 162 | // Enough for http header + whole scrape string |
164 | reply = malloc( 128 ); | 163 | reply = malloc( 208 ); |
165 | if( reply ) | 164 | if( reply ) |
166 | reply_size = return_scrape_for_torrent( hash, reply ); | 165 | reply_size = return_scrape_for_torrent( hash, 80 + reply ); |
167 | if( !reply || ( reply_size < 0 ) ) { | 166 | if( !reply || ( reply_size < 0 ) ) { |
168 | if( reply ) free( reply ); | 167 | if( reply ) free( reply ); |
169 | goto e500; | 168 | goto e500; |
@@ -252,7 +251,10 @@ e400: | |||
252 | 251 | ||
253 | if( OT_FLAG( &peer ) & PEER_FLAG_STOPPED ) { | 252 | if( OT_FLAG( &peer ) & PEER_FLAG_STOPPED ) { |
254 | remove_peer_from_torrent( hash, &peer ); | 253 | remove_peer_from_torrent( hash, &peer ); |
255 | reply = strdup( "d15:warning message4:Okaye" ); reply_size = 26; | 254 | reply = malloc( 106 ); |
255 | if( !reply ) | ||
256 | goto e500; | ||
257 | MEMMOVE( reply + 80, "d15:warning message4:Okaye", reply_size = 26 ); | ||
256 | } else { | 258 | } else { |
257 | torrent = add_peer_to_torrent( hash, &peer ); | 259 | torrent = add_peer_to_torrent( hash, &peer ); |
258 | if( !torrent ) { | 260 | if( !torrent ) { |
@@ -260,9 +262,9 @@ e500: | |||
260 | httperror(h,"500 Internal Server Error","A server error has occured. Please retry later."); | 262 | httperror(h,"500 Internal Server Error","A server error has occured. Please retry later."); |
261 | goto bailout; | 263 | goto bailout; |
262 | } | 264 | } |
263 | reply = malloc( numwant*6+128 ); // peerlist + seeder, peers and lametta n*6+81 a.t.m. | 265 | reply = malloc( 80+numwant*6+128 ); // http header + peerlist + seeder, peers and lametta 80 + n*6+81 a.t.m. |
264 | if( reply ) | 266 | if( reply ) |
265 | reply_size = return_peers_for_torrent( torrent, numwant, reply ); | 267 | reply_size = return_peers_for_torrent( torrent, numwant, 80 + reply ); |
266 | if( !reply || ( reply_size <= 0 ) ) { | 268 | if( !reply || ( reply_size <= 0 ) ) { |
267 | if( reply ) free( reply ); | 269 | if( reply ) free( reply ); |
268 | goto e500; | 270 | goto e500; |
@@ -272,10 +274,10 @@ e500: | |||
272 | case 11: | 274 | case 11: |
273 | if( byte_diff(data,11,"mrtg_scrape")) | 275 | if( byte_diff(data,11,"mrtg_scrape")) |
274 | goto e404; | 276 | goto e404; |
275 | reply = malloc( 128 ); | 277 | reply = malloc( 256 ); |
276 | { | 278 | { |
277 | unsigned long seconds_elapsed = time( NULL ) - ot_start_time; | 279 | unsigned long seconds_elapsed = time( NULL ) - ot_start_time; |
278 | reply_size = sprintf( reply, "%d\n%d\nUp: %ld seconds (%ld hours)\nPretuned by german engineers, currently handling %li connections per second.", | 280 | reply_size = sprintf( 80+reply, "%d\n%d\nUp: %ld seconds (%ld hours)\nPretuned by german engineers, currently handling %li connections per second.", |
279 | ot_overall_connections, ot_overall_connections, seconds_elapsed, seconds_elapsed / 3600, ot_overall_connections / ( seconds_elapsed ? seconds_elapsed : 1 ) ); | 281 | ot_overall_connections, ot_overall_connections, seconds_elapsed, seconds_elapsed / 3600, ot_overall_connections / ( seconds_elapsed ? seconds_elapsed : 1 ) ); |
280 | } | 282 | } |
281 | break; | 283 | break; |
@@ -285,9 +287,11 @@ e404: | |||
285 | goto bailout; | 287 | goto bailout; |
286 | } | 288 | } |
287 | 289 | ||
288 | c=(char*)malloc(80); | 290 | if( reply && reply_size ) { |
289 | iob_addbuf_free( &h->iob, c, sprintf( c, "HTTP/1.0 200 OK\r\nContent-Type: text/plain\r\nContent-Length: %ld\r\n\r\n", (long)reply_size )); | 291 | MEMMOVE( reply, "HTTP/1.0 200 OK\r\nContent-Type: text/plain\r\nContent-Length: X \r\n\r\n", 80 ); |
290 | if( reply && reply_size ) iob_addbuf_free(&h->iob, reply, reply_size ); | 292 | fmt_ulonglong( reply+59, (long long)reply_size ); |
293 | iob_addbuf_free(&h->iob, reply, 80+reply_size ); | ||
294 | } | ||
291 | 295 | ||
292 | bailout: | 296 | bailout: |
293 | io_dontwantread(s); | 297 | io_dontwantread(s); |