From e6edc1ba036f66f07878779d4d7a973c80d30efb Mon Sep 17 00:00:00 2001 From: George Hazan Date: Thu, 7 Feb 2019 13:25:07 +0300 Subject: hopefully last custom UrlDecode implementation removed --- src/mir_core/src/http.cpp | 44 +++++++++++++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/mir_core/src/http.cpp b/src/mir_core/src/http.cpp index 312647405e..64076968ed 100755 --- a/src/mir_core/src/http.cpp +++ b/src/mir_core/src/http.cpp @@ -19,25 +19,47 @@ along with this program. If not, see . ///////////////////////////////////////////////////////////////////////////////////////// -static const char szHexDigits[] = "0123456789ABCDEF"; +static int SingleHexToDecimal(char c) +{ + if (c >= '0' && c <= '9') return c - '0'; + if (c >= 'a' && c <= 'f') return c - 'a' + 10; + if (c >= 'A' && c <= 'F') return c - 'A' + 10; + return -1; +} -MIR_CORE_DLL(CMStringA) mir_urlDecode(const char *szUrl) +MIR_CORE_DLL(char*) mir_urlDecode(char *szUrl) { if (szUrl == nullptr) - return CMStringA(); + return nullptr; - CMStringA ret(szUrl); - ret.Replace("+", " "); + char *d = szUrl; + for (char *s = szUrl; *s; d++, s++) { + if (*s == '%') { + int digit1 = SingleHexToDecimal(s[1]); + if (digit1 != -1) { + int digit2 = SingleHexToDecimal(s[2]); + if (digit2 != -1) { + s += 2; + *d = (char)((digit1 << 4) | digit2); + continue; + } + } + } - for (int i = ret.Find("%", 0); i != -1; i = ret.Find("%", i)) { - int ii; - sscanf(ret.c_str()+i+1, "%2x", &ii); - ret.Delete(i, 3); - ret.Insert(i, ii); + if (*s == '+') + *d = ' '; + else + *d = *s; } - return ret; + *d = 0; + + return szUrl; } +///////////////////////////////////////////////////////////////////////////////////////// + +static const char szHexDigits[] = "0123456789ABCDEF"; + MIR_CORE_DLL(CMStringA) mir_urlEncode(const char *szUrl) { if (szUrl == nullptr) -- cgit v1.2.3