Changeset 44 for branches/oneport/libtransmission/tracker.c
- Timestamp:
- Jan 24, 2006, 2:57:03 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/oneport/libtransmission/tracker.c
r42 r44 311 311 benc_val_t beAll; 312 312 benc_val_t * bePeers, * beFoo; 313 uint8_t * body; 314 int bodylen; 313 315 314 316 if( tc->pos == tc->size ) … … 339 341 tc->dateTry = tr_date(); 340 342 341 if( tc->pos < 1 ) 342 { 343 /* We got nothing */ 343 if( tc->pos < 12 || ( 0 != memcmp( tc->buf, "HTTP/1.0 ", 9 ) && 344 0 != memcmp( tc->buf, "HTTP/1.1 ", 9 ) ) ) 345 { 346 /* We don't have a complete HTTP status line */ 347 tr_err( "Tracker: incomplete HTTP status line" ); 344 348 return; 345 349 } 346 350 351 if( '2' != tc->buf[9] ) 352 { 353 /* we didn't get a 2xx status code */ 354 tr_err( "Tracker: invalid HTTP status code: %c%c%c", 355 tc->buf[9], tc->buf[10], tc->buf[11] ); 356 return; 357 } 358 359 /* find the end of the http headers */ 360 body = tr_memmem( tc->buf, tc->pos, "\015\012\015\012", 4 ); 361 if( NULL != body ) 362 { 363 body += 4; 364 } 365 /* hooray for trackers that violate the HTTP spec */ 366 else if( NULL != ( body = tr_memmem( tc->buf, tc->pos, "\015\015", 2 ) ) || 367 NULL != ( body = tr_memmem( tc->buf, tc->pos, "\012\012", 2 ) ) ) 368 { 369 body += 2; 370 } 371 else 372 { 373 tr_err( "Tracker: could not find end of HTTP headers" ); 374 return; 375 } 376 bodylen = tc->pos - (body - tc->buf); 377 347 378 /* Find the beginning of the dictionary */ 348 for( i = 0; i < tc->pos- 18; i++ )379 for( i = 0; i < bodylen - 18; i++ ) 349 380 { 350 381 /* Hem */ 351 if( !memcmp( & tc->buf[i], "d8:interval", 11 ) ||352 !memcmp( & tc->buf[i], "d8:complete", 11 ) ||353 !memcmp( & tc->buf[i], "d14:failure reason", 18 ) )382 if( !memcmp( &body[i], "d8:interval", 11 ) || 383 !memcmp( &body[i], "d8:complete", 11 ) || 384 !memcmp( &body[i], "d14:failure reason", 18 ) ) 354 385 { 355 386 break; … … 357 388 } 358 389 359 if( i >= tc->pos- 18 )390 if( i >= bodylen - 18 ) 360 391 { 361 392 if( tc->stopped || 0 < tc->newPort ) … … 364 395 } 365 396 tr_err( "Tracker: no dictionary in answer" ); 366 // printf( "%s\n", tc->buf);397 // printf( "%s\n", body ); 367 398 return; 368 399 } 369 400 370 if( tr_bencLoad( & tc->buf[i], &beAll, NULL ) )401 if( tr_bencLoad( &body[i], &beAll, NULL ) ) 371 402 { 372 403 tr_err( "Tracker: error parsing bencoded data" );
Note: See TracChangeset
for help on using the changeset viewer.