зеркало из https://github.com/mozilla/pjs.git
Respect system-wide SOCKS proxy settings. b=457377 r=josh r=roc
This commit is contained in:
Родитель
4427484d44
Коммит
6a4c27c3b7
|
@ -27,6 +27,7 @@
|
|||
* Robert O'Callahan <rocallahan@novell.com>
|
||||
* Håkan Waara <hwaara@gmail.com>
|
||||
* Josh Aas <josh@mozilla.com>
|
||||
* Andrew Shilliday <andrewshilliday@gmail.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
|
||||
|
@ -54,7 +55,6 @@
|
|||
#include "nsIURI.h"
|
||||
#include "nsObjCExceptions.h"
|
||||
|
||||
|
||||
class nsOSXSystemProxySettings : public nsISystemProxySettings {
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
@ -72,7 +72,7 @@ public:
|
|||
nsresult GetAutoconfigURL(nsCAutoString& aResult) const;
|
||||
|
||||
// Find the SystemConfiguration proxy & port for a given URI
|
||||
nsresult FindSCProxyPort(nsIURI* aURI, nsACString& aResultHost, PRInt32& aResultPort);
|
||||
nsresult FindSCProxyPort(nsIURI* aURI, nsACString& aResultHost, PRInt32& aResultPort, PRBool& aResultSocksProxy);
|
||||
|
||||
// is host:port on the proxy exception list?
|
||||
PRBool IsInExceptionList(const nsACString& aHost) const;
|
||||
|
@ -91,6 +91,7 @@ private:
|
|||
CFStringRef mEnabled;
|
||||
CFStringRef mHost;
|
||||
CFStringRef mPort;
|
||||
PRPackedBool mIsSocksProxy;
|
||||
};
|
||||
static const SchemeMapping gSchemeMappingList[];
|
||||
};
|
||||
|
@ -99,11 +100,11 @@ NS_IMPL_ISUPPORTS1(nsOSXSystemProxySettings, nsISystemProxySettings)
|
|||
|
||||
// Mapping of URI schemes to SystemConfiguration keys
|
||||
const nsOSXSystemProxySettings::SchemeMapping nsOSXSystemProxySettings::gSchemeMappingList[] = {
|
||||
{"http", kSCPropNetProxiesHTTPEnable, kSCPropNetProxiesHTTPProxy, kSCPropNetProxiesHTTPPort},
|
||||
{"https", kSCPropNetProxiesHTTPSEnable, kSCPropNetProxiesHTTPSProxy, kSCPropNetProxiesHTTPSPort},
|
||||
{"ftp", kSCPropNetProxiesFTPEnable, kSCPropNetProxiesFTPProxy, kSCPropNetProxiesFTPPort},
|
||||
{"socks", kSCPropNetProxiesSOCKSEnable, kSCPropNetProxiesSOCKSProxy, kSCPropNetProxiesSOCKSPort},
|
||||
{NULL, NULL, NULL, NULL},
|
||||
{"http", kSCPropNetProxiesHTTPEnable, kSCPropNetProxiesHTTPProxy, kSCPropNetProxiesHTTPPort, PR_FALSE},
|
||||
{"https", kSCPropNetProxiesHTTPSEnable, kSCPropNetProxiesHTTPSProxy, kSCPropNetProxiesHTTPSPort, PR_FALSE},
|
||||
{"ftp", kSCPropNetProxiesFTPEnable, kSCPropNetProxiesFTPProxy, kSCPropNetProxiesFTPPort, PR_FALSE},
|
||||
{"socks", kSCPropNetProxiesSOCKSEnable, kSCPropNetProxiesSOCKSProxy, kSCPropNetProxiesSOCKSPort, PR_TRUE},
|
||||
{NULL, NULL, NULL, NULL, PR_FALSE},
|
||||
};
|
||||
|
||||
static void
|
||||
|
@ -193,25 +194,24 @@ nsOSXSystemProxySettings::ProxyHasChanged()
|
|||
}
|
||||
|
||||
nsresult
|
||||
nsOSXSystemProxySettings::FindSCProxyPort(nsIURI* aURI, nsACString& aResultHost, PRInt32& aResultPort)
|
||||
nsOSXSystemProxySettings::FindSCProxyPort(nsIURI* aURI, nsACString& aResultHost, PRInt32& aResultPort, PRBool& aResultSocksProxy)
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
||||
|
||||
NS_ENSURE_TRUE(mProxyDict != NULL, NS_ERROR_FAILURE);
|
||||
|
||||
for (const SchemeMapping* keys = gSchemeMappingList; keys->mScheme != NULL; ++keys) {
|
||||
// Check for matching scheme
|
||||
// Check for matching scheme (when appropriate)
|
||||
PRBool res;
|
||||
if (NS_FAILED(aURI->SchemeIs(keys->mScheme, &res)) || !res) {
|
||||
if ((NS_FAILED(aURI->SchemeIs(keys->mScheme, &res)) || !res) && !keys->mIsSocksProxy)
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check the proxy is enabled
|
||||
NSNumber* enabled = [mProxyDict objectForKey:(NSString*)keys->mEnabled];
|
||||
NS_ENSURE_TRUE(enabled == NULL || [enabled isKindOfClass:[NSNumber class]], NS_ERROR_FAILURE);
|
||||
if ([enabled intValue] == 0)
|
||||
break;
|
||||
|
||||
continue;
|
||||
|
||||
// Get the proxy host
|
||||
NSString* host = [mProxyDict objectForKey:(NSString*)keys->mHost];
|
||||
if (host == NULL)
|
||||
|
@ -224,6 +224,8 @@ nsOSXSystemProxySettings::FindSCProxyPort(nsIURI* aURI, nsACString& aResultHost,
|
|||
NS_ENSURE_TRUE([port isKindOfClass:[NSNumber class]], NS_ERROR_FAILURE);
|
||||
aResultPort = [port intValue];
|
||||
|
||||
aResultSocksProxy = keys->mIsSocksProxy;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -267,11 +269,6 @@ IsHostProxyEntry(const nsACString& aHost, const nsACString& aOverride)
|
|||
nsCAutoString host(aHost);
|
||||
nsCAutoString override(aOverride);
|
||||
|
||||
/*
|
||||
printf("IsHostProxyEntry\nRequest: %s\nOverride: %s\n",
|
||||
nsPromiseFlatCString(host).get(), nsPromiseFlatCString(override).get());
|
||||
*/
|
||||
|
||||
PRInt32 overrideLength = override.Length();
|
||||
PRInt32 tokenStart = 0;
|
||||
PRInt32 offset = 0;
|
||||
|
@ -354,11 +351,14 @@ nsOSXSystemProxySettings::GetProxyForURI(nsIURI* aURI, nsACString& aResult)
|
|||
|
||||
PRInt32 proxyPort;
|
||||
nsCAutoString proxyHost;
|
||||
rv = FindSCProxyPort(aURI, proxyHost, proxyPort);
|
||||
PRBool proxySocks;
|
||||
rv = FindSCProxyPort(aURI, proxyHost, proxyPort, proxySocks);
|
||||
|
||||
if (NS_FAILED(rv) || IsInExceptionList(host)) {
|
||||
aResult.AssignLiteral("DIRECT");
|
||||
} else {
|
||||
} else if (proxySocks) {
|
||||
aResult.Assign(NS_LITERAL_CSTRING("SOCKS ") + proxyHost + nsPrintfCString(":%d", proxyPort));
|
||||
} else {
|
||||
aResult.Assign(NS_LITERAL_CSTRING("PROXY ") + proxyHost + nsPrintfCString(":%d", proxyPort));
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче