# HG changeset patch # User arpi # Date 1031270596 0 # Node ID 0d794210043762c0fa9d4da9165f9264f183bd8c # Parent 85b678250de44786d3326213691eae8b8a3e2761 - simpler http_response_append (uses realloc()) - http_response_append addes extra 0 byte to close teh string (some functions like http_is_header_entire() use standard string functions like strstr which requires trailing zero) - check for NULL string in http_is_header_entire() diff -r 85b678250de4 -r 0d7942100437 libmpdemux/http.c --- a/libmpdemux/http.c Thu Sep 05 23:25:00 2002 +0000 +++ b/libmpdemux/http.c Fri Sep 06 00:03:16 2002 +0000 @@ -45,32 +45,24 @@ int http_response_append( HTTP_header_t *http_hdr, char *response, int length ) { - char *ptr = NULL; + char *ptr; if( http_hdr==NULL || response==NULL || length<0 ) return -1; - ptr = (char*)malloc( http_hdr->buffer_size+length ); + http_hdr->buffer = (char*)realloc( http_hdr->buffer, http_hdr->buffer_size+length+1 ); if( ptr==NULL ) { - mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory allocation failed\n"); + mp_msg(MSGT_NETWORK,MSGL_FATAL,"Memory (re)allocation failed\n"); return -1; } - if( http_hdr->buffer_size==0 ) { - // Buffer empty, copy response into it. - memcpy( ptr, response, length ); - http_hdr->buffer_size = length; - } else { - // Buffer not empty, grow buffer, copy and append the response. - memcpy( ptr, http_hdr->buffer, http_hdr->buffer_size ); - free( http_hdr->buffer ); - memcpy( ptr+http_hdr->buffer_size, response, length ); - http_hdr->buffer_size += length; - } - http_hdr->buffer = ptr; + memcpy( http_hdr->buffer+http_hdr->buffer_size, response, length ); + http_hdr->buffer_size += length; + http_hdr->buffer[http_hdr->buffer_size]=0; // close the string! return http_hdr->buffer_size; } int http_is_header_entire( HTTP_header_t *http_hdr ) { if( http_hdr==NULL ) return -1; - + if( http_hdr->buffer==NULL ) return 0; // empty + if( strstr(http_hdr->buffer, "\r\n\r\n")==NULL && strstr(http_hdr->buffer, "\n\n")==NULL ) return 0; return 1;