[Mplayer-cvslog] CVS: main/libmpdemux http.c,1.14,1.15
Arpi of Ize
arpi at mplayerhq.hu
Fri Sep 6 02:03:20 CEST 2002
Update of /cvsroot/mplayer/main/libmpdemux
In directory mail:/var/tmp.root/cvs-serv3407
Modified Files:
http.c
Log Message:
- 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()
Index: http.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/http.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- http.c 23 Jun 2002 09:16:08 -0000 1.14
+++ http.c 6 Sep 2002 00:03:16 -0000 1.15
@@ -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;
More information about the MPlayer-cvslog
mailing list