mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Improve proxy exception parsing on Mac OS X and Windows. b=470207 sr=roc
This commit is contained in:
parent
75d85ea612
commit
f18c279e92
@ -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 <jamesbunton@fastmail.fm>
|
||||
* Diane Trout <diane@ghic.org>
|
||||
* Robert O'Callahan <rocallahan@novell.com>
|
||||
* Håkan Waara <hwaara@gmail.com>
|
||||
* Josh Aas <josh@mozilla.com>
|
||||
*
|
||||
* 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<char> start;
|
||||
nsReadingIterator<char> colon;
|
||||
nsReadingIterator<char> 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;
|
||||
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 {
|
||||
colon = end;
|
||||
}
|
||||
|
||||
if (port == -1 || port == aPort) {
|
||||
nsDependentCSubstring hostStr(start, colon);
|
||||
if (StringEndsWith(aHost, hostStr, nsCaseInsensitiveCStringComparator())) {
|
||||
return PR_TRUE;
|
||||
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<PRInt32>(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));
|
||||
|
@ -21,7 +21,7 @@
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Mitchell Field (mitch_1_2@live.com.au)
|
||||
* Mitchell Field <mitch_1_2@live.com.au>
|
||||
*
|
||||
* 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;
|
||||
|
Loading…
Reference in New Issue
Block a user