summaryrefslogtreecommitdiff
path: root/opentracker.c
diff options
context:
space:
mode:
authorerdgeist <>2007-03-27 12:07:29 +0000
committererdgeist <>2007-03-27 12:07:29 +0000
commitb38104b9862a57271567c3dcb7e004addbe70ffc (patch)
tree1c44255dbd89d50619be75914680e79eb5f17e24 /opentracker.c
parent1d2d3c9d957a9fe5ed81b016af11d434752d92eb (diff)
Added outbound part of sync Proposed format: d4:syncd20:<info_hash>8*N:(xxxxyy)*Nee, therefore had to refactor torrent cleanup now that it will hit all torrents once every OT_POOL_TIMEOUT units.
Diffstat (limited to 'opentracker.c')
-rw-r--r--opentracker.c41
1 files changed, 12 insertions, 29 deletions
diff --git a/opentracker.c b/opentracker.c
index b8c90d2..7be1421 100644
--- a/opentracker.c
+++ b/opentracker.c
@@ -200,31 +200,9 @@ static void httpresponse( const int64 s, char *data ) {
200 switch( scan_urlencoded_query( &c, data = c, SCAN_PATH ) ) { 200 switch( scan_urlencoded_query( &c, data = c, SCAN_PATH ) ) {
201 case 4: /* sync ? */ 201 case 4: /* sync ? */
202 if( byte_diff( data, 4, "sync") ) HTTPERROR_404; 202 if( byte_diff( data, 4, "sync") ) HTTPERROR_404;
203 scanon = 1; 203 if( !( reply_size = return_changeset_for_tracker( &reply ) ) ) HTTPERROR_500;
204
205 while( scanon ) {
206 switch( scan_urlencoded_query( &c, data = c, SCAN_SEARCHPATH_PARAM ) ) {
207 case -2: scanon = 0; break; /* TERMINATOR */
208 case -1: HTTPERROR_400_PARAM; /* PARSE ERROR */
209 case 9:
210 if(byte_diff(data,9,"info_hash")) {
211 scan_urlencoded_query( &c, NULL, SCAN_SEARCHPATH_VALUE );
212 continue;
213 }
214 /* ignore this, when we have less than 20 bytes */
215 if( scan_urlencoded_query( &c, data = c, SCAN_SEARCHPATH_VALUE ) != 20 ) HTTPERROR_400_PARAM;
216 hash = (ot_hash*)data; /* Fall through intended */
217 break;
218 default:
219 scan_urlencoded_query( &c, NULL, SCAN_SEARCHPATH_VALUE );
220 break;
221 }
222 }
223
224 if( !hash ) HTTPERROR_400_PARAM;
225 if( !( reply_size = return_sync_for_torrent( hash, &reply ) ) ) HTTPERROR_500;
226
227 return sendmallocdata( s, reply, reply_size ); 204 return sendmallocdata( s, reply, reply_size );
205
228 case 5: /* stats ? */ 206 case 5: /* stats ? */
229 if( byte_diff(data,5,"stats")) HTTPERROR_404; 207 if( byte_diff(data,5,"stats")) HTTPERROR_404;
230 scanon = 1; 208 scanon = 1;
@@ -523,11 +501,13 @@ static void handle_read( const int64 clientsocket ) {
523 array_catb( &h->request, static_inbuf, l ); 501 array_catb( &h->request, static_inbuf, l );
524 502
525 if( array_failed( &h->request ) ) 503 if( array_failed( &h->request ) )
526 httperror( clientsocket, "500 Server Error", "Request too long."); 504 return httperror( clientsocket, "500 Server Error", "Request too long.");
527 else if( array_bytes( &h->request ) > 8192 ) 505
528 httperror( clientsocket, "500 request too long", "You sent too much headers"); 506 if( array_bytes( &h->request ) > 8192 )
529 else if( memchr( array_start( &h->request ), '\n', array_length( &h->request, 1 ) ) ) 507 return httperror( clientsocket, "500 request too long", "You sent too much headers");
530 httpresponse( clientsocket, array_start( &h->request ) ); 508
509 if( memchr( array_start( &h->request ), '\n', array_length( &h->request, 1 ) ) )
510 return httpresponse( clientsocket, array_start( &h->request ) );
531} 511}
532 512
533static void handle_write( const int64 clientsocket ) { 513static void handle_write( const int64 clientsocket ) {
@@ -701,6 +681,9 @@ static void server_mainloop( ) {
701 taia_now( &next_timeout_check ); 681 taia_now( &next_timeout_check );
702 taia_addsec( &next_timeout_check, &next_timeout_check, OT_CLIENT_TIMEOUT_CHECKINTERVAL); 682 taia_addsec( &next_timeout_check, &next_timeout_check, OT_CLIENT_TIMEOUT_CHECKINTERVAL);
703 } 683 }
684
685 /* See if we need to move our pools */
686 clean_all_torrents();
704 } 687 }
705} 688}
706 689