summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2022-05-18 14:56:43 +0300
committerGeorge Hazan <ghazan@miranda.im>2022-05-18 14:56:43 +0300
commit5ba7647062ed142af980f9f06349c1e27d52fd9b (patch)
tree9c1a1a4490e9a634b2293af96de893aefa0a72b9 /src
parentd43af44272d2ea256d60fb7169b8b33fbb602089 (diff)
Netlib: fix for url parsing
Diffstat (limited to 'src')
-rw-r--r--src/mir_app/src/netlib_http.cpp18
1 files changed, 8 insertions, 10 deletions
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);