aboutsummaryrefslogtreecommitdiffhomepage
path: root/libmpdemux
diff options
context:
space:
mode:
authorGravatar arpi <arpi@b3059339-0415-0410-9bf9-f77b7e298cf2>2002-09-06 00:03:16 +0000
committerGravatar arpi <arpi@b3059339-0415-0410-9bf9-f77b7e298cf2>2002-09-06 00:03:16 +0000
commit9954e006ae38051b7dc37bc09ce0c80c9d271bb0 (patch)
treee970ab4441f12df38d24964fb8b794f20ef24e15 /libmpdemux
parent5f051af97e6a5a024be55d449c4f0730f19cfce7 (diff)
- 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() git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@7294 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'libmpdemux')
-rw-r--r--libmpdemux/http.c24
1 files changed, 8 insertions, 16 deletions
diff --git a/libmpdemux/http.c b/libmpdemux/http.c
index 639023ae62..4d6491644f 100644
--- a/libmpdemux/http.c
+++ b/libmpdemux/http.c
@@ -45,32 +45,24 @@ http_free( HTTP_header_t *http_hdr ) {
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;