2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2004-07-02 03:31:47 +04:00
|
|
|
/* vim:set ts=4 sw=4 sts=4 et: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2000-02-14 13:04:56 +03:00
|
|
|
|
2013-12-09 06:52:54 +04:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
2012-06-06 07:18:25 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2011-10-11 09:50:08 +04:00
|
|
|
|
2000-02-14 13:04:56 +03:00
|
|
|
#include "nsProtocolProxyService.h"
|
2005-03-25 06:41:33 +03:00
|
|
|
#include "nsProxyInfo.h"
|
2006-03-30 21:31:15 +04:00
|
|
|
#include "nsIClassInfoImpl.h"
|
2001-04-17 06:34:47 +04:00
|
|
|
#include "nsIIOService.h"
|
2005-03-25 06:41:33 +03:00
|
|
|
#include "nsIObserverService.h"
|
2001-09-13 06:21:05 +04:00
|
|
|
#include "nsIProtocolHandler.h"
|
2005-03-25 06:41:33 +03:00
|
|
|
#include "nsIProtocolProxyCallback.h"
|
2015-01-21 23:13:00 +03:00
|
|
|
#include "nsIChannel.h"
|
2005-04-02 03:31:04 +04:00
|
|
|
#include "nsICancelable.h"
|
2004-07-31 21:39:29 +04:00
|
|
|
#include "nsIDNSService.h"
|
2012-09-15 00:27:46 +04:00
|
|
|
#include "nsPIDNSService.h"
|
2015-03-20 22:27:34 +03:00
|
|
|
#include "nsIScriptSecurityManager.h"
|
2003-07-15 01:36:24 +04:00
|
|
|
#include "nsIPrefService.h"
|
2012-01-17 05:48:29 +04:00
|
|
|
#include "nsIPrefBranch.h"
|
2006-05-10 21:30:15 +04:00
|
|
|
#include "nsThreadUtils.h"
|
2003-07-15 01:36:24 +04:00
|
|
|
#include "nsString.h"
|
2002-09-23 05:31:17 +04:00
|
|
|
#include "nsNetUtil.h"
|
2010-06-22 20:59:57 +04:00
|
|
|
#include "nsNetCID.h"
|
2016-01-09 04:20:50 +03:00
|
|
|
#include "plstr.h"
|
2003-04-11 22:24:55 +04:00
|
|
|
#include "prnetdb.h"
|
2005-03-25 06:41:33 +03:00
|
|
|
#include "nsPACMan.h"
|
2012-09-15 00:27:46 +04:00
|
|
|
#include "nsProxyRelease.h"
|
|
|
|
#include "mozilla/Mutex.h"
|
|
|
|
#include "mozilla/CondVar.h"
|
2013-09-22 07:04:57 +04:00
|
|
|
#include "nsISystemProxySettings.h"
|
2014-09-05 17:29:00 +04:00
|
|
|
#include "nsINetworkLinkService.h"
|
2015-01-21 23:13:00 +03:00
|
|
|
#include "nsIHttpChannelInternal.h"
|
2000-02-14 13:04:56 +03:00
|
|
|
|
2004-07-02 03:31:47 +04:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
2013-08-21 21:21:40 +04:00
|
|
|
namespace mozilla {
|
|
|
|
extern const char kProxyType_HTTP[];
|
2014-04-16 02:16:41 +04:00
|
|
|
extern const char kProxyType_HTTPS[];
|
2013-08-21 21:21:40 +04:00
|
|
|
extern const char kProxyType_SOCKS[];
|
|
|
|
extern const char kProxyType_SOCKS4[];
|
|
|
|
extern const char kProxyType_SOCKS5[];
|
|
|
|
extern const char kProxyType_DIRECT[];
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace mozilla
|
2013-08-21 21:21:40 +04:00
|
|
|
|
2011-10-11 09:50:08 +04:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2015-05-19 21:15:34 +03:00
|
|
|
#include "mozilla/Logging.h"
|
2013-11-21 02:55:44 +04:00
|
|
|
#undef LOG
|
2015-11-03 07:35:29 +03:00
|
|
|
#define LOG(args) MOZ_LOG(net::gProxyLog, mozilla::LogLevel::Debug, args)
|
2004-07-02 03:31:47 +04:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
2006-03-30 21:31:15 +04:00
|
|
|
#define PROXY_PREF_BRANCH "network.proxy"
|
|
|
|
#define PROXY_PREF(x) PROXY_PREF_BRANCH "." x
|
|
|
|
|
|
|
|
#define WPAD_URL "http://wpad/wpad.dat"
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
2005-03-25 06:41:33 +03:00
|
|
|
// This structure is intended to be allocated on the stack
|
|
|
|
struct nsProtocolInfo {
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString scheme;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t flags;
|
|
|
|
int32_t defaultPort;
|
2005-03-25 06:41:33 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
2015-01-21 23:13:00 +03:00
|
|
|
// Return the channel's proxy URI, or if it doesn't exist, the
|
|
|
|
// channel's main URI.
|
|
|
|
static nsresult
|
|
|
|
GetProxyURI(nsIChannel *channel, nsIURI **aOut)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIURI> proxyURI;
|
|
|
|
nsCOMPtr<nsIHttpChannelInternal> httpChannel(do_QueryInterface(channel));
|
|
|
|
if (httpChannel) {
|
|
|
|
rv = httpChannel->GetProxyURI(getter_AddRefs(proxyURI));
|
|
|
|
}
|
|
|
|
if (!proxyURI) {
|
|
|
|
rv = channel->GetURI(getter_AddRefs(proxyURI));
|
|
|
|
}
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
proxyURI.forget(aOut);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2012-09-27 21:29:34 +04:00
|
|
|
// The nsPACManCallback portion of this implementation should be run
|
|
|
|
// on the main thread - so call nsPACMan::AsyncGetProxyForURI() with
|
|
|
|
// a true mainThreadResponse parameter.
|
2015-03-21 19:28:04 +03:00
|
|
|
class nsAsyncResolveRequest final : public nsIRunnable
|
2015-03-27 21:52:19 +03:00
|
|
|
, public nsPACManCallback
|
|
|
|
, public nsICancelable
|
2005-03-25 06:41:33 +03:00
|
|
|
{
|
|
|
|
public:
|
2013-07-19 06:24:13 +04:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2005-03-25 06:41:33 +03:00
|
|
|
|
2015-01-21 23:13:00 +03:00
|
|
|
nsAsyncResolveRequest(nsProtocolProxyService *pps, nsIChannel *channel,
|
2015-03-26 10:11:05 +03:00
|
|
|
uint32_t aAppId, bool aIsInBrowser,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aResolveFlags,
|
2005-03-25 06:41:33 +03:00
|
|
|
nsIProtocolProxyCallback *callback)
|
|
|
|
: mStatus(NS_OK)
|
2011-10-17 18:59:28 +04:00
|
|
|
, mDispatched(false)
|
2012-07-28 05:23:16 +04:00
|
|
|
, mResolveFlags(aResolveFlags)
|
2005-03-25 06:41:33 +03:00
|
|
|
, mPPS(pps)
|
2012-09-15 00:27:46 +04:00
|
|
|
, mXPComPPS(pps)
|
2015-01-21 23:13:00 +03:00
|
|
|
, mChannel(channel)
|
2015-03-26 10:11:05 +03:00
|
|
|
, mAppId(aAppId)
|
|
|
|
, mIsInBrowser(aIsInBrowser)
|
2005-03-25 06:41:33 +03:00
|
|
|
, mCallback(callback)
|
|
|
|
{
|
2005-04-02 03:31:04 +04:00
|
|
|
NS_ASSERTION(mCallback, "null callback");
|
2005-03-25 06:41:33 +03:00
|
|
|
}
|
|
|
|
|
2014-06-24 20:36:44 +04:00
|
|
|
private:
|
2012-09-15 00:27:46 +04:00
|
|
|
~nsAsyncResolveRequest()
|
|
|
|
{
|
|
|
|
if (!NS_IsMainThread()) {
|
|
|
|
// these xpcom pointers might need to be proxied back to the
|
|
|
|
// main thread to delete safely, but if this request had its
|
|
|
|
// callbacks called normally they will all be null and this is a nop
|
|
|
|
|
2016-02-08 13:17:38 +03:00
|
|
|
nsCOMPtr<nsIThread> mainThread;
|
|
|
|
NS_GetMainThread(getter_AddRefs(mainThread));
|
|
|
|
|
2015-01-21 23:13:00 +03:00
|
|
|
if (mChannel) {
|
2016-02-08 13:17:38 +03:00
|
|
|
nsIChannel *forgettable;
|
|
|
|
mChannel.forget(&forgettable);
|
|
|
|
NS_ProxyRelease(mainThread, forgettable, false);
|
2012-09-15 00:27:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mCallback) {
|
2016-02-08 13:17:38 +03:00
|
|
|
nsIProtocolProxyCallback *forgettable;
|
|
|
|
mCallback.forget(&forgettable);
|
|
|
|
NS_ProxyRelease(mainThread, forgettable, false);
|
2012-09-15 00:27:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mProxyInfo) {
|
2016-02-08 13:17:38 +03:00
|
|
|
nsIProxyInfo *forgettable;
|
|
|
|
mProxyInfo.forget(&forgettable);
|
|
|
|
NS_ProxyRelease(mainThread, forgettable, false);
|
2012-09-15 00:27:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mXPComPPS) {
|
2016-02-08 13:17:38 +03:00
|
|
|
nsIProtocolProxyService *forgettable;
|
|
|
|
mXPComPPS.forget(&forgettable);
|
|
|
|
NS_ProxyRelease(mainThread, forgettable, false);
|
2012-09-15 00:27:46 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-24 20:36:44 +04:00
|
|
|
public:
|
2005-03-25 06:41:33 +03:00
|
|
|
void SetResult(nsresult status, nsIProxyInfo *pi)
|
|
|
|
{
|
|
|
|
mStatus = status;
|
|
|
|
mProxyInfo = pi;
|
|
|
|
}
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
NS_IMETHOD Run() override
|
2006-05-10 21:30:15 +04:00
|
|
|
{
|
|
|
|
if (mCallback)
|
|
|
|
DoCallback();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
NS_IMETHOD Cancel(nsresult reason) override
|
2005-03-25 06:41:33 +03:00
|
|
|
{
|
2005-04-02 03:31:04 +04:00
|
|
|
NS_ENSURE_ARG(NS_FAILED(reason));
|
|
|
|
|
|
|
|
// If we've already called DoCallback then, nothing more to do.
|
|
|
|
if (!mCallback)
|
|
|
|
return NS_OK;
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
SetResult(reason, nullptr);
|
2005-04-02 03:31:04 +04:00
|
|
|
return DispatchCallback();
|
2005-03-25 06:41:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult DispatchCallback()
|
|
|
|
{
|
2005-04-02 03:31:04 +04:00
|
|
|
if (mDispatched) // Only need to dispatch once
|
|
|
|
return NS_OK;
|
|
|
|
|
2006-05-10 21:30:15 +04:00
|
|
|
nsresult rv = NS_DispatchToCurrentThread(this);
|
2005-04-02 03:31:04 +04:00
|
|
|
if (NS_FAILED(rv))
|
2006-05-10 21:30:15 +04:00
|
|
|
NS_WARNING("unable to dispatch callback event");
|
2005-04-02 03:31:04 +04:00
|
|
|
else {
|
2011-10-17 18:59:28 +04:00
|
|
|
mDispatched = true;
|
2006-05-10 21:30:15 +04:00
|
|
|
return NS_OK;
|
2005-03-25 06:41:33 +03:00
|
|
|
}
|
2005-04-02 03:31:04 +04:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
mCallback = nullptr; // break possible reference cycle
|
2005-04-02 03:31:04 +04:00
|
|
|
return rv;
|
2005-03-25 06:41:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
// Called asynchronously, so we do not need to post another PLEvent
|
|
|
|
// before calling DoCallback.
|
2012-09-15 00:27:46 +04:00
|
|
|
void OnQueryComplete(nsresult status,
|
|
|
|
const nsCString &pacString,
|
2015-03-21 19:28:04 +03:00
|
|
|
const nsCString &newPACURL) override
|
2005-03-25 06:41:33 +03:00
|
|
|
{
|
2005-04-02 03:31:04 +04:00
|
|
|
// If we've already called DoCallback then, nothing more to do.
|
|
|
|
if (!mCallback)
|
2005-03-25 06:41:33 +03:00
|
|
|
return;
|
|
|
|
|
2005-04-02 03:31:04 +04:00
|
|
|
// Provided we haven't been canceled...
|
|
|
|
if (mStatus == NS_OK) {
|
|
|
|
mStatus = status;
|
|
|
|
mPACString = pacString;
|
2012-09-15 00:27:46 +04:00
|
|
|
mPACURL = newPACURL;
|
2005-04-02 03:31:04 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// In the cancelation case, we may still have another PLEvent in
|
|
|
|
// the queue that wants to call DoCallback. No need to wait for
|
|
|
|
// it, just run the callback now.
|
2005-03-25 06:41:33 +03:00
|
|
|
DoCallback();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DoCallback()
|
|
|
|
{
|
2013-02-12 22:35:04 +04:00
|
|
|
if (mStatus == NS_ERROR_NOT_AVAILABLE && !mProxyInfo) {
|
|
|
|
// If the PAC service is not avail (e.g. failed pac load
|
|
|
|
// or shutdown) then we will be going direct. Make that
|
|
|
|
// mapping now so that any filters are still applied.
|
|
|
|
mPACString = NS_LITERAL_CSTRING("DIRECT;");
|
|
|
|
mStatus = NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-03-25 06:41:33 +03:00
|
|
|
// Generate proxy info from the PAC string if appropriate
|
2012-08-28 00:25:53 +04:00
|
|
|
if (NS_SUCCEEDED(mStatus) && !mProxyInfo && !mPACString.IsEmpty()) {
|
2011-05-13 21:53:27 +04:00
|
|
|
mPPS->ProcessPACString(mPACString, mResolveFlags,
|
|
|
|
getter_AddRefs(mProxyInfo));
|
2015-01-21 23:13:00 +03:00
|
|
|
nsCOMPtr<nsIURI> proxyURI;
|
|
|
|
GetProxyURI(mChannel, getter_AddRefs(proxyURI));
|
2005-03-25 06:41:33 +03:00
|
|
|
|
2012-08-28 00:25:53 +04:00
|
|
|
// Now apply proxy filters
|
2005-03-25 06:41:33 +03:00
|
|
|
nsProtocolInfo info;
|
2015-01-21 23:13:00 +03:00
|
|
|
mStatus = mPPS->GetProtocolInfo(proxyURI, &info);
|
2005-03-25 06:41:33 +03:00
|
|
|
if (NS_SUCCEEDED(mStatus))
|
2015-01-21 23:13:00 +03:00
|
|
|
mPPS->ApplyFilters(mChannel, info, mProxyInfo);
|
2005-03-25 06:41:33 +03:00
|
|
|
else
|
2012-07-30 18:20:58 +04:00
|
|
|
mProxyInfo = nullptr;
|
2012-09-15 00:27:46 +04:00
|
|
|
|
|
|
|
LOG(("pac thread callback %s\n", mPACString.get()));
|
2012-09-15 00:27:46 +04:00
|
|
|
if (NS_SUCCEEDED(mStatus))
|
|
|
|
mPPS->MaybeDisableDNSPrefetch(mProxyInfo);
|
2015-01-21 23:13:00 +03:00
|
|
|
mCallback->OnProxyAvailable(this, mChannel, mProxyInfo, mStatus);
|
2005-03-25 06:41:33 +03:00
|
|
|
}
|
2012-09-15 00:27:46 +04:00
|
|
|
else if (NS_SUCCEEDED(mStatus) && !mPACURL.IsEmpty()) {
|
|
|
|
LOG(("pac thread callback indicates new pac file load\n"));
|
2012-09-15 00:27:46 +04:00
|
|
|
|
2015-01-21 23:13:00 +03:00
|
|
|
nsCOMPtr<nsIURI> proxyURI;
|
|
|
|
GetProxyURI(mChannel, getter_AddRefs(proxyURI));
|
|
|
|
|
2012-09-15 00:27:46 +04:00
|
|
|
// trigger load of new pac url
|
|
|
|
nsresult rv = mPPS->ConfigureFromPAC(mPACURL, false);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
// now that the load is triggered, we can resubmit the query
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsAsyncResolveRequest> newRequest =
|
2015-03-26 10:11:05 +03:00
|
|
|
new nsAsyncResolveRequest(mPPS, mChannel, mAppId,
|
|
|
|
mIsInBrowser, mResolveFlags,
|
|
|
|
mCallback);
|
|
|
|
rv = mPPS->mPACMan->AsyncGetProxyForURI(proxyURI, mAppId,
|
|
|
|
mIsInBrowser,
|
|
|
|
newRequest,
|
|
|
|
true);
|
2012-09-15 00:27:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
2015-01-21 23:13:00 +03:00
|
|
|
mCallback->OnProxyAvailable(this, mChannel, nullptr, rv);
|
2012-09-15 00:27:46 +04:00
|
|
|
|
|
|
|
// do not call onproxyavailable() in SUCCESS case - the newRequest will
|
|
|
|
// take care of that
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
LOG(("pac thread callback did not provide information %X\n", mStatus));
|
2012-09-15 00:27:46 +04:00
|
|
|
if (NS_SUCCEEDED(mStatus))
|
|
|
|
mPPS->MaybeDisableDNSPrefetch(mProxyInfo);
|
2015-01-21 23:13:00 +03:00
|
|
|
mCallback->OnProxyAvailable(this, mChannel, mProxyInfo, mStatus);
|
2012-09-15 00:27:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// We are on the main thread now and don't need these any more so
|
|
|
|
// release them to avoid having to proxy them back to the main thread
|
|
|
|
// in the dtor
|
2012-07-30 18:20:58 +04:00
|
|
|
mCallback = nullptr; // in case the callback holds an owning ref to us
|
2012-09-15 00:27:46 +04:00
|
|
|
mPPS = nullptr;
|
|
|
|
mXPComPPS = nullptr;
|
2015-01-21 23:13:00 +03:00
|
|
|
mChannel = nullptr;
|
2012-09-15 00:27:46 +04:00
|
|
|
mProxyInfo = nullptr;
|
2005-03-25 06:41:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
nsresult mStatus;
|
|
|
|
nsCString mPACString;
|
2012-09-15 00:27:46 +04:00
|
|
|
nsCString mPACURL;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mDispatched;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mResolveFlags;
|
2005-03-25 06:41:33 +03:00
|
|
|
|
2012-09-15 00:27:46 +04:00
|
|
|
nsProtocolProxyService *mPPS;
|
|
|
|
nsCOMPtr<nsIProtocolProxyService> mXPComPPS;
|
2015-01-21 23:13:00 +03:00
|
|
|
nsCOMPtr<nsIChannel> mChannel;
|
2015-03-26 10:11:05 +03:00
|
|
|
uint32_t mAppId;
|
|
|
|
bool mIsInBrowser;
|
2005-03-25 06:41:33 +03:00
|
|
|
nsCOMPtr<nsIProtocolProxyCallback> mCallback;
|
|
|
|
nsCOMPtr<nsIProxyInfo> mProxyInfo;
|
|
|
|
};
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(nsAsyncResolveRequest, nsICancelable, nsIRunnable)
|
2005-03-25 06:41:33 +03:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
2003-04-11 22:24:55 +04:00
|
|
|
#define IS_ASCII_SPACE(_c) ((_c) == ' ' || (_c) == '\t')
|
|
|
|
|
|
|
|
//
|
|
|
|
// apply mask to address (zeros out excluded bits).
|
|
|
|
//
|
|
|
|
// NOTE: we do the byte swapping here to minimize overall swapping.
|
|
|
|
//
|
2003-07-15 01:36:24 +04:00
|
|
|
static void
|
2012-08-22 19:56:38 +04:00
|
|
|
proxy_MaskIPv6Addr(PRIPv6Addr &addr, uint16_t mask_len)
|
2003-04-11 22:24:55 +04:00
|
|
|
{
|
|
|
|
if (mask_len == 128)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (mask_len > 96) {
|
|
|
|
addr.pr_s6_addr32[3] = PR_htonl(
|
|
|
|
PR_ntohl(addr.pr_s6_addr32[3]) & (~0L << (128 - mask_len)));
|
|
|
|
}
|
|
|
|
else if (mask_len > 64) {
|
|
|
|
addr.pr_s6_addr32[3] = 0;
|
|
|
|
addr.pr_s6_addr32[2] = PR_htonl(
|
|
|
|
PR_ntohl(addr.pr_s6_addr32[2]) & (~0L << (96 - mask_len)));
|
|
|
|
}
|
|
|
|
else if (mask_len > 32) {
|
|
|
|
addr.pr_s6_addr32[3] = 0;
|
|
|
|
addr.pr_s6_addr32[2] = 0;
|
|
|
|
addr.pr_s6_addr32[1] = PR_htonl(
|
|
|
|
PR_ntohl(addr.pr_s6_addr32[1]) & (~0L << (64 - mask_len)));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
addr.pr_s6_addr32[3] = 0;
|
|
|
|
addr.pr_s6_addr32[2] = 0;
|
|
|
|
addr.pr_s6_addr32[1] = 0;
|
|
|
|
addr.pr_s6_addr32[0] = PR_htonl(
|
|
|
|
PR_ntohl(addr.pr_s6_addr32[0]) & (~0L << (32 - mask_len)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-07-15 01:36:24 +04:00
|
|
|
static void
|
|
|
|
proxy_GetStringPref(nsIPrefBranch *aPrefBranch,
|
|
|
|
const char *aPref,
|
|
|
|
nsCString &aResult)
|
2000-02-14 13:04:56 +03:00
|
|
|
{
|
2003-07-15 01:36:24 +04:00
|
|
|
nsXPIDLCString temp;
|
|
|
|
nsresult rv = aPrefBranch->GetCharPref(aPref, getter_Copies(temp));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
aResult.Truncate();
|
|
|
|
else {
|
|
|
|
aResult.Assign(temp);
|
|
|
|
// all of our string prefs are hostnames, so we should remove any
|
|
|
|
// whitespace characters that the user might have unknowingly entered.
|
|
|
|
aResult.StripWhitespace();
|
|
|
|
}
|
2000-02-14 13:04:56 +03:00
|
|
|
}
|
|
|
|
|
2003-07-15 01:36:24 +04:00
|
|
|
static void
|
|
|
|
proxy_GetIntPref(nsIPrefBranch *aPrefBranch,
|
|
|
|
const char *aPref,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t &aResult)
|
2003-07-15 01:36:24 +04:00
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t temp;
|
2003-07-15 01:36:24 +04:00
|
|
|
nsresult rv = aPrefBranch->GetIntPref(aPref, &temp);
|
2014-09-05 17:29:00 +04:00
|
|
|
if (NS_FAILED(rv))
|
2003-07-15 01:36:24 +04:00
|
|
|
aResult = -1;
|
|
|
|
else
|
|
|
|
aResult = temp;
|
|
|
|
}
|
2000-02-14 13:04:56 +03:00
|
|
|
|
2004-12-16 05:46:12 +03:00
|
|
|
static void
|
|
|
|
proxy_GetBoolPref(nsIPrefBranch *aPrefBranch,
|
|
|
|
const char *aPref,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool &aResult)
|
2004-12-16 05:46:12 +03:00
|
|
|
{
|
2011-09-29 10:19:26 +04:00
|
|
|
bool temp;
|
2004-12-16 05:46:12 +03:00
|
|
|
nsresult rv = aPrefBranch->GetBoolPref(aPref, &temp);
|
2014-09-05 17:29:00 +04:00
|
|
|
if (NS_FAILED(rv))
|
2011-10-17 18:59:28 +04:00
|
|
|
aResult = false;
|
2004-12-16 05:46:12 +03:00
|
|
|
else
|
|
|
|
aResult = temp;
|
|
|
|
}
|
|
|
|
|
2004-07-02 03:31:47 +04:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
static const int32_t PROXYCONFIG_DIRECT4X = 3;
|
|
|
|
static const int32_t PROXYCONFIG_COUNT = 6;
|
2010-06-17 22:33:42 +04:00
|
|
|
|
2006-03-30 21:31:15 +04:00
|
|
|
NS_IMPL_ADDREF(nsProtocolProxyService)
|
|
|
|
NS_IMPL_RELEASE(nsProtocolProxyService)
|
2013-09-19 23:28:26 +04:00
|
|
|
NS_IMPL_CLASSINFO(nsProtocolProxyService, nullptr, nsIClassInfo::SINGLETON,
|
2010-06-22 20:59:57 +04:00
|
|
|
NS_PROTOCOLPROXYSERVICE_CID)
|
2015-05-20 00:15:53 +03:00
|
|
|
|
|
|
|
// NS_IMPL_QUERY_INTERFACE_CI with the nsProtocolProxyService QI change
|
|
|
|
NS_INTERFACE_MAP_BEGIN(nsProtocolProxyService)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIProtocolProxyService)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIProtocolProxyService2)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIObserver)
|
|
|
|
if ( aIID.Equals(NS_GET_IID(nsProtocolProxyService)) ) foundInterface = static_cast<nsIProtocolProxyService2*>(this); else
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIProtocolProxyService)
|
|
|
|
NS_IMPL_QUERY_CLASSINFO(nsProtocolProxyService)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_CI_INTERFACE_GETTER(nsProtocolProxyService,
|
2006-03-30 21:31:15 +04:00
|
|
|
nsIProtocolProxyService,
|
2014-04-27 11:06:00 +04:00
|
|
|
nsIProtocolProxyService2)
|
2000-02-14 13:04:56 +03:00
|
|
|
|
2002-09-23 05:31:17 +04:00
|
|
|
nsProtocolProxyService::nsProtocolProxyService()
|
2011-10-17 18:59:28 +04:00
|
|
|
: mFilterLocalHosts(false)
|
2012-07-30 18:20:58 +04:00
|
|
|
, mFilters(nullptr)
|
2010-06-17 22:33:42 +04:00
|
|
|
, mProxyConfig(PROXYCONFIG_DIRECT)
|
2002-09-23 05:31:17 +04:00
|
|
|
, mHTTPProxyPort(-1)
|
|
|
|
, mFTPProxyPort(-1)
|
|
|
|
, mHTTPSProxyPort(-1)
|
|
|
|
, mSOCKSProxyPort(-1)
|
|
|
|
, mSOCKSProxyVersion(4)
|
2011-10-17 18:59:28 +04:00
|
|
|
, mSOCKSProxyRemoteDNS(false)
|
2014-05-20 00:29:46 +04:00
|
|
|
, mProxyOverTLS(true)
|
2012-07-30 18:20:58 +04:00
|
|
|
, mPACMan(nullptr)
|
2004-07-02 03:31:47 +04:00
|
|
|
, mSessionStart(PR_Now())
|
|
|
|
, mFailedProxyTimeout(30 * 60) // 30 minute default
|
2000-04-22 04:35:05 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsProtocolProxyService::~nsProtocolProxyService()
|
|
|
|
{
|
2005-03-25 06:41:33 +03:00
|
|
|
// These should have been cleaned up in our Observe method.
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_ASSERTION(mHostFiltersArray.Length() == 0 && mFilters == nullptr &&
|
|
|
|
mPACMan == nullptr, "what happened to xpcom-shutdown?");
|
2000-04-22 04:35:05 +04:00
|
|
|
}
|
|
|
|
|
2000-02-14 13:04:56 +03:00
|
|
|
// nsProtocolProxyService methods
|
2003-04-11 22:24:55 +04:00
|
|
|
nsresult
|
2003-04-16 03:07:12 +04:00
|
|
|
nsProtocolProxyService::Init()
|
|
|
|
{
|
2003-07-15 01:36:24 +04:00
|
|
|
// failure to access prefs is non-fatal
|
2012-01-17 05:48:29 +04:00
|
|
|
nsCOMPtr<nsIPrefBranch> prefBranch =
|
2004-07-02 03:31:47 +04:00
|
|
|
do_GetService(NS_PREFSERVICE_CONTRACTID);
|
2003-07-15 01:36:24 +04:00
|
|
|
if (prefBranch) {
|
|
|
|
// monitor proxy prefs
|
2011-10-17 18:59:28 +04:00
|
|
|
prefBranch->AddObserver(PROXY_PREF_BRANCH, this, false);
|
2003-07-15 01:36:24 +04:00
|
|
|
|
|
|
|
// read all prefs
|
2012-07-30 18:20:58 +04:00
|
|
|
PrefsChanged(prefBranch, nullptr);
|
2002-09-23 05:31:17 +04:00
|
|
|
}
|
2004-07-02 03:31:47 +04:00
|
|
|
|
Bug 560095 - Use mozilla::services::GetObserverService(). r=biesi,dveditz,gavin,josh,jst,mrbkap,roc,sdwilsh,shaver,sicking,smontagu,surkov
2010-04-29 20:59:13 +04:00
|
|
|
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
|
2014-09-05 17:29:00 +04:00
|
|
|
if (obs) {
|
|
|
|
// register for shutdown notification so we can clean ourselves up
|
|
|
|
// properly.
|
2011-10-17 18:59:28 +04:00
|
|
|
obs->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false);
|
2014-09-05 17:29:00 +04:00
|
|
|
obs->AddObserver(this, NS_NETWORK_LINK_TOPIC, false);
|
|
|
|
}
|
|
|
|
|
2003-07-15 01:36:24 +04:00
|
|
|
return NS_OK;
|
2002-09-23 05:31:17 +04:00
|
|
|
}
|
|
|
|
|
2014-09-05 17:29:00 +04:00
|
|
|
// ReloadNetworkPAC() checks if there's a non-networked PAC in use then avoids
|
|
|
|
// to call ReloadPAC()
|
|
|
|
nsresult
|
|
|
|
nsProtocolProxyService::ReloadNetworkPAC()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIPrefBranch> prefs =
|
|
|
|
do_GetService(NS_PREFSERVICE_CONTRACTID);
|
|
|
|
if (!prefs) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t type;
|
|
|
|
nsresult rv = prefs->GetIntPref(PROXY_PREF("type"), &type);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type == PROXYCONFIG_PAC) {
|
|
|
|
nsXPIDLCString pacSpec;
|
|
|
|
prefs->GetCharPref(PROXY_PREF("autoconfig_url"),
|
|
|
|
getter_Copies(pacSpec));
|
|
|
|
if (!pacSpec.IsEmpty()) {
|
|
|
|
nsCOMPtr<nsIURI> pacURI;
|
|
|
|
rv = NS_NewURI(getter_AddRefs(pacURI), pacSpec);
|
|
|
|
if(!NS_SUCCEEDED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsProtocolInfo pac;
|
|
|
|
rv = GetProtocolInfo(pacURI, &pac);
|
|
|
|
if(!NS_SUCCEEDED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!pac.scheme.EqualsLiteral("file") &&
|
|
|
|
!pac.scheme.EqualsLiteral("data")) {
|
|
|
|
LOG((": received network changed event, reload PAC"));
|
|
|
|
ReloadPAC();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if ((type == PROXYCONFIG_WPAD) || (type == PROXYCONFIG_SYSTEM)) {
|
|
|
|
ReloadPAC();
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-07-15 01:36:24 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsProtocolProxyService::Observe(nsISupports *aSubject,
|
|
|
|
const char *aTopic,
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t *aData)
|
2002-09-23 05:31:17 +04:00
|
|
|
{
|
2005-03-25 06:41:33 +03:00
|
|
|
if (strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID) == 0) {
|
|
|
|
// cleanup
|
2009-02-23 04:05:28 +03:00
|
|
|
if (mHostFiltersArray.Length() > 0) {
|
2005-03-25 06:41:33 +03:00
|
|
|
mHostFiltersArray.Clear();
|
|
|
|
}
|
|
|
|
if (mFilters) {
|
|
|
|
delete mFilters;
|
2012-07-30 18:20:58 +04:00
|
|
|
mFilters = nullptr;
|
2005-03-25 06:41:33 +03:00
|
|
|
}
|
|
|
|
if (mPACMan) {
|
|
|
|
mPACMan->Shutdown();
|
2012-07-30 18:20:58 +04:00
|
|
|
mPACMan = nullptr;
|
2005-03-25 06:41:33 +03:00
|
|
|
}
|
2015-05-05 17:04:34 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
|
|
|
|
if (obs) {
|
|
|
|
obs->RemoveObserver(this, NS_NETWORK_LINK_TOPIC);
|
|
|
|
obs->RemoveObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID);
|
|
|
|
}
|
|
|
|
|
2014-09-05 17:29:00 +04:00
|
|
|
} else if (strcmp(aTopic, NS_NETWORK_LINK_TOPIC) == 0) {
|
|
|
|
nsCString converted = NS_ConvertUTF16toUTF8(aData);
|
|
|
|
const char *state = converted.get();
|
|
|
|
if (!strcmp(state, NS_NETWORK_LINK_DATA_CHANGED)) {
|
|
|
|
ReloadNetworkPAC();
|
|
|
|
}
|
2005-03-25 06:41:33 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
NS_ASSERTION(strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID) == 0,
|
|
|
|
"what is this random observer event?");
|
|
|
|
nsCOMPtr<nsIPrefBranch> prefs = do_QueryInterface(aSubject);
|
|
|
|
if (prefs)
|
|
|
|
PrefsChanged(prefs, NS_LossyConvertUTF16toASCII(aData).get());
|
|
|
|
}
|
2003-07-15 01:36:24 +04:00
|
|
|
return NS_OK;
|
2002-09-23 05:31:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2003-07-15 01:36:24 +04:00
|
|
|
nsProtocolProxyService::PrefsChanged(nsIPrefBranch *prefBranch,
|
|
|
|
const char *pref)
|
2002-09-23 05:31:17 +04:00
|
|
|
{
|
2000-02-14 13:04:56 +03:00
|
|
|
nsresult rv = NS_OK;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool reloadPAC = false;
|
2000-04-22 04:35:05 +04:00
|
|
|
nsXPIDLCString tempString;
|
2000-02-14 13:04:56 +03:00
|
|
|
|
2006-03-30 21:31:15 +04:00
|
|
|
if (!pref || !strcmp(pref, PROXY_PREF("type"))) {
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t type = -1;
|
2006-03-30 21:31:15 +04:00
|
|
|
rv = prefBranch->GetIntPref(PROXY_PREF("type"), &type);
|
2001-04-27 03:53:27 +04:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2011-09-07 04:20:35 +04:00
|
|
|
// bug 115720 - for ns4.x backwards compatibility
|
2010-06-17 22:33:42 +04:00
|
|
|
if (type == PROXYCONFIG_DIRECT4X) {
|
|
|
|
type = PROXYCONFIG_DIRECT;
|
2002-01-30 02:15:41 +03:00
|
|
|
// Reset the type so that the dialog looks correct, and we
|
|
|
|
// don't have to handle this case everywhere else
|
|
|
|
// I'm paranoid about a loop of some sort - only do this
|
|
|
|
// if we're enumerating all prefs, and ignore any error
|
|
|
|
if (!pref)
|
2006-03-30 21:31:15 +04:00
|
|
|
prefBranch->SetIntPref(PROXY_PREF("type"), type);
|
2010-06-17 22:33:42 +04:00
|
|
|
} else if (type >= PROXYCONFIG_COUNT) {
|
2005-03-25 06:41:33 +03:00
|
|
|
LOG(("unknown proxy type: %lu; assuming direct\n", type));
|
2010-06-17 22:33:42 +04:00
|
|
|
type = PROXYCONFIG_DIRECT;
|
2002-01-30 02:15:41 +03:00
|
|
|
}
|
2010-06-17 22:33:42 +04:00
|
|
|
mProxyConfig = type;
|
2011-10-17 18:59:28 +04:00
|
|
|
reloadPAC = true;
|
2001-04-27 03:53:27 +04:00
|
|
|
}
|
2008-01-29 21:38:15 +03:00
|
|
|
|
2010-06-17 22:33:42 +04:00
|
|
|
if (mProxyConfig == PROXYCONFIG_SYSTEM) {
|
2008-01-29 21:38:15 +03:00
|
|
|
mSystemProxySettings = do_GetService(NS_SYSTEMPROXYSETTINGS_CONTRACTID);
|
2009-12-03 10:31:55 +03:00
|
|
|
if (!mSystemProxySettings)
|
2010-06-17 22:33:42 +04:00
|
|
|
mProxyConfig = PROXYCONFIG_DIRECT;
|
2012-09-15 00:27:46 +04:00
|
|
|
ResetPACThread();
|
2008-01-29 21:38:15 +03:00
|
|
|
} else {
|
2012-09-15 00:27:46 +04:00
|
|
|
if (mSystemProxySettings) {
|
|
|
|
mSystemProxySettings = nullptr;
|
|
|
|
ResetPACThread();
|
|
|
|
}
|
2008-01-29 21:38:15 +03:00
|
|
|
}
|
2000-02-14 13:04:56 +03:00
|
|
|
}
|
|
|
|
|
2006-03-30 21:31:15 +04:00
|
|
|
if (!pref || !strcmp(pref, PROXY_PREF("http")))
|
|
|
|
proxy_GetStringPref(prefBranch, PROXY_PREF("http"), mHTTPProxyHost);
|
2000-02-14 13:04:56 +03:00
|
|
|
|
2006-03-30 21:31:15 +04:00
|
|
|
if (!pref || !strcmp(pref, PROXY_PREF("http_port")))
|
|
|
|
proxy_GetIntPref(prefBranch, PROXY_PREF("http_port"), mHTTPProxyPort);
|
2000-02-14 13:04:56 +03:00
|
|
|
|
2006-03-30 21:31:15 +04:00
|
|
|
if (!pref || !strcmp(pref, PROXY_PREF("ssl")))
|
|
|
|
proxy_GetStringPref(prefBranch, PROXY_PREF("ssl"), mHTTPSProxyHost);
|
2000-04-22 04:35:05 +04:00
|
|
|
|
2006-03-30 21:31:15 +04:00
|
|
|
if (!pref || !strcmp(pref, PROXY_PREF("ssl_port")))
|
|
|
|
proxy_GetIntPref(prefBranch, PROXY_PREF("ssl_port"), mHTTPSProxyPort);
|
2000-04-22 04:35:05 +04:00
|
|
|
|
2006-03-30 21:31:15 +04:00
|
|
|
if (!pref || !strcmp(pref, PROXY_PREF("ftp")))
|
|
|
|
proxy_GetStringPref(prefBranch, PROXY_PREF("ftp"), mFTPProxyHost);
|
2000-02-14 13:04:56 +03:00
|
|
|
|
2006-03-30 21:31:15 +04:00
|
|
|
if (!pref || !strcmp(pref, PROXY_PREF("ftp_port")))
|
|
|
|
proxy_GetIntPref(prefBranch, PROXY_PREF("ftp_port"), mFTPProxyPort);
|
2000-02-14 13:04:56 +03:00
|
|
|
|
2006-03-30 21:31:15 +04:00
|
|
|
if (!pref || !strcmp(pref, PROXY_PREF("socks")))
|
|
|
|
proxy_GetStringPref(prefBranch, PROXY_PREF("socks"), mSOCKSProxyHost);
|
2014-09-05 17:29:00 +04:00
|
|
|
|
2006-03-30 21:31:15 +04:00
|
|
|
if (!pref || !strcmp(pref, PROXY_PREF("socks_port")))
|
|
|
|
proxy_GetIntPref(prefBranch, PROXY_PREF("socks_port"), mSOCKSProxyPort);
|
2001-07-25 04:28:28 +04:00
|
|
|
|
2006-03-30 21:31:15 +04:00
|
|
|
if (!pref || !strcmp(pref, PROXY_PREF("socks_version"))) {
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t version;
|
2006-03-30 21:31:15 +04:00
|
|
|
proxy_GetIntPref(prefBranch, PROXY_PREF("socks_version"), version);
|
2002-09-23 05:31:17 +04:00
|
|
|
// make sure this preference value remains sane
|
|
|
|
if (version == 5)
|
|
|
|
mSOCKSProxyVersion = 5;
|
|
|
|
else
|
|
|
|
mSOCKSProxyVersion = 4;
|
2001-07-25 04:28:28 +04:00
|
|
|
}
|
|
|
|
|
2006-03-30 21:31:15 +04:00
|
|
|
if (!pref || !strcmp(pref, PROXY_PREF("socks_remote_dns")))
|
|
|
|
proxy_GetBoolPref(prefBranch, PROXY_PREF("socks_remote_dns"),
|
|
|
|
mSOCKSProxyRemoteDNS);
|
2004-12-16 05:46:12 +03:00
|
|
|
|
2014-05-20 00:29:46 +04:00
|
|
|
if (!pref || !strcmp(pref, PROXY_PREF("proxy_over_tls"))) {
|
|
|
|
proxy_GetBoolPref(prefBranch, PROXY_PREF("proxy_over_tls"),
|
|
|
|
mProxyOverTLS);
|
|
|
|
}
|
|
|
|
|
2006-03-30 21:31:15 +04:00
|
|
|
if (!pref || !strcmp(pref, PROXY_PREF("failover_timeout")))
|
|
|
|
proxy_GetIntPref(prefBranch, PROXY_PREF("failover_timeout"),
|
|
|
|
mFailedProxyTimeout);
|
2004-07-02 03:31:47 +04:00
|
|
|
|
2006-03-30 21:31:15 +04:00
|
|
|
if (!pref || !strcmp(pref, PROXY_PREF("no_proxies_on"))) {
|
|
|
|
rv = prefBranch->GetCharPref(PROXY_PREF("no_proxies_on"),
|
2003-07-15 01:36:24 +04:00
|
|
|
getter_Copies(tempString));
|
2001-04-17 06:34:47 +04:00
|
|
|
if (NS_SUCCEEDED(rv))
|
2005-03-25 06:41:33 +03:00
|
|
|
LoadHostFilters(tempString.get());
|
2000-02-14 13:04:56 +03:00
|
|
|
}
|
2001-04-17 06:34:47 +04:00
|
|
|
|
2008-01-29 21:38:15 +03:00
|
|
|
// We're done if not using something that could give us a PAC URL
|
|
|
|
// (PAC, WPAD or System)
|
2010-06-17 22:33:42 +04:00
|
|
|
if (mProxyConfig != PROXYCONFIG_PAC && mProxyConfig != PROXYCONFIG_WPAD &&
|
|
|
|
mProxyConfig != PROXYCONFIG_SYSTEM)
|
2005-03-25 06:41:33 +03:00
|
|
|
return;
|
2001-04-17 06:34:47 +04:00
|
|
|
|
2005-03-25 06:41:33 +03:00
|
|
|
// OK, we need to reload the PAC file if:
|
|
|
|
// 1) network.proxy.type changed, or
|
|
|
|
// 2) network.proxy.autoconfig_url changed and PAC is configured
|
2001-05-04 06:42:44 +04:00
|
|
|
|
2006-03-30 21:31:15 +04:00
|
|
|
if (!pref || !strcmp(pref, PROXY_PREF("autoconfig_url")))
|
2011-10-17 18:59:28 +04:00
|
|
|
reloadPAC = true;
|
2001-04-17 06:34:47 +04:00
|
|
|
|
2005-03-25 06:41:33 +03:00
|
|
|
if (reloadPAC) {
|
|
|
|
tempString.Truncate();
|
2010-06-17 22:33:42 +04:00
|
|
|
if (mProxyConfig == PROXYCONFIG_PAC) {
|
2006-03-30 21:31:15 +04:00
|
|
|
prefBranch->GetCharPref(PROXY_PREF("autoconfig_url"),
|
2005-03-25 06:41:33 +03:00
|
|
|
getter_Copies(tempString));
|
2014-08-07 01:16:32 +04:00
|
|
|
if (mPACMan && !mPACMan->IsPACURI(tempString)) {
|
|
|
|
LOG(("PAC Thread URI Changed - Reset Pac Thread"));
|
|
|
|
ResetPACThread();
|
|
|
|
}
|
2010-06-17 22:33:42 +04:00
|
|
|
} else if (mProxyConfig == PROXYCONFIG_WPAD) {
|
2005-03-25 06:41:33 +03:00
|
|
|
// We diverge from the WPAD spec here in that we don't walk the
|
|
|
|
// hosts's FQDN, stripping components until we hit a TLD. Doing so
|
|
|
|
// is dangerous in the face of an incomplete list of TLDs, and TLDs
|
|
|
|
// get added over time. We could consider doing only a single
|
|
|
|
// substitution of the first component, if that proves to help
|
|
|
|
// compatibility.
|
2008-03-08 12:58:17 +03:00
|
|
|
tempString.AssignLiteral(WPAD_URL);
|
|
|
|
} else if (mSystemProxySettings) {
|
|
|
|
// Get System Proxy settings if available
|
|
|
|
mSystemProxySettings->GetPACURI(tempString);
|
2005-03-25 06:41:33 +03:00
|
|
|
}
|
2008-01-29 21:38:15 +03:00
|
|
|
if (!tempString.IsEmpty())
|
2011-10-17 18:59:28 +04:00
|
|
|
ConfigureFromPAC(tempString, false);
|
2001-04-17 06:34:47 +04:00
|
|
|
}
|
2000-02-14 13:04:56 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2014-09-05 17:29:00 +04:00
|
|
|
nsProtocolProxyService::CanUseProxy(nsIURI *aURI, int32_t defaultPort)
|
2000-02-24 00:17:17 +03:00
|
|
|
{
|
2009-02-23 04:05:28 +03:00
|
|
|
if (mHostFiltersArray.Length() == 0)
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2000-02-14 13:04:56 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t port;
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString host;
|
2014-09-05 17:29:00 +04:00
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
nsresult rv = aURI->GetAsciiHost(host);
|
|
|
|
if (NS_FAILED(rv) || host.IsEmpty())
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2003-04-11 22:24:55 +04:00
|
|
|
|
2000-02-14 13:04:56 +03:00
|
|
|
rv = aURI->GetPort(&port);
|
2003-04-11 22:24:55 +04:00
|
|
|
if (NS_FAILED(rv))
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2003-04-11 22:24:55 +04:00
|
|
|
if (port == -1)
|
|
|
|
port = defaultPort;
|
|
|
|
|
|
|
|
PRNetAddr addr;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool is_ipaddr = (PR_StringToNetAddr(host.get(), &addr) == PR_SUCCESS);
|
2003-04-11 22:24:55 +04:00
|
|
|
|
|
|
|
PRIPv6Addr ipv6;
|
|
|
|
if (is_ipaddr) {
|
|
|
|
// convert parsed address to IPv6
|
|
|
|
if (addr.raw.family == PR_AF_INET) {
|
|
|
|
// convert to IPv4-mapped address
|
|
|
|
PR_ConvertIPv4AddrToIPv6(addr.inet.ip, &ipv6);
|
|
|
|
}
|
|
|
|
else if (addr.raw.family == PR_AF_INET6) {
|
|
|
|
// copy the address
|
|
|
|
memcpy(&ipv6, &addr.ipv6.ip, sizeof(PRIPv6Addr));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
NS_WARNING("unknown address family");
|
2011-10-17 18:59:28 +04:00
|
|
|
return true; // allow proxying
|
2003-04-11 22:24:55 +04:00
|
|
|
}
|
2000-02-14 13:04:56 +03:00
|
|
|
}
|
2014-09-05 17:29:00 +04:00
|
|
|
|
2011-09-21 23:13:45 +04:00
|
|
|
// Don't use proxy for local hosts (plain hostname, no dots)
|
2015-08-14 01:49:15 +03:00
|
|
|
if (!is_ipaddr && mFilterLocalHosts && !host.Contains('.')) {
|
2011-09-21 23:13:45 +04:00
|
|
|
LOG(("Not using proxy for this local host [%s]!\n", host.get()));
|
2011-10-17 18:59:28 +04:00
|
|
|
return false; // don't allow proxying
|
2011-09-21 23:13:45 +04:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t index = -1;
|
|
|
|
while (++index < int32_t(mHostFiltersArray.Length())) {
|
2009-02-23 04:05:28 +03:00
|
|
|
HostInfo *hinfo = mHostFiltersArray[index];
|
2003-04-11 22:24:55 +04:00
|
|
|
|
|
|
|
if (is_ipaddr != hinfo->is_ipaddr)
|
|
|
|
continue;
|
|
|
|
if (hinfo->port && hinfo->port != port)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (is_ipaddr) {
|
|
|
|
// generate masked version of target IPv6 address
|
|
|
|
PRIPv6Addr masked;
|
|
|
|
memcpy(&masked, &ipv6, sizeof(PRIPv6Addr));
|
2003-07-15 01:36:24 +04:00
|
|
|
proxy_MaskIPv6Addr(masked, hinfo->ip.mask_len);
|
2003-04-11 22:24:55 +04:00
|
|
|
|
|
|
|
// check for a match
|
|
|
|
if (memcmp(&masked, &hinfo->ip.addr, sizeof(PRIPv6Addr)) == 0)
|
2011-10-17 18:59:28 +04:00
|
|
|
return false; // proxy disallowed
|
2003-04-11 22:24:55 +04:00
|
|
|
}
|
|
|
|
else {
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t host_len = host.Length();
|
|
|
|
uint32_t filter_host_len = hinfo->name.host_len;
|
2003-04-11 22:24:55 +04:00
|
|
|
|
|
|
|
if (host_len >= filter_host_len) {
|
|
|
|
//
|
|
|
|
// compare last |filter_host_len| bytes of target hostname.
|
|
|
|
//
|
|
|
|
const char *host_tail = host.get() + host_len - filter_host_len;
|
2015-10-21 04:05:00 +03:00
|
|
|
if (!PL_strncasecmp(host_tail, hinfo->name.host, filter_host_len)) {
|
|
|
|
// If the tail of the host string matches the filter
|
|
|
|
|
|
|
|
if (filter_host_len > 0 && hinfo->name.host[0] == '.') {
|
|
|
|
// If the filter was of the form .foo.bar.tld, all such
|
|
|
|
// matches are correct
|
|
|
|
return false; // proxy disallowed
|
|
|
|
}
|
|
|
|
|
|
|
|
// abc-def.example.org should not match def.example.org
|
|
|
|
// however, *.def.example.org should match .def.example.org
|
|
|
|
// We check that the filter doesn't start with a `.`. If it does,
|
|
|
|
// then the strncasecmp above should suffice. If it doesn't,
|
|
|
|
// then we should only consider it a match if the strncasecmp happened
|
|
|
|
// at a subdomain boundary
|
|
|
|
if (host_len > filter_host_len && *(host_tail - 1) == '.') {
|
|
|
|
// If the host was something.foo.bar.tld and the filter
|
|
|
|
// was foo.bar.tld, it's still a match.
|
|
|
|
// the character right before the tail must be a
|
|
|
|
// `.` for this to work
|
|
|
|
return false; // proxy disallowed
|
|
|
|
}
|
|
|
|
|
|
|
|
if (host_len == filter_host_len) {
|
|
|
|
// If the host and filter are of the same length,
|
|
|
|
// they should match
|
|
|
|
return false; // proxy disallowed
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-04-11 22:24:55 +04:00
|
|
|
}
|
2000-02-14 13:04:56 +03:00
|
|
|
}
|
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2000-02-14 13:04:56 +03:00
|
|
|
}
|
|
|
|
|
2012-10-27 23:24:19 +04:00
|
|
|
// kProxyType\* may be referred to externally in
|
|
|
|
// nsProxyInfo in order to compare by string pointer
|
|
|
|
namespace mozilla {
|
2013-08-21 21:21:40 +04:00
|
|
|
const char kProxyType_HTTP[] = "http";
|
2014-04-16 02:16:41 +04:00
|
|
|
const char kProxyType_HTTPS[] = "https";
|
2013-08-21 21:21:40 +04:00
|
|
|
const char kProxyType_PROXY[] = "proxy";
|
|
|
|
const char kProxyType_SOCKS[] = "socks";
|
|
|
|
const char kProxyType_SOCKS4[] = "socks4";
|
|
|
|
const char kProxyType_SOCKS5[] = "socks5";
|
|
|
|
const char kProxyType_DIRECT[] = "direct";
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace mozilla
|
2003-04-16 03:07:12 +04:00
|
|
|
|
|
|
|
const char *
|
2011-05-13 21:53:27 +04:00
|
|
|
nsProtocolProxyService::ExtractProxyInfo(const char *start,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aResolveFlags,
|
2011-05-13 21:53:27 +04:00
|
|
|
nsProxyInfo **result)
|
2003-04-16 03:07:12 +04:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
*result = nullptr;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t flags = 0;
|
2004-07-29 02:03:27 +04:00
|
|
|
|
2012-09-15 00:27:46 +04:00
|
|
|
// see BNF in ProxyAutoConfig.h and notes in nsISystemProxySettings.idl
|
2003-04-16 03:07:12 +04:00
|
|
|
|
|
|
|
// find end of proxy info delimiter
|
|
|
|
const char *end = start;
|
|
|
|
while (*end && *end != ';') ++end;
|
|
|
|
|
|
|
|
// find end of proxy type delimiter
|
|
|
|
const char *sp = start;
|
|
|
|
while (sp < end && *sp != ' ' && *sp != '\t') ++sp;
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t len = sp - start;
|
2012-07-30 18:20:58 +04:00
|
|
|
const char *type = nullptr;
|
2003-04-16 03:07:12 +04:00
|
|
|
switch (len) {
|
2014-04-16 02:16:41 +04:00
|
|
|
case 4:
|
|
|
|
if (PL_strncasecmp(start, kProxyType_HTTP, 5) == 0) {
|
|
|
|
type = kProxyType_HTTP;
|
|
|
|
}
|
|
|
|
break;
|
2003-04-16 03:07:12 +04:00
|
|
|
case 5:
|
2014-04-16 02:16:41 +04:00
|
|
|
if (PL_strncasecmp(start, kProxyType_PROXY, 5) == 0) {
|
2003-04-16 03:07:12 +04:00
|
|
|
type = kProxyType_HTTP;
|
2014-04-16 02:16:41 +04:00
|
|
|
} else if (PL_strncasecmp(start, kProxyType_SOCKS, 5) == 0) {
|
2003-04-16 03:07:12 +04:00
|
|
|
type = kProxyType_SOCKS4; // assume v4 for 4x compat
|
2014-04-16 02:16:41 +04:00
|
|
|
} else if (PL_strncasecmp(start, kProxyType_HTTPS, 5) == 0) {
|
|
|
|
type = kProxyType_HTTPS;
|
|
|
|
}
|
2003-04-16 03:07:12 +04:00
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
if (PL_strncasecmp(start, kProxyType_DIRECT, 6) == 0)
|
|
|
|
type = kProxyType_DIRECT;
|
|
|
|
else if (PL_strncasecmp(start, kProxyType_SOCKS4, 6) == 0)
|
|
|
|
type = kProxyType_SOCKS4;
|
|
|
|
else if (PL_strncasecmp(start, kProxyType_SOCKS5, 6) == 0)
|
2003-12-17 00:23:36 +03:00
|
|
|
// map "SOCKS5" to "socks" to match contract-id of registered
|
|
|
|
// SOCKS-v5 socket provider.
|
|
|
|
type = kProxyType_SOCKS;
|
2003-04-16 03:07:12 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (type) {
|
2012-07-30 18:20:58 +04:00
|
|
|
const char *host = nullptr, *hostEnd = nullptr;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t port = -1;
|
2004-12-16 05:46:12 +03:00
|
|
|
|
|
|
|
// If it's a SOCKS5 proxy, do name resolution on the server side.
|
|
|
|
// We could use this with SOCKS4a servers too, but they might not
|
|
|
|
// support it.
|
2011-11-19 17:36:05 +04:00
|
|
|
if (type == kProxyType_SOCKS || mSOCKSProxyRemoteDNS)
|
2004-12-16 05:46:12 +03:00
|
|
|
flags |= nsIProxyInfo::TRANSPARENT_PROXY_RESOLVES_HOST;
|
|
|
|
|
2003-04-16 03:07:12 +04:00
|
|
|
// extract host:port
|
|
|
|
start = sp;
|
|
|
|
while ((*start == ' ' || *start == '\t') && start < end)
|
|
|
|
start++;
|
2012-09-15 00:27:46 +04:00
|
|
|
|
|
|
|
// port defaults
|
2014-04-16 02:16:41 +04:00
|
|
|
if (type == kProxyType_HTTP) {
|
2012-09-15 00:27:46 +04:00
|
|
|
port = 80;
|
2014-04-16 02:16:41 +04:00
|
|
|
} else if (type == kProxyType_HTTPS) {
|
|
|
|
port = 443;
|
|
|
|
} else {
|
2012-09-15 00:27:46 +04:00
|
|
|
port = 1080;
|
2014-04-16 02:16:41 +04:00
|
|
|
}
|
2012-09-15 00:27:46 +04:00
|
|
|
|
|
|
|
nsProxyInfo *pi = new nsProxyInfo();
|
|
|
|
pi->mType = type;
|
|
|
|
pi->mFlags = flags;
|
|
|
|
pi->mResolveFlags = aResolveFlags;
|
|
|
|
pi->mTimeout = mFailedProxyTimeout;
|
|
|
|
|
|
|
|
// www.foo.com:8080 and http://www.foo.com:8080
|
|
|
|
nsDependentCSubstring maybeURL(start, end - start);
|
|
|
|
nsCOMPtr<nsIURI> pacURI;
|
|
|
|
|
|
|
|
nsAutoCString urlHost;
|
|
|
|
if (NS_SUCCEEDED(NS_NewURI(getter_AddRefs(pacURI), maybeURL)) &&
|
|
|
|
NS_SUCCEEDED(pacURI->GetAsciiHost(urlHost)) &&
|
|
|
|
!urlHost.IsEmpty()) {
|
|
|
|
// http://www.example.com:8080
|
|
|
|
|
|
|
|
pi->mHost = urlHost;
|
|
|
|
|
|
|
|
int32_t tPort;
|
|
|
|
if (NS_SUCCEEDED(pacURI->GetPort(&tPort)) && tPort != -1) {
|
|
|
|
port = tPort;
|
2003-04-16 03:07:12 +04:00
|
|
|
}
|
2012-09-15 00:27:46 +04:00
|
|
|
pi->mPort = port;
|
2003-04-16 03:07:12 +04:00
|
|
|
}
|
2012-09-15 00:27:46 +04:00
|
|
|
else {
|
|
|
|
// www.example.com:8080
|
|
|
|
if (start < end) {
|
|
|
|
host = start;
|
|
|
|
hostEnd = strchr(host, ':');
|
|
|
|
if (!hostEnd || hostEnd > end) {
|
|
|
|
hostEnd = end;
|
|
|
|
// no port, so assume default
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
port = atoi(hostEnd + 1);
|
|
|
|
}
|
|
|
|
}
|
2003-04-16 03:07:12 +04:00
|
|
|
// YES, it is ok to specify a null proxy host.
|
|
|
|
if (host) {
|
2004-07-02 03:31:47 +04:00
|
|
|
pi->mHost.Assign(host, hostEnd - host);
|
2003-04-16 03:07:12 +04:00
|
|
|
pi->mPort = port;
|
|
|
|
}
|
|
|
|
}
|
2012-09-15 00:27:46 +04:00
|
|
|
NS_ADDREF(*result = pi);
|
2003-04-16 03:07:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
while (*end == ';' || *end == ' ' || *end == '\t')
|
|
|
|
++end;
|
|
|
|
return end;
|
|
|
|
}
|
|
|
|
|
2004-07-02 03:31:47 +04:00
|
|
|
void
|
|
|
|
nsProtocolProxyService::GetProxyKey(nsProxyInfo *pi, nsCString &key)
|
|
|
|
{
|
|
|
|
key.AssignASCII(pi->mType);
|
|
|
|
if (!pi->mHost.IsEmpty()) {
|
|
|
|
key.Append(' ');
|
|
|
|
key.Append(pi->mHost);
|
|
|
|
key.Append(':');
|
|
|
|
key.AppendInt(pi->mPort);
|
|
|
|
}
|
2014-09-05 17:29:00 +04:00
|
|
|
}
|
2004-07-02 03:31:47 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t
|
2004-07-02 03:31:47 +04:00
|
|
|
nsProtocolProxyService::SecondsSinceSessionStart()
|
|
|
|
{
|
|
|
|
PRTime now = PR_Now();
|
|
|
|
|
|
|
|
// get time elapsed since session start
|
2012-10-05 09:05:27 +04:00
|
|
|
int64_t diff = now - mSessionStart;
|
2004-07-02 03:31:47 +04:00
|
|
|
|
|
|
|
// convert microseconds to seconds
|
2012-10-12 21:29:11 +04:00
|
|
|
diff /= PR_USEC_PER_SEC;
|
2004-07-02 03:31:47 +04:00
|
|
|
|
2012-10-12 21:29:11 +04:00
|
|
|
// return converted 32 bit value
|
|
|
|
return uint32_t(diff);
|
2004-07-02 03:31:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsProtocolProxyService::EnableProxy(nsProxyInfo *pi)
|
|
|
|
{
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString key;
|
2004-07-02 03:31:47 +04:00
|
|
|
GetProxyKey(pi, key);
|
|
|
|
mFailedProxies.Remove(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsProtocolProxyService::DisableProxy(nsProxyInfo *pi)
|
|
|
|
{
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString key;
|
2004-07-02 03:31:47 +04:00
|
|
|
GetProxyKey(pi, key);
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t dsec = SecondsSinceSessionStart();
|
2004-07-02 03:31:47 +04:00
|
|
|
|
|
|
|
// Add timeout to interval (this is the time when the proxy can
|
|
|
|
// be tried again).
|
2005-03-25 06:41:33 +03:00
|
|
|
dsec += pi->mTimeout;
|
2004-07-02 03:31:47 +04:00
|
|
|
|
|
|
|
// NOTE: The classic codebase would increase the timeout value
|
2010-05-13 16:19:50 +04:00
|
|
|
// incrementally each time a subsequent failure occurred.
|
2004-07-02 03:31:47 +04:00
|
|
|
// We could do the same, but it would require that we not
|
|
|
|
// remove proxy entries in IsProxyDisabled or otherwise
|
|
|
|
// change the way we are recording disabled proxies.
|
|
|
|
// Simpler is probably better for now, and at least the
|
|
|
|
// user can tune the timeout setting via preferences.
|
|
|
|
|
|
|
|
LOG(("DisableProxy %s %d\n", key.get(), dsec));
|
|
|
|
|
|
|
|
// If this fails, oh well... means we don't have enough memory
|
|
|
|
// to remember the failed proxy.
|
|
|
|
mFailedProxies.Put(key, dsec);
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2004-07-02 03:31:47 +04:00
|
|
|
nsProtocolProxyService::IsProxyDisabled(nsProxyInfo *pi)
|
|
|
|
{
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString key;
|
2004-07-02 03:31:47 +04:00
|
|
|
GetProxyKey(pi, key);
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t val;
|
2004-07-02 03:31:47 +04:00
|
|
|
if (!mFailedProxies.Get(key, &val))
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2004-07-02 03:31:47 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t dsec = SecondsSinceSessionStart();
|
2004-07-02 03:31:47 +04:00
|
|
|
|
|
|
|
// if time passed has exceeded interval, then try proxy again.
|
|
|
|
if (dsec > val) {
|
|
|
|
mFailedProxies.Remove(key);
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2004-07-02 03:31:47 +04:00
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2004-07-02 03:31:47 +04:00
|
|
|
}
|
|
|
|
|
2012-09-15 00:27:46 +04:00
|
|
|
nsresult
|
|
|
|
nsProtocolProxyService::SetupPACThread()
|
|
|
|
{
|
|
|
|
if (mPACMan)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
mPACMan = new nsPACMan();
|
|
|
|
|
|
|
|
bool mainThreadOnly;
|
|
|
|
nsresult rv;
|
|
|
|
if (mSystemProxySettings &&
|
|
|
|
NS_SUCCEEDED(mSystemProxySettings->GetMainThreadOnly(&mainThreadOnly)) &&
|
|
|
|
!mainThreadOnly) {
|
|
|
|
rv = mPACMan->Init(mSystemProxySettings);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rv = mPACMan->Init(nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
mPACMan = nullptr;
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsProtocolProxyService::ResetPACThread()
|
|
|
|
{
|
|
|
|
if (!mPACMan)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
mPACMan->Shutdown();
|
|
|
|
mPACMan = nullptr;
|
|
|
|
return SetupPACThread();
|
|
|
|
}
|
|
|
|
|
2006-03-30 21:31:15 +04:00
|
|
|
nsresult
|
2008-05-08 13:05:11 +04:00
|
|
|
nsProtocolProxyService::ConfigureFromPAC(const nsCString &spec,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool forceReload)
|
2006-03-30 21:31:15 +04:00
|
|
|
{
|
2012-09-15 00:27:46 +04:00
|
|
|
SetupPACThread();
|
2006-03-30 21:31:15 +04:00
|
|
|
|
2012-12-04 01:28:19 +04:00
|
|
|
if (mPACMan->IsPACURI(spec) && !forceReload)
|
2008-01-29 21:38:15 +03:00
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
mFailedProxies.Clear();
|
|
|
|
|
2012-12-04 01:28:19 +04:00
|
|
|
return mPACMan->LoadPACFromURI(spec);
|
2006-03-30 21:31:15 +04:00
|
|
|
}
|
|
|
|
|
2005-03-25 06:41:33 +03:00
|
|
|
void
|
|
|
|
nsProtocolProxyService::ProcessPACString(const nsCString &pacString,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aResolveFlags,
|
2005-03-25 06:41:33 +03:00
|
|
|
nsIProxyInfo **result)
|
2004-07-02 03:31:47 +04:00
|
|
|
{
|
2005-03-25 06:41:33 +03:00
|
|
|
if (pacString.IsEmpty()) {
|
2012-07-30 18:20:58 +04:00
|
|
|
*result = nullptr;
|
2005-03-25 06:41:33 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *proxies = pacString.get();
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
nsProxyInfo *pi = nullptr, *first = nullptr, *last = nullptr;
|
2004-07-02 03:31:47 +04:00
|
|
|
while (*proxies) {
|
2011-05-13 21:53:27 +04:00
|
|
|
proxies = ExtractProxyInfo(proxies, aResolveFlags, &pi);
|
2014-07-30 20:02:00 +04:00
|
|
|
if (pi && (pi->mType == kProxyType_HTTPS) && !mProxyOverTLS) {
|
2014-05-20 00:29:46 +04:00
|
|
|
delete pi;
|
|
|
|
pi = nullptr;
|
|
|
|
}
|
|
|
|
|
2004-07-02 03:31:47 +04:00
|
|
|
if (pi) {
|
2005-03-25 06:41:33 +03:00
|
|
|
if (last) {
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_ASSERTION(last->mNext == nullptr, "leaking nsProxyInfo");
|
2005-03-25 06:41:33 +03:00
|
|
|
last->mNext = pi;
|
2004-07-02 03:31:47 +04:00
|
|
|
}
|
2005-03-25 06:41:33 +03:00
|
|
|
else
|
|
|
|
first = pi;
|
|
|
|
last = pi;
|
2004-07-02 03:31:47 +04:00
|
|
|
}
|
|
|
|
}
|
2005-03-25 06:41:33 +03:00
|
|
|
*result = first;
|
2004-07-02 03:31:47 +04:00
|
|
|
}
|
|
|
|
|
2006-03-30 21:31:15 +04:00
|
|
|
// nsIProtocolProxyService2
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsProtocolProxyService::ReloadPAC()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
|
|
|
|
if (!prefs)
|
|
|
|
return NS_OK;
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t type;
|
2006-03-30 21:31:15 +04:00
|
|
|
nsresult rv = prefs->GetIntPref(PROXY_PREF("type"), &type);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
nsXPIDLCString pacSpec;
|
2010-06-17 22:33:42 +04:00
|
|
|
if (type == PROXYCONFIG_PAC)
|
2006-03-30 21:31:15 +04:00
|
|
|
prefs->GetCharPref(PROXY_PREF("autoconfig_url"), getter_Copies(pacSpec));
|
2010-06-17 22:33:42 +04:00
|
|
|
else if (type == PROXYCONFIG_WPAD)
|
2006-03-30 21:31:15 +04:00
|
|
|
pacSpec.AssignLiteral(WPAD_URL);
|
|
|
|
|
|
|
|
if (!pacSpec.IsEmpty())
|
2011-10-17 18:59:28 +04:00
|
|
|
ConfigureFromPAC(pacSpec, true);
|
2006-03-30 21:31:15 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-09-15 00:27:46 +04:00
|
|
|
// When sync interface is removed this can go away too
|
2012-09-27 21:29:34 +04:00
|
|
|
// The nsPACManCallback portion of this implementation should be run
|
|
|
|
// off the main thread, because it uses a condvar for signaling and
|
|
|
|
// the main thread is blocking on that condvar -
|
|
|
|
// so call nsPACMan::AsyncGetProxyForURI() with
|
|
|
|
// a false mainThreadResponse parameter.
|
2015-03-21 19:28:04 +03:00
|
|
|
class nsAsyncBridgeRequest final : public nsPACManCallback
|
2012-09-15 00:27:46 +04:00
|
|
|
{
|
2013-07-19 06:24:13 +04:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2012-09-15 00:27:46 +04:00
|
|
|
|
|
|
|
nsAsyncBridgeRequest()
|
|
|
|
: mMutex("nsDeprecatedCallback")
|
|
|
|
, mCondVar(mMutex, "nsDeprecatedCallback")
|
|
|
|
, mCompleted(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnQueryComplete(nsresult status,
|
|
|
|
const nsCString &pacString,
|
2015-03-21 19:28:04 +03:00
|
|
|
const nsCString &newPACURL) override
|
2012-09-15 00:27:46 +04:00
|
|
|
{
|
|
|
|
MutexAutoLock lock(mMutex);
|
|
|
|
mCompleted = true;
|
|
|
|
mStatus = status;
|
|
|
|
mPACString = pacString;
|
|
|
|
mPACURL = newPACURL;
|
|
|
|
mCondVar.Notify();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Lock() { mMutex.Lock(); }
|
|
|
|
void Unlock() { mMutex.Unlock(); }
|
|
|
|
void Wait() { mCondVar.Wait(PR_SecondsToInterval(3)); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
~nsAsyncBridgeRequest()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
friend class nsProtocolProxyService;
|
|
|
|
|
|
|
|
Mutex mMutex;
|
|
|
|
CondVar mCondVar;
|
|
|
|
|
|
|
|
nsresult mStatus;
|
|
|
|
nsCString mPACString;
|
|
|
|
nsCString mPACURL;
|
|
|
|
bool mCompleted;
|
|
|
|
};
|
2014-03-28 12:40:13 +04:00
|
|
|
NS_IMPL_ISUPPORTS0(nsAsyncBridgeRequest)
|
2012-09-15 00:27:46 +04:00
|
|
|
|
2015-01-21 23:13:00 +03:00
|
|
|
// nsProtocolProxyService
|
|
|
|
nsresult
|
|
|
|
nsProtocolProxyService::DeprecatedBlockingResolve(nsIChannel *aChannel,
|
2012-09-15 00:27:46 +04:00
|
|
|
uint32_t aFlags,
|
|
|
|
nsIProxyInfo **retval)
|
2004-07-02 03:31:47 +04:00
|
|
|
{
|
2015-01-21 23:13:00 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aChannel);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
nsresult rv = GetProxyURI(aChannel, getter_AddRefs(uri));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2012-09-05 16:44:27 +04:00
|
|
|
|
2005-03-25 06:41:33 +03:00
|
|
|
nsProtocolInfo info;
|
2015-01-21 23:13:00 +03:00
|
|
|
rv = GetProtocolInfo(uri, &info);
|
2005-03-25 06:41:33 +03:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2004-07-02 03:31:47 +04:00
|
|
|
|
2012-09-15 00:27:46 +04:00
|
|
|
nsCOMPtr<nsIProxyInfo> pi;
|
|
|
|
bool usePACThread;
|
|
|
|
|
|
|
|
// SystemProxySettings and PAC files can block the main thread
|
|
|
|
// but if neither of them are in use, we can just do the work
|
|
|
|
// right here and directly invoke the callback
|
|
|
|
|
2015-03-26 10:11:05 +03:00
|
|
|
rv = Resolve_Internal(aChannel, NECKO_NO_APP_ID, false, info, aFlags,
|
|
|
|
&usePACThread, getter_AddRefs(pi));
|
2012-09-15 00:27:46 +04:00
|
|
|
if (NS_FAILED(rv))
|
2005-03-25 06:41:33 +03:00
|
|
|
return rv;
|
2012-09-15 00:27:46 +04:00
|
|
|
|
|
|
|
if (!usePACThread || !mPACMan) {
|
2015-01-21 23:13:00 +03:00
|
|
|
ApplyFilters(aChannel, info, pi);
|
2012-09-15 00:27:46 +04:00
|
|
|
pi.forget(retval);
|
|
|
|
return NS_OK;
|
2011-09-21 23:13:45 +04:00
|
|
|
}
|
2004-07-02 03:31:47 +04:00
|
|
|
|
2012-09-15 00:27:46 +04:00
|
|
|
// Use the PAC thread to do the work, so we don't have to reimplement that
|
|
|
|
// code, but block this thread on that completion.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsAsyncBridgeRequest> ctx = new nsAsyncBridgeRequest();
|
2012-09-15 00:27:46 +04:00
|
|
|
ctx->Lock();
|
2015-03-26 10:11:05 +03:00
|
|
|
if (NS_SUCCEEDED(mPACMan->AsyncGetProxyForURI(uri, NECKO_NO_APP_ID, false,
|
|
|
|
ctx, false))) {
|
2012-09-15 00:27:46 +04:00
|
|
|
// this can really block the main thread, so cap it at 3 seconds
|
|
|
|
ctx->Wait();
|
|
|
|
}
|
|
|
|
ctx->Unlock();
|
|
|
|
if (!ctx->mCompleted)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
if (NS_FAILED(ctx->mStatus))
|
|
|
|
return ctx->mStatus;
|
|
|
|
|
|
|
|
// pretty much duplicate real DoCallback logic
|
|
|
|
|
|
|
|
// Generate proxy info from the PAC string if appropriate
|
|
|
|
if (!ctx->mPACString.IsEmpty()) {
|
|
|
|
LOG(("sync pac thread callback %s\n", ctx->mPACString.get()));
|
|
|
|
ProcessPACString(ctx->mPACString, 0, getter_AddRefs(pi));
|
2015-01-21 23:13:00 +03:00
|
|
|
ApplyFilters(aChannel, info, pi);
|
2012-09-15 00:27:46 +04:00
|
|
|
pi.forget(retval);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2004-07-02 03:31:47 +04:00
|
|
|
|
2012-09-15 00:27:46 +04:00
|
|
|
if (!ctx->mPACURL.IsEmpty()) {
|
|
|
|
NS_WARNING("sync pac thread callback indicates new pac file load\n");
|
|
|
|
// This is a problem and is one of the reasons this blocking interface
|
|
|
|
// is deprecated. The main loop needs to spin to make this reload happen. So
|
|
|
|
// we are going to kick off the reload and return an error - it will work
|
|
|
|
// next time. Because this sync interface is only used in the java plugin it
|
|
|
|
// is extremely likely that the pac file has already been loaded anyhow.
|
2004-07-02 03:31:47 +04:00
|
|
|
|
2012-09-15 00:27:46 +04:00
|
|
|
rv = ConfigureFromPAC(ctx->mPACURL, false);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
2004-07-02 03:31:47 +04:00
|
|
|
}
|
|
|
|
|
2012-09-15 00:27:46 +04:00
|
|
|
*retval = nullptr;
|
2004-07-02 03:31:47 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-06-28 01:02:04 +04:00
|
|
|
nsresult
|
2015-01-21 23:13:00 +03:00
|
|
|
nsProtocolProxyService::AsyncResolveInternal(nsIChannel *channel, uint32_t flags,
|
2013-06-28 01:02:04 +04:00
|
|
|
nsIProtocolProxyCallback *callback,
|
|
|
|
nsICancelable **result,
|
|
|
|
bool isSyncOK)
|
2003-04-16 03:07:12 +04:00
|
|
|
{
|
2015-01-21 23:13:00 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(channel);
|
2012-09-05 16:44:27 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(callback);
|
|
|
|
|
2015-01-21 23:13:00 +03:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
nsresult rv = GetProxyURI(channel, getter_AddRefs(uri));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2015-03-26 10:11:05 +03:00
|
|
|
uint32_t appId = NECKO_NO_APP_ID;
|
|
|
|
bool isInBrowser = false;
|
|
|
|
NS_GetAppInfo(channel, &appId, &isInBrowser);
|
|
|
|
|
2013-06-28 01:02:04 +04:00
|
|
|
*result = nullptr;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsAsyncResolveRequest> ctx =
|
2015-03-26 10:11:05 +03:00
|
|
|
new nsAsyncResolveRequest(this, channel, appId, isInBrowser, flags,
|
|
|
|
callback);
|
2001-09-13 06:21:05 +04:00
|
|
|
|
2005-03-25 06:41:33 +03:00
|
|
|
nsProtocolInfo info;
|
2015-01-21 23:13:00 +03:00
|
|
|
rv = GetProtocolInfo(uri, &info);
|
2005-03-25 06:41:33 +03:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2001-09-13 06:21:05 +04:00
|
|
|
|
2005-03-25 06:41:33 +03:00
|
|
|
nsCOMPtr<nsIProxyInfo> pi;
|
2012-09-15 00:27:46 +04:00
|
|
|
bool usePACThread;
|
|
|
|
|
|
|
|
// SystemProxySettings and PAC files can block the main thread
|
|
|
|
// but if neither of them are in use, we can just do the work
|
|
|
|
// right here and directly invoke the callback
|
|
|
|
|
2015-03-26 10:11:05 +03:00
|
|
|
rv = Resolve_Internal(channel, appId, isInBrowser, info, flags,
|
|
|
|
&usePACThread, getter_AddRefs(pi));
|
2005-03-25 06:41:33 +03:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2001-09-13 06:21:05 +04:00
|
|
|
|
2012-09-15 00:27:46 +04:00
|
|
|
if (!usePACThread || !mPACMan) {
|
|
|
|
// we can do it locally
|
2015-01-21 23:13:00 +03:00
|
|
|
ApplyFilters(channel, info, pi);
|
2005-03-25 06:41:33 +03:00
|
|
|
ctx->SetResult(NS_OK, pi);
|
2013-06-28 01:02:04 +04:00
|
|
|
if (isSyncOK) {
|
|
|
|
ctx->Run();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = ctx->DispatchCallback();
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
ctx.forget(result);
|
|
|
|
return rv;
|
2001-05-12 01:04:09 +04:00
|
|
|
}
|
2001-07-25 04:28:28 +04:00
|
|
|
|
2012-09-15 00:27:46 +04:00
|
|
|
// else kick off a PAC thread query
|
|
|
|
|
2015-03-26 10:11:05 +03:00
|
|
|
rv = mPACMan->AsyncGetProxyForURI(uri, appId, isInBrowser, ctx, true);
|
2013-06-28 01:02:04 +04:00
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
ctx.forget(result);
|
2005-03-25 06:41:33 +03:00
|
|
|
return rv;
|
|
|
|
}
|
2001-07-25 04:28:28 +04:00
|
|
|
|
2013-06-28 01:02:04 +04:00
|
|
|
// nsIProtocolProxyService
|
|
|
|
NS_IMETHODIMP
|
2015-01-21 23:13:00 +03:00
|
|
|
nsProtocolProxyService::AsyncResolve2(nsIChannel *channel, uint32_t flags,
|
2013-06-28 01:02:04 +04:00
|
|
|
nsIProtocolProxyCallback *callback,
|
|
|
|
nsICancelable **result)
|
|
|
|
{
|
2015-01-21 23:13:00 +03:00
|
|
|
return AsyncResolveInternal(channel, flags, callback, result, true);
|
2013-06-28 01:02:04 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2015-01-28 00:30:49 +03:00
|
|
|
nsProtocolProxyService::AsyncResolve(nsISupports *channelOrURI, uint32_t flags,
|
2013-06-28 01:02:04 +04:00
|
|
|
nsIProtocolProxyCallback *callback,
|
|
|
|
nsICancelable **result)
|
|
|
|
{
|
2015-01-28 00:30:49 +03:00
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
// Check if we got a channel:
|
|
|
|
nsCOMPtr<nsIChannel> channel = do_QueryInterface(channelOrURI);
|
|
|
|
if (!channel) {
|
|
|
|
nsCOMPtr<nsIURI> uri = do_QueryInterface(channelOrURI);
|
|
|
|
if (!uri) {
|
|
|
|
return NS_ERROR_NO_INTERFACE;
|
|
|
|
}
|
|
|
|
|
2015-03-20 22:27:34 +03:00
|
|
|
nsCOMPtr<nsIScriptSecurityManager> secMan(
|
|
|
|
do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
nsCOMPtr<nsIPrincipal> systemPrincipal;
|
|
|
|
rv = secMan->GetSystemPrincipal(getter_AddRefs(systemPrincipal));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// creating a temporary channel from the URI which is not
|
|
|
|
// used to perform any network loads, hence its safe to
|
|
|
|
// use systemPrincipal as the loadingPrincipal.
|
|
|
|
rv = NS_NewChannel(getter_AddRefs(channel),
|
|
|
|
uri,
|
|
|
|
systemPrincipal,
|
|
|
|
nsILoadInfo::SEC_NORMAL,
|
|
|
|
nsIContentPolicy::TYPE_OTHER);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2015-01-28 00:30:49 +03:00
|
|
|
}
|
|
|
|
|
2015-01-21 23:13:00 +03:00
|
|
|
return AsyncResolveInternal(channel, flags, callback, result, false);
|
2013-06-28 01:02:04 +04:00
|
|
|
}
|
|
|
|
|
2001-09-13 06:21:05 +04:00
|
|
|
NS_IMETHODIMP
|
2004-07-02 03:31:47 +04:00
|
|
|
nsProtocolProxyService::NewProxyInfo(const nsACString &aType,
|
|
|
|
const nsACString &aHost,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aPort,
|
|
|
|
uint32_t aFlags,
|
|
|
|
uint32_t aFailoverTimeout,
|
2005-03-25 06:41:33 +03:00
|
|
|
nsIProxyInfo *aFailoverProxy,
|
2002-09-23 05:31:17 +04:00
|
|
|
nsIProxyInfo **aResult)
|
2015-11-25 00:56:00 +03:00
|
|
|
{
|
|
|
|
return NewProxyInfoWithAuth(aType, aHost, aPort,
|
|
|
|
EmptyCString(), EmptyCString(),
|
|
|
|
aFlags, aFailoverTimeout,
|
|
|
|
aFailoverProxy, aResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsProtocolProxyService::NewProxyInfoWithAuth(const nsACString &aType,
|
|
|
|
const nsACString &aHost,
|
|
|
|
int32_t aPort,
|
|
|
|
const nsACString &aUsername,
|
|
|
|
const nsACString &aPassword,
|
|
|
|
uint32_t aFlags,
|
|
|
|
uint32_t aFailoverTimeout,
|
|
|
|
nsIProxyInfo *aFailoverProxy,
|
|
|
|
nsIProxyInfo **aResult)
|
2001-09-13 06:21:05 +04:00
|
|
|
{
|
2003-12-17 00:23:36 +03:00
|
|
|
static const char *types[] = {
|
|
|
|
kProxyType_HTTP,
|
2014-04-16 02:16:41 +04:00
|
|
|
kProxyType_HTTPS,
|
2003-12-17 00:23:36 +03:00
|
|
|
kProxyType_SOCKS,
|
2005-03-25 06:41:33 +03:00
|
|
|
kProxyType_SOCKS4,
|
2012-07-25 06:40:34 +04:00
|
|
|
kProxyType_DIRECT
|
2003-12-17 00:23:36 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
// resolve type; this allows us to avoid copying the type string into each
|
|
|
|
// proxy info instance. we just reference the string literals directly :)
|
2012-07-30 18:20:58 +04:00
|
|
|
const char *type = nullptr;
|
2014-04-16 02:16:41 +04:00
|
|
|
for (uint32_t i = 0; i < ArrayLength(types); ++i) {
|
2005-02-02 09:34:29 +03:00
|
|
|
if (aType.LowerCaseEqualsASCII(types[i])) {
|
2003-12-17 00:23:36 +03:00
|
|
|
type = types[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NS_ENSURE_TRUE(type, NS_ERROR_INVALID_ARG);
|
2002-09-23 05:31:17 +04:00
|
|
|
|
2015-11-25 00:56:00 +03:00
|
|
|
// We have only implemented username/password for SOCKS proxies.
|
|
|
|
if ((!aUsername.IsEmpty() || !aPassword.IsEmpty()) &&
|
|
|
|
!aType.LowerCaseEqualsASCII(kProxyType_SOCKS) &&
|
|
|
|
!aType.LowerCaseEqualsASCII(kProxyType_SOCKS4)) {
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
2002-09-23 05:31:17 +04:00
|
|
|
|
2015-11-25 00:56:00 +03:00
|
|
|
return NewProxyInfo_Internal(type, aHost, aPort,
|
|
|
|
aUsername, aPassword,
|
|
|
|
aFlags, aFailoverTimeout,
|
2011-05-13 21:53:27 +04:00
|
|
|
aFailoverProxy, 0, aResult);
|
2001-09-13 06:21:05 +04:00
|
|
|
}
|
|
|
|
|
2004-07-02 03:31:47 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsProtocolProxyService::GetFailoverForProxy(nsIProxyInfo *aProxy,
|
|
|
|
nsIURI *aURI,
|
|
|
|
nsresult aStatus,
|
|
|
|
nsIProxyInfo **aResult)
|
|
|
|
{
|
2015-12-10 09:21:00 +03:00
|
|
|
// We only support failover when a PAC file is configured, either
|
|
|
|
// directly or via system settings
|
|
|
|
if (mProxyConfig != PROXYCONFIG_PAC && mProxyConfig != PROXYCONFIG_WPAD &&
|
|
|
|
mProxyConfig != PROXYCONFIG_SYSTEM)
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
2004-07-02 03:31:47 +04:00
|
|
|
|
|
|
|
// Verify that |aProxy| is one of our nsProxyInfo objects.
|
2005-03-25 06:41:33 +03:00
|
|
|
nsCOMPtr<nsProxyInfo> pi = do_QueryInterface(aProxy);
|
|
|
|
NS_ENSURE_ARG(pi);
|
2004-07-02 03:37:40 +04:00
|
|
|
// OK, the QI checked out. We can proceed.
|
2004-07-02 03:31:47 +04:00
|
|
|
|
|
|
|
// Remember that this proxy is down.
|
|
|
|
DisableProxy(pi);
|
|
|
|
|
|
|
|
// NOTE: At this point, we might want to prompt the user if we have
|
|
|
|
// not already tried going DIRECT. This is something that the
|
|
|
|
// classic codebase supported; however, IE6 does not prompt.
|
|
|
|
|
|
|
|
if (!pi->mNext)
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
|
|
|
|
LOG(("PAC failover from %s %s:%d to %s %s:%d\n",
|
|
|
|
pi->mType, pi->mHost.get(), pi->mPort,
|
|
|
|
pi->mNext->mType, pi->mNext->mHost.get(), pi->mNext->mPort));
|
|
|
|
|
|
|
|
NS_ADDREF(*aResult = pi->mNext);
|
2000-02-24 04:56:12 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-04-22 04:35:05 +04:00
|
|
|
|
2015-01-21 23:13:00 +03:00
|
|
|
nsresult
|
|
|
|
nsProtocolProxyService::InsertFilterLink(FilterLink *link, uint32_t position)
|
2005-03-25 06:41:33 +03:00
|
|
|
{
|
|
|
|
if (!mFilters) {
|
|
|
|
mFilters = link;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// insert into mFilters in sorted order
|
2012-07-30 18:20:58 +04:00
|
|
|
FilterLink *last = nullptr;
|
2005-03-25 06:41:33 +03:00
|
|
|
for (FilterLink *iter = mFilters; iter; iter = iter->next) {
|
|
|
|
if (position < iter->position) {
|
|
|
|
if (last) {
|
|
|
|
link->next = last->next;
|
|
|
|
last->next = link;
|
2006-03-30 21:31:15 +04:00
|
|
|
}
|
|
|
|
else {
|
2005-03-25 06:41:33 +03:00
|
|
|
link->next = mFilters;
|
|
|
|
mFilters = link;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
last = iter;
|
|
|
|
}
|
|
|
|
// our position is equal to or greater than the last link in the list
|
|
|
|
last->next = link;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2015-01-21 23:13:00 +03:00
|
|
|
nsProtocolProxyService::RegisterFilter(nsIProtocolProxyFilter *filter,
|
|
|
|
uint32_t position)
|
2005-03-25 06:41:33 +03:00
|
|
|
{
|
2015-01-21 23:13:00 +03:00
|
|
|
UnregisterFilter(filter); // remove this filter if we already have it
|
|
|
|
|
|
|
|
FilterLink *link = new FilterLink(position, filter);
|
|
|
|
if (!link) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
return InsertFilterLink(link, position);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsProtocolProxyService::RegisterChannelFilter(nsIProtocolProxyChannelFilter *channelFilter,
|
|
|
|
uint32_t position)
|
|
|
|
{
|
|
|
|
UnregisterChannelFilter(channelFilter); // remove this filter if we already have it
|
2005-03-25 06:41:33 +03:00
|
|
|
|
2015-01-21 23:13:00 +03:00
|
|
|
FilterLink *link = new FilterLink(position, channelFilter);
|
|
|
|
if (!link) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
return InsertFilterLink(link, position);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsProtocolProxyService::RemoveFilterLink(nsISupports* givenObject)
|
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
FilterLink *last = nullptr;
|
2005-03-25 06:41:33 +03:00
|
|
|
for (FilterLink *iter = mFilters; iter; iter = iter->next) {
|
|
|
|
nsCOMPtr<nsISupports> object = do_QueryInterface(iter->filter);
|
2015-01-21 23:13:00 +03:00
|
|
|
nsCOMPtr<nsISupports> object2 = do_QueryInterface(iter->channelFilter);
|
|
|
|
if (object == givenObject || object2 == givenObject) {
|
2005-03-25 06:41:33 +03:00
|
|
|
if (last)
|
|
|
|
last->next = iter->next;
|
|
|
|
else
|
|
|
|
mFilters = iter->next;
|
2012-07-30 18:20:58 +04:00
|
|
|
iter->next = nullptr;
|
2005-03-25 06:41:33 +03:00
|
|
|
delete iter;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
last = iter;
|
|
|
|
}
|
|
|
|
|
|
|
|
// No need to throw an exception in this case.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2010-06-17 22:33:42 +04:00
|
|
|
|
2015-01-21 23:13:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsProtocolProxyService::UnregisterFilter(nsIProtocolProxyFilter *filter) {
|
|
|
|
// QI to nsISupports so we can safely test object identity.
|
|
|
|
nsCOMPtr<nsISupports> givenObject = do_QueryInterface(filter);
|
|
|
|
return RemoveFilterLink(givenObject);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsProtocolProxyService::UnregisterChannelFilter(nsIProtocolProxyChannelFilter *channelFilter) {
|
|
|
|
// QI to nsISupports so we can safely test object identity.
|
|
|
|
nsCOMPtr<nsISupports> givenObject = do_QueryInterface(channelFilter);
|
|
|
|
return RemoveFilterLink(givenObject);
|
|
|
|
}
|
|
|
|
|
2010-06-17 22:33:42 +04:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsProtocolProxyService::GetProxyConfigType(uint32_t* aProxyConfigType)
|
2010-06-17 22:33:42 +04:00
|
|
|
{
|
|
|
|
*aProxyConfigType = mProxyConfig;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-04-22 04:35:05 +04:00
|
|
|
void
|
2005-03-25 06:41:33 +03:00
|
|
|
nsProtocolProxyService::LoadHostFilters(const char *filters)
|
2000-04-22 04:35:05 +04:00
|
|
|
{
|
|
|
|
// check to see the owners flag? /!?/ TODO
|
2009-02-23 04:05:28 +03:00
|
|
|
if (mHostFiltersArray.Length() > 0) {
|
2005-03-25 06:41:33 +03:00
|
|
|
mHostFiltersArray.Clear();
|
2000-04-22 04:35:05 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!filters)
|
2003-04-11 22:24:55 +04:00
|
|
|
return; // fail silently...
|
2000-04-22 04:35:05 +04:00
|
|
|
|
2003-04-11 22:24:55 +04:00
|
|
|
//
|
2014-09-05 17:29:00 +04:00
|
|
|
// filter = ( host | domain | ipaddr ["/" mask] ) [":" port]
|
2003-04-11 22:24:55 +04:00
|
|
|
// filters = filter *( "," LWS filter)
|
|
|
|
//
|
2011-09-21 23:13:45 +04:00
|
|
|
// Reset mFilterLocalHosts - will be set to true if "<local>" is in pref string
|
2011-10-17 18:59:28 +04:00
|
|
|
mFilterLocalHosts = false;
|
2003-04-11 22:24:55 +04:00
|
|
|
while (*filters) {
|
2000-04-22 04:35:05 +04:00
|
|
|
// skip over spaces and ,
|
2003-04-11 22:24:55 +04:00
|
|
|
while (*filters && (*filters == ',' || IS_ASCII_SPACE(*filters)))
|
|
|
|
filters++;
|
|
|
|
|
|
|
|
const char *starthost = filters;
|
|
|
|
const char *endhost = filters + 1; // at least that...
|
2014-09-05 17:29:00 +04:00
|
|
|
const char *portLocation = 0;
|
2003-04-11 22:24:55 +04:00
|
|
|
const char *maskLocation = 0;
|
|
|
|
|
|
|
|
while (*endhost && (*endhost != ',' && !IS_ASCII_SPACE(*endhost))) {
|
|
|
|
if (*endhost == ':')
|
|
|
|
portLocation = endhost;
|
|
|
|
else if (*endhost == '/')
|
|
|
|
maskLocation = endhost;
|
2009-08-11 12:28:34 +04:00
|
|
|
else if (*endhost == ']') // IPv6 address literals
|
|
|
|
portLocation = 0;
|
2003-04-11 22:24:55 +04:00
|
|
|
endhost++;
|
2000-04-22 04:35:05 +04:00
|
|
|
}
|
|
|
|
|
2003-04-11 22:24:55 +04:00
|
|
|
filters = endhost; // advance iterator up front
|
|
|
|
|
|
|
|
// locate end of host
|
|
|
|
const char *end = maskLocation ? maskLocation :
|
|
|
|
portLocation ? portLocation :
|
|
|
|
endhost;
|
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString str(starthost, end - starthost);
|
2003-04-11 22:24:55 +04:00
|
|
|
|
2011-09-21 23:13:45 +04:00
|
|
|
// If the current host filter is "<local>", then all local (i.e.
|
|
|
|
// no dots in the hostname) hosts should bypass the proxy
|
|
|
|
if (str.EqualsIgnoreCase("<local>")) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mFilterLocalHosts = true;
|
2011-09-21 23:13:45 +04:00
|
|
|
LOG(("loaded filter for local hosts "
|
|
|
|
"(plain host names, no dots)\n"));
|
|
|
|
// Continue to next host filter;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// For all other host filters, create HostInfo object and add to list
|
|
|
|
HostInfo *hinfo = new HostInfo();
|
|
|
|
hinfo->port = portLocation ? atoi(portLocation + 1) : 0;
|
|
|
|
|
2003-04-11 22:24:55 +04:00
|
|
|
PRNetAddr addr;
|
|
|
|
if (PR_StringToNetAddr(str.get(), &addr) == PR_SUCCESS) {
|
2011-10-17 18:59:28 +04:00
|
|
|
hinfo->is_ipaddr = true;
|
2003-04-11 22:24:55 +04:00
|
|
|
hinfo->ip.family = PR_AF_INET6; // we always store address as IPv6
|
|
|
|
hinfo->ip.mask_len = maskLocation ? atoi(maskLocation + 1) : 128;
|
|
|
|
|
|
|
|
if (hinfo->ip.mask_len == 0) {
|
|
|
|
NS_WARNING("invalid mask");
|
|
|
|
goto loser;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (addr.raw.family == PR_AF_INET) {
|
|
|
|
// convert to IPv4-mapped address
|
|
|
|
PR_ConvertIPv4AddrToIPv6(addr.inet.ip, &hinfo->ip.addr);
|
|
|
|
// adjust mask_len accordingly
|
|
|
|
if (hinfo->ip.mask_len <= 32)
|
|
|
|
hinfo->ip.mask_len += 96;
|
|
|
|
}
|
|
|
|
else if (addr.raw.family == PR_AF_INET6) {
|
|
|
|
// copy the address
|
|
|
|
memcpy(&hinfo->ip.addr, &addr.ipv6.ip, sizeof(PRIPv6Addr));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
NS_WARNING("unknown address family");
|
|
|
|
goto loser;
|
|
|
|
}
|
|
|
|
|
|
|
|
// apply mask to IPv6 address
|
2003-07-15 01:36:24 +04:00
|
|
|
proxy_MaskIPv6Addr(hinfo->ip.addr, hinfo->ip.mask_len);
|
2001-08-01 06:13:00 +04:00
|
|
|
}
|
2003-04-11 22:24:55 +04:00
|
|
|
else {
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t startIndex, endIndex;
|
2003-04-11 22:24:55 +04:00
|
|
|
if (str.First() == '*')
|
|
|
|
startIndex = 1; // *.domain -> .domain
|
|
|
|
else
|
|
|
|
startIndex = 0;
|
|
|
|
endIndex = (portLocation ? portLocation : endhost) - starthost;
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
hinfo->is_ipaddr = false;
|
2003-04-11 22:24:55 +04:00
|
|
|
hinfo->name.host = ToNewCString(Substring(str, startIndex, endIndex));
|
|
|
|
|
|
|
|
if (!hinfo->name.host)
|
|
|
|
goto loser;
|
2000-04-22 04:35:05 +04:00
|
|
|
|
2003-04-11 22:24:55 +04:00
|
|
|
hinfo->name.host_len = endIndex - startIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
//#define DEBUG_DUMP_FILTERS
|
|
|
|
#ifdef DEBUG_DUMP_FILTERS
|
2009-02-23 04:05:28 +03:00
|
|
|
printf("loaded filter[%u]:\n", mHostFiltersArray.Length());
|
2003-04-11 22:24:55 +04:00
|
|
|
printf(" is_ipaddr = %u\n", hinfo->is_ipaddr);
|
|
|
|
printf(" port = %u\n", hinfo->port);
|
|
|
|
if (hinfo->is_ipaddr) {
|
|
|
|
printf(" ip.family = %x\n", hinfo->ip.family);
|
|
|
|
printf(" ip.mask_len = %u\n", hinfo->ip.mask_len);
|
|
|
|
|
|
|
|
PRNetAddr netAddr;
|
|
|
|
PR_SetNetAddr(PR_IpAddrNull, PR_AF_INET6, 0, &netAddr);
|
|
|
|
memcpy(&netAddr.ipv6.ip, &hinfo->ip.addr, sizeof(hinfo->ip.addr));
|
|
|
|
|
|
|
|
char buf[256];
|
|
|
|
PR_NetAddrToString(&netAddr, buf, sizeof(buf));
|
|
|
|
|
|
|
|
printf(" ip.addr = %s\n", buf);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
printf(" name.host = %s\n", hinfo->name.host);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2005-03-25 06:41:33 +03:00
|
|
|
mHostFiltersArray.AppendElement(hinfo);
|
2012-07-30 18:20:58 +04:00
|
|
|
hinfo = nullptr;
|
2003-04-11 22:24:55 +04:00
|
|
|
loser:
|
2011-05-17 18:01:36 +04:00
|
|
|
delete hinfo;
|
2000-04-22 04:35:05 +04:00
|
|
|
}
|
|
|
|
}
|
2002-09-23 05:31:17 +04:00
|
|
|
|
|
|
|
nsresult
|
2005-03-25 06:41:33 +03:00
|
|
|
nsProtocolProxyService::GetProtocolInfo(nsIURI *uri, nsProtocolInfo *info)
|
2002-09-23 05:31:17 +04:00
|
|
|
{
|
2012-09-05 16:44:27 +04:00
|
|
|
NS_PRECONDITION(uri, "URI is null");
|
|
|
|
NS_PRECONDITION(info, "info is null");
|
|
|
|
|
2002-09-23 05:31:17 +04:00
|
|
|
nsresult rv;
|
|
|
|
|
2005-03-25 06:41:33 +03:00
|
|
|
rv = uri->GetScheme(info->scheme);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2004-07-02 03:31:47 +04:00
|
|
|
nsCOMPtr<nsIIOService> ios = do_GetIOService(&rv);
|
2005-03-25 06:41:33 +03:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2002-09-23 05:31:17 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIProtocolHandler> handler;
|
2005-03-25 06:41:33 +03:00
|
|
|
rv = ios->GetProtocolHandler(info->scheme.get(), getter_AddRefs(handler));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2002-09-23 05:31:17 +04:00
|
|
|
|
2015-07-27 23:27:38 +03:00
|
|
|
rv = handler->DoGetProtocolFlags(uri, &info->flags);
|
2005-03-25 06:41:33 +03:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2003-04-11 22:24:55 +04:00
|
|
|
|
2005-03-25 06:41:33 +03:00
|
|
|
rv = handler->GetDefaultPort(&info->defaultPort);
|
|
|
|
return rv;
|
2002-09-23 05:31:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsProtocolProxyService::NewProxyInfo_Internal(const char *aType,
|
2004-07-02 03:31:47 +04:00
|
|
|
const nsACString &aHost,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aPort,
|
2015-11-25 00:56:00 +03:00
|
|
|
const nsACString &aUsername,
|
|
|
|
const nsACString &aPassword,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aFlags,
|
|
|
|
uint32_t aFailoverTimeout,
|
2005-03-25 06:41:33 +03:00
|
|
|
nsIProxyInfo *aFailoverProxy,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aResolveFlags,
|
2002-09-23 05:31:17 +04:00
|
|
|
nsIProxyInfo **aResult)
|
|
|
|
{
|
2015-11-25 00:56:00 +03:00
|
|
|
if (aPort <= 0)
|
|
|
|
aPort = -1;
|
|
|
|
|
2005-03-25 06:41:33 +03:00
|
|
|
nsCOMPtr<nsProxyInfo> failover;
|
|
|
|
if (aFailoverProxy) {
|
|
|
|
failover = do_QueryInterface(aFailoverProxy);
|
|
|
|
NS_ENSURE_ARG(failover);
|
|
|
|
}
|
|
|
|
|
2004-07-02 03:31:47 +04:00
|
|
|
nsProxyInfo *proxyInfo = new nsProxyInfo();
|
2002-09-23 05:31:17 +04:00
|
|
|
if (!proxyInfo)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
proxyInfo->mType = aType;
|
|
|
|
proxyInfo->mHost = aHost;
|
|
|
|
proxyInfo->mPort = aPort;
|
2015-11-25 00:56:00 +03:00
|
|
|
proxyInfo->mUsername = aUsername;
|
|
|
|
proxyInfo->mPassword = aPassword;
|
2004-12-16 05:46:12 +03:00
|
|
|
proxyInfo->mFlags = aFlags;
|
2011-05-13 21:53:27 +04:00
|
|
|
proxyInfo->mResolveFlags = aResolveFlags;
|
2012-09-28 10:57:33 +04:00
|
|
|
proxyInfo->mTimeout = aFailoverTimeout == UINT32_MAX
|
2005-03-25 06:41:33 +03:00
|
|
|
? mFailedProxyTimeout : aFailoverTimeout;
|
|
|
|
failover.swap(proxyInfo->mNext);
|
2002-09-23 05:31:17 +04:00
|
|
|
|
|
|
|
NS_ADDREF(*aResult = proxyInfo);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2004-07-31 21:39:29 +04:00
|
|
|
|
2005-03-25 06:41:33 +03:00
|
|
|
nsresult
|
2015-01-21 23:13:00 +03:00
|
|
|
nsProtocolProxyService::Resolve_Internal(nsIChannel *channel,
|
2015-03-26 10:11:05 +03:00
|
|
|
uint32_t appId,
|
|
|
|
bool isInBrowser,
|
2005-03-25 06:41:33 +03:00
|
|
|
const nsProtocolInfo &info,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t flags,
|
2012-09-15 00:27:46 +04:00
|
|
|
bool *usePACThread,
|
2005-03-25 06:41:33 +03:00
|
|
|
nsIProxyInfo **result)
|
|
|
|
{
|
2015-01-21 23:13:00 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(channel);
|
2012-09-15 00:27:46 +04:00
|
|
|
nsresult rv = SetupPACThread();
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2005-03-25 06:41:33 +03:00
|
|
|
|
2012-09-15 00:27:46 +04:00
|
|
|
*usePACThread = false;
|
2012-07-30 18:20:58 +04:00
|
|
|
*result = nullptr;
|
2005-03-25 06:41:33 +03:00
|
|
|
|
|
|
|
if (!(info.flags & nsIProtocolHandler::ALLOWS_PROXY))
|
|
|
|
return NS_OK; // Can't proxy this (filters may not override)
|
|
|
|
|
2015-01-21 23:13:00 +03:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
rv = GetProxyURI(channel, getter_AddRefs(uri));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2012-09-15 00:27:46 +04:00
|
|
|
// See bug #586908.
|
|
|
|
// Avoid endless loop if |uri| is the current PAC-URI. Returning OK
|
|
|
|
// here means that we will not use a proxy for this connection.
|
|
|
|
if (mPACMan && mPACMan->IsPACURI(uri))
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
bool mainThreadOnly;
|
|
|
|
if (mSystemProxySettings &&
|
|
|
|
mProxyConfig == PROXYCONFIG_SYSTEM &&
|
|
|
|
NS_SUCCEEDED(mSystemProxySettings->GetMainThreadOnly(&mainThreadOnly)) &&
|
|
|
|
!mainThreadOnly) {
|
|
|
|
*usePACThread = true;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mSystemProxySettings && mProxyConfig == PROXYCONFIG_SYSTEM) {
|
|
|
|
// If the system proxy setting implementation is not threadsafe (e.g
|
|
|
|
// linux gconf), we'll do it inline here. Such implementations promise
|
|
|
|
// not to block
|
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString PACURI;
|
2012-09-15 00:27:46 +04:00
|
|
|
nsAutoCString pacString;
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(mSystemProxySettings->GetPACURI(PACURI)) &&
|
|
|
|
!PACURI.IsEmpty()) {
|
|
|
|
// There is a PAC URI configured. If it is unchanged, then
|
|
|
|
// just execute the PAC thread. If it is changed then load
|
|
|
|
// the new value
|
|
|
|
|
|
|
|
if (mPACMan && mPACMan->IsPACURI(PACURI)) {
|
|
|
|
// unchanged
|
|
|
|
*usePACThread = true;
|
2008-01-29 21:38:15 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-09-15 00:27:46 +04:00
|
|
|
|
|
|
|
ConfigureFromPAC(PACURI, false);
|
2008-01-29 21:38:15 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2009-12-03 10:31:55 +03:00
|
|
|
|
2012-09-15 00:27:46 +04:00
|
|
|
nsAutoCString spec;
|
|
|
|
nsAutoCString host;
|
|
|
|
nsAutoCString scheme;
|
|
|
|
int32_t port = -1;
|
2012-09-17 19:54:09 +04:00
|
|
|
|
2012-09-15 00:27:46 +04:00
|
|
|
uri->GetAsciiSpec(spec);
|
|
|
|
uri->GetAsciiHost(host);
|
|
|
|
uri->GetScheme(scheme);
|
|
|
|
uri->GetPort(&port);
|
|
|
|
|
|
|
|
// now try the system proxy settings for this particular url
|
|
|
|
if (NS_SUCCEEDED(mSystemProxySettings->
|
|
|
|
GetProxyForURI(spec, scheme, host, port,
|
|
|
|
pacString))) {
|
|
|
|
ProcessPACString(pacString, 0, result);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2008-01-29 21:38:15 +03:00
|
|
|
}
|
|
|
|
|
2005-03-25 06:41:33 +03:00
|
|
|
// if proxies are enabled and this host:port combo is supposed to use a
|
|
|
|
// proxy, check for a proxy.
|
2010-06-17 22:33:42 +04:00
|
|
|
if (mProxyConfig == PROXYCONFIG_DIRECT ||
|
|
|
|
(mProxyConfig == PROXYCONFIG_MANUAL &&
|
2009-12-03 10:31:55 +03:00
|
|
|
!CanUseProxy(uri, info.defaultPort)))
|
2005-03-25 06:41:33 +03:00
|
|
|
return NS_OK;
|
2008-01-29 21:38:15 +03:00
|
|
|
|
2005-03-25 06:41:33 +03:00
|
|
|
// Proxy auto config magic...
|
2012-09-15 00:27:46 +04:00
|
|
|
if (mProxyConfig == PROXYCONFIG_PAC || mProxyConfig == PROXYCONFIG_WPAD) {
|
2005-03-25 06:41:33 +03:00
|
|
|
// Do not query PAC now.
|
2012-09-15 00:27:46 +04:00
|
|
|
*usePACThread = true;
|
2005-03-25 06:41:33 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-04-10 23:48:17 +04:00
|
|
|
// If we aren't in manual proxy configuration mode then we don't
|
|
|
|
// want to honor any manual specific prefs that might be still set
|
|
|
|
if (mProxyConfig != PROXYCONFIG_MANUAL)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
// proxy info values for manual configuration mode
|
2012-07-30 18:20:58 +04:00
|
|
|
const char *type = nullptr;
|
|
|
|
const nsACString *host = nullptr;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t port = -1;
|
2005-03-25 06:41:33 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t proxyFlags = 0;
|
2005-03-25 06:41:33 +03:00
|
|
|
|
2010-06-17 22:33:42 +04:00
|
|
|
if ((flags & RESOLVE_PREFER_SOCKS_PROXY) &&
|
|
|
|
!mSOCKSProxyHost.IsEmpty() && mSOCKSProxyPort > 0) {
|
|
|
|
host = &mSOCKSProxyHost;
|
2012-09-15 00:27:46 +04:00
|
|
|
if (mSOCKSProxyVersion == 4)
|
2010-06-17 22:33:42 +04:00
|
|
|
type = kProxyType_SOCKS4;
|
|
|
|
else
|
|
|
|
type = kProxyType_SOCKS;
|
|
|
|
port = mSOCKSProxyPort;
|
|
|
|
if (mSOCKSProxyRemoteDNS)
|
|
|
|
proxyFlags |= nsIProxyInfo::TRANSPARENT_PROXY_RESOLVES_HOST;
|
|
|
|
}
|
|
|
|
else if ((flags & RESOLVE_PREFER_HTTPS_PROXY) &&
|
|
|
|
!mHTTPSProxyHost.IsEmpty() && mHTTPSProxyPort > 0) {
|
|
|
|
host = &mHTTPSProxyHost;
|
|
|
|
type = kProxyType_HTTP;
|
|
|
|
port = mHTTPSProxyPort;
|
|
|
|
}
|
|
|
|
else if (!mHTTPProxyHost.IsEmpty() && mHTTPProxyPort > 0 &&
|
|
|
|
((flags & RESOLVE_IGNORE_URI_SCHEME) ||
|
|
|
|
info.scheme.EqualsLiteral("http"))) {
|
2005-03-25 06:41:33 +03:00
|
|
|
host = &mHTTPProxyHost;
|
|
|
|
type = kProxyType_HTTP;
|
|
|
|
port = mHTTPProxyPort;
|
|
|
|
}
|
|
|
|
else if (!mHTTPSProxyHost.IsEmpty() && mHTTPSProxyPort > 0 &&
|
2010-06-17 22:33:42 +04:00
|
|
|
!(flags & RESOLVE_IGNORE_URI_SCHEME) &&
|
2005-03-25 06:41:33 +03:00
|
|
|
info.scheme.EqualsLiteral("https")) {
|
|
|
|
host = &mHTTPSProxyHost;
|
|
|
|
type = kProxyType_HTTP;
|
|
|
|
port = mHTTPSProxyPort;
|
|
|
|
}
|
|
|
|
else if (!mFTPProxyHost.IsEmpty() && mFTPProxyPort > 0 &&
|
2010-06-17 22:33:42 +04:00
|
|
|
!(flags & RESOLVE_IGNORE_URI_SCHEME) &&
|
2005-03-25 06:41:33 +03:00
|
|
|
info.scheme.EqualsLiteral("ftp")) {
|
|
|
|
host = &mFTPProxyHost;
|
|
|
|
type = kProxyType_HTTP;
|
|
|
|
port = mFTPProxyPort;
|
|
|
|
}
|
|
|
|
else if (!mSOCKSProxyHost.IsEmpty() && mSOCKSProxyPort > 0) {
|
|
|
|
host = &mSOCKSProxyHost;
|
2012-09-15 00:27:46 +04:00
|
|
|
if (mSOCKSProxyVersion == 4)
|
2005-03-25 06:41:33 +03:00
|
|
|
type = kProxyType_SOCKS4;
|
|
|
|
else
|
|
|
|
type = kProxyType_SOCKS;
|
|
|
|
port = mSOCKSProxyPort;
|
|
|
|
if (mSOCKSProxyRemoteDNS)
|
|
|
|
proxyFlags |= nsIProxyInfo::TRANSPARENT_PROXY_RESOLVES_HOST;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type) {
|
2015-11-25 00:56:00 +03:00
|
|
|
rv = NewProxyInfo_Internal(type, *host, port,
|
|
|
|
EmptyCString(), EmptyCString(),
|
|
|
|
proxyFlags, UINT32_MAX, nullptr, flags,
|
2012-09-15 00:27:46 +04:00
|
|
|
result);
|
2005-03-25 06:41:33 +03:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-09-15 00:27:46 +04:00
|
|
|
void
|
|
|
|
nsProtocolProxyService::MaybeDisableDNSPrefetch(nsIProxyInfo *aProxy)
|
|
|
|
{
|
|
|
|
// Disable Prefetch in the DNS service if a proxy is in use.
|
|
|
|
if (!aProxy)
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsCOMPtr<nsProxyInfo> pi = do_QueryInterface(aProxy);
|
|
|
|
if (!pi ||
|
|
|
|
!pi->mType ||
|
|
|
|
pi->mType == kProxyType_DIRECT)
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDNSService> dns = do_GetService(NS_DNSSERVICE_CONTRACTID);
|
|
|
|
if (!dns)
|
|
|
|
return;
|
|
|
|
nsCOMPtr<nsPIDNSService> pdns = do_QueryInterface(dns);
|
|
|
|
if (!pdns)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// We lose the prefetch optimization for the life of the dns service.
|
|
|
|
pdns->SetPrefetchEnabled(false);
|
|
|
|
}
|
|
|
|
|
2004-07-31 21:39:29 +04:00
|
|
|
void
|
2015-01-21 23:13:00 +03:00
|
|
|
nsProtocolProxyService::ApplyFilters(nsIChannel *channel,
|
|
|
|
const nsProtocolInfo &info,
|
2005-03-25 06:41:33 +03:00
|
|
|
nsIProxyInfo **list)
|
2004-07-31 21:39:29 +04:00
|
|
|
{
|
2005-03-25 06:41:33 +03:00
|
|
|
if (!(info.flags & nsIProtocolHandler::ALLOWS_PROXY))
|
2004-07-31 21:39:29 +04:00
|
|
|
return;
|
2005-03-25 06:41:33 +03:00
|
|
|
|
|
|
|
// We prune the proxy list prior to invoking each filter. This may be
|
|
|
|
// somewhat inefficient, but it seems like a good idea since we want each
|
|
|
|
// filter to "see" a valid proxy list.
|
|
|
|
|
|
|
|
nsCOMPtr<nsIProxyInfo> result;
|
|
|
|
|
|
|
|
for (FilterLink *iter = mFilters; iter; iter = iter->next) {
|
|
|
|
PruneProxyInfo(info, list);
|
2015-03-17 03:45:00 +03:00
|
|
|
nsresult rv = NS_OK;
|
2015-01-21 23:13:00 +03:00
|
|
|
if (iter->filter) {
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
rv = GetProxyURI(channel, getter_AddRefs(uri));
|
|
|
|
if (uri) {
|
|
|
|
rv = iter->filter->ApplyFilter(this, uri, *list,
|
|
|
|
getter_AddRefs(result));
|
|
|
|
}
|
|
|
|
} else if (iter->channelFilter) {
|
|
|
|
rv = iter->channelFilter->ApplyFilter(this, channel, *list,
|
|
|
|
getter_AddRefs(result));
|
|
|
|
}
|
2005-03-25 06:41:33 +03:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
continue;
|
|
|
|
result.swap(*list);
|
2004-07-31 21:39:29 +04:00
|
|
|
}
|
2005-03-25 06:41:33 +03:00
|
|
|
|
|
|
|
PruneProxyInfo(info, list);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsProtocolProxyService::PruneProxyInfo(const nsProtocolInfo &info,
|
|
|
|
nsIProxyInfo **list)
|
|
|
|
{
|
|
|
|
if (!*list)
|
|
|
|
return;
|
2012-07-30 18:20:58 +04:00
|
|
|
nsProxyInfo *head = nullptr;
|
2005-03-25 06:41:33 +03:00
|
|
|
CallQueryInterface(*list, &head);
|
|
|
|
if (!head) {
|
|
|
|
NS_NOTREACHED("nsIProxyInfo must QI to nsProxyInfo");
|
2004-07-31 21:39:29 +04:00
|
|
|
return;
|
|
|
|
}
|
2005-03-25 06:41:33 +03:00
|
|
|
NS_RELEASE(*list);
|
|
|
|
|
|
|
|
// Pruning of disabled proxies works like this:
|
|
|
|
// - If all proxies are disabled, return the full list
|
|
|
|
// - Otherwise, remove the disabled proxies.
|
|
|
|
//
|
|
|
|
// Pruning of disallowed proxies works like this:
|
|
|
|
// - If the protocol handler disallows the proxy, then we disallow it.
|
|
|
|
|
|
|
|
// Start by removing all disallowed proxies if required:
|
|
|
|
if (!(info.flags & nsIProtocolHandler::ALLOWS_PROXY_HTTP)) {
|
2012-09-15 00:27:46 +04:00
|
|
|
nsProxyInfo *last = nullptr, *iter = head;
|
2005-03-29 00:11:16 +04:00
|
|
|
while (iter) {
|
2014-04-16 02:16:41 +04:00
|
|
|
if ((iter->Type() == kProxyType_HTTP) ||
|
|
|
|
(iter->Type() == kProxyType_HTTPS)) {
|
2005-03-25 06:41:33 +03:00
|
|
|
// reject!
|
|
|
|
if (last)
|
|
|
|
last->mNext = iter->mNext;
|
|
|
|
else
|
|
|
|
head = iter->mNext;
|
2005-03-29 00:11:16 +04:00
|
|
|
nsProxyInfo *next = iter->mNext;
|
2012-07-30 18:20:58 +04:00
|
|
|
iter->mNext = nullptr;
|
2005-03-29 00:11:16 +04:00
|
|
|
iter->Release();
|
|
|
|
iter = next;
|
|
|
|
} else {
|
|
|
|
last = iter;
|
|
|
|
iter = iter->mNext;
|
2005-03-25 06:41:33 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!head)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-12-10 09:21:00 +03:00
|
|
|
// Now, scan to see if all remaining proxies are disabled. If so, then
|
|
|
|
// we'll just bail and return them all. Otherwise, we'll go and prune the
|
|
|
|
// disabled ones.
|
2012-09-15 00:27:46 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool allDisabled = true;
|
2004-07-31 21:39:29 +04:00
|
|
|
|
2015-12-10 09:21:00 +03:00
|
|
|
nsProxyInfo *iter;
|
|
|
|
for (iter = head; iter; iter = iter->mNext) {
|
|
|
|
if (!IsProxyDisabled(iter)) {
|
|
|
|
allDisabled = false;
|
|
|
|
break;
|
2015-11-10 17:27:45 +03:00
|
|
|
}
|
|
|
|
}
|
2005-03-25 06:41:33 +03:00
|
|
|
|
2015-12-10 09:21:00 +03:00
|
|
|
if (allDisabled)
|
2015-11-10 17:27:45 +03:00
|
|
|
LOG(("All proxies are disabled, so trying all again"));
|
2015-12-10 09:21:00 +03:00
|
|
|
else {
|
2015-11-10 17:27:45 +03:00
|
|
|
// remove any disabled proxies.
|
|
|
|
nsProxyInfo *last = nullptr;
|
|
|
|
for (iter = head; iter; ) {
|
|
|
|
if (IsProxyDisabled(iter)) {
|
|
|
|
// reject!
|
|
|
|
nsProxyInfo *reject = iter;
|
|
|
|
|
|
|
|
iter = iter->mNext;
|
2015-12-10 09:21:00 +03:00
|
|
|
if (last)
|
2015-11-10 17:27:45 +03:00
|
|
|
last->mNext = iter;
|
2015-12-10 09:21:00 +03:00
|
|
|
else
|
|
|
|
head = iter;
|
2005-03-25 06:41:33 +03:00
|
|
|
|
2015-11-10 17:27:45 +03:00
|
|
|
reject->mNext = nullptr;
|
|
|
|
NS_RELEASE(reject);
|
|
|
|
continue;
|
|
|
|
}
|
2005-03-25 06:41:33 +03:00
|
|
|
|
2015-12-10 09:21:00 +03:00
|
|
|
// since we are about to use this proxy, make sure it is not on
|
|
|
|
// the disabled proxy list. we'll add it back to that list if
|
|
|
|
// we have to (in GetFailoverForProxy).
|
|
|
|
//
|
|
|
|
// XXX(darin): It might be better to do this as a final pass.
|
|
|
|
//
|
2015-11-10 17:27:45 +03:00
|
|
|
EnableProxy(iter);
|
2005-03-25 06:41:33 +03:00
|
|
|
|
2015-11-10 17:27:45 +03:00
|
|
|
last = iter;
|
|
|
|
iter = iter->mNext;
|
|
|
|
}
|
2015-10-09 02:59:00 +03:00
|
|
|
}
|
|
|
|
|
2005-03-25 06:41:33 +03:00
|
|
|
// if only DIRECT was specified then return no proxy info, and we're done.
|
|
|
|
if (head && !head->mNext && head->mType == kProxyType_DIRECT)
|
|
|
|
NS_RELEASE(head);
|
|
|
|
|
|
|
|
*list = head; // Transfer ownership
|
2004-07-31 21:39:29 +04:00
|
|
|
}
|