summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichał Cichoń <michcic@gmail.com>2017-05-18 18:16:20 +0200
committerMichał Cichoń <michcic@gmail.com>2017-05-18 18:16:20 +0200
commite1eed89e03c0aadbd6c7781ce680768a16be7c03 (patch)
treea0e44a81c7590e6a1d66faec80af4a0ee18e2549
parentaa2d42f83607d7eae63cc7d860b919e60e1defd8 (diff)
downloadpianobar-windows-e1eed89e03c0aadbd6c7781ce680768a16be7c03.tar.gz
pianobar-windows-e1eed89e03c0aadbd6c7781ce680768a16be7c03.tar.bz2
pianobar-windows-e1eed89e03c0aadbd6c7781ce680768a16be7c03.zip
Handle escaped authority url components. pianobar-windows-binaries/#3
Authority username and password now can be escaped to handle special characters.
-rw-r--r--src/http/http.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/http/http.c b/src/http/http.c
index 609317f..4576d04 100644
--- a/src/http/http.c
+++ b/src/http/http.c
@@ -250,6 +250,32 @@ bool HttpSetAutoProxy (http_t http, const char* url) {
return false;
}
+static void HttpUrlDecodeInplace (wchar_t* url)
+{
+ wchar_t* input = url;
+ wchar_t* output = url;
+ size_t size = wcslen (url);
+ while (size > 0) {
+ if (input[0] == '%' && iswxdigit(input[1]) && iswxdigit(input[2])) {
+ wchar_t hex[3];
+ hex[0] = input[1];
+ hex[1] = input[2];
+ hex[2] = 0;
+ *output++ = (wchar_t)(wcstol (hex, NULL, 16));
+ input += 3;
+ size -= 3;
+ }
+ else {
+ *output++ = *input++;
+ --size;
+ }
+ }
+
+ if (output < input) {
+ *output = '\0';
+ }
+}
+
bool HttpSetProxy (http_t http, const char* url) {
URL_COMPONENTS urlComponents;
wchar_t* wideUrl = NULL;
@@ -267,10 +293,12 @@ bool HttpSetProxy (http_t http, const char* url) {
if (urlComponents.lpszUserName && urlComponents.dwUserNameLength > 0) {
wideUsername = wcsdup(urlComponents.lpszUserName);
wideUsername[urlComponents.dwUserNameLength] = 0;
+ HttpUrlDecodeInplace (wideUsername);
}
if (urlComponents.lpszPassword && urlComponents.dwPasswordLength > 0) {
widePassword = wcsdup(urlComponents.lpszPassword);
widePassword[urlComponents.dwPasswordLength] = 0;
+ HttpUrlDecodeInplace (widePassword);
}
}