From 5ba7647062ed142af980f9f06349c1e27d52fd9b Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 18 May 2022 14:56:43 +0300 Subject: Netlib: fix for url parsing --- src/mir_app/src/netlib_http.cpp | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'src/mir_app') diff --git a/src/mir_app/src/netlib_http.cpp b/src/mir_app/src/netlib_http.cpp index 3ab187389b..c0cacadb82 100644 --- a/src/mir_app/src/netlib_http.cpp +++ b/src/mir_app/src/netlib_http.cpp @@ -148,19 +148,17 @@ static char* NetlibHttpFindAuthHeader(NETLIBHTTPREQUEST *nlhrReply, const char * void NetlibConnFromUrl(const char *szUrl, bool secur, NetlibUrl &url) { secur = secur || _strnicmp(szUrl, "https", 5) == 0; + const char* phost = strstr(szUrl, "://"); + url.szHost = phost ? phost + 3 : szUrl; - char* szHost = mir_strdup(phost ? phost + 3 : szUrl); + int idx = url.szHost.Find('/'); + if (idx != -1) + url.szHost.Truncate(idx); - char* ppath = strchr(szHost, '/'); - if (ppath) *ppath = '\0'; - - url.szHost = szHost; - - char* pcolon = strrchr(szHost, ':'); - if (pcolon) { - *pcolon = '\0'; - url.port = strtol(pcolon+1, nullptr, 10); + if ((idx = url.szHost.Find(':') != -1)) { + url.port = strtol(url.szHost.c_str() + idx + 1, nullptr, 10); + url.szHost.Truncate(idx); } else url.port = secur ? 443 : 80; url.flags = (secur ? NLOCF_SSL : 0); -- cgit v1.2.3