diff --git a/toolkit/system/osxproxy/nsOSXSystemProxySettings.mm b/toolkit/system/osxproxy/nsOSXSystemProxySettings.mm index 888008cfc33..9a8abefa0bf 100644 --- a/toolkit/system/osxproxy/nsOSXSystemProxySettings.mm +++ b/toolkit/system/osxproxy/nsOSXSystemProxySettings.mm @@ -22,10 +22,11 @@ * the Initial Developer. All Rights Reserved. * * Contributor(s): - * James Bunton (jamesbunton@fastmail.fm) - * Diane Trout (diane@ghic.org) - * Robert O'Callahan (rocallahan@novell.com) - * Håkan Waara (hwaara@gmail.com) + * James Bunton + * Diane Trout + * Robert O'Callahan + * Håkan Waara + * Josh Aas * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or @@ -74,7 +75,7 @@ public: nsresult FindSCProxyPort(nsIURI* aURI, nsACString& aResultHost, PRInt32& aResultPort); // is host:port on the proxy exception list? - PRBool IsInExceptionList(const nsACString& aHost, PRInt32 aPort) const; + PRBool IsInExceptionList(const nsACString& aHost) const; private: ~nsOSXSystemProxySettings(); @@ -261,48 +262,49 @@ nsOSXSystemProxySettings::GetAutoconfigURL(nsCAutoString& aResult) const } static PRBool -IsHostProxyEntry(const nsACString& aHost, PRInt32 aPort, NSString* aStr) +IsHostProxyEntry(const nsACString& aHost, const nsACString& aOverride) { - NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN; + nsCAutoString host(aHost); + nsCAutoString override(aOverride); - nsCAutoString proxyEntry([aStr UTF8String]); + /* + printf("IsHostProxyEntry\nRequest: %s\nOverride: %s\n", + nsPromiseFlatCString(host).get(), nsPromiseFlatCString(override).get()); + */ - nsReadingIterator start; - nsReadingIterator colon; - nsReadingIterator end; + PRInt32 overrideLength = override.Length(); + PRInt32 tokenStart = 0; + PRInt32 offset = 0; + PRBool star = PR_FALSE; - proxyEntry.BeginReading(start); - proxyEntry.EndReading(end); - colon = start; - PRInt32 port = -1; - - if (FindCharInReadable(':', colon, end)) { - ++colon; - nsDependentCSubstring portStr(colon, end); - nsCAutoString portStr2(portStr); - PRInt32 err; - port = portStr2.ToInteger(&err); - if (err != 0) { - port = -2; // don't match any port, so we ignore this pattern - } - --colon; - } else { - colon = end; - } - - if (port == -1 || port == aPort) { - nsDependentCSubstring hostStr(start, colon); - if (StringEndsWith(aHost, hostStr, nsCaseInsensitiveCStringComparator())) { - return PR_TRUE; + while (tokenStart < overrideLength) { + PRInt32 tokenEnd = override.FindChar('*', tokenStart); + if (tokenEnd == tokenStart) { + // Star is the first character in the token. + star = PR_TRUE; + tokenStart++; + // If the character following the '*' is a '.' character then skip + // it so that "*.foo.com" allows "foo.com". + if (override.FindChar('.', tokenStart) == tokenStart) + tokenStart++; + } else { + if (tokenEnd == -1) + tokenEnd = overrideLength; // no '*' char, match rest of string + nsCAutoString token(Substring(override, tokenStart, tokenEnd - tokenStart)); + offset = host.Find(token, offset); + if (offset == -1 || (!star && offset)) + return PR_FALSE; + star = PR_FALSE; + tokenStart = tokenEnd; + offset += token.Length(); } } - NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(PR_FALSE); + return (star || (offset == static_cast(host.Length()))); } PRBool -nsOSXSystemProxySettings::IsInExceptionList(const nsACString& aHost, - PRInt32 aPort) const +nsOSXSystemProxySettings::IsInExceptionList(const nsACString& aHost) const { NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN; @@ -315,14 +317,14 @@ nsOSXSystemProxySettings::IsInExceptionList(const nsACString& aHost, NSString* currentValue = NULL; while ((currentValue = [exceptionEnumerator nextObject])) { NS_ENSURE_TRUE([currentValue isKindOfClass:[NSString class]], PR_FALSE); - if (IsHostProxyEntry(aHost, aPort, currentValue)) + nsCAutoString overrideStr([currentValue UTF8String]); + if (IsHostProxyEntry(aHost, overrideStr)) return PR_TRUE; } NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(PR_FALSE); } - nsresult nsOSXSystemProxySettings::GetPACURI(nsACString& aResult) { @@ -350,15 +352,11 @@ nsOSXSystemProxySettings::GetProxyForURI(nsIURI* aURI, nsACString& aResult) nsresult rv = aURI->GetHost(host); NS_ENSURE_SUCCESS(rv, rv); - PRInt32 port; - rv = aURI->GetPort(&port); - NS_ENSURE_SUCCESS(rv, rv); - PRInt32 proxyPort; nsCAutoString proxyHost; rv = FindSCProxyPort(aURI, proxyHost, proxyPort); - if (NS_FAILED(rv) || IsInExceptionList(host, port)) { + if (NS_FAILED(rv) || IsInExceptionList(host)) { aResult.AssignLiteral("DIRECT"); } else { aResult.Assign(NS_LITERAL_CSTRING("PROXY ") + proxyHost + nsPrintfCString(":%d", proxyPort)); diff --git a/toolkit/system/windowsproxy/nsWindowsSystemProxySettings.cpp b/toolkit/system/windowsproxy/nsWindowsSystemProxySettings.cpp index 4158a5b33b4..ef53eb76e7e 100644 --- a/toolkit/system/windowsproxy/nsWindowsSystemProxySettings.cpp +++ b/toolkit/system/windowsproxy/nsWindowsSystemProxySettings.cpp @@ -21,7 +21,7 @@ * the Initial Developer. All Rights Reserved. * * Contributor(s): - * Mitchell Field (mitch_1_2@live.com.au) + * Mitchell Field * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or @@ -181,6 +181,10 @@ nsWindowsSystemProxySettings::PatternMatch(const nsACString& aHost, if (tokenEnd == tokenStart) { star = PR_TRUE; tokenStart++; + // If the character following the '*' is a '.' character then skip + // it so that "*.foo.com" allows "foo.com". + if (override.FindChar('.', tokenStart) == tokenStart) + tokenStart++; } else { if (tokenEnd == -1) tokenEnd = overrideLength; @@ -231,10 +235,6 @@ nsWindowsSystemProxySettings::GetProxyForURI(nsIURI* aURI, nsACString& aResult) rv = aURI->GetHost(host); NS_ENSURE_SUCCESS(rv, rv); - PRInt32 port; - rv = aURI->GetPort(&port); - NS_ENSURE_SUCCESS(rv, rv); - if (MatchOverride(host)) { SetProxyResultDirect(aResult); return NS_OK;