diff options
author | Diego 'Flameeyes' Pettenò <flameeyes@gmail.com> | 2006-11-10 23:47:48 +0000 |
---|---|---|
committer | Diego 'Flameeyes' Pettenò <flameeyes@gmail.com> | 2006-11-10 23:47:48 +0000 |
commit | c87eb88b9ed442c1592fb123f977b03629b96605 (patch) | |
tree | 78e14facaea3e1be107ced8b738df5095a308b24 /src | |
parent | 6d9fb6abf3758a3fa3e904679f723c73fdeaa464 (diff) | |
download | xine-lib-c87eb88b9ed442c1592fb123f977b03629b96605.tar.gz xine-lib-c87eb88b9ed442c1592fb123f977b03629b96605.tar.bz2 |
When parsing the URL, escape characters like spaces and similar in the URI string, so that it can play mp3 files with spaces in the name through HTTP, for instance.
Thanks to Timothy Redaelli for reporting.
CVS patchset: 8369
CVS date: 2006/11/10 23:47:48
Diffstat (limited to 'src')
-rw-r--r-- | src/input/http_helper.c | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/src/input/http_helper.c b/src/input/http_helper.c index a725abc39..9d469a757 100644 --- a/src/input/http_helper.c +++ b/src/input/http_helper.c @@ -19,7 +19,7 @@ * * URL helper functions * - * $Id: http_helper.c,v 1.7 2006/06/20 01:46:41 dgp85 Exp $ + * $Id: http_helper.c,v 1.8 2006/11/10 23:47:48 dgp85 Exp $ */ #ifdef HAVE_CONFIG_H @@ -159,7 +159,35 @@ int _x_parse_url (char *url, char **proto, char** host, int *port, *uri[0] = '/'; strcpy(*uri + 1, start); } else { - *uri = strdup(start); + static const char toescape[] = " %#"; + char *it = start; + unsigned int escapechars = 0; + + while( it && *it ) { + if ( strchr(toescape, *it) != NULL ) + escapechars++; + it++; + } + + if ( escapechars == 0 ) + *uri = strdup(start); + else { + const size_t len = strlen(start); + size_t i; + + *uri = malloc(len + 1 + escapechars*2); + it = *uri; + + for(i = 0; i < len; i++, it++) { + if ( strchr(toescape, start[i]) != NULL ) { + it[0] = '%'; + it[1] = ( (start[i] >> 4) > 9 ) ? 'A' + ((start[i] >> 4)-10) : '0' + (start[i] >> 4); + it[2] = ( (start[i] & 0x0f) > 9 ) ? 'A' + ((start[i] & 0x0f)-10) : '0' + (start[i] & 0x0f); + it += 2; + } else + *it = start[i]; + } + } } } else { *uri = strdup("/"); |