зеркало из https://github.com/mozilla/gecko-dev.git
Improve proxy exception parsing on Mac OS X and Windows. b=470207 sr=roc
This commit is contained in:
Родитель
02c46cf7f7
Коммит
7cba0da805
|
@ -22,10 +22,11 @@
|
||||||
* the Initial Developer. All Rights Reserved.
|
* the Initial Developer. All Rights Reserved.
|
||||||
*
|
*
|
||||||
* Contributor(s):
|
* Contributor(s):
|
||||||
* James Bunton (jamesbunton@fastmail.fm)
|
* James Bunton <jamesbunton@fastmail.fm>
|
||||||
* Diane Trout (diane@ghic.org)
|
* Diane Trout <diane@ghic.org>
|
||||||
* Robert O'Callahan (rocallahan@novell.com)
|
* Robert O'Callahan <rocallahan@novell.com>
|
||||||
* Håkan Waara (hwaara@gmail.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
|
* 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
|
* 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);
|
nsresult FindSCProxyPort(nsIURI* aURI, nsACString& aResultHost, PRInt32& aResultPort);
|
||||||
|
|
||||||
// is host:port on the proxy exception list?
|
// is host:port on the proxy exception list?
|
||||||
PRBool IsInExceptionList(const nsACString& aHost, PRInt32 aPort) const;
|
PRBool IsInExceptionList(const nsACString& aHost) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
~nsOSXSystemProxySettings();
|
~nsOSXSystemProxySettings();
|
||||||
|
@ -261,48 +262,49 @@ nsOSXSystemProxySettings::GetAutoconfigURL(nsCAutoString& aResult) const
|
||||||
}
|
}
|
||||||
|
|
||||||
static PRBool
|
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;
|
PRInt32 overrideLength = override.Length();
|
||||||
nsReadingIterator<char> colon;
|
PRInt32 tokenStart = 0;
|
||||||
nsReadingIterator<char> end;
|
PRInt32 offset = 0;
|
||||||
|
PRBool star = PR_FALSE;
|
||||||
|
|
||||||
proxyEntry.BeginReading(start);
|
while (tokenStart < overrideLength) {
|
||||||
proxyEntry.EndReading(end);
|
PRInt32 tokenEnd = override.FindChar('*', tokenStart);
|
||||||
colon = start;
|
if (tokenEnd == tokenStart) {
|
||||||
PRInt32 port = -1;
|
// Star is the first character in the token.
|
||||||
|
star = PR_TRUE;
|
||||||
if (FindCharInReadable(':', colon, end)) {
|
tokenStart++;
|
||||||
++colon;
|
// If the character following the '*' is a '.' character then skip
|
||||||
nsDependentCSubstring portStr(colon, end);
|
// it so that "*.foo.com" allows "foo.com".
|
||||||
nsCAutoString portStr2(portStr);
|
if (override.FindChar('.', tokenStart) == tokenStart)
|
||||||
PRInt32 err;
|
tokenStart++;
|
||||||
port = portStr2.ToInteger(&err);
|
} else {
|
||||||
if (err != 0) {
|
if (tokenEnd == -1)
|
||||||
port = -2; // don't match any port, so we ignore this pattern
|
tokenEnd = overrideLength; // no '*' char, match rest of string
|
||||||
}
|
nsCAutoString token(Substring(override, tokenStart, tokenEnd - tokenStart));
|
||||||
--colon;
|
offset = host.Find(token, offset);
|
||||||
} else {
|
if (offset == -1 || (!star && offset))
|
||||||
colon = end;
|
return PR_FALSE;
|
||||||
}
|
star = PR_FALSE;
|
||||||
|
tokenStart = tokenEnd;
|
||||||
if (port == -1 || port == aPort) {
|
offset += token.Length();
|
||||||
nsDependentCSubstring hostStr(start, colon);
|
|
||||||
if (StringEndsWith(aHost, hostStr, nsCaseInsensitiveCStringComparator())) {
|
|
||||||
return PR_TRUE;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(PR_FALSE);
|
return (star || (offset == static_cast<PRInt32>(host.Length())));
|
||||||
}
|
}
|
||||||
|
|
||||||
PRBool
|
PRBool
|
||||||
nsOSXSystemProxySettings::IsInExceptionList(const nsACString& aHost,
|
nsOSXSystemProxySettings::IsInExceptionList(const nsACString& aHost) const
|
||||||
PRInt32 aPort) const
|
|
||||||
{
|
{
|
||||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
|
||||||
|
|
||||||
|
@ -315,14 +317,14 @@ nsOSXSystemProxySettings::IsInExceptionList(const nsACString& aHost,
|
||||||
NSString* currentValue = NULL;
|
NSString* currentValue = NULL;
|
||||||
while ((currentValue = [exceptionEnumerator nextObject])) {
|
while ((currentValue = [exceptionEnumerator nextObject])) {
|
||||||
NS_ENSURE_TRUE([currentValue isKindOfClass:[NSString class]], PR_FALSE);
|
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;
|
return PR_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(PR_FALSE);
|
NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(PR_FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
nsresult
|
nsresult
|
||||||
nsOSXSystemProxySettings::GetPACURI(nsACString& aResult)
|
nsOSXSystemProxySettings::GetPACURI(nsACString& aResult)
|
||||||
{
|
{
|
||||||
|
@ -350,15 +352,11 @@ nsOSXSystemProxySettings::GetProxyForURI(nsIURI* aURI, nsACString& aResult)
|
||||||
nsresult rv = aURI->GetHost(host);
|
nsresult rv = aURI->GetHost(host);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
PRInt32 port;
|
|
||||||
rv = aURI->GetPort(&port);
|
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
|
||||||
|
|
||||||
PRInt32 proxyPort;
|
PRInt32 proxyPort;
|
||||||
nsCAutoString proxyHost;
|
nsCAutoString proxyHost;
|
||||||
rv = FindSCProxyPort(aURI, proxyHost, proxyPort);
|
rv = FindSCProxyPort(aURI, proxyHost, proxyPort);
|
||||||
|
|
||||||
if (NS_FAILED(rv) || IsInExceptionList(host, port)) {
|
if (NS_FAILED(rv) || IsInExceptionList(host)) {
|
||||||
aResult.AssignLiteral("DIRECT");
|
aResult.AssignLiteral("DIRECT");
|
||||||
} else {
|
} else {
|
||||||
aResult.Assign(NS_LITERAL_CSTRING("PROXY ") + proxyHost + nsPrintfCString(":%d", proxyPort));
|
aResult.Assign(NS_LITERAL_CSTRING("PROXY ") + proxyHost + nsPrintfCString(":%d", proxyPort));
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
* the Initial Developer. All Rights Reserved.
|
* the Initial Developer. All Rights Reserved.
|
||||||
*
|
*
|
||||||
* Contributor(s):
|
* 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
|
* 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
|
* 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) {
|
if (tokenEnd == tokenStart) {
|
||||||
star = PR_TRUE;
|
star = PR_TRUE;
|
||||||
tokenStart++;
|
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 {
|
} else {
|
||||||
if (tokenEnd == -1)
|
if (tokenEnd == -1)
|
||||||
tokenEnd = overrideLength;
|
tokenEnd = overrideLength;
|
||||||
|
@ -231,10 +235,6 @@ nsWindowsSystemProxySettings::GetProxyForURI(nsIURI* aURI, nsACString& aResult)
|
||||||
rv = aURI->GetHost(host);
|
rv = aURI->GetHost(host);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
PRInt32 port;
|
|
||||||
rv = aURI->GetPort(&port);
|
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
|
||||||
|
|
||||||
if (MatchOverride(host)) {
|
if (MatchOverride(host)) {
|
||||||
SetProxyResultDirect(aResult);
|
SetProxyResultDirect(aResult);
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
|
|
Загрузка…
Ссылка в новой задаче