From 8b26a9a6c98124b86c03e36c218bf959495ffce8 Mon Sep 17 00:00:00 2001 From: bertrand Date: Sun, 16 Dec 2001 07:40:52 +0000 Subject: [PATCH] Handle broken server that doesn't send CRLF but jusr LF. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@3515 b3059339-0415-0410-9bf9-f77b7e298cf2 --- libmpdemux/http.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/libmpdemux/http.c b/libmpdemux/http.c index 563db5f160..589ae73f2e 100644 --- a/libmpdemux/http.c +++ b/libmpdemux/http.c @@ -70,7 +70,9 @@ int http_is_header_entire( HTTP_header_t *http_hdr ) { if( http_hdr==NULL ) return -1; - if( strstr(http_hdr->buffer, "\r\n\r\n")==NULL ) return 0; + if( strstr(http_hdr->buffer, "\r\n\r\n")==NULL ) { + if( strstr(http_hdr->buffer, "\n\n")==NULL ) return 0; + } else return 1; } @@ -111,7 +113,7 @@ http_response_parse( HTTP_header_t *http_hdr ) { hdr_ptr += 4; // Get the reason phrase - ptr = strstr( hdr_ptr, "\r\n" ); + ptr = strstr( hdr_ptr, "\n" ); if( hdr_ptr==NULL ) { printf("Malformed answer. Unable to get the reason phrase.\n"); return -1; @@ -128,18 +130,19 @@ http_response_parse( HTTP_header_t *http_hdr ) { // Set the position of the header separator: \r\n\r\n ptr = strstr( http_hdr->buffer, "\r\n\r\n" ); if( ptr==NULL ) { - printf("Header may be incomplete. No CRLF CRLF found.\n"); - return -1; + ptr = strstr( http_hdr->buffer, "\n\n" ); + if( ptr==NULL ) { + printf("Header may be incomplete. No CRLF CRLF found.\n"); + return -1; + } } pos_hdr_sep = ptr-http_hdr->buffer; - hdr_ptr = strstr( http_hdr->buffer, "\r\n" )+2; + // Point to the first line after the method line. + hdr_ptr = strstr( http_hdr->buffer, "\n" )+1; do { - ptr = strstr( hdr_ptr, "\r\n"); - if( ptr==NULL ) { - printf("No CRLF found\n"); - return -1; - } + ptr = hdr_ptr; + while( *ptr!='\r' && *ptr!='\n' ) ptr++; len = ptr-hdr_ptr; field = (char*)realloc(field, len+1); if( field==NULL ) { @@ -149,7 +152,7 @@ http_response_parse( HTTP_header_t *http_hdr ) { strncpy( field, hdr_ptr, len ); field[len]='\0'; http_set_field( http_hdr, field ); - hdr_ptr = ptr+2; + hdr_ptr = ptr+((*ptr=='\r')?2:1); } while( hdr_ptr<(http_hdr->buffer+pos_hdr_sep) ); if( field!=NULL ) free( field );