From c87eb88b9ed442c1592fb123f977b03629b96605 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Fri, 10 Nov 2006 23:47:48 +0000 Subject: 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 --- src/input/http_helper.c | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'src') 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("/"); -- cgit v1.2.3