[Mplayer-cvslog] CVS: main/libmpdemux http.c,1.5,1.6
Bertrand Baudet
bertrand at mplayer.dev.hu
Sat Dec 15 00:51:00 CET 2001
Update of /cvsroot/mplayer/main/libmpdemux
In directory mplayer:/var/tmp.root/cvs-serv12036
Modified Files:
http.c
Log Message:
Made the HTTP request escaped the url.
This now allow for example the spaces in the URL.
Index: http.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/http.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- http.c 20 Nov 2001 22:14:16 -0000 1.5
+++ http.c 14 Dec 2001 23:50:57 -0000 1.6
@@ -172,47 +172,66 @@
char *
http_build_request( HTTP_header_t *http_hdr ) {
- char *ptr;
+ char *ptr, *uri=NULL;
int len;
HTTP_field_t *field;
if( http_hdr==NULL ) return NULL;
if( http_hdr->method==NULL ) http_set_method( http_hdr, "GET");
if( http_hdr->uri==NULL ) http_set_uri( http_hdr, "/");
+ else {
+ uri = (char*)malloc(strlen(http_hdr->uri)*2);
+ if( uri==NULL ) {
+ printf("Memory allocation failed\n");
+ return NULL;
+ }
+ url_escape_string( uri, http_hdr->uri );
+ }
- // Compute the request length
- len = strlen(http_hdr->method)+strlen(http_hdr->uri)+12; // Method line
- field = http_hdr->first_field; // Fields
+ //**** Compute the request length
+ // Add the Method line
+ len = strlen(http_hdr->method)+strlen(uri)+12;
+ // Add the fields
+ field = http_hdr->first_field;
while( field!=NULL ) {
len += strlen(field->field_name)+2;
field = field->next;
}
- len += 2; // CRLF
+ // Add the CRLF
+ len += 2;
+ // Add the body
if( http_hdr->body!=NULL ) {
len += http_hdr->body_size;
}
+ // Free the buffer if it was previously used
if( http_hdr->buffer!=NULL ) {
free( http_hdr->buffer );
http_hdr->buffer = NULL;
}
- http_hdr->buffer = (char*)malloc(len);
+ http_hdr->buffer = (char*)malloc(len+1);
if( http_hdr->buffer==NULL ) {
printf("Memory allocation failed\n");
return NULL;
}
http_hdr->buffer_size = len;
+ //*** Building the request
ptr = http_hdr->buffer;
- ptr += sprintf( ptr, "%s %s HTTP/1.%d\r\n", http_hdr->method, http_hdr->uri, http_hdr->http_minor_version );
+ // Add the method line
+ ptr += sprintf( ptr, "%s %s HTTP/1.%d\r\n", http_hdr->method, uri, http_hdr->http_minor_version );
field = http_hdr->first_field;
+ // Add the field
while( field!=NULL ) {
ptr += sprintf( ptr, "%s\r\n", field->field_name );
field = field->next;
}
ptr += sprintf( ptr, "\r\n" );
+ // Add the body
if( http_hdr->body!=NULL ) {
memcpy( ptr, http_hdr->body, http_hdr->body_size );
}
+
+ if( uri ) free( uri );
return http_hdr->buffer;
}
More information about the MPlayer-cvslog
mailing list