From 13bef3b94dc18578318f917c47716c74db6221a8 Mon Sep 17 00:00:00 2001 From: Nimetu Date: Sat, 14 May 2016 13:47:03 +0300 Subject: [PATCH] Merge with develop --- code/nel/include/nel/gui/group_html.h | 2 +- code/nel/include/nel/gui/url_parser.h | 3 ++- code/nel/src/gui/group_html.cpp | 24 +++++++++-------- code/nel/src/gui/libwww.cpp | 22 +++------------ code/nel/src/gui/url_parser.cpp | 39 +++++++++++++++++++-------- 5 files changed, 47 insertions(+), 43 deletions(-) diff --git a/code/nel/include/nel/gui/group_html.h b/code/nel/include/nel/gui/group_html.h index 635136220..aecf5f855 100644 --- a/code/nel/include/nel/gui/group_html.h +++ b/code/nel/include/nel/gui/group_html.h @@ -39,7 +39,6 @@ namespace NLGUI class CGroupParagraph; extern std::string CurrentCookie; - extern std::string HTTPCurrentDomain; // HTML group /** @@ -376,6 +375,7 @@ namespace NLGUI std::string _URL; // Current URL std::string _DocumentUrl; + std::string _DocumentDomain; // Valid base href was found bool _IgnoreBaseUrlTag; // Fragment from loading url diff --git a/code/nel/include/nel/gui/url_parser.h b/code/nel/include/nel/gui/url_parser.h index b47e67b37..758f1d340 100644 --- a/code/nel/include/nel/gui/url_parser.h +++ b/code/nel/include/nel/gui/url_parser.h @@ -51,7 +51,8 @@ namespace NLGUI public: std::string scheme; - std::string domain; + std::string authority; + std::string host; std::string path; std::string query; std::string hash; diff --git a/code/nel/src/gui/group_html.cpp b/code/nel/src/gui/group_html.cpp index 30dd3ec3f..18aa3e1eb 100644 --- a/code/nel/src/gui/group_html.cpp +++ b/code/nel/src/gui/group_html.cpp @@ -506,7 +506,7 @@ namespace NLGUI } else { - receiveCookies(_CurlWWW->Request, HTTPCurrentDomain, _TrustedDomain); + receiveCookies(_CurlWWW->Request, _DocumentDomain, _TrustedDomain); // redirect, get the location and try browse again // we cant use curl redirection because 'addHTTPGetParams()' must be called on new destination @@ -533,7 +533,7 @@ namespace NLGUI } else { - receiveCookies(_CurlWWW->Request, HTTPCurrentDomain, _TrustedDomain); + receiveCookies(_CurlWWW->Request, _DocumentDomain, _TrustedDomain); _RedirectsRemaining = DEFAULT_RYZOM_REDIRECT_LIMIT; @@ -2548,6 +2548,7 @@ namespace NLGUI _SelectOption = false; _GroupListAdaptor = NULL; _DocumentUrl = ""; + _DocumentDomain = ""; _UrlFragment.clear(); _RefreshUrl.clear(); _NextRefreshTime = 0.0; @@ -4657,9 +4658,12 @@ namespace NLGUI string finalUrl; bool isLocal = lookupLocalFile (finalUrl, _URL.c_str(), true); - // Save new url _URL = finalUrl; + CUrlParser uri (_URL); + _TrustedDomain = isTrustedDomain(uri.host); + _DocumentDomain = uri.host; + // file is probably from bnp (ingame help) if (isLocal) { @@ -4667,8 +4671,6 @@ namespace NLGUI } else { - _TrustedDomain = isTrustedDomain(setCurrentDomain(finalUrl)); - SFormFields formfields; if (_PostNextTime) { @@ -4704,9 +4706,11 @@ namespace NLGUI // Ref the form CForm &form = _Forms[_PostFormId]; - // Save new url _URL = form.Action; - _TrustedDomain = isTrustedDomain(setCurrentDomain(_URL)); + + CUrlParser uri(_URL); + _TrustedDomain = isTrustedDomain(uri.host); + _DocumentDomain = uri.host; for (i=0; i markup for image downloads if (type.find("image/") == 0 && content.size() > 0) { diff --git a/code/nel/src/gui/libwww.cpp b/code/nel/src/gui/libwww.cpp index 800c4d1e3..53cc9e403 100644 --- a/code/nel/src/gui/libwww.cpp +++ b/code/nel/src/gui/libwww.cpp @@ -31,7 +31,6 @@ namespace NLGUI /// store all cookies we receive and resent them depending of the domain static std::map > HTTPCookies; - std::string HTTPCurrentDomain; // The current domain that will be used to get which cookies to send // *************************************************************************** @@ -332,24 +331,6 @@ namespace NLGUI return dst; } - // set current HTTPCurrentDomain for cookie selection, return new domain - const std::string &setCurrentDomain(const std::string &uri) - { - if (uri.find("http://") == 0) - HTTPCurrentDomain = uri.substr(7, uri.find("/", 7) - 7); - else - if (uri.find("https://") == 0) - HTTPCurrentDomain = uri.substr(8, uri.find("/", 8) - 8); - else - if (uri.find("//") == 0) - HTTPCurrentDomain = uri.substr(2, uri.find("/", 2) - 2); - else - if (uri.find("/") != std::string::npos) - HTTPCurrentDomain = uri.substr(0, uri.find("/") - 1); - - return HTTPCurrentDomain; - } - // update HTTPCookies list static void receiveCookie(const char *nsformat, const std::string &domain, bool trusted) { @@ -371,6 +352,9 @@ namespace NLGUI chunks[0] = chunks[0].substr(10); } + // make sure domain is lowercase + chunks[0] = toLower(chunks[0]); + if (chunks[0] != domain && chunks[0] != std::string("." + domain)) { // cookie is for different domain diff --git a/code/nel/src/gui/url_parser.cpp b/code/nel/src/gui/url_parser.cpp index 7369289f2..5db7f6d72 100644 --- a/code/nel/src/gui/url_parser.cpp +++ b/code/nel/src/gui/url_parser.cpp @@ -14,8 +14,7 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . -#include -#include "nel/misc/types_nl.h" +#include "nel/misc/common.h" #include "nel/gui/url_parser.h" using namespace std; @@ -63,15 +62,33 @@ namespace NLGUI } } - // scan for domain + // scan for authority if (uri.substr(0, 2) == "//") { - pos = uri.find("/", 3); - domain = uri.substr(0, pos); + pos = uri.find_first_of("/?", 2); + authority = uri.substr(0, pos); if (pos != npos) uri = uri.substr(pos); else uri.clear(); + + // strip empty port from authority + if (authority.find_last_of(":") == authority.length() - 1) + authority = authority.substr(0, authority.length() - 1); + + // extract host from user:pass@host:port + pos = authority.find("@"); + if (pos != npos) + host = authority.substr(pos + 1); + else + host = authority.substr(2); + + // case-insensitive + host = NLMISC::toLower(host); + + pos = host.find(":"); + if (pos != npos) + host = host.substr(0, pos); } // scan for query @@ -99,11 +116,11 @@ namespace NLGUI scheme = base.scheme; - // if we already have domain, then ignore base path - if (!domain.empty()) + // if we already have authority, then ignore base path + if (!authority.empty()) return; - domain = base.domain; + authority = base.authority; if (path.empty()) { path = base.path; @@ -190,7 +207,7 @@ namespace NLGUI bool CUrlParser::isAbsolute() const { - return !scheme.empty() && !domain.empty(); + return !scheme.empty() && !authority.empty(); } // serialize URL back to string @@ -200,9 +217,9 @@ namespace NLGUI if (!scheme.empty()) result += scheme + ":"; - if (!domain.empty()) + if (!authority.empty()) { - result += domain; + result += authority; } // path already has leading slash