Changeset 84
- Timestamp:
- Feb 4, 2006, 7:27:48 AM (16 years ago)
- Location:
- branches/simple_http_parsing
- Files:
-
- 3 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/simple_http_parsing/libtransmission/tracker.c
r61 r84 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_inf( "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 ) 360 { 390 if( i >= bodylen - 18 ) 391 { 392 if( tc->stopped || 0 < tc->newPort ) 393 { 394 goto nodict; 395 } 361 396 tr_err( "Tracker: no dictionary in answer" ); 362 // printf( "%s\n", tc->buf);397 // printf( "%s\n", body ); 363 398 return; 364 399 } 365 400 366 if( tr_bencLoad( & tc->buf[i], &beAll, NULL ) )401 if( tr_bencLoad( &body[i], &beAll, NULL ) ) 367 402 { 368 403 tr_err( "Tracker: error parsing bencoded data" ); … … 478 513 } 479 514 515 nodict: 480 516 /* Success */ 481 517 tc->started = 0; -
branches/simple_http_parsing/libtransmission/utils.c
r1 r84 62 62 return rand() % sup; 63 63 } 64 65 void * tr_memmem( const void *vbig, size_t big_len, 66 const void *vlittle, size_t little_len ) 67 { 68 const char *big = vbig; 69 const char *little = vlittle; 70 size_t ii, jj; 71 72 if( 0 == big_len || 0 == little_len ) 73 { 74 return NULL; 75 } 76 77 for( ii = 0; ii + little_len <= big_len; ii++ ) 78 { 79 for( jj = 0; jj < little_len; jj++ ) 80 { 81 if( big[ii + jj] != little[jj] ) 82 { 83 break; 84 } 85 } 86 if( jj == little_len ) 87 { 88 return (char*)big + ii; 89 } 90 } 91 92 return NULL; 93 } -
branches/simple_http_parsing/libtransmission/utils.h
r7 r84 33 33 34 34 int tr_rand ( int ); 35 36 void * tr_memmem( const void *, size_t, const void *, size_t ); 35 37 36 38 /***********************************************************************
Note: See TracChangeset
for help on using the changeset viewer.