Mercurial > mplayer.hg
changeset 7293:0d7942100437
- 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()
author | arpi |
---|---|
date | Fri, 06 Sep 2002 00:03:16 +0000 |
parents | 85b678250de4 |
children | 962b10b0f36c |
files | libmpdemux/http.c |
diffstat | 1 files changed, 8 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- 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;