2018-11-30 22:52:05 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2018-11-30 18:39:55 +03:00
|
|
|
/* vim:set ts=4 sw=2 sts=2 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"
|
2018-02-08 08:18:00 +03:00
|
|
|
#include "mozilla/AutoRestore.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"
|
2021-11-29 18:19:15 +03:00
|
|
|
#include "nsDNSService2.h"
|
2012-09-15 00:27:46 +04:00
|
|
|
#include "nsPIDNSService.h"
|
2012-01-17 05:48:29 +04:00
|
|
|
#include "nsIPrefBranch.h"
|
2020-11-23 19:21:38 +03:00
|
|
|
#include "nsIPrefService.h"
|
2017-07-11 00:24:54 +03:00
|
|
|
#include "nsContentUtils.h"
|
2021-05-05 21:09:28 +03:00
|
|
|
#include "nsCRT.h"
|
2006-05-10 21:30:15 +04:00
|
|
|
#include "nsThreadUtils.h"
|
2017-05-24 09:36:53 +03:00
|
|
|
#include "nsQueryObject.h"
|
2016-09-01 10:48:39 +03:00
|
|
|
#include "nsSOCKSIOLayer.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"
|
2020-10-22 10:36:15 +03:00
|
|
|
#include "mozilla/dom/nsMixedContentBlocker.h"
|
2016-05-19 05:02:57 +03:00
|
|
|
#include "mozilla/Logging.h"
|
2021-11-29 18:19:15 +03:00
|
|
|
#include "mozilla/ScopeExit.h"
|
2020-10-22 10:36:15 +03:00
|
|
|
#include "mozilla/StaticPrefs_network.h"
|
2017-03-20 22:21:15 +03:00
|
|
|
#include "mozilla/Tokenizer.h"
|
2017-05-24 09:36:53 +03:00
|
|
|
#include "mozilla/Unused.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 {
|
2016-05-19 05:02:57 +03:00
|
|
|
namespace net {
|
|
|
|
|
2013-08-21 21:21:40 +04:00
|
|
|
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[];
|
|
|
|
|
2013-11-21 02:55:44 +04:00
|
|
|
#undef LOG
|
2016-05-19 05:02:57 +03:00
|
|
|
#define LOG(args) MOZ_LOG(gProxyLog, 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
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
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;
|
2021-06-04 15:35:16 +03:00
|
|
|
uint32_t flags = 0;
|
|
|
|
int32_t defaultPort = 0;
|
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) {
|
2016-02-26 19:29:28 +03:00
|
|
|
nsresult rv = NS_OK;
|
2015-01-21 23:13:00 +03:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2018-02-08 08:18:00 +03:00
|
|
|
nsProtocolProxyService::FilterLink::FilterLink(uint32_t p,
|
|
|
|
nsIProtocolProxyFilter* f)
|
|
|
|
: position(p), filter(f), channelFilter(nullptr) {
|
|
|
|
LOG(("nsProtocolProxyService::FilterLink::FilterLink %p, filter=%p", this,
|
|
|
|
f));
|
|
|
|
}
|
|
|
|
nsProtocolProxyService::FilterLink::FilterLink(
|
|
|
|
uint32_t p, nsIProtocolProxyChannelFilter* cf)
|
|
|
|
: position(p), filter(nullptr), channelFilter(cf) {
|
|
|
|
LOG(("nsProtocolProxyService::FilterLink::FilterLink %p, channel-filter=%p",
|
|
|
|
this, cf));
|
|
|
|
}
|
|
|
|
|
|
|
|
nsProtocolProxyService::FilterLink::~FilterLink() {
|
|
|
|
LOG(("nsProtocolProxyService::FilterLink::~FilterLink %p", this));
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
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
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-01-21 23:13:00 +03:00
|
|
|
nsAsyncResolveRequest(nsProtocolProxyService* pps, nsIChannel* channel,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aResolveFlags,
|
2005-03-25 06:41:33 +03:00
|
|
|
nsIProtocolProxyCallback* callback)
|
2021-06-11 10:10:41 +03: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),
|
2005-03-25 06:41:33 +03:00
|
|
|
mCallback(callback) {
|
2005-04-02 03:31:04 +04:00
|
|
|
NS_ASSERTION(mCallback, "null callback");
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2005-03-25 06:41:33 +03:00
|
|
|
|
2015-01-21 23:13:00 +03:00
|
|
|
private:
|
|
|
|
~nsAsyncResolveRequest() {
|
2012-08-22 19:56:38 +04:00
|
|
|
if (!NS_IsMainThread()) {
|
2005-03-25 06:41:33 +03:00
|
|
|
// these xpcom pointers might need to be proxied back to the
|
2015-01-21 23:13:00 +03:00
|
|
|
// main thread to delete safely, but if this request had its
|
2005-04-02 03:31:04 +04:00
|
|
|
// callbacks called normally they will all be null and this is a nop
|
2005-03-25 06:41:33 +03:00
|
|
|
|
2015-01-21 23:13:00 +03:00
|
|
|
if (mChannel) {
|
2020-04-07 18:16:23 +03:00
|
|
|
NS_ReleaseOnMainThread("nsAsyncResolveRequest::mChannel",
|
|
|
|
mChannel.forget());
|
2012-09-15 00:27:46 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-09-15 00:27:46 +04:00
|
|
|
if (mCallback) {
|
2020-04-07 18:16:23 +03:00
|
|
|
NS_ReleaseOnMainThread("nsAsyncResolveRequest::mCallback",
|
|
|
|
mCallback.forget());
|
2012-09-15 00:27:46 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-09-15 00:27:46 +04:00
|
|
|
if (mProxyInfo) {
|
2020-04-07 18:16:23 +03:00
|
|
|
NS_ReleaseOnMainThread("nsAsyncResolveRequest::mProxyInfo",
|
|
|
|
mProxyInfo.forget());
|
2012-09-15 00:27:46 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-09-15 00:27:46 +04:00
|
|
|
if (mXPComPPS) {
|
2020-04-07 18:16:23 +03:00
|
|
|
NS_ReleaseOnMainThread("nsAsyncResolveRequest::mXPComPPS",
|
|
|
|
mXPComPPS.forget());
|
2012-09-15 00:27:46 +04:00
|
|
|
}
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2012-09-15 00:27:46 +04:00
|
|
|
|
2018-02-08 08:18:00 +03:00
|
|
|
// Helper class to loop over all registered asynchronous filters.
|
|
|
|
// There is a cycle between nsAsyncResolveRequest and this class that
|
|
|
|
// is broken after the last filter has called back on this object.
|
|
|
|
class AsyncApplyFilters final : public nsIProxyProtocolFilterResult,
|
|
|
|
public nsIRunnable,
|
|
|
|
public nsICancelable {
|
|
|
|
// The reference counter is thread-safe, but the processing logic is
|
|
|
|
// considered single thread only. We want the counter be thread safe,
|
|
|
|
// since this class can be released on a background thread.
|
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
|
|
|
NS_DECL_NSIPROXYPROTOCOLFILTERRESULT
|
|
|
|
NS_DECL_NSIRUNNABLE
|
|
|
|
NS_DECL_NSICANCELABLE
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2021-06-04 15:35:16 +03:00
|
|
|
using Callback =
|
|
|
|
std::function<nsresult(nsAsyncResolveRequest*, nsIProxyInfo*, bool)>;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-02-08 08:18:00 +03:00
|
|
|
explicit AsyncApplyFilters(nsProtocolInfo& aInfo,
|
|
|
|
Callback const& aCallback);
|
|
|
|
// This method starts the processing or filters. If all of them
|
|
|
|
// answer synchronously (call back from within applyFilters) this method
|
|
|
|
// will return immediately and the returning result will carry return
|
|
|
|
// result of the callback given in constructor.
|
|
|
|
// This method is looping the registered filters (that have been copied
|
|
|
|
// locally) as long as an answer from a filter is obtained synchronously.
|
|
|
|
// Note that filters are processed serially to let them build a list
|
|
|
|
// of proxy info.
|
|
|
|
nsresult AsyncProcess(nsAsyncResolveRequest* aRequest);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-02-08 08:18:00 +03:00
|
|
|
private:
|
2021-06-04 15:35:16 +03:00
|
|
|
using FilterLink = nsProtocolProxyService::FilterLink;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-02-08 08:18:00 +03:00
|
|
|
virtual ~AsyncApplyFilters();
|
|
|
|
// Processes the next filter and loops until a filter is successfully
|
|
|
|
// called on or it has called back to us.
|
|
|
|
nsresult ProcessNextFilter();
|
|
|
|
// Called after the last filter has been processed (=called back or failed
|
|
|
|
// to be called on)
|
|
|
|
nsresult Finish();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-02-08 08:18:00 +03:00
|
|
|
nsProtocolInfo mInfo;
|
|
|
|
// This is nullified before we call back on the request or when
|
|
|
|
// Cancel() on this object has been called to break the cycle
|
|
|
|
// and signal to stop.
|
|
|
|
RefPtr<nsAsyncResolveRequest> mRequest;
|
|
|
|
Callback mCallback;
|
|
|
|
// A shallow snapshot of filters as they were registered at the moment
|
|
|
|
// we started to process filters for the given resolve request.
|
|
|
|
nsTArray<RefPtr<FilterLink>> mFiltersCopy;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-02-08 08:18:00 +03:00
|
|
|
nsTArray<RefPtr<FilterLink>>::index_type mNextFilterIndex;
|
|
|
|
// true when we are calling ProcessNextFilter() from inside AsyncProcess(),
|
|
|
|
// false otherwise.
|
|
|
|
bool mProcessingInLoop;
|
|
|
|
// true after a filter called back to us with a result, dropped to false
|
|
|
|
// just before we call a filter.
|
|
|
|
bool mFilterCalledBack;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-02-08 08:18:00 +03:00
|
|
|
// This keeps the initial value we pass to the first filter in line and also
|
|
|
|
// collects the result from each filter call.
|
|
|
|
nsCOMPtr<nsIProxyInfo> mProxyInfo;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-02-08 08:18:00 +03:00
|
|
|
// The logic is written as non-thread safe, assert single-thread usage.
|
2020-06-22 14:13:24 +03:00
|
|
|
nsCOMPtr<nsISerialEventTarget> mProcessingThread;
|
2018-11-30 13:46:48 +03:00
|
|
|
};
|
|
|
|
|
2019-09-17 21:19:38 +03:00
|
|
|
void EnsureResolveFlagsMatch() {
|
2021-07-15 20:36:55 +03:00
|
|
|
nsCOMPtr<nsProxyInfo> pi = do_QueryInterface(mProxyInfo);
|
|
|
|
if (!pi || pi->ResolveFlags() == mResolveFlags) {
|
|
|
|
return;
|
2019-09-17 21:19:38 +03:00
|
|
|
}
|
2021-07-15 20:36:55 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIProxyInfo> proxyInfo =
|
|
|
|
pi->CloneProxyInfoWithNewResolveFlags(mResolveFlags);
|
|
|
|
mProxyInfo.swap(proxyInfo);
|
2019-09-17 21:19:38 +03:00
|
|
|
}
|
|
|
|
|
2018-11-30 13:46:48 +03:00
|
|
|
public:
|
2018-02-08 08:18:00 +03:00
|
|
|
nsresult ProcessLocally(nsProtocolInfo& info, nsIProxyInfo* pi,
|
|
|
|
bool isSyncOK) {
|
|
|
|
SetResult(NS_OK, pi);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-02-08 08:18:00 +03:00
|
|
|
auto consumeFiltersResult = [isSyncOK](nsAsyncResolveRequest* ctx,
|
|
|
|
nsIProxyInfo* pi,
|
|
|
|
bool aCalledAsync) -> nsresult {
|
|
|
|
ctx->SetResult(NS_OK, pi);
|
|
|
|
if (isSyncOK || aCalledAsync) {
|
|
|
|
ctx->Run();
|
|
|
|
return NS_OK;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2018-02-08 08:18:00 +03:00
|
|
|
return ctx->DispatchCallback();
|
|
|
|
};
|
|
|
|
|
|
|
|
mAsyncFilterApplier = new AsyncApplyFilters(info, consumeFiltersResult);
|
|
|
|
// may call consumeFiltersResult() directly
|
|
|
|
return mAsyncFilterApplier->AsyncProcess(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetResult(nsresult status, nsIProxyInfo* pi) {
|
|
|
|
mStatus = status;
|
|
|
|
mProxyInfo = pi;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD Run() override {
|
|
|
|
if (mCallback) DoCallback();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-03-25 06:41:33 +03:00
|
|
|
NS_IMETHOD Cancel(nsresult reason) override {
|
|
|
|
NS_ENSURE_ARG(NS_FAILED(reason));
|
|
|
|
|
2006-05-10 21:30:15 +04:00
|
|
|
if (mAsyncFilterApplier) {
|
|
|
|
mAsyncFilterApplier->Cancel(reason);
|
|
|
|
}
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
// If we've already called DoCallback then, nothing more to do.
|
2005-04-02 03:31:04 +04:00
|
|
|
if (!mCallback) return NS_OK;
|
|
|
|
|
2018-02-08 08:18:00 +03:00
|
|
|
SetResult(reason, nullptr);
|
|
|
|
return DispatchCallback();
|
|
|
|
}
|
|
|
|
|
2005-04-02 03:31:04 +04:00
|
|
|
nsresult DispatchCallback() {
|
2021-06-04 15:35:16 +03:00
|
|
|
if (mDispatched) { // Only need to dispatch once
|
2005-04-02 03:31:04 +04:00
|
|
|
return NS_OK;
|
2021-06-04 15:35:16 +03:00
|
|
|
}
|
2005-04-02 03:31:04 +04:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
nsresult rv = NS_DispatchToCurrentThread(this);
|
2021-06-04 15:35:16 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
2005-04-02 03:31:04 +04:00
|
|
|
NS_WARNING("unable to dispatch callback event");
|
2021-06-04 15:35:16 +03:00
|
|
|
} else {
|
2011-10-17 18:59:28 +04:00
|
|
|
mDispatched = true;
|
2005-04-02 03:31:04 +04:00
|
|
|
return NS_OK;
|
2005-03-25 06:41:33 +03:00
|
|
|
}
|
|
|
|
|
2006-05-10 21:30:15 +04:00
|
|
|
mCallback = nullptr; // break possible reference cycle
|
|
|
|
return rv;
|
2005-03-25 06:41:33 +03:00
|
|
|
}
|
2005-04-02 03:31:04 +04:00
|
|
|
|
2018-11-30 13:46:48 +03:00
|
|
|
private:
|
2012-07-30 18:20:58 +04:00
|
|
|
// Called asynchronously, so we do not need to post another PLEvent
|
|
|
|
// before calling DoCallback.
|
|
|
|
void OnQueryComplete(nsresult status, const nsACString& pacString,
|
Bug 356831 - Proxy autodiscovery doesn't check DHCP (option 252) r=bagder,valentin
This patch addresses an issue with Firefox's proxy detection on networks which
do not have their a proxy auto-configuration (PAC) file hosted at
http://wpad/wpad.dat, and instead make use of DHCP option 252 for broadcasting
the address of the PAC file. See https://findproxyforurl.com/wpad-introduction/
for an introduction to the protocol.
Prior to this patch, proxy auto-detect missed out the DHCP query stage, and just
looked for a PAC file at http://wpad/wpad.dat
This patch only addresses the issue for Firefox on Windows, although it defines a
DHCP client interface which could be implemented on other platforms.
The high-level components of this patch are:
* nsIDHCPClient.idl - this is an interface which has been defined for querying the
DHCP server.
* nsPACMan.cpp - where previously when the PAC URL was simply set to a constant of
http://wpad/wpad.dat, it now dispatches an asynchronous command to the proxy
thread. The class ExecutePACThreadAction has been augmented to include an
instruction to 'ConfigureWPAD' (Configure Web-proxy auto-detect), and a new class,
'ConfigureWPADComplete' has been created to relay the result (the URL of the PAC
file) back to the nsPACMan object.
* nsProtocolProxyService.cpp
Minor changes to reflect the fact that the PAC URL not being set does not always
mean there is no PAC to be used; instead it could be in the process of being
detected.
* TestPACMan.cpp
This is a new file, and tests only the DHCP auto-detect functionality.
Some tests use multiple threads, as they test the non-blocking proxy detection.
* DHCPUtils.cpp
A class containing the main logic for querying DHCP.
* WindowsNetworkFunctionsWrapper.cpp
A very thin wrapper around the Windows API calls needed by DHCPUtils.
This class was introduced so it could be mocked out in tests.
* nsWindowsDHCPClient.cpp
* An implementation of the interface defined in nsIDHCPClient.idl. Fairly thin:
most logic is implemented in DHCPUtils.
* TestDHCPUtils.cpp
Tests for DHCPUtils and nsWindowsDHCPClient
MozReview-Commit-ID: 4xFQz3tOLEx
--HG--
extra : rebase_source : dfd5c588406a8b0d92f91cc8a0038ca722b7140a
2018-06-08 01:07:28 +03:00
|
|
|
const nsACString& newPACURL) override {
|
2012-07-30 18:20:58 +04:00
|
|
|
// If we've already called DoCallback then, nothing more to do.
|
2005-04-02 03:31:04 +04:00
|
|
|
if (!mCallback) return;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
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-03-25 06:41:33 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
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();
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2005-03-25 06:41:33 +03:00
|
|
|
|
|
|
|
void DoCallback() {
|
2016-03-29 06:23:00 +03:00
|
|
|
bool pacAvailable = true;
|
2005-03-25 06:41:33 +03: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
|
2012-09-15 00:27:46 +04:00
|
|
|
// mapping now so that any filters are still applied.
|
2013-02-12 22:35:04 +04:00
|
|
|
mPACString = "DIRECT;"_ns;
|
|
|
|
mStatus = NS_OK;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-09-15 00:27:46 +04:00
|
|
|
LOG(("pac not available, use DIRECT\n"));
|
2016-03-29 06:23:00 +03:00
|
|
|
pacAvailable = false;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2012-09-15 00:27:46 +04:00
|
|
|
// Generate proxy info from the PAC string if appropriate
|
|
|
|
if (NS_SUCCEEDED(mStatus) && !mProxyInfo && !mPACString.IsEmpty()) {
|
Bug 356831 - Proxy autodiscovery doesn't check DHCP (option 252) r=bagder,valentin
This patch addresses an issue with Firefox's proxy detection on networks which
do not have their a proxy auto-configuration (PAC) file hosted at
http://wpad/wpad.dat, and instead make use of DHCP option 252 for broadcasting
the address of the PAC file. See https://findproxyforurl.com/wpad-introduction/
for an introduction to the protocol.
Prior to this patch, proxy auto-detect missed out the DHCP query stage, and just
looked for a PAC file at http://wpad/wpad.dat
This patch only addresses the issue for Firefox on Windows, although it defines a
DHCP client interface which could be implemented on other platforms.
The high-level components of this patch are:
* nsIDHCPClient.idl - this is an interface which has been defined for querying the
DHCP server.
* nsPACMan.cpp - where previously when the PAC URL was simply set to a constant of
http://wpad/wpad.dat, it now dispatches an asynchronous command to the proxy
thread. The class ExecutePACThreadAction has been augmented to include an
instruction to 'ConfigureWPAD' (Configure Web-proxy auto-detect), and a new class,
'ConfigureWPADComplete' has been created to relay the result (the URL of the PAC
file) back to the nsPACMan object.
* nsProtocolProxyService.cpp
Minor changes to reflect the fact that the PAC URL not being set does not always
mean there is no PAC to be used; instead it could be in the process of being
detected.
* TestPACMan.cpp
This is a new file, and tests only the DHCP auto-detect functionality.
Some tests use multiple threads, as they test the non-blocking proxy detection.
* DHCPUtils.cpp
A class containing the main logic for querying DHCP.
* WindowsNetworkFunctionsWrapper.cpp
A very thin wrapper around the Windows API calls needed by DHCPUtils.
This class was introduced so it could be mocked out in tests.
* nsWindowsDHCPClient.cpp
* An implementation of the interface defined in nsIDHCPClient.idl. Fairly thin:
most logic is implemented in DHCPUtils.
* TestDHCPUtils.cpp
Tests for DHCPUtils and nsWindowsDHCPClient
MozReview-Commit-ID: 4xFQz3tOLEx
--HG--
extra : rebase_source : dfd5c588406a8b0d92f91cc8a0038ca722b7140a
2018-06-08 01:07:28 +03:00
|
|
|
mPPS->ProcessPACString(mPACString, mResolveFlags,
|
2011-05-13 21:53:27 +04:00
|
|
|
getter_AddRefs(mProxyInfo));
|
Bug 356831 - Proxy autodiscovery doesn't check DHCP (option 252) r=bagder,valentin
This patch addresses an issue with Firefox's proxy detection on networks which
do not have their a proxy auto-configuration (PAC) file hosted at
http://wpad/wpad.dat, and instead make use of DHCP option 252 for broadcasting
the address of the PAC file. See https://findproxyforurl.com/wpad-introduction/
for an introduction to the protocol.
Prior to this patch, proxy auto-detect missed out the DHCP query stage, and just
looked for a PAC file at http://wpad/wpad.dat
This patch only addresses the issue for Firefox on Windows, although it defines a
DHCP client interface which could be implemented on other platforms.
The high-level components of this patch are:
* nsIDHCPClient.idl - this is an interface which has been defined for querying the
DHCP server.
* nsPACMan.cpp - where previously when the PAC URL was simply set to a constant of
http://wpad/wpad.dat, it now dispatches an asynchronous command to the proxy
thread. The class ExecutePACThreadAction has been augmented to include an
instruction to 'ConfigureWPAD' (Configure Web-proxy auto-detect), and a new class,
'ConfigureWPADComplete' has been created to relay the result (the URL of the PAC
file) back to the nsPACMan object.
* nsProtocolProxyService.cpp
Minor changes to reflect the fact that the PAC URL not being set does not always
mean there is no PAC to be used; instead it could be in the process of being
detected.
* TestPACMan.cpp
This is a new file, and tests only the DHCP auto-detect functionality.
Some tests use multiple threads, as they test the non-blocking proxy detection.
* DHCPUtils.cpp
A class containing the main logic for querying DHCP.
* WindowsNetworkFunctionsWrapper.cpp
A very thin wrapper around the Windows API calls needed by DHCPUtils.
This class was introduced so it could be mocked out in tests.
* nsWindowsDHCPClient.cpp
* An implementation of the interface defined in nsIDHCPClient.idl. Fairly thin:
most logic is implemented in DHCPUtils.
* TestDHCPUtils.cpp
Tests for DHCPUtils and nsWindowsDHCPClient
MozReview-Commit-ID: 4xFQz3tOLEx
--HG--
extra : rebase_source : dfd5c588406a8b0d92f91cc8a0038ca722b7140a
2018-06-08 01:07:28 +03:00
|
|
|
nsCOMPtr<nsIURI> proxyURI;
|
|
|
|
GetProxyURI(mChannel, getter_AddRefs(proxyURI));
|
2018-11-30 13:46:48 +03:00
|
|
|
|
Bug 356831 - Proxy autodiscovery doesn't check DHCP (option 252) r=bagder,valentin
This patch addresses an issue with Firefox's proxy detection on networks which
do not have their a proxy auto-configuration (PAC) file hosted at
http://wpad/wpad.dat, and instead make use of DHCP option 252 for broadcasting
the address of the PAC file. See https://findproxyforurl.com/wpad-introduction/
for an introduction to the protocol.
Prior to this patch, proxy auto-detect missed out the DHCP query stage, and just
looked for a PAC file at http://wpad/wpad.dat
This patch only addresses the issue for Firefox on Windows, although it defines a
DHCP client interface which could be implemented on other platforms.
The high-level components of this patch are:
* nsIDHCPClient.idl - this is an interface which has been defined for querying the
DHCP server.
* nsPACMan.cpp - where previously when the PAC URL was simply set to a constant of
http://wpad/wpad.dat, it now dispatches an asynchronous command to the proxy
thread. The class ExecutePACThreadAction has been augmented to include an
instruction to 'ConfigureWPAD' (Configure Web-proxy auto-detect), and a new class,
'ConfigureWPADComplete' has been created to relay the result (the URL of the PAC
file) back to the nsPACMan object.
* nsProtocolProxyService.cpp
Minor changes to reflect the fact that the PAC URL not being set does not always
mean there is no PAC to be used; instead it could be in the process of being
detected.
* TestPACMan.cpp
This is a new file, and tests only the DHCP auto-detect functionality.
Some tests use multiple threads, as they test the non-blocking proxy detection.
* DHCPUtils.cpp
A class containing the main logic for querying DHCP.
* WindowsNetworkFunctionsWrapper.cpp
A very thin wrapper around the Windows API calls needed by DHCPUtils.
This class was introduced so it could be mocked out in tests.
* nsWindowsDHCPClient.cpp
* An implementation of the interface defined in nsIDHCPClient.idl. Fairly thin:
most logic is implemented in DHCPUtils.
* TestDHCPUtils.cpp
Tests for DHCPUtils and nsWindowsDHCPClient
MozReview-Commit-ID: 4xFQz3tOLEx
--HG--
extra : rebase_source : dfd5c588406a8b0d92f91cc8a0038ca722b7140a
2018-06-08 01:07:28 +03:00
|
|
|
// Now apply proxy filters
|
2005-03-25 06:41:33 +03:00
|
|
|
nsProtocolInfo info;
|
Bug 356831 - Proxy autodiscovery doesn't check DHCP (option 252) r=bagder,valentin
This patch addresses an issue with Firefox's proxy detection on networks which
do not have their a proxy auto-configuration (PAC) file hosted at
http://wpad/wpad.dat, and instead make use of DHCP option 252 for broadcasting
the address of the PAC file. See https://findproxyforurl.com/wpad-introduction/
for an introduction to the protocol.
Prior to this patch, proxy auto-detect missed out the DHCP query stage, and just
looked for a PAC file at http://wpad/wpad.dat
This patch only addresses the issue for Firefox on Windows, although it defines a
DHCP client interface which could be implemented on other platforms.
The high-level components of this patch are:
* nsIDHCPClient.idl - this is an interface which has been defined for querying the
DHCP server.
* nsPACMan.cpp - where previously when the PAC URL was simply set to a constant of
http://wpad/wpad.dat, it now dispatches an asynchronous command to the proxy
thread. The class ExecutePACThreadAction has been augmented to include an
instruction to 'ConfigureWPAD' (Configure Web-proxy auto-detect), and a new class,
'ConfigureWPADComplete' has been created to relay the result (the URL of the PAC
file) back to the nsPACMan object.
* nsProtocolProxyService.cpp
Minor changes to reflect the fact that the PAC URL not being set does not always
mean there is no PAC to be used; instead it could be in the process of being
detected.
* TestPACMan.cpp
This is a new file, and tests only the DHCP auto-detect functionality.
Some tests use multiple threads, as they test the non-blocking proxy detection.
* DHCPUtils.cpp
A class containing the main logic for querying DHCP.
* WindowsNetworkFunctionsWrapper.cpp
A very thin wrapper around the Windows API calls needed by DHCPUtils.
This class was introduced so it could be mocked out in tests.
* nsWindowsDHCPClient.cpp
* An implementation of the interface defined in nsIDHCPClient.idl. Fairly thin:
most logic is implemented in DHCPUtils.
* TestDHCPUtils.cpp
Tests for DHCPUtils and nsWindowsDHCPClient
MozReview-Commit-ID: 4xFQz3tOLEx
--HG--
extra : rebase_source : dfd5c588406a8b0d92f91cc8a0038ca722b7140a
2018-06-08 01:07:28 +03:00
|
|
|
mStatus = mPPS->GetProtocolInfo(proxyURI, &info);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
Bug 356831 - Proxy autodiscovery doesn't check DHCP (option 252) r=bagder,valentin
This patch addresses an issue with Firefox's proxy detection on networks which
do not have their a proxy auto-configuration (PAC) file hosted at
http://wpad/wpad.dat, and instead make use of DHCP option 252 for broadcasting
the address of the PAC file. See https://findproxyforurl.com/wpad-introduction/
for an introduction to the protocol.
Prior to this patch, proxy auto-detect missed out the DHCP query stage, and just
looked for a PAC file at http://wpad/wpad.dat
This patch only addresses the issue for Firefox on Windows, although it defines a
DHCP client interface which could be implemented on other platforms.
The high-level components of this patch are:
* nsIDHCPClient.idl - this is an interface which has been defined for querying the
DHCP server.
* nsPACMan.cpp - where previously when the PAC URL was simply set to a constant of
http://wpad/wpad.dat, it now dispatches an asynchronous command to the proxy
thread. The class ExecutePACThreadAction has been augmented to include an
instruction to 'ConfigureWPAD' (Configure Web-proxy auto-detect), and a new class,
'ConfigureWPADComplete' has been created to relay the result (the URL of the PAC
file) back to the nsPACMan object.
* nsProtocolProxyService.cpp
Minor changes to reflect the fact that the PAC URL not being set does not always
mean there is no PAC to be used; instead it could be in the process of being
detected.
* TestPACMan.cpp
This is a new file, and tests only the DHCP auto-detect functionality.
Some tests use multiple threads, as they test the non-blocking proxy detection.
* DHCPUtils.cpp
A class containing the main logic for querying DHCP.
* WindowsNetworkFunctionsWrapper.cpp
A very thin wrapper around the Windows API calls needed by DHCPUtils.
This class was introduced so it could be mocked out in tests.
* nsWindowsDHCPClient.cpp
* An implementation of the interface defined in nsIDHCPClient.idl. Fairly thin:
most logic is implemented in DHCPUtils.
* TestDHCPUtils.cpp
Tests for DHCPUtils and nsWindowsDHCPClient
MozReview-Commit-ID: 4xFQz3tOLEx
--HG--
extra : rebase_source : dfd5c588406a8b0d92f91cc8a0038ca722b7140a
2018-06-08 01:07:28 +03:00
|
|
|
auto consumeFiltersResult = [pacAvailable](nsAsyncResolveRequest* self,
|
2005-04-02 03:31:04 +04:00
|
|
|
nsIProxyInfo* pi,
|
2018-02-08 08:18:00 +03:00
|
|
|
bool async) -> nsresult {
|
2005-04-02 03:31:04 +04:00
|
|
|
LOG(("DoCallback::consumeFiltersResult this=%p, pi=%p, async=%d", self,
|
2018-02-08 08:18:00 +03:00
|
|
|
pi, async));
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-02-08 08:18:00 +03:00
|
|
|
self->mProxyInfo = pi;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-02-08 08:18:00 +03:00
|
|
|
if (pacAvailable) {
|
2005-04-02 03:31:04 +04:00
|
|
|
// if !pacAvailable, it was already logged above
|
|
|
|
LOG(("pac thread callback %s\n", self->mPACString.get()));
|
|
|
|
}
|
|
|
|
|
2013-02-12 22:35:04 +04:00
|
|
|
if (NS_SUCCEEDED(self->mStatus)) {
|
|
|
|
self->mPPS->MaybeDisableDNSPrefetch(self->mProxyInfo);
|
|
|
|
}
|
|
|
|
|
2019-09-17 21:19:38 +03:00
|
|
|
self->EnsureResolveFlagsMatch();
|
2018-02-08 08:18:00 +03:00
|
|
|
self->mCallback->OnProxyAvailable(self, self->mChannel,
|
2016-10-15 19:41:32 +03:00
|
|
|
self->mProxyInfo, self->mStatus);
|
2012-09-15 00:27:46 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
2018-11-30 13:46:48 +03:00
|
|
|
};
|
|
|
|
|
2012-09-15 00:27:46 +04:00
|
|
|
if (NS_SUCCEEDED(mStatus)) {
|
|
|
|
mAsyncFilterApplier = new AsyncApplyFilters(info, consumeFiltersResult);
|
|
|
|
// This may call consumeFiltersResult() directly.
|
|
|
|
mAsyncFilterApplier->AsyncProcess(this);
|
|
|
|
return;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
consumeFiltersResult(this, nullptr, false);
|
|
|
|
} else if (NS_SUCCEEDED(mStatus) && !mPACURL.IsEmpty()) {
|
|
|
|
LOG(("pac thread callback indicates new pac file load\n"));
|
2005-03-25 06:41:33 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> proxyURI;
|
2012-09-15 00:27:46 +04:00
|
|
|
GetProxyURI(mChannel, getter_AddRefs(proxyURI));
|
2005-03-25 06:41:33 +03:00
|
|
|
|
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
|
|
|
|
RefPtr<nsAsyncResolveRequest> newRequest =
|
2016-10-15 19:41:32 +03:00
|
|
|
new nsAsyncResolveRequest(mPPS, mChannel, mResolveFlags, mCallback);
|
2020-04-06 22:11:33 +03:00
|
|
|
rv = mPPS->mPACMan->AsyncGetProxyForURI(proxyURI, newRequest,
|
|
|
|
mResolveFlags, true);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2021-06-04 15:35:16 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
2005-03-25 06:41:33 +03:00
|
|
|
mCallback->OnProxyAvailable(this, mChannel, nullptr, rv);
|
2021-06-04 15:35:16 +03:00
|
|
|
}
|
2018-02-08 08:18:00 +03:00
|
|
|
|
2012-09-15 00:27:46 +04:00
|
|
|
// do not call onproxyavailable() in SUCCESS case - the newRequest will
|
|
|
|
// take care of that
|
2018-11-30 13:46:48 +03:00
|
|
|
} else {
|
2016-12-16 06:16:31 +03:00
|
|
|
LOG(("pac thread callback did not provide information %" PRIX32 "\n",
|
|
|
|
static_cast<uint32_t>(mStatus)));
|
2012-09-15 00:27:46 +04:00
|
|
|
if (NS_SUCCEEDED(mStatus)) mPPS->MaybeDisableDNSPrefetch(mProxyInfo);
|
2019-09-17 21:19:38 +03:00
|
|
|
EnsureResolveFlagsMatch();
|
2015-01-21 23:13:00 +03:00
|
|
|
mCallback->OnProxyAvailable(this, mChannel, mProxyInfo, mStatus);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
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;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2021-06-11 10:10:41 +03:00
|
|
|
nsresult mStatus{NS_OK};
|
2012-09-15 00:27:46 +04:00
|
|
|
nsCString mPACString;
|
|
|
|
nsCString mPACURL;
|
2021-06-11 10:10:41 +03:00
|
|
|
bool mDispatched{false};
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mResolveFlags;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-01-21 23:13:00 +03:00
|
|
|
nsProtocolProxyService* mPPS;
|
2017-05-24 09:36:53 +03:00
|
|
|
nsCOMPtr<nsIProtocolProxyService> mXPComPPS;
|
2015-01-21 23:13:00 +03:00
|
|
|
nsCOMPtr<nsIChannel> mChannel;
|
2013-06-28 01:02:04 +04:00
|
|
|
nsCOMPtr<nsIProtocolProxyCallback> mCallback;
|
2005-03-25 06:41:33 +03:00
|
|
|
nsCOMPtr<nsIProxyInfo> mProxyInfo;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-02-08 08:18:00 +03:00
|
|
|
RefPtr<AsyncApplyFilters> mAsyncFilterApplier;
|
2005-03-25 06:41:33 +03:00
|
|
|
};
|
|
|
|
|
2018-02-08 08:18:00 +03:00
|
|
|
NS_IMPL_ISUPPORTS(nsAsyncResolveRequest, nsICancelable, nsIRunnable)
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS(nsAsyncResolveRequest::AsyncApplyFilters,
|
|
|
|
nsIProxyProtocolFilterResult, nsICancelable, nsIRunnable)
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-02-08 08:18:00 +03:00
|
|
|
nsAsyncResolveRequest::AsyncApplyFilters::AsyncApplyFilters(
|
|
|
|
nsProtocolInfo& aInfo, Callback const& aCallback)
|
|
|
|
: mInfo(aInfo),
|
|
|
|
mCallback(aCallback),
|
|
|
|
mNextFilterIndex(0),
|
|
|
|
mProcessingInLoop(false),
|
|
|
|
mFilterCalledBack(false) {
|
|
|
|
LOG(("AsyncApplyFilters %p", this));
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAsyncResolveRequest::AsyncApplyFilters::~AsyncApplyFilters() {
|
|
|
|
LOG(("~AsyncApplyFilters %p", this));
|
|
|
|
|
|
|
|
MOZ_ASSERT(!mRequest);
|
|
|
|
MOZ_ASSERT(!mProxyInfo);
|
|
|
|
MOZ_ASSERT(!mFiltersCopy.Length());
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsAsyncResolveRequest::AsyncApplyFilters::AsyncProcess(
|
|
|
|
nsAsyncResolveRequest* aRequest) {
|
|
|
|
LOG(("AsyncApplyFilters::AsyncProcess %p for req %p", this, aRequest));
|
|
|
|
|
|
|
|
MOZ_ASSERT(!mRequest, "AsyncApplyFilters started more than once!");
|
|
|
|
|
|
|
|
if (!(mInfo.flags & nsIProtocolHandler::ALLOWS_PROXY)) {
|
|
|
|
// Calling the callback directly (not via Finish()) since we
|
|
|
|
// don't want to prune.
|
|
|
|
return mCallback(aRequest, aRequest->mProxyInfo, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
mProcessingThread = NS_GetCurrentThread();
|
|
|
|
|
|
|
|
mRequest = aRequest;
|
|
|
|
mProxyInfo = aRequest->mProxyInfo;
|
|
|
|
|
|
|
|
aRequest->mPPS->CopyFilters(mFiltersCopy);
|
|
|
|
|
|
|
|
// We want to give filters a chance to process in a single loop to prevent
|
|
|
|
// any current-thread dispatch delays when those are not needed.
|
|
|
|
// This code is rather "loopy" than "recursive" to prevent long stack traces.
|
|
|
|
do {
|
|
|
|
MOZ_ASSERT(!mProcessingInLoop);
|
|
|
|
|
|
|
|
mozilla::AutoRestore<bool> restore(mProcessingInLoop);
|
|
|
|
mProcessingInLoop = true;
|
|
|
|
|
|
|
|
nsresult rv = ProcessNextFilter();
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
} while (mFilterCalledBack);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsAsyncResolveRequest::AsyncApplyFilters::ProcessNextFilter() {
|
|
|
|
LOG(("AsyncApplyFilters::ProcessNextFilter %p ENTER pi=%p", this,
|
|
|
|
mProxyInfo.get()));
|
|
|
|
|
|
|
|
RefPtr<FilterLink> filter;
|
|
|
|
do {
|
|
|
|
mFilterCalledBack = false;
|
|
|
|
|
|
|
|
if (!mRequest) {
|
|
|
|
// We got canceled
|
|
|
|
LOG((" canceled"));
|
|
|
|
return NS_OK; // should we let the consumer know?
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mNextFilterIndex == mFiltersCopy.Length()) {
|
|
|
|
return Finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
filter = mFiltersCopy[mNextFilterIndex++];
|
|
|
|
|
|
|
|
// Loop until a call to a filter succeeded. Other option is to recurse
|
|
|
|
// but that would waste stack trace when a number of filters gets registered
|
|
|
|
// and all from some reason tend to fail.
|
|
|
|
// The !mFilterCalledBack part of the condition is there to protect us from
|
|
|
|
// calling on another filter when the current one managed to call back and
|
|
|
|
// then threw. We already have the result so take it and use it since
|
|
|
|
// the next filter will be processed by the root loop or a call to
|
|
|
|
// ProcessNextFilter has already been dispatched to this thread.
|
|
|
|
LOG((" calling filter %p pi=%p", filter.get(), mProxyInfo.get()));
|
|
|
|
} while (!mRequest->mPPS->ApplyFilter(filter, mRequest->mChannel, mInfo,
|
|
|
|
mProxyInfo, this) &&
|
|
|
|
!mFilterCalledBack);
|
|
|
|
|
|
|
|
LOG(("AsyncApplyFilters::ProcessNextFilter %p LEAVE pi=%p", this,
|
|
|
|
mProxyInfo.get()));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAsyncResolveRequest::AsyncApplyFilters::OnProxyFilterResult(
|
|
|
|
nsIProxyInfo* aProxyInfo) {
|
|
|
|
LOG(("AsyncApplyFilters::OnProxyFilterResult %p pi=%p", this, aProxyInfo));
|
|
|
|
|
|
|
|
MOZ_ASSERT(mProcessingThread && mProcessingThread->IsOnCurrentThread());
|
|
|
|
MOZ_ASSERT(!mFilterCalledBack);
|
|
|
|
|
|
|
|
if (mFilterCalledBack) {
|
|
|
|
LOG((" duplicate notification?"));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
mFilterCalledBack = true;
|
2019-07-16 17:17:57 +03:00
|
|
|
|
|
|
|
if (!mRequest) {
|
|
|
|
// We got canceled
|
|
|
|
LOG((" canceled"));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2019-07-15 23:57:57 +03:00
|
|
|
mProxyInfo = aProxyInfo;
|
2018-02-08 08:18:00 +03:00
|
|
|
|
|
|
|
if (mProcessingInLoop) {
|
|
|
|
// No need to call/dispatch ProcessNextFilter(), we are in a control
|
|
|
|
// loop that will do this for us and save recursion/dispatching.
|
|
|
|
LOG((" in a root loop"));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mNextFilterIndex == mFiltersCopy.Length()) {
|
|
|
|
// We are done, all filters have been called on!
|
|
|
|
Finish();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Redispatch, since we don't want long stacks when filters respond
|
|
|
|
// synchronously.
|
|
|
|
LOG((" redispatching"));
|
|
|
|
NS_DispatchToCurrentThread(this);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAsyncResolveRequest::AsyncApplyFilters::Run() {
|
|
|
|
LOG(("AsyncApplyFilters::Run %p", this));
|
|
|
|
|
|
|
|
MOZ_ASSERT(mProcessingThread && mProcessingThread->IsOnCurrentThread());
|
|
|
|
|
|
|
|
ProcessNextFilter();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsAsyncResolveRequest::AsyncApplyFilters::Finish() {
|
|
|
|
LOG(("AsyncApplyFilters::Finish %p pi=%p", this, mProxyInfo.get()));
|
|
|
|
|
|
|
|
MOZ_ASSERT(mRequest);
|
|
|
|
|
|
|
|
mFiltersCopy.Clear();
|
|
|
|
|
|
|
|
RefPtr<nsAsyncResolveRequest> request;
|
|
|
|
request.swap(mRequest);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIProxyInfo> pi;
|
|
|
|
pi.swap(mProxyInfo);
|
|
|
|
|
|
|
|
request->mPPS->PruneProxyInfo(mInfo, pi);
|
|
|
|
return mCallback(request, pi, !mProcessingInLoop);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAsyncResolveRequest::AsyncApplyFilters::Cancel(nsresult reason) {
|
|
|
|
LOG(("AsyncApplyFilters::Cancel %p", this));
|
|
|
|
|
|
|
|
MOZ_ASSERT(mProcessingThread && mProcessingThread->IsOnCurrentThread());
|
|
|
|
|
|
|
|
// This will be called only from inside the request, so don't call
|
|
|
|
// its's callback. Dropping the members means we simply break the cycle.
|
|
|
|
mFiltersCopy.Clear();
|
|
|
|
mProxyInfo = nullptr;
|
|
|
|
mRequest = nullptr;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2005-03-25 06:41:33 +03:00
|
|
|
|
2017-05-24 09:36:53 +03:00
|
|
|
// Bug 1366133: make GetPACURI off-main-thread since it may hang on Windows
|
|
|
|
// platform
|
|
|
|
class AsyncGetPACURIRequest final : public nsIRunnable {
|
|
|
|
public:
|
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-05-24 09:36:53 +03:00
|
|
|
using CallbackFunc = nsresult (nsProtocolProxyService::*)(bool, bool,
|
|
|
|
nsresult,
|
|
|
|
const nsACString&);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-05-24 09:36:53 +03:00
|
|
|
AsyncGetPACURIRequest(nsProtocolProxyService* aService,
|
|
|
|
CallbackFunc aCallback,
|
|
|
|
nsISystemProxySettings* aSystemProxySettings,
|
|
|
|
bool aMainThreadOnly, bool aForceReload,
|
|
|
|
bool aResetPACThread)
|
|
|
|
: mIsMainThreadOnly(aMainThreadOnly),
|
|
|
|
mService(aService),
|
|
|
|
mServiceHolder(do_QueryObject(aService)),
|
|
|
|
mCallback(aCallback),
|
|
|
|
mSystemProxySettings(aSystemProxySettings),
|
|
|
|
mForceReload(aForceReload),
|
|
|
|
mResetPACThread(aResetPACThread) {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
Unused << mIsMainThreadOnly;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2017-05-24 09:36:53 +03:00
|
|
|
|
|
|
|
NS_IMETHOD Run() override {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread() == mIsMainThreadOnly);
|
|
|
|
|
|
|
|
nsCString pacUri;
|
|
|
|
nsresult rv = mSystemProxySettings->GetPACURI(pacUri);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIRunnable> event =
|
2017-07-14 09:49:22 +03:00
|
|
|
NewNonOwningCancelableRunnableMethod<bool, bool, nsresult, nsCString>(
|
2017-06-14 04:27:17 +03:00
|
|
|
"AsyncGetPACURIRequestCallback", mService, mCallback, mForceReload,
|
|
|
|
mResetPACThread, rv, pacUri);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-05-24 09:36:53 +03:00
|
|
|
return NS_DispatchToMainThread(event);
|
|
|
|
}
|
|
|
|
|
2018-11-30 13:46:48 +03:00
|
|
|
private:
|
2017-05-24 09:36:53 +03:00
|
|
|
~AsyncGetPACURIRequest() {
|
2020-04-07 18:16:23 +03:00
|
|
|
NS_ReleaseOnMainThread("AsyncGetPACURIRequest::mServiceHolder",
|
|
|
|
mServiceHolder.forget());
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2017-05-24 09:36:53 +03:00
|
|
|
bool mIsMainThreadOnly;
|
|
|
|
|
|
|
|
nsProtocolProxyService* mService; // ref-count is hold by mServiceHolder
|
|
|
|
nsCOMPtr<nsIProtocolProxyService2> mServiceHolder;
|
|
|
|
CallbackFunc mCallback;
|
|
|
|
nsCOMPtr<nsISystemProxySettings> mSystemProxySettings;
|
|
|
|
|
|
|
|
bool mForceReload;
|
|
|
|
bool mResetPACThread;
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS(AsyncGetPACURIRequest, nsIRunnable)
|
|
|
|
|
2005-03-25 06:41:33 +03:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
2003-04-11 22:24:55 +04:00
|
|
|
//
|
|
|
|
// apply mask to address (zeros out excluded bits).
|
|
|
|
//
|
|
|
|
// NOTE: we do the byte swapping here to minimize overall swapping.
|
|
|
|
//
|
2012-08-22 19:56:38 +04:00
|
|
|
static void proxy_MaskIPv6Addr(PRIPv6Addr& addr, uint16_t mask_len) {
|
2003-04-11 22:24:55 +04:00
|
|
|
if (mask_len == 128) return;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2003-04-11 22:24:55 +04:00
|
|
|
if (mask_len > 96) {
|
|
|
|
addr.pr_s6_addr32[3] =
|
2019-09-17 23:24:42 +03:00
|
|
|
PR_htonl(PR_ntohl(addr.pr_s6_addr32[3]) & (~0uL << (128 - mask_len)));
|
2003-04-11 22:24:55 +04:00
|
|
|
} else if (mask_len > 64) {
|
|
|
|
addr.pr_s6_addr32[3] = 0;
|
|
|
|
addr.pr_s6_addr32[2] =
|
2019-09-17 23:24:42 +03:00
|
|
|
PR_htonl(PR_ntohl(addr.pr_s6_addr32[2]) & (~0uL << (96 - mask_len)));
|
2003-04-11 22:24:55 +04:00
|
|
|
} else if (mask_len > 32) {
|
|
|
|
addr.pr_s6_addr32[3] = 0;
|
|
|
|
addr.pr_s6_addr32[2] = 0;
|
|
|
|
addr.pr_s6_addr32[1] =
|
2019-09-17 23:24:42 +03:00
|
|
|
PR_htonl(PR_ntohl(addr.pr_s6_addr32[1]) & (~0uL << (64 - mask_len)));
|
2003-04-11 22:24:55 +04:00
|
|
|
} else {
|
|
|
|
addr.pr_s6_addr32[3] = 0;
|
|
|
|
addr.pr_s6_addr32[2] = 0;
|
|
|
|
addr.pr_s6_addr32[1] = 0;
|
|
|
|
addr.pr_s6_addr32[0] =
|
2019-09-17 23:24:42 +03:00
|
|
|
PR_htonl(PR_ntohl(addr.pr_s6_addr32[0]) & (~0uL << (32 - mask_len)));
|
2003-04-11 22:24:55 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-07-15 01:36:24 +04:00
|
|
|
static void proxy_GetStringPref(nsIPrefBranch* aPrefBranch, const char* aPref,
|
|
|
|
nsCString& aResult) {
|
2017-10-27 02:30:33 +03:00
|
|
|
nsAutoCString temp;
|
|
|
|
nsresult rv = aPrefBranch->GetCharPref(aPref, temp);
|
2021-06-04 15:35:16 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
2003-07-15 01:36:24 +04:00
|
|
|
aResult.Truncate();
|
2021-06-04 15:35:16 +03:00
|
|
|
} else {
|
2003-07-15 01:36:24 +04:00
|
|
|
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) {
|
|
|
|
int32_t temp;
|
2003-07-15 01:36:24 +04:00
|
|
|
nsresult rv = aPrefBranch->GetIntPref(aPref, &temp);
|
2021-06-04 15:35:16 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
2003-07-15 01:36:24 +04:00
|
|
|
aResult = -1;
|
2021-06-04 15:35:16 +03:00
|
|
|
} else {
|
2003-07-15 01:36:24 +04:00
|
|
|
aResult = temp;
|
2021-06-04 15:35:16 +03:00
|
|
|
}
|
2003-07-15 01:36:24 +04:00
|
|
|
}
|
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) {
|
|
|
|
bool temp;
|
2004-12-16 05:46:12 +03:00
|
|
|
nsresult rv = aPrefBranch->GetBoolPref(aPref, &temp);
|
2021-06-04 15:35:16 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
aResult = false;
|
2021-06-04 15:35:16 +03:00
|
|
|
} else {
|
2004-12-16 05:46:12 +03:00
|
|
|
aResult = temp;
|
2021-06-04 15:35:16 +03:00
|
|
|
}
|
2004-12-16 05:46:12 +03:00
|
|
|
}
|
|
|
|
|
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)
|
2021-02-09 12:05:45 +03:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsITimerCallback)
|
2021-09-07 11:01:18 +03:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsINamed)
|
2018-05-22 02:33:18 +03:00
|
|
|
NS_INTERFACE_MAP_ENTRY_CONCRETE(nsProtocolProxyService)
|
2015-05-20 00:15:53 +03:00
|
|
|
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, nsIProtocolProxyService,
|
|
|
|
nsIProtocolProxyService2)
|
2000-02-14 13:04:56 +03:00
|
|
|
|
2021-06-11 10:10:41 +03:00
|
|
|
nsProtocolProxyService::nsProtocolProxyService() : mSessionStart(PR_Now()) {}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
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.
|
2018-02-08 08:18:00 +03:00
|
|
|
NS_ASSERTION(mHostFiltersArray.Length() == 0 && mFilters.Length() == 0 &&
|
2012-07-30 18:20:58 +04:00
|
|
|
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-16 03:07:12 +04:00
|
|
|
nsresult nsProtocolProxyService::Init() {
|
2016-05-19 05:02:57 +03:00
|
|
|
// failure to access prefs is non-fatal
|
|
|
|
nsCOMPtr<nsIPrefBranch> prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID);
|
2014-09-05 17:29:00 +04:00
|
|
|
if (prefBranch) {
|
|
|
|
// monitor proxy prefs
|
|
|
|
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);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2016-05-19 05:02:57 +03:00
|
|
|
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
|
2015-05-05 17:04:34 +03:00
|
|
|
if (obs) {
|
2014-09-05 17:29:00 +04:00
|
|
|
// 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);
|
2015-05-05 17:04:34 +03:00
|
|
|
obs->AddObserver(this, NS_NETWORK_LINK_TOPIC, false);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
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) {
|
2017-10-27 02:30:33 +03:00
|
|
|
nsAutoCString pacSpec;
|
|
|
|
prefs->GetCharPref(PROXY_PREF("autoconfig_url"), pacSpec);
|
2014-09-05 17:29:00 +04:00
|
|
|
if (!pacSpec.IsEmpty()) {
|
|
|
|
nsCOMPtr<nsIURI> pacURI;
|
|
|
|
rv = NS_NewURI(getter_AddRefs(pacURI), pacSpec);
|
|
|
|
if (!NS_SUCCEEDED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-05 17:29:00 +04:00
|
|
|
nsProtocolInfo pac;
|
|
|
|
rv = GetProtocolInfo(pacURI, &pac);
|
|
|
|
if (!NS_SUCCEEDED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-05 17:29:00 +04:00
|
|
|
if (!pac.scheme.EqualsLiteral("file") &&
|
|
|
|
!pac.scheme.EqualsLiteral("data")) {
|
|
|
|
LOG((": received network changed event, reload PAC"));
|
|
|
|
ReloadPAC();
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2014-09-05 17:29:00 +04:00
|
|
|
}
|
|
|
|
} else if ((type == PROXYCONFIG_WPAD) || (type == PROXYCONFIG_SYSTEM)) {
|
|
|
|
ReloadPAC();
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2014-09-05 17:29:00 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-05-24 09:36:53 +03:00
|
|
|
nsresult nsProtocolProxyService::AsyncConfigureFromPAC(bool aForceReload,
|
|
|
|
bool aResetPACThread) {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
bool mainThreadOnly;
|
|
|
|
nsresult rv = mSystemProxySettings->GetMainThreadOnly(&mainThreadOnly);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIRunnable> req = new AsyncGetPACURIRequest(
|
|
|
|
this, &nsProtocolProxyService::OnAsyncGetPACURI, mSystemProxySettings,
|
|
|
|
mainThreadOnly, aForceReload, aResetPACThread);
|
|
|
|
|
|
|
|
if (mainThreadOnly) {
|
|
|
|
return req->Run();
|
|
|
|
}
|
2017-06-09 10:11:24 +03:00
|
|
|
|
2021-02-09 12:05:45 +03:00
|
|
|
return NS_DispatchBackgroundTask(req.forget(),
|
|
|
|
nsIEventTarget::DISPATCH_NORMAL);
|
2017-05-24 09:36:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsProtocolProxyService::OnAsyncGetPACURI(bool aForceReload,
|
|
|
|
bool aResetPACThread,
|
|
|
|
nsresult aResult,
|
|
|
|
const nsACString& aUri) {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
if (aResetPACThread) {
|
|
|
|
ResetPACThread();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(aResult) && !aUri.IsEmpty()) {
|
|
|
|
ConfigureFromPAC(PromiseFlatCString(aUri), aForceReload);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2014-09-05 17:29:00 +04:00
|
|
|
|
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) {
|
2005-03-25 06:41:33 +03:00
|
|
|
if (strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID) == 0) {
|
2017-04-19 15:42:09 +03:00
|
|
|
mIsShutdown = true;
|
2005-03-25 06:41:33 +03:00
|
|
|
// cleanup
|
2018-02-08 08:18:00 +03:00
|
|
|
mHostFiltersArray.Clear();
|
|
|
|
mFilters.Clear();
|
2015-05-05 17:04:34 +03:00
|
|
|
|
2018-07-11 04:02:21 +03:00
|
|
|
if (mPACMan) {
|
2005-03-25 06:41:33 +03:00
|
|
|
mPACMan->Shutdown();
|
2018-07-11 04:02:21 +03:00
|
|
|
mPACMan = nullptr;
|
2017-05-24 09:36:53 +03:00
|
|
|
}
|
|
|
|
|
2021-02-09 12:05:45 +03:00
|
|
|
if (mReloadPACTimer) {
|
|
|
|
mReloadPACTimer->Cancel();
|
|
|
|
mReloadPACTimer = nullptr;
|
2015-05-05 17:04:34 +03:00
|
|
|
}
|
|
|
|
|
2014-09-05 17:29:00 +04:00
|
|
|
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
|
|
|
|
if (obs) {
|
|
|
|
obs->RemoveObserver(this, NS_NETWORK_LINK_TOPIC);
|
|
|
|
obs->RemoveObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID);
|
2005-03-25 06:41:33 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2005-03-25 06:41:33 +03: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)) {
|
2021-02-09 12:05:45 +03:00
|
|
|
uint32_t delay = StaticPrefs::network_proxy_reload_pac_delay();
|
|
|
|
LOG(("nsProtocolProxyService::Observe call ReloadNetworkPAC() delay=%u",
|
|
|
|
delay));
|
|
|
|
|
|
|
|
if (delay) {
|
|
|
|
if (mReloadPACTimer) {
|
|
|
|
mReloadPACTimer->Cancel();
|
|
|
|
mReloadPACTimer = nullptr;
|
|
|
|
}
|
|
|
|
NS_NewTimerWithCallback(getter_AddRefs(mReloadPACTimer), this, delay,
|
|
|
|
nsITimer::TYPE_ONE_SHOT);
|
|
|
|
} else {
|
|
|
|
ReloadNetworkPAC();
|
|
|
|
}
|
2005-03-25 06:41:33 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
} else {
|
2005-03-25 06:41:33 +03:00
|
|
|
NS_ASSERTION(strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID) == 0,
|
|
|
|
"what is this random observer event?");
|
|
|
|
nsCOMPtr<nsIPrefBranch> prefs = do_QueryInterface(aSubject);
|
2006-03-30 21:31:15 +04:00
|
|
|
if (prefs) PrefsChanged(prefs, NS_LossyConvertUTF16toASCII(aData).get());
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2003-07-15 01:36:24 +04:00
|
|
|
return NS_OK;
|
2002-09-23 05:31:17 +04:00
|
|
|
}
|
|
|
|
|
2021-02-09 12:05:45 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsProtocolProxyService::Notify(nsITimer* aTimer) {
|
|
|
|
MOZ_ASSERT(aTimer == mReloadPACTimer);
|
|
|
|
ReloadNetworkPAC();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2021-09-07 11:01:18 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsProtocolProxyService::GetName(nsACString& aName) {
|
|
|
|
aName.AssignLiteral("nsProtocolProxyService");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-07-15 01:36:24 +04:00
|
|
|
void nsProtocolProxyService::PrefsChanged(nsIPrefBranch* prefBranch,
|
|
|
|
const char* pref) {
|
2000-02-14 13:04:56 +03:00
|
|
|
nsresult rv = NS_OK;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool reloadPAC = false;
|
2017-10-27 02:30:33 +03:00
|
|
|
nsAutoCString tempString;
|
2021-11-29 18:19:15 +03:00
|
|
|
auto invokeCallback =
|
|
|
|
MakeScopeExit([&] { NotifyProxyConfigChangedInternal(); });
|
2018-11-30 13:46:48 +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
|
2006-03-30 21:31:15 +04:00
|
|
|
if (!pref) prefBranch->SetIntPref(PROXY_PREF("type"), type);
|
2010-06-17 22:33:42 +04:00
|
|
|
} else if (type >= PROXYCONFIG_COUNT) {
|
2016-12-16 06:16:31 +03:00
|
|
|
LOG(("unknown proxy type: %" PRId32 "; 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);
|
2010-06-17 22:33:42 +04:00
|
|
|
if (!mSystemProxySettings) 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
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2000-02-14 13:04:56 +03:00
|
|
|
|
2021-06-04 15:35:16 +03:00
|
|
|
if (!pref || !strcmp(pref, PROXY_PREF("http"))) {
|
2006-03-30 21:31:15 +04:00
|
|
|
proxy_GetStringPref(prefBranch, PROXY_PREF("http"), mHTTPProxyHost);
|
2021-06-04 15:35:16 +03:00
|
|
|
}
|
2000-02-14 13:04:56 +03:00
|
|
|
|
2021-06-04 15:35:16 +03:00
|
|
|
if (!pref || !strcmp(pref, PROXY_PREF("http_port"))) {
|
2006-03-30 21:31:15 +04:00
|
|
|
proxy_GetIntPref(prefBranch, PROXY_PREF("http_port"), mHTTPProxyPort);
|
2021-06-04 15:35:16 +03:00
|
|
|
}
|
2000-02-14 13:04:56 +03:00
|
|
|
|
2021-06-04 15:35:16 +03:00
|
|
|
if (!pref || !strcmp(pref, PROXY_PREF("ssl"))) {
|
2006-03-30 21:31:15 +04:00
|
|
|
proxy_GetStringPref(prefBranch, PROXY_PREF("ssl"), mHTTPSProxyHost);
|
2021-06-04 15:35:16 +03:00
|
|
|
}
|
2000-04-22 04:35:05 +04:00
|
|
|
|
2021-06-04 15:35:16 +03:00
|
|
|
if (!pref || !strcmp(pref, PROXY_PREF("ssl_port"))) {
|
2006-03-30 21:31:15 +04:00
|
|
|
proxy_GetIntPref(prefBranch, PROXY_PREF("ssl_port"), mHTTPSProxyPort);
|
2021-06-04 15:35:16 +03:00
|
|
|
}
|
2000-04-22 04:35:05 +04:00
|
|
|
|
2021-06-04 15:35:16 +03:00
|
|
|
if (!pref || !strcmp(pref, PROXY_PREF("socks"))) {
|
2016-06-30 06:23:40 +03:00
|
|
|
proxy_GetStringPref(prefBranch, PROXY_PREF("socks"), mSOCKSProxyTarget);
|
2021-06-04 15:35:16 +03:00
|
|
|
}
|
2014-09-05 17:29:00 +04:00
|
|
|
|
2021-06-04 15:35:16 +03:00
|
|
|
if (!pref || !strcmp(pref, PROXY_PREF("socks_port"))) {
|
2006-03-30 21:31:15 +04:00
|
|
|
proxy_GetIntPref(prefBranch, PROXY_PREF("socks_port"), mSOCKSProxyPort);
|
2021-06-04 15:35:16 +03:00
|
|
|
}
|
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
|
2021-06-04 15:35:16 +03:00
|
|
|
if (version == 5) {
|
2002-09-23 05:31:17 +04:00
|
|
|
mSOCKSProxyVersion = 5;
|
2021-06-04 15:35:16 +03:00
|
|
|
} else {
|
2002-09-23 05:31:17 +04:00
|
|
|
mSOCKSProxyVersion = 4;
|
2021-06-04 15:35:16 +03:00
|
|
|
}
|
2001-07-25 04:28:28 +04:00
|
|
|
}
|
|
|
|
|
2021-06-04 15:35:16 +03:00
|
|
|
if (!pref || !strcmp(pref, PROXY_PREF("socks_remote_dns"))) {
|
2006-03-30 21:31:15 +04:00
|
|
|
proxy_GetBoolPref(prefBranch, PROXY_PREF("socks_remote_dns"),
|
|
|
|
mSOCKSProxyRemoteDNS);
|
2021-06-04 15:35:16 +03:00
|
|
|
}
|
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);
|
|
|
|
}
|
|
|
|
|
Bug 356831 - Proxy autodiscovery doesn't check DHCP (option 252) r=bagder,valentin
This patch addresses an issue with Firefox's proxy detection on networks which
do not have their a proxy auto-configuration (PAC) file hosted at
http://wpad/wpad.dat, and instead make use of DHCP option 252 for broadcasting
the address of the PAC file. See https://findproxyforurl.com/wpad-introduction/
for an introduction to the protocol.
Prior to this patch, proxy auto-detect missed out the DHCP query stage, and just
looked for a PAC file at http://wpad/wpad.dat
This patch only addresses the issue for Firefox on Windows, although it defines a
DHCP client interface which could be implemented on other platforms.
The high-level components of this patch are:
* nsIDHCPClient.idl - this is an interface which has been defined for querying the
DHCP server.
* nsPACMan.cpp - where previously when the PAC URL was simply set to a constant of
http://wpad/wpad.dat, it now dispatches an asynchronous command to the proxy
thread. The class ExecutePACThreadAction has been augmented to include an
instruction to 'ConfigureWPAD' (Configure Web-proxy auto-detect), and a new class,
'ConfigureWPADComplete' has been created to relay the result (the URL of the PAC
file) back to the nsPACMan object.
* nsProtocolProxyService.cpp
Minor changes to reflect the fact that the PAC URL not being set does not always
mean there is no PAC to be used; instead it could be in the process of being
detected.
* TestPACMan.cpp
This is a new file, and tests only the DHCP auto-detect functionality.
Some tests use multiple threads, as they test the non-blocking proxy detection.
* DHCPUtils.cpp
A class containing the main logic for querying DHCP.
* WindowsNetworkFunctionsWrapper.cpp
A very thin wrapper around the Windows API calls needed by DHCPUtils.
This class was introduced so it could be mocked out in tests.
* nsWindowsDHCPClient.cpp
* An implementation of the interface defined in nsIDHCPClient.idl. Fairly thin:
most logic is implemented in DHCPUtils.
* TestDHCPUtils.cpp
Tests for DHCPUtils and nsWindowsDHCPClient
MozReview-Commit-ID: 4xFQz3tOLEx
--HG--
extra : rebase_source : dfd5c588406a8b0d92f91cc8a0038ca722b7140a
2018-06-08 01:07:28 +03:00
|
|
|
if (!pref || !strcmp(pref, PROXY_PREF("enable_wpad_over_dhcp"))) {
|
|
|
|
proxy_GetBoolPref(prefBranch, PROXY_PREF("enable_wpad_over_dhcp"),
|
|
|
|
mWPADOverDHCPEnabled);
|
|
|
|
reloadPAC = reloadPAC || mProxyConfig == PROXYCONFIG_WPAD;
|
|
|
|
}
|
|
|
|
|
2021-06-04 15:35:16 +03:00
|
|
|
if (!pref || !strcmp(pref, PROXY_PREF("failover_timeout"))) {
|
2006-03-30 21:31:15 +04:00
|
|
|
proxy_GetIntPref(prefBranch, PROXY_PREF("failover_timeout"),
|
|
|
|
mFailedProxyTimeout);
|
2021-06-04 15:35:16 +03:00
|
|
|
}
|
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"))) {
|
2017-10-27 02:30:33 +03:00
|
|
|
rv = prefBranch->GetCharPref(PROXY_PREF("no_proxies_on"), tempString);
|
2017-03-20 22:21:15 +03:00
|
|
|
if (NS_SUCCEEDED(rv)) LoadHostFilters(tempString);
|
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 &&
|
2021-06-04 15:35:16 +03:00
|
|
|
mProxyConfig != PROXYCONFIG_SYSTEM) {
|
2005-03-25 06:41:33 +03:00
|
|
|
return;
|
2021-06-04 15:35:16 +03:00
|
|
|
}
|
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
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2006-03-30 21:31:15 +04:00
|
|
|
if (!pref || !strcmp(pref, PROXY_PREF("autoconfig_url"))) reloadPAC = true;
|
2018-11-30 13:46:48 +03: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) {
|
2017-10-27 02:30:33 +03:00
|
|
|
prefBranch->GetCharPref(PROXY_PREF("autoconfig_url"), 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) {
|
Bug 356831 - Proxy autodiscovery doesn't check DHCP (option 252) r=bagder,valentin
This patch addresses an issue with Firefox's proxy detection on networks which
do not have their a proxy auto-configuration (PAC) file hosted at
http://wpad/wpad.dat, and instead make use of DHCP option 252 for broadcasting
the address of the PAC file. See https://findproxyforurl.com/wpad-introduction/
for an introduction to the protocol.
Prior to this patch, proxy auto-detect missed out the DHCP query stage, and just
looked for a PAC file at http://wpad/wpad.dat
This patch only addresses the issue for Firefox on Windows, although it defines a
DHCP client interface which could be implemented on other platforms.
The high-level components of this patch are:
* nsIDHCPClient.idl - this is an interface which has been defined for querying the
DHCP server.
* nsPACMan.cpp - where previously when the PAC URL was simply set to a constant of
http://wpad/wpad.dat, it now dispatches an asynchronous command to the proxy
thread. The class ExecutePACThreadAction has been augmented to include an
instruction to 'ConfigureWPAD' (Configure Web-proxy auto-detect), and a new class,
'ConfigureWPADComplete' has been created to relay the result (the URL of the PAC
file) back to the nsPACMan object.
* nsProtocolProxyService.cpp
Minor changes to reflect the fact that the PAC URL not being set does not always
mean there is no PAC to be used; instead it could be in the process of being
detected.
* TestPACMan.cpp
This is a new file, and tests only the DHCP auto-detect functionality.
Some tests use multiple threads, as they test the non-blocking proxy detection.
* DHCPUtils.cpp
A class containing the main logic for querying DHCP.
* WindowsNetworkFunctionsWrapper.cpp
A very thin wrapper around the Windows API calls needed by DHCPUtils.
This class was introduced so it could be mocked out in tests.
* nsWindowsDHCPClient.cpp
* An implementation of the interface defined in nsIDHCPClient.idl. Fairly thin:
most logic is implemented in DHCPUtils.
* TestDHCPUtils.cpp
Tests for DHCPUtils and nsWindowsDHCPClient
MozReview-Commit-ID: 4xFQz3tOLEx
--HG--
extra : rebase_source : dfd5c588406a8b0d92f91cc8a0038ca722b7140a
2018-06-08 01:07:28 +03:00
|
|
|
LOG(("Auto-detecting proxy - Reset Pac Thread"));
|
|
|
|
ResetPACThread();
|
2008-03-08 12:58:17 +03:00
|
|
|
} else if (mSystemProxySettings) {
|
|
|
|
// Get System Proxy settings if available
|
2017-05-24 09:36:53 +03:00
|
|
|
AsyncConfigureFromPAC(false, false);
|
2005-03-25 06:41:33 +03:00
|
|
|
}
|
Bug 356831 - Proxy autodiscovery doesn't check DHCP (option 252) r=bagder,valentin
This patch addresses an issue with Firefox's proxy detection on networks which
do not have their a proxy auto-configuration (PAC) file hosted at
http://wpad/wpad.dat, and instead make use of DHCP option 252 for broadcasting
the address of the PAC file. See https://findproxyforurl.com/wpad-introduction/
for an introduction to the protocol.
Prior to this patch, proxy auto-detect missed out the DHCP query stage, and just
looked for a PAC file at http://wpad/wpad.dat
This patch only addresses the issue for Firefox on Windows, although it defines a
DHCP client interface which could be implemented on other platforms.
The high-level components of this patch are:
* nsIDHCPClient.idl - this is an interface which has been defined for querying the
DHCP server.
* nsPACMan.cpp - where previously when the PAC URL was simply set to a constant of
http://wpad/wpad.dat, it now dispatches an asynchronous command to the proxy
thread. The class ExecutePACThreadAction has been augmented to include an
instruction to 'ConfigureWPAD' (Configure Web-proxy auto-detect), and a new class,
'ConfigureWPADComplete' has been created to relay the result (the URL of the PAC
file) back to the nsPACMan object.
* nsProtocolProxyService.cpp
Minor changes to reflect the fact that the PAC URL not being set does not always
mean there is no PAC to be used; instead it could be in the process of being
detected.
* TestPACMan.cpp
This is a new file, and tests only the DHCP auto-detect functionality.
Some tests use multiple threads, as they test the non-blocking proxy detection.
* DHCPUtils.cpp
A class containing the main logic for querying DHCP.
* WindowsNetworkFunctionsWrapper.cpp
A very thin wrapper around the Windows API calls needed by DHCPUtils.
This class was introduced so it could be mocked out in tests.
* nsWindowsDHCPClient.cpp
* An implementation of the interface defined in nsIDHCPClient.idl. Fairly thin:
most logic is implemented in DHCPUtils.
* TestDHCPUtils.cpp
Tests for DHCPUtils and nsWindowsDHCPClient
MozReview-Commit-ID: 4xFQz3tOLEx
--HG--
extra : rebase_source : dfd5c588406a8b0d92f91cc8a0038ca722b7140a
2018-06-08 01:07:28 +03:00
|
|
|
if (!tempString.IsEmpty() || mProxyConfig == PROXYCONFIG_WPAD) {
|
2018-04-30 16:34:39 +03:00
|
|
|
ConfigureFromPAC(tempString, false);
|
2001-04-17 06:34:47 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2000-02-14 13:04:56 +03:00
|
|
|
}
|
|
|
|
|
2014-09-05 17:29:00 +04:00
|
|
|
bool nsProtocolProxyService::CanUseProxy(nsIURI* aURI, int32_t defaultPort) {
|
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()) 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)) return false;
|
|
|
|
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
|
2000-02-14 13:04:56 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +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)
|
2017-02-08 10:10:02 +03:00
|
|
|
if ((!is_ipaddr && mFilterLocalHosts && !host.Contains('.')) ||
|
2020-10-22 10:36:15 +03:00
|
|
|
// This method detects if we have network.proxy.allow_hijacking_localhost
|
|
|
|
// pref enabled. If it's true then this method will always return false
|
|
|
|
// otherwise it returns true if the host matches an address that's
|
|
|
|
// hardcoded to the loopback address.
|
|
|
|
(!StaticPrefs::network_proxy_allow_hijacking_localhost() &&
|
|
|
|
nsMixedContentBlocker::IsPotentiallyTrustworthyLoopbackHost(host))) {
|
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())) {
|
2020-02-11 19:20:08 +03:00
|
|
|
const auto& 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);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2003-04-11 22:24:55 +04:00
|
|
|
// check for a match
|
2021-06-04 15:35:16 +03:00
|
|
|
if (memcmp(&masked, &hinfo->ip.addr, sizeof(PRIPv6Addr)) == 0) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false; // proxy disallowed
|
2021-06-04 15:35:16 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03: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;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2003-04-11 22:24:55 +04:00
|
|
|
if (host_len >= filter_host_len) {
|
2018-11-30 13:46:48 +03:00
|
|
|
//
|
2003-04-11 22:24:55 +04:00
|
|
|
// compare last |filter_host_len| bytes of target hostname.
|
2018-11-30 13:46:48 +03:00
|
|
|
//
|
2003-04-11 22:24:55 +04:00
|
|
|
const char* host_tail = host.get() + host_len - filter_host_len;
|
2021-05-05 21:09:28 +03:00
|
|
|
if (!nsCRT::strncasecmp(host_tail, hinfo->name.host, filter_host_len)) {
|
2015-10-21 04:05:00 +03:00
|
|
|
// If the tail of the host string matches the filter
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-10-21 04:05:00 +03:00
|
|
|
if (filter_host_len > 0 && hinfo->name.host[0] == '.') {
|
|
|
|
// If the filter was of the form .foo.bar.tld, all such
|
|
|
|
// matches are correct
|
2011-10-17 18:59:28 +04:00
|
|
|
return false; // proxy disallowed
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2003-04-11 22:24:55 +04:00
|
|
|
|
|
|
|
// abc-def.example.org should not match def.example.org
|
2015-10-21 04:05:00 +03:00
|
|
|
// however, *.def.example.org should match .def.example.org
|
2003-04-11 22:24:55 +04:00
|
|
|
// 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) == '.') {
|
2015-10-21 04:05:00 +03:00
|
|
|
// 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
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-10-21 04:05:00 +03:00
|
|
|
if (host_len == filter_host_len) {
|
|
|
|
// If the host and filter are of the same length,
|
|
|
|
// they should match
|
|
|
|
return false; // proxy disallowed
|
|
|
|
}
|
2000-02-14 13:04:56 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2000-02-14 13:04:56 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +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
|
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";
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2011-05-13 21:53:27 +04:00
|
|
|
const char* 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) {
|
2012-07-30 18:20:58 +04:00
|
|
|
*result = nullptr;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t flags = 0;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-09-15 00:27:46 +04:00
|
|
|
// see BNF in ProxyAutoConfig.h and notes in nsISystemProxySettings.idl
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2003-04-16 03:07:12 +04:00
|
|
|
// find end of proxy info delimiter
|
|
|
|
const char* end = start;
|
|
|
|
while (*end && *end != ';') ++end;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2003-04-16 03:07:12 +04:00
|
|
|
// find end of proxy type delimiter
|
|
|
|
const char* sp = start;
|
|
|
|
while (sp < end && *sp != ' ' && *sp != '\t') ++sp;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
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:
|
2021-05-05 21:09:28 +03:00
|
|
|
if (nsCRT::strncasecmp(start, kProxyType_HTTP, 4) == 0) {
|
2014-04-16 02:16:41 +04:00
|
|
|
type = kProxyType_HTTP;
|
|
|
|
}
|
|
|
|
break;
|
2003-04-16 03:07:12 +04:00
|
|
|
case 5:
|
2021-05-05 21:09:28 +03:00
|
|
|
if (nsCRT::strncasecmp(start, kProxyType_PROXY, 5) == 0) {
|
2003-04-16 03:07:12 +04:00
|
|
|
type = kProxyType_HTTP;
|
2021-05-05 21:09:28 +03:00
|
|
|
} else if (nsCRT::strncasecmp(start, kProxyType_SOCKS, 5) == 0) {
|
2003-04-16 03:07:12 +04:00
|
|
|
type = kProxyType_SOCKS4; // assume v4 for 4x compat
|
2021-06-02 11:05:23 +03:00
|
|
|
if (StaticPrefs::network_proxy_default_pac_script_socks_version() ==
|
|
|
|
5) {
|
|
|
|
type = kProxyType_SOCKS;
|
|
|
|
}
|
2021-05-05 21:09:28 +03:00
|
|
|
} else if (nsCRT::strncasecmp(start, kProxyType_HTTPS, 5) == 0) {
|
2014-04-16 02:16:41 +04:00
|
|
|
type = kProxyType_HTTPS;
|
|
|
|
}
|
2003-04-16 03:07:12 +04:00
|
|
|
break;
|
|
|
|
case 6:
|
2021-06-04 15:35:16 +03:00
|
|
|
if (nsCRT::strncasecmp(start, kProxyType_DIRECT, 6) == 0) {
|
2003-04-16 03:07:12 +04:00
|
|
|
type = kProxyType_DIRECT;
|
2021-06-04 15:35:16 +03:00
|
|
|
} else if (nsCRT::strncasecmp(start, kProxyType_SOCKS4, 6) == 0) {
|
2003-04-16 03:07:12 +04:00
|
|
|
type = kProxyType_SOCKS4;
|
2021-06-04 15:35:16 +03:00
|
|
|
} else if (nsCRT::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;
|
2021-06-04 15:35:16 +03:00
|
|
|
}
|
2003-04-16 03:07:12 +04:00
|
|
|
break;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2003-04-16 03:07:12 +04:00
|
|
|
if (type) {
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t port = -1;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
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.
|
2021-06-04 15:35:16 +03:00
|
|
|
if (type == kProxyType_SOCKS || mSOCKSProxyRemoteDNS) {
|
2004-12-16 05:46:12 +03:00
|
|
|
flags |= nsIProxyInfo::TRANSPARENT_PROXY_RESOLVES_HOST;
|
2021-06-04 15:35:16 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2003-04-16 03:07:12 +04:00
|
|
|
// extract host:port
|
|
|
|
start = sp;
|
|
|
|
while ((*start == ' ' || *start == '\t') && start < end) start++;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
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;
|
2018-11-30 13:46:48 +03:00
|
|
|
} else {
|
2012-09-15 00:27:46 +04:00
|
|
|
port = 1080;
|
2003-04-16 03:07:12 +04:00
|
|
|
}
|
2012-09-15 00:27:46 +04:00
|
|
|
|
2020-03-17 18:05:26 +03:00
|
|
|
RefPtr<nsProxyInfo> pi = new nsProxyInfo();
|
2012-09-15 00:27:46 +04:00
|
|
|
pi->mType = type;
|
|
|
|
pi->mFlags = flags;
|
|
|
|
pi->mResolveFlags = aResolveFlags;
|
|
|
|
pi->mTimeout = mFailedProxyTimeout;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-09-15 00:27:46 +04:00
|
|
|
// www.foo.com:8080 and http://www.foo.com:8080
|
|
|
|
nsDependentCSubstring maybeURL(start, end - start);
|
|
|
|
nsCOMPtr<nsIURI> pacURI;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-09-15 00:27:46 +04:00
|
|
|
nsAutoCString urlHost;
|
2019-10-02 15:32:39 +03:00
|
|
|
// First assume the scheme is present, e.g. http://www.example.com:8080
|
|
|
|
if (NS_FAILED(NS_NewURI(getter_AddRefs(pacURI), maybeURL)) ||
|
|
|
|
NS_FAILED(pacURI->GetAsciiHost(urlHost)) || urlHost.IsEmpty()) {
|
|
|
|
// It isn't, assume www.example.com:8080
|
|
|
|
maybeURL.Insert("http://", 0);
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(NS_NewURI(getter_AddRefs(pacURI), maybeURL))) {
|
|
|
|
pacURI->GetAsciiHost(urlHost);
|
|
|
|
}
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-10-02 15:32:39 +03:00
|
|
|
if (!urlHost.IsEmpty()) {
|
2012-09-15 00:27:46 +04:00
|
|
|
pi->mHost = urlHost;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-09-15 00:27:46 +04:00
|
|
|
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
|
|
|
}
|
2019-10-02 15:32:39 +03:00
|
|
|
|
2020-03-17 18:05:26 +03:00
|
|
|
pi.forget(result);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
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
|
|
|
|
|
|
|
uint32_t 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.
|
2021-02-26 12:11:46 +03:00
|
|
|
mFailedProxies.InsertOrUpdate(key, dsec);
|
2004-07-02 03:31:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool 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)) return false;
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2017-07-05 01:48:00 +03:00
|
|
|
nsresult nsProtocolProxyService::SetupPACThread(
|
2020-06-22 14:13:24 +03:00
|
|
|
nsISerialEventTarget* mainThreadEventTarget) {
|
2017-04-19 15:42:09 +03:00
|
|
|
if (mIsShutdown) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2012-09-15 00:27:46 +04:00
|
|
|
if (mPACMan) return NS_OK;
|
|
|
|
|
2017-07-05 01:48:00 +03:00
|
|
|
mPACMan = new nsPACMan(mainThreadEventTarget);
|
2012-09-15 00:27:46 +04:00
|
|
|
|
|
|
|
bool mainThreadOnly;
|
|
|
|
nsresult rv;
|
|
|
|
if (mSystemProxySettings &&
|
|
|
|
NS_SUCCEEDED(mSystemProxySettings->GetMainThreadOnly(&mainThreadOnly)) &&
|
|
|
|
!mainThreadOnly) {
|
|
|
|
rv = mPACMan->Init(mSystemProxySettings);
|
|
|
|
} else {
|
|
|
|
rv = mPACMan->Init(nullptr);
|
|
|
|
}
|
2017-12-01 10:10:36 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
2018-04-30 16:34:39 +03:00
|
|
|
mPACMan->Shutdown();
|
2012-09-15 00:27:46 +04:00
|
|
|
mPACMan = nullptr;
|
2017-12-01 10:10:36 +03:00
|
|
|
}
|
2012-09-15 00:27:46 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsProtocolProxyService::ResetPACThread() {
|
|
|
|
if (!mPACMan) return NS_OK;
|
|
|
|
|
|
|
|
mPACMan->Shutdown();
|
|
|
|
mPACMan = nullptr;
|
|
|
|
return SetupPACThread();
|
|
|
|
}
|
|
|
|
|
2008-05-08 13:05:11 +04:00
|
|
|
nsresult nsProtocolProxyService::ConfigureFromPAC(const nsCString& spec,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool forceReload) {
|
2017-04-19 15:42:09 +03:00
|
|
|
nsresult rv = SetupPACThread();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2006-03-30 21:31:15 +04:00
|
|
|
|
Bug 356831 - Proxy autodiscovery doesn't check DHCP (option 252) r=bagder,valentin
This patch addresses an issue with Firefox's proxy detection on networks which
do not have their a proxy auto-configuration (PAC) file hosted at
http://wpad/wpad.dat, and instead make use of DHCP option 252 for broadcasting
the address of the PAC file. See https://findproxyforurl.com/wpad-introduction/
for an introduction to the protocol.
Prior to this patch, proxy auto-detect missed out the DHCP query stage, and just
looked for a PAC file at http://wpad/wpad.dat
This patch only addresses the issue for Firefox on Windows, although it defines a
DHCP client interface which could be implemented on other platforms.
The high-level components of this patch are:
* nsIDHCPClient.idl - this is an interface which has been defined for querying the
DHCP server.
* nsPACMan.cpp - where previously when the PAC URL was simply set to a constant of
http://wpad/wpad.dat, it now dispatches an asynchronous command to the proxy
thread. The class ExecutePACThreadAction has been augmented to include an
instruction to 'ConfigureWPAD' (Configure Web-proxy auto-detect), and a new class,
'ConfigureWPADComplete' has been created to relay the result (the URL of the PAC
file) back to the nsPACMan object.
* nsProtocolProxyService.cpp
Minor changes to reflect the fact that the PAC URL not being set does not always
mean there is no PAC to be used; instead it could be in the process of being
detected.
* TestPACMan.cpp
This is a new file, and tests only the DHCP auto-detect functionality.
Some tests use multiple threads, as they test the non-blocking proxy detection.
* DHCPUtils.cpp
A class containing the main logic for querying DHCP.
* WindowsNetworkFunctionsWrapper.cpp
A very thin wrapper around the Windows API calls needed by DHCPUtils.
This class was introduced so it could be mocked out in tests.
* nsWindowsDHCPClient.cpp
* An implementation of the interface defined in nsIDHCPClient.idl. Fairly thin:
most logic is implemented in DHCPUtils.
* TestDHCPUtils.cpp
Tests for DHCPUtils and nsWindowsDHCPClient
MozReview-Commit-ID: 4xFQz3tOLEx
--HG--
extra : rebase_source : dfd5c588406a8b0d92f91cc8a0038ca722b7140a
2018-06-08 01:07:28 +03:00
|
|
|
bool autodetect = spec.IsEmpty();
|
|
|
|
if (!forceReload && ((!autodetect && mPACMan->IsPACURI(spec)) ||
|
|
|
|
(autodetect && mPACMan->IsUsingWPAD()))) {
|
2008-01-29 21:38:15 +03:00
|
|
|
return NS_OK;
|
Bug 356831 - Proxy autodiscovery doesn't check DHCP (option 252) r=bagder,valentin
This patch addresses an issue with Firefox's proxy detection on networks which
do not have their a proxy auto-configuration (PAC) file hosted at
http://wpad/wpad.dat, and instead make use of DHCP option 252 for broadcasting
the address of the PAC file. See https://findproxyforurl.com/wpad-introduction/
for an introduction to the protocol.
Prior to this patch, proxy auto-detect missed out the DHCP query stage, and just
looked for a PAC file at http://wpad/wpad.dat
This patch only addresses the issue for Firefox on Windows, although it defines a
DHCP client interface which could be implemented on other platforms.
The high-level components of this patch are:
* nsIDHCPClient.idl - this is an interface which has been defined for querying the
DHCP server.
* nsPACMan.cpp - where previously when the PAC URL was simply set to a constant of
http://wpad/wpad.dat, it now dispatches an asynchronous command to the proxy
thread. The class ExecutePACThreadAction has been augmented to include an
instruction to 'ConfigureWPAD' (Configure Web-proxy auto-detect), and a new class,
'ConfigureWPADComplete' has been created to relay the result (the URL of the PAC
file) back to the nsPACMan object.
* nsProtocolProxyService.cpp
Minor changes to reflect the fact that the PAC URL not being set does not always
mean there is no PAC to be used; instead it could be in the process of being
detected.
* TestPACMan.cpp
This is a new file, and tests only the DHCP auto-detect functionality.
Some tests use multiple threads, as they test the non-blocking proxy detection.
* DHCPUtils.cpp
A class containing the main logic for querying DHCP.
* WindowsNetworkFunctionsWrapper.cpp
A very thin wrapper around the Windows API calls needed by DHCPUtils.
This class was introduced so it could be mocked out in tests.
* nsWindowsDHCPClient.cpp
* An implementation of the interface defined in nsIDHCPClient.idl. Fairly thin:
most logic is implemented in DHCPUtils.
* TestDHCPUtils.cpp
Tests for DHCPUtils and nsWindowsDHCPClient
MozReview-Commit-ID: 4xFQz3tOLEx
--HG--
extra : rebase_source : dfd5c588406a8b0d92f91cc8a0038ca722b7140a
2018-06-08 01:07:28 +03:00
|
|
|
}
|
2008-01-29 21:38:15 +03:00
|
|
|
|
|
|
|
mFailedProxies.Clear();
|
|
|
|
|
Bug 356831 - Proxy autodiscovery doesn't check DHCP (option 252) r=bagder,valentin
This patch addresses an issue with Firefox's proxy detection on networks which
do not have their a proxy auto-configuration (PAC) file hosted at
http://wpad/wpad.dat, and instead make use of DHCP option 252 for broadcasting
the address of the PAC file. See https://findproxyforurl.com/wpad-introduction/
for an introduction to the protocol.
Prior to this patch, proxy auto-detect missed out the DHCP query stage, and just
looked for a PAC file at http://wpad/wpad.dat
This patch only addresses the issue for Firefox on Windows, although it defines a
DHCP client interface which could be implemented on other platforms.
The high-level components of this patch are:
* nsIDHCPClient.idl - this is an interface which has been defined for querying the
DHCP server.
* nsPACMan.cpp - where previously when the PAC URL was simply set to a constant of
http://wpad/wpad.dat, it now dispatches an asynchronous command to the proxy
thread. The class ExecutePACThreadAction has been augmented to include an
instruction to 'ConfigureWPAD' (Configure Web-proxy auto-detect), and a new class,
'ConfigureWPADComplete' has been created to relay the result (the URL of the PAC
file) back to the nsPACMan object.
* nsProtocolProxyService.cpp
Minor changes to reflect the fact that the PAC URL not being set does not always
mean there is no PAC to be used; instead it could be in the process of being
detected.
* TestPACMan.cpp
This is a new file, and tests only the DHCP auto-detect functionality.
Some tests use multiple threads, as they test the non-blocking proxy detection.
* DHCPUtils.cpp
A class containing the main logic for querying DHCP.
* WindowsNetworkFunctionsWrapper.cpp
A very thin wrapper around the Windows API calls needed by DHCPUtils.
This class was introduced so it could be mocked out in tests.
* nsWindowsDHCPClient.cpp
* An implementation of the interface defined in nsIDHCPClient.idl. Fairly thin:
most logic is implemented in DHCPUtils.
* TestDHCPUtils.cpp
Tests for DHCPUtils and nsWindowsDHCPClient
MozReview-Commit-ID: 4xFQz3tOLEx
--HG--
extra : rebase_source : dfd5c588406a8b0d92f91cc8a0038ca722b7140a
2018-06-08 01:07:28 +03:00
|
|
|
mPACMan->SetWPADOverDHCPEnabled(mWPADOverDHCPEnabled);
|
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) {
|
|
|
|
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;
|
2021-06-04 15:35:16 +03:00
|
|
|
} else {
|
2005-03-25 06:41:33 +03:00
|
|
|
first = pi;
|
2021-06-04 15:35:16 +03:00
|
|
|
}
|
2005-03-25 06:41:33 +03:00
|
|
|
last = pi;
|
2004-07-02 03:31:47 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03: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;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
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;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-10-27 02:30:33 +03:00
|
|
|
nsAutoCString pacSpec;
|
2021-06-04 15:35:16 +03:00
|
|
|
if (type == PROXYCONFIG_PAC) {
|
2017-10-27 02:30:33 +03:00
|
|
|
prefs->GetCharPref(PROXY_PREF("autoconfig_url"), pacSpec);
|
2021-06-04 15:35:16 +03:00
|
|
|
} else if (type == PROXYCONFIG_SYSTEM) {
|
2017-05-24 09:36:53 +03:00
|
|
|
if (mSystemProxySettings) {
|
|
|
|
AsyncConfigureFromPAC(true, true);
|
|
|
|
} else {
|
|
|
|
ResetPACThread();
|
2017-03-15 10:21:00 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2006-03-30 21:31:15 +04:00
|
|
|
|
2021-06-04 15:35:16 +03:00
|
|
|
if (!pacSpec.IsEmpty() || type == PROXYCONFIG_WPAD) {
|
2011-10-17 18:59:28 +04:00
|
|
|
ConfigureFromPAC(pacSpec, true);
|
2021-06-04 15:35:16 +03:00
|
|
|
}
|
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 {
|
2013-07-19 06:24:13 +04:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-09-15 00:27:46 +04:00
|
|
|
nsAsyncBridgeRequest()
|
|
|
|
: mMutex("nsDeprecatedCallback"),
|
2021-06-11 10:10:41 +03:00
|
|
|
mCondVar(mMutex, "nsDeprecatedCallback") {}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-09-15 00:27:46 +04:00
|
|
|
void OnQueryComplete(nsresult status, const nsACString& pacString,
|
Bug 356831 - Proxy autodiscovery doesn't check DHCP (option 252) r=bagder,valentin
This patch addresses an issue with Firefox's proxy detection on networks which
do not have their a proxy auto-configuration (PAC) file hosted at
http://wpad/wpad.dat, and instead make use of DHCP option 252 for broadcasting
the address of the PAC file. See https://findproxyforurl.com/wpad-introduction/
for an introduction to the protocol.
Prior to this patch, proxy auto-detect missed out the DHCP query stage, and just
looked for a PAC file at http://wpad/wpad.dat
This patch only addresses the issue for Firefox on Windows, although it defines a
DHCP client interface which could be implemented on other platforms.
The high-level components of this patch are:
* nsIDHCPClient.idl - this is an interface which has been defined for querying the
DHCP server.
* nsPACMan.cpp - where previously when the PAC URL was simply set to a constant of
http://wpad/wpad.dat, it now dispatches an asynchronous command to the proxy
thread. The class ExecutePACThreadAction has been augmented to include an
instruction to 'ConfigureWPAD' (Configure Web-proxy auto-detect), and a new class,
'ConfigureWPADComplete' has been created to relay the result (the URL of the PAC
file) back to the nsPACMan object.
* nsProtocolProxyService.cpp
Minor changes to reflect the fact that the PAC URL not being set does not always
mean there is no PAC to be used; instead it could be in the process of being
detected.
* TestPACMan.cpp
This is a new file, and tests only the DHCP auto-detect functionality.
Some tests use multiple threads, as they test the non-blocking proxy detection.
* DHCPUtils.cpp
A class containing the main logic for querying DHCP.
* WindowsNetworkFunctionsWrapper.cpp
A very thin wrapper around the Windows API calls needed by DHCPUtils.
This class was introduced so it could be mocked out in tests.
* nsWindowsDHCPClient.cpp
* An implementation of the interface defined in nsIDHCPClient.idl. Fairly thin:
most logic is implemented in DHCPUtils.
* TestDHCPUtils.cpp
Tests for DHCPUtils and nsWindowsDHCPClient
MozReview-Commit-ID: 4xFQz3tOLEx
--HG--
extra : rebase_source : dfd5c588406a8b0d92f91cc8a0038ca722b7140a
2018-06-08 01:07:28 +03:00
|
|
|
const nsACString& 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(); }
|
2018-02-09 23:17:26 +03:00
|
|
|
void Wait() { mCondVar.Wait(TimeDuration::FromSeconds(3)); }
|
2012-09-15 00:27:46 +04:00
|
|
|
|
|
|
|
private:
|
2018-04-30 19:46:04 +03:00
|
|
|
~nsAsyncBridgeRequest() = default;
|
2012-09-15 00:27:46 +04:00
|
|
|
|
|
|
|
friend class nsProtocolProxyService;
|
|
|
|
|
|
|
|
Mutex mMutex;
|
|
|
|
CondVar mCondVar;
|
|
|
|
|
2021-06-11 10:10:41 +03:00
|
|
|
nsresult mStatus{NS_OK};
|
2012-09-15 00:27:46 +04:00
|
|
|
nsCString mPACString;
|
|
|
|
nsCString mPACURL;
|
2021-06-11 10:10:41 +03:00
|
|
|
bool mCompleted{false};
|
2012-09-15 00:27:46 +04:00
|
|
|
};
|
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
|
|
|
nsresult nsProtocolProxyService::AsyncResolveInternal(
|
2013-06-28 01:02:04 +04:00
|
|
|
nsIChannel* channel, uint32_t flags, nsIProtocolProxyCallback* callback,
|
|
|
|
nsICancelable** result, bool isSyncOK,
|
2020-06-22 14:13:24 +03:00
|
|
|
nsISerialEventTarget* mainThreadEventTarget) {
|
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;
|
|
|
|
|
2013-06-28 01:02:04 +04:00
|
|
|
*result = nullptr;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsAsyncResolveRequest> ctx =
|
2016-10-15 19:41:32 +03:00
|
|
|
new nsAsyncResolveRequest(this, channel, 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;
|
|
|
|
|
2017-05-05 21:32:19 +03:00
|
|
|
// adapt to realtime changes in the system proxy service
|
|
|
|
if (mProxyConfig == PROXYCONFIG_SYSTEM) {
|
|
|
|
nsCOMPtr<nsISystemProxySettings> sp2 =
|
|
|
|
do_GetService(NS_SYSTEMPROXYSETTINGS_CONTRACTID);
|
|
|
|
if (sp2 != mSystemProxySettings) {
|
|
|
|
mSystemProxySettings = sp2;
|
|
|
|
ResetPACThread();
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2017-05-05 21:32:19 +03:00
|
|
|
|
2017-07-05 01:48:00 +03:00
|
|
|
rv = SetupPACThread(mainThreadEventTarget);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2012-09-15 00:27:46 +04:00
|
|
|
// 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
|
|
|
|
|
2016-10-15 19:41:32 +03:00
|
|
|
rv =
|
|
|
|
Resolve_Internal(channel, 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
|
2018-02-08 08:18:00 +03:00
|
|
|
rv = ctx->ProcessLocally(info, pi, isSyncOK);
|
|
|
|
if (NS_SUCCEEDED(rv) && !isSyncOK) {
|
2013-06-28 01:02:04 +04:00
|
|
|
ctx.forget(result);
|
2001-05-12 01:04:09 +04:00
|
|
|
}
|
2005-03-25 06:41:33 +03:00
|
|
|
return rv;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2001-07-25 04:28:28 +04:00
|
|
|
|
2012-09-15 00:27:46 +04:00
|
|
|
// else kick off a PAC thread query
|
2020-04-06 22:11:33 +03:00
|
|
|
rv = mPACMan->AsyncGetProxyForURI(uri, ctx, flags, 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
|
2020-06-22 14:13:24 +03:00
|
|
|
nsProtocolProxyService::AsyncResolve2(
|
|
|
|
nsIChannel* channel, uint32_t flags, nsIProtocolProxyCallback* callback,
|
|
|
|
nsISerialEventTarget* mainThreadEventTarget, nsICancelable** result) {
|
2017-07-05 01:48:00 +03:00
|
|
|
return AsyncResolveInternal(channel, flags, callback, result, true,
|
|
|
|
mainThreadEventTarget);
|
2013-06-28 01:02:04 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2020-06-22 14:13:24 +03:00
|
|
|
nsProtocolProxyService::AsyncResolve(
|
|
|
|
nsISupports* channelOrURI, uint32_t flags,
|
|
|
|
nsIProtocolProxyCallback* callback,
|
|
|
|
nsISerialEventTarget* mainThreadEventTarget, 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;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-03-20 22:27:34 +03:00
|
|
|
// 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,
|
2017-07-11 00:24:54 +03:00
|
|
|
nsContentUtils::GetSystemPrincipal(),
|
2020-07-15 14:20:45 +03:00
|
|
|
nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_SEC_CONTEXT_IS_NULL,
|
2015-03-20 22:27:34 +03:00
|
|
|
nsIContentPolicy::TYPE_OTHER);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2015-01-28 00:30:49 +03:00
|
|
|
}
|
|
|
|
|
2017-07-05 01:48:00 +03:00
|
|
|
return AsyncResolveInternal(channel, flags, callback, result, false,
|
|
|
|
mainThreadEventTarget);
|
2013-06-28 01:02:04 +04:00
|
|
|
}
|
|
|
|
|
2001-09-13 06:21:05 +04:00
|
|
|
NS_IMETHODIMP
|
2019-05-06 10:22:18 +03:00
|
|
|
nsProtocolProxyService::NewProxyInfo(
|
|
|
|
const nsACString& aType, const nsACString& aHost, int32_t aPort,
|
|
|
|
const nsACString& aProxyAuthorizationHeader,
|
|
|
|
const nsACString& aConnectionIsolationKey, uint32_t aFlags,
|
|
|
|
uint32_t aFailoverTimeout, nsIProxyInfo* aFailoverProxy,
|
|
|
|
nsIProxyInfo** aResult) {
|
2020-09-23 18:17:15 +03:00
|
|
|
return NewProxyInfoWithAuth(aType, aHost, aPort, ""_ns, ""_ns,
|
|
|
|
aProxyAuthorizationHeader,
|
2019-05-06 10:22:18 +03:00
|
|
|
aConnectionIsolationKey, aFlags, aFailoverTimeout,
|
2015-11-25 00:56:00 +03:00
|
|
|
aFailoverProxy, aResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsProtocolProxyService::NewProxyInfoWithAuth(
|
|
|
|
const nsACString& aType, const nsACString& aHost, int32_t aPort,
|
2019-05-06 10:22:18 +03:00
|
|
|
const nsACString& aUsername, const nsACString& aPassword,
|
|
|
|
const nsACString& aProxyAuthorizationHeader,
|
|
|
|
const nsACString& aConnectionIsolationKey, uint32_t aFlags,
|
2015-11-25 00:56:00 +03:00
|
|
|
uint32_t aFailoverTimeout, nsIProxyInfo* aFailoverProxy,
|
|
|
|
nsIProxyInfo** aResult) {
|
2003-12-17 00:23:36 +03:00
|
|
|
static const char* types[] = {kProxyType_HTTP, kProxyType_HTTPS,
|
2005-03-25 06:41:33 +03:00
|
|
|
kProxyType_SOCKS, kProxyType_SOCKS4,
|
2012-07-25 06:40:34 +04:00
|
|
|
kProxyType_DIRECT};
|
2018-11-30 13:46:48 +03:00
|
|
|
|
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 :)
|
2018-04-30 19:46:04 +03:00
|
|
|
const char* type = nullptr;
|
|
|
|
for (auto& t : types) {
|
|
|
|
if (aType.LowerCaseEqualsASCII(t)) {
|
|
|
|
type = t;
|
|
|
|
break;
|
2003-12-17 00:23:36 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2003-12-17 00:23:36 +03:00
|
|
|
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
|
|
|
|
2019-05-06 10:22:18 +03:00
|
|
|
return NewProxyInfo_Internal(type, aHost, aPort, aUsername, aPassword,
|
|
|
|
aProxyAuthorizationHeader,
|
|
|
|
aConnectionIsolationKey, aFlags,
|
2011-05-13 21:53:27 +04:00
|
|
|
aFailoverTimeout, 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) {
|
2021-07-19 20:24:29 +03:00
|
|
|
// Failover is supported through a variety of methods including:
|
|
|
|
// * PAC scripts (PROXYCONFIG_PAC and PROXYCONFIG_WPAD)
|
|
|
|
// * System proxy
|
|
|
|
// * Extensions
|
|
|
|
// With extensions the mProxyConfig can be any type and the extension
|
|
|
|
// is still involved in the proxy filtering. It may have also supplied
|
|
|
|
// any number of failover proxies. We cannot determine what the mix is
|
|
|
|
// here, so we will attempt to get a failover regardless of the config
|
|
|
|
// type. MANUAL configuration will not disable a proxy.
|
2018-11-30 13:46:48 +03:00
|
|
|
|
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.
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2021-07-19 20:24:29 +03:00
|
|
|
// Remember that this proxy is down. If the user has manually configured some
|
|
|
|
// proxies we do not want to disable them.
|
|
|
|
if (mProxyConfig != PROXYCONFIG_MANUAL) {
|
|
|
|
DisableProxy(pi);
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2004-07-02 03:31:47 +04:00
|
|
|
// 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.
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2004-07-02 03:31:47 +04:00
|
|
|
if (!pi->mNext) return NS_ERROR_NOT_AVAILABLE;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2004-07-02 03:31:47 +04:00
|
|
|
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));
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2020-03-17 18:05:26 +03:00
|
|
|
*aResult = do_AddRef(pi->mNext).take();
|
2000-02-24 04:56:12 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-04-22 04:35:05 +04:00
|
|
|
|
2018-02-08 08:18:00 +03:00
|
|
|
namespace { // anon
|
|
|
|
|
|
|
|
class ProxyFilterPositionComparator {
|
2021-06-04 15:35:16 +03:00
|
|
|
using FilterLinkRef = RefPtr<nsProtocolProxyService::FilterLink>;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-02-08 08:18:00 +03:00
|
|
|
public:
|
|
|
|
bool Equals(const FilterLinkRef& a, const FilterLinkRef& b) const {
|
|
|
|
return a->position == b->position;
|
|
|
|
}
|
|
|
|
bool LessThan(const FilterLinkRef& a, const FilterLinkRef& b) const {
|
|
|
|
return a->position < b->position;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class ProxyFilterObjectComparator {
|
2021-06-04 15:35:16 +03:00
|
|
|
using FilterLinkRef = RefPtr<nsProtocolProxyService::FilterLink>;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-02-08 08:18:00 +03:00
|
|
|
public:
|
|
|
|
bool Equals(const FilterLinkRef& link, const nsISupports* obj) const {
|
|
|
|
return obj == nsCOMPtr<nsISupports>(do_QueryInterface(link->filter)) ||
|
|
|
|
obj == nsCOMPtr<nsISupports>(do_QueryInterface(link->channelFilter));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
nsresult nsProtocolProxyService::InsertFilterLink(RefPtr<FilterLink>&& link) {
|
|
|
|
LOG(("nsProtocolProxyService::InsertFilterLink filter=%p", link.get()));
|
|
|
|
|
2017-04-19 15:42:09 +03:00
|
|
|
if (mIsShutdown) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2018-02-08 08:18:00 +03:00
|
|
|
mFilters.AppendElement(link);
|
|
|
|
mFilters.Sort(ProxyFilterPositionComparator());
|
2021-11-29 18:19:15 +03:00
|
|
|
|
|
|
|
NotifyProxyConfigChangedInternal();
|
|
|
|
|
2005-03-25 06:41:33 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2015-01-21 23:13:00 +03:00
|
|
|
nsProtocolProxyService::RegisterFilter(nsIProtocolProxyFilter* filter,
|
|
|
|
uint32_t position) {
|
|
|
|
UnregisterFilter(filter); // remove this filter if we already have it
|
|
|
|
|
2018-02-08 08:18:00 +03:00
|
|
|
RefPtr<FilterLink> link = new FilterLink(position, filter);
|
2018-05-30 22:15:35 +03:00
|
|
|
return InsertFilterLink(std::move(link));
|
2015-01-21 23:13:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2018-02-08 08:18:00 +03:00
|
|
|
RefPtr<FilterLink> link = new FilterLink(position, channelFilter);
|
2018-05-30 22:15:35 +03:00
|
|
|
return InsertFilterLink(std::move(link));
|
2015-01-21 23:13:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsProtocolProxyService::RemoveFilterLink(nsISupports* givenObject) {
|
2018-02-08 08:18:00 +03:00
|
|
|
LOG(("nsProtocolProxyService::RemoveFilterLink target=%p", givenObject));
|
2005-03-25 06:41:33 +03:00
|
|
|
|
2021-11-29 18:19:15 +03:00
|
|
|
nsresult rv =
|
|
|
|
mFilters.RemoveElement(givenObject, ProxyFilterObjectComparator())
|
|
|
|
? NS_OK
|
|
|
|
: NS_ERROR_UNEXPECTED;
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
NotifyProxyConfigChangedInternal();
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
2005-03-25 06:41:33 +03:00
|
|
|
}
|
2010-06-17 22:33:42 +04:00
|
|
|
|
2015-01-21 23:13:00 +03:00
|
|
|
NS_IMETHODIMP
|
2018-02-08 08:18:00 +03:00
|
|
|
nsProtocolProxyService::UnregisterFilter(nsIProtocolProxyFilter* filter) {
|
2015-01-21 23:13:00 +03:00
|
|
|
// QI to nsISupports so we can safely test object identity.
|
|
|
|
nsCOMPtr<nsISupports> givenObject = do_QueryInterface(filter);
|
|
|
|
return RemoveFilterLink(givenObject);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2018-02-08 08:18:00 +03:00
|
|
|
nsProtocolProxyService::UnregisterChannelFilter(
|
|
|
|
nsIProtocolProxyChannelFilter* channelFilter) {
|
2015-01-21 23:13:00 +03:00
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2017-03-20 22:21:15 +03:00
|
|
|
void nsProtocolProxyService::LoadHostFilters(const nsACString& aFilters) {
|
2017-04-19 15:42:09 +03:00
|
|
|
if (mIsShutdown) {
|
|
|
|
return;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
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();
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2019-02-20 00:53:22 +03:00
|
|
|
// Reset mFilterLocalHosts - will be set to true if "<local>" is in pref
|
|
|
|
// string
|
|
|
|
mFilterLocalHosts = false;
|
|
|
|
|
2017-03-20 22:21:15 +03:00
|
|
|
if (aFilters.IsEmpty()) {
|
2018-11-30 13:46:48 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
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)
|
2018-11-30 13:46:48 +03:00
|
|
|
//
|
2017-03-20 22:21:15 +03:00
|
|
|
mozilla::Tokenizer t(aFilters);
|
|
|
|
mozilla::Tokenizer::Token token;
|
|
|
|
bool eof = false;
|
|
|
|
// while (*filters) {
|
|
|
|
while (!eof) {
|
2000-04-22 04:35:05 +04:00
|
|
|
// skip over spaces and ,
|
2017-03-20 22:21:15 +03:00
|
|
|
t.SkipWhites();
|
|
|
|
while (t.CheckChar(',')) {
|
|
|
|
t.SkipWhites();
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2017-03-20 22:21:15 +03:00
|
|
|
nsAutoCString portStr;
|
|
|
|
nsAutoCString hostStr;
|
|
|
|
nsAutoCString maskStr;
|
|
|
|
t.Record();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-03-20 22:21:15 +03:00
|
|
|
bool parsingIPv6 = false;
|
|
|
|
bool parsingPort = false;
|
|
|
|
bool parsingMask = false;
|
|
|
|
while (t.Next(token)) {
|
|
|
|
if (token.Equals(mozilla::Tokenizer::Token::EndOfFile())) {
|
|
|
|
eof = true;
|
2018-11-30 13:46:48 +03:00
|
|
|
break;
|
|
|
|
}
|
2017-03-20 22:21:15 +03:00
|
|
|
if (token.Equals(mozilla::Tokenizer::Token::Char(',')) ||
|
|
|
|
token.Type() == mozilla::Tokenizer::TOKEN_WS) {
|
2018-11-30 13:46:48 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-03-20 22:21:15 +03:00
|
|
|
if (token.Equals(mozilla::Tokenizer::Token::Char('['))) {
|
|
|
|
parsingIPv6 = true;
|
|
|
|
continue;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2017-03-20 22:21:15 +03:00
|
|
|
if (!parsingIPv6 && token.Equals(mozilla::Tokenizer::Token::Char(':'))) {
|
|
|
|
// Port is starting. Claim the previous as host.
|
|
|
|
if (parsingMask) {
|
|
|
|
t.Claim(maskStr);
|
2018-11-30 13:46:48 +03:00
|
|
|
} else {
|
2017-03-20 22:21:15 +03:00
|
|
|
t.Claim(hostStr);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2017-03-20 22:21:15 +03:00
|
|
|
t.Record();
|
|
|
|
parsingPort = true;
|
|
|
|
continue;
|
2020-04-10 15:43:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (token.Equals(mozilla::Tokenizer::Token::Char('/'))) {
|
2017-03-20 22:21:15 +03:00
|
|
|
t.Claim(hostStr);
|
|
|
|
t.Record();
|
|
|
|
parsingMask = true;
|
|
|
|
continue;
|
2020-04-10 15:43:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (token.Equals(mozilla::Tokenizer::Token::Char(']'))) {
|
2017-03-20 22:21:15 +03:00
|
|
|
parsingIPv6 = false;
|
|
|
|
continue;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
}
|
2017-03-20 22:21:15 +03:00
|
|
|
if (!parsingPort && !parsingMask) {
|
|
|
|
t.Claim(hostStr);
|
|
|
|
} else if (parsingPort) {
|
|
|
|
t.Claim(portStr);
|
|
|
|
} else if (parsingMask) {
|
|
|
|
t.Claim(maskStr);
|
2018-11-30 13:46:48 +03:00
|
|
|
} else {
|
2017-03-20 22:21:15 +03:00
|
|
|
NS_WARNING("Could not parse this rule");
|
|
|
|
continue;
|
2017-04-19 15:42:09 +03:00
|
|
|
}
|
|
|
|
|
2009-02-23 04:05:28 +03:00
|
|
|
if (hostStr.IsEmpty()) {
|
2005-03-25 06:41:33 +03:00
|
|
|
continue;
|
2000-04-22 04:35:05 +04:00
|
|
|
}
|
|
|
|
|
2017-03-20 22:21:15 +03:00
|
|
|
// If the current host filter is "<local>", then all local (i.e.
|
2011-09-21 23:13:45 +04:00
|
|
|
// no dots in the hostname) hosts should bypass the proxy
|
2017-03-20 22:21:15 +03:00
|
|
|
if (hostStr.EqualsIgnoreCase("<local>")) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mFilterLocalHosts = true;
|
2018-11-30 13:46:48 +03:00
|
|
|
LOG(
|
2011-09-21 23:13:45 +04:00
|
|
|
("loaded filter for local hosts "
|
2017-03-20 22:21:15 +03:00
|
|
|
"(plain host names, no dots)\n"));
|
2011-09-21 23:13:45 +04:00
|
|
|
// Continue to next host filter;
|
2017-03-20 22:21:15 +03:00
|
|
|
continue;
|
|
|
|
}
|
2000-04-22 04:35:05 +04:00
|
|
|
|
2011-09-21 23:13:45 +04:00
|
|
|
// For all other host filters, create HostInfo object and add to list
|
2011-10-17 18:59:28 +04:00
|
|
|
HostInfo* hinfo = new HostInfo();
|
2017-03-20 22:21:15 +03:00
|
|
|
nsresult rv = NS_OK;
|
2000-04-22 04:35:05 +04:00
|
|
|
|
2017-03-20 22:21:15 +03:00
|
|
|
int32_t port = portStr.ToInteger(&rv);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
port = 0;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2017-03-20 22:21:15 +03:00
|
|
|
hinfo->port = port;
|
|
|
|
|
|
|
|
int32_t maskLen = maskStr.ToInteger(&rv);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
maskLen = 128;
|
|
|
|
}
|
2003-04-11 22:24:55 +04:00
|
|
|
|
2017-03-20 22:21:15 +03:00
|
|
|
// PR_StringToNetAddr can't parse brackets enclosed IPv6
|
|
|
|
nsAutoCString addrString = hostStr;
|
|
|
|
if (hostStr.First() == '[' && hostStr.Last() == ']') {
|
|
|
|
addrString = Substring(hostStr, 1, hostStr.Length() - 2);
|
|
|
|
}
|
2003-04-11 22:24:55 +04:00
|
|
|
|
2011-09-21 23:13:45 +04:00
|
|
|
PRNetAddr addr;
|
|
|
|
if (PR_StringToNetAddr(addrString.get(), &addr) == PR_SUCCESS) {
|
|
|
|
hinfo->is_ipaddr = true;
|
|
|
|
hinfo->ip.family = PR_AF_INET6; // we always store address as IPv6
|
|
|
|
hinfo->ip.mask_len = maskLen;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-03-20 22:21:15 +03:00
|
|
|
if (hinfo->ip.mask_len == 0) {
|
2011-09-21 23:13:45 +04:00
|
|
|
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) {
|
2003-04-11 22:24:55 +04:00
|
|
|
// copy the address
|
2011-09-21 23:13:45 +04:00
|
|
|
memcpy(&hinfo->ip.addr, &addr.ipv6.ip, sizeof(PRIPv6Addr));
|
2018-11-30 13:46:48 +03:00
|
|
|
} else {
|
2017-03-20 22:21:15 +03:00
|
|
|
NS_WARNING("unknown address family");
|
2003-04-11 22:24:55 +04:00
|
|
|
goto loser;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2017-03-20 22:21:15 +03:00
|
|
|
|
|
|
|
// apply mask to IPv6 address
|
|
|
|
proxy_MaskIPv6Addr(hinfo->ip.addr, hinfo->ip.mask_len);
|
2018-11-30 13:46:48 +03:00
|
|
|
} else {
|
2017-03-20 22:21:15 +03:00
|
|
|
nsAutoCString host;
|
|
|
|
if (hostStr.First() == '*') {
|
|
|
|
host = Substring(hostStr, 1);
|
|
|
|
} else {
|
|
|
|
host = hostStr;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2017-03-20 22:21:15 +03:00
|
|
|
|
|
|
|
if (host.IsEmpty()) {
|
|
|
|
hinfo->name.host = nullptr;
|
2003-04-11 22:24:55 +04:00
|
|
|
goto loser;
|
2017-03-20 22:21:15 +03:00
|
|
|
}
|
2011-09-21 23:13:45 +04:00
|
|
|
|
2017-03-20 22:21:15 +03:00
|
|
|
hinfo->name.host_len = host.Length();
|
2017-03-20 22:20:42 +03:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
hinfo->is_ipaddr = false;
|
2020-05-17 09:58:48 +03:00
|
|
|
hinfo->name.host = ToNewCString(host, mozilla::fallible);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-03-20 22:21:15 +03:00
|
|
|
if (!hinfo->name.host) goto loser;
|
|
|
|
}
|
2003-04-11 22:24:55 +04:00
|
|
|
|
|
|
|
//#define DEBUG_DUMP_FILTERS
|
|
|
|
#ifdef DEBUG_DUMP_FILTERS
|
2017-03-20 22:20:42 +03:00
|
|
|
printf("loaded filter[%zu]:\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);
|
2017-03-20 22:21:15 +03:00
|
|
|
printf(" host = %s\n", hostStr.get());
|
2003-04-11 22:24:55 +04:00
|
|
|
if (hinfo->is_ipaddr) {
|
|
|
|
printf(" ip.family = %x\n", hinfo->ip.family);
|
|
|
|
printf(" ip.mask_len = %u\n", hinfo->ip.mask_len);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2003-04-11 22:24:55 +04:00
|
|
|
PRNetAddr netAddr;
|
|
|
|
PR_SetNetAddr(PR_IpAddrNull, PR_AF_INET6, 0, &netAddr);
|
|
|
|
memcpy(&netAddr.ipv6.ip, &hinfo->ip.addr, sizeof(hinfo->ip.addr));
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2003-04-11 22:24:55 +04:00
|
|
|
char buf[256];
|
|
|
|
PR_NetAddrToString(&netAddr, buf, sizeof(buf));
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2003-04-11 22:24:55 +04:00
|
|
|
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
|
|
|
|
2005-03-25 06:41:33 +03:00
|
|
|
nsresult nsProtocolProxyService::GetProtocolInfo(nsIURI* uri,
|
|
|
|
nsProtocolInfo* info) {
|
2018-04-28 22:50:58 +03:00
|
|
|
MOZ_ASSERT(uri, "URI is null");
|
|
|
|
MOZ_ASSERT(info, "info is null");
|
2012-09-05 16:44:27 +04:00
|
|
|
|
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(
|
2004-07-02 03:31:47 +04:00
|
|
|
const char* aType, const nsACString& aHost, int32_t aPort,
|
2019-05-06 10:22:18 +03:00
|
|
|
const nsACString& aUsername, const nsACString& aPassword,
|
|
|
|
const nsACString& aProxyAuthorizationHeader,
|
|
|
|
const nsACString& aConnectionIsolationKey, uint32_t aFlags,
|
2005-03-25 06:41:33 +03:00
|
|
|
uint32_t aFailoverTimeout, nsIProxyInfo* aFailoverProxy,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aResolveFlags, nsIProxyInfo** aResult) {
|
2015-11-25 00:56:00 +03:00
|
|
|
if (aPort <= 0) aPort = -1;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2005-03-25 06:41:33 +03:00
|
|
|
nsCOMPtr<nsProxyInfo> failover;
|
|
|
|
if (aFailoverProxy) {
|
|
|
|
failover = do_QueryInterface(aFailoverProxy);
|
|
|
|
NS_ENSURE_ARG(failover);
|
|
|
|
}
|
|
|
|
|
2020-03-17 18:05:26 +03:00
|
|
|
RefPtr<nsProxyInfo> proxyInfo = new nsProxyInfo();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2002-09-23 05:31:17 +04:00
|
|
|
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 =
|
2005-03-25 06:41:33 +03:00
|
|
|
aFailoverTimeout == UINT32_MAX ? mFailedProxyTimeout : aFailoverTimeout;
|
2019-05-06 10:22:18 +03:00
|
|
|
proxyInfo->mProxyAuthorizationHeader = aProxyAuthorizationHeader;
|
|
|
|
proxyInfo->mConnectionIsolationKey = aConnectionIsolationKey;
|
2005-03-25 06:41:33 +03:00
|
|
|
failover.swap(proxyInfo->mNext);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2020-03-17 18:05:26 +03:00
|
|
|
proxyInfo.forget(aResult);
|
2002-09-23 05:31:17 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2004-07-31 21:39:29 +04:00
|
|
|
|
2015-01-21 23:13:00 +03:00
|
|
|
nsresult nsProtocolProxyService::Resolve_Internal(nsIChannel* channel,
|
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);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-09-15 00:27:46 +04:00
|
|
|
*usePACThread = false;
|
2012-07-30 18:20:58 +04:00
|
|
|
*result = nullptr;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2021-06-04 15:35:16 +03:00
|
|
|
if (!(info.flags & nsIProtocolHandler::ALLOWS_PROXY)) {
|
2005-03-25 06:41:33 +03:00
|
|
|
return NS_OK; // Can't proxy this (filters may not override)
|
2021-06-04 15:35:16 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-01-21 23:13:00 +03:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
2017-07-05 01:48:00 +03:00
|
|
|
nsresult rv = GetProxyURI(channel, getter_AddRefs(uri));
|
2015-01-21 23:13:00 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
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;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-12-03 17:27:11 +03:00
|
|
|
// if proxies are enabled and this host:port combo is supposed to use a
|
|
|
|
// proxy, check for a proxy.
|
|
|
|
if ((mProxyConfig == PROXYCONFIG_DIRECT) ||
|
2021-06-04 15:35:16 +03:00
|
|
|
!CanUseProxy(uri, info.defaultPort)) {
|
2018-12-03 17:27:11 +03:00
|
|
|
return NS_OK;
|
2021-06-04 15:35:16 +03:00
|
|
|
}
|
2018-12-03 17:27:11 +03:00
|
|
|
|
2012-09-15 00:27:46 +04:00
|
|
|
bool mainThreadOnly;
|
|
|
|
if (mSystemProxySettings && mProxyConfig == PROXYCONFIG_SYSTEM &&
|
|
|
|
NS_SUCCEEDED(mSystemProxySettings->GetMainThreadOnly(&mainThreadOnly)) &&
|
|
|
|
!mainThreadOnly) {
|
|
|
|
*usePACThread = true;
|
|
|
|
return NS_OK;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2012-09-15 00:27:46 +04:00
|
|
|
|
|
|
|
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
|
|
|
|
// bug 1366133: this block uses GetPACURI & GetProxyForURI, which may
|
|
|
|
// hang on Windows platform. Fortunately, current implementation on
|
|
|
|
// Windows is not main thread only, so we are safe here.
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString PACURI;
|
2012-09-15 00:27:46 +04:00
|
|
|
nsAutoCString pacString;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-09-15 00:27:46 +04:00
|
|
|
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
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-09-15 00:27:46 +04:00
|
|
|
if (mPACMan && mPACMan->IsPACURI(PACURI)) {
|
|
|
|
// unchanged
|
|
|
|
*usePACThread = true;
|
|
|
|
return NS_OK;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2012-09-15 00:27:46 +04:00
|
|
|
ConfigureFromPAC(PACURI, false);
|
2010-06-17 22:33:42 +04:00
|
|
|
return NS_OK;
|
2012-09-15 00:27:46 +04:00
|
|
|
}
|
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString spec;
|
2012-09-15 00:27:46 +04:00
|
|
|
nsAutoCString host;
|
|
|
|
nsAutoCString scheme;
|
|
|
|
int32_t port = -1;
|
2009-12-03 10:31:55 +03:00
|
|
|
|
2012-09-15 00:27:46 +04:00
|
|
|
uri->GetAsciiSpec(spec);
|
|
|
|
uri->GetAsciiHost(host);
|
|
|
|
uri->GetScheme(scheme);
|
|
|
|
uri->GetPort(&port);
|
2017-06-12 06:41:14 +03:00
|
|
|
|
2012-09-15 00:27:46 +04:00
|
|
|
if (flags & RESOLVE_PREFER_SOCKS_PROXY) {
|
|
|
|
LOG(("Ignoring RESOLVE_PREFER_SOCKS_PROXY for system proxy setting\n"));
|
|
|
|
} else if (flags & RESOLVE_PREFER_HTTPS_PROXY) {
|
|
|
|
scheme.AssignLiteral("https");
|
|
|
|
} else if (flags & RESOLVE_IGNORE_URI_SCHEME) {
|
|
|
|
scheme.AssignLiteral("http");
|
2008-01-29 21:38:15 +03:00
|
|
|
}
|
|
|
|
|
2005-03-25 06:41:33 +03:00
|
|
|
// now try the system proxy settings for this particular url
|
2010-06-17 22:33:42 +04:00
|
|
|
if (NS_SUCCEEDED(mSystemProxySettings->GetProxyForURI(spec, scheme, host,
|
2009-12-03 10:31:55 +03:00
|
|
|
port, pacString))) {
|
2019-12-24 22:51:09 +03:00
|
|
|
nsCOMPtr<nsIProxyInfo> pi;
|
|
|
|
ProcessPACString(pacString, 0, getter_AddRefs(pi));
|
|
|
|
|
|
|
|
if (flags & RESOLVE_PREFER_SOCKS_PROXY &&
|
|
|
|
flags & RESOLVE_PREFER_HTTPS_PROXY) {
|
|
|
|
nsAutoCString type;
|
|
|
|
pi->GetType(type);
|
|
|
|
// DIRECT from ProcessPACString indicates that system proxy settings
|
|
|
|
// are not configured to use SOCKS proxy. Try https proxy as a
|
|
|
|
// secondary preferrable proxy. This is mainly for websocket whose
|
|
|
|
// proxy precedence is SOCKS > HTTPS > DIRECT.
|
|
|
|
if (type.EqualsLiteral(kProxyType_DIRECT)) {
|
|
|
|
scheme.AssignLiteral(kProxyType_HTTPS);
|
|
|
|
if (NS_SUCCEEDED(mSystemProxySettings->GetProxyForURI(
|
|
|
|
spec, scheme, host, port, pacString))) {
|
|
|
|
ProcessPACString(pacString, 0, getter_AddRefs(pi));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pi.forget(result);
|
2005-03-25 06:41:33 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2005-03-25 06:41:33 +03:00
|
|
|
|
2013-04-10 23:48:17 +04:00
|
|
|
// if proxies are enabled and this host:port combo is supposed to use a
|
|
|
|
// proxy, check for a proxy.
|
|
|
|
if (mProxyConfig == PROXYCONFIG_DIRECT ||
|
|
|
|
(mProxyConfig == PROXYCONFIG_MANUAL &&
|
2021-06-04 15:35:16 +03:00
|
|
|
!CanUseProxy(uri, info.defaultPort))) {
|
2013-04-10 23:48:17 +04:00
|
|
|
return NS_OK;
|
2021-06-04 15:35:16 +03:00
|
|
|
}
|
2013-04-10 23:48:17 +04:00
|
|
|
|
|
|
|
// Proxy auto config magic...
|
2012-07-30 18:20:58 +04:00
|
|
|
if (mProxyConfig == PROXYCONFIG_PAC || mProxyConfig == PROXYCONFIG_WPAD) {
|
|
|
|
// Do not query PAC now.
|
|
|
|
*usePACThread = true;
|
|
|
|
return NS_OK;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2005-03-25 06:41:33 +03:00
|
|
|
|
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
|
2010-06-17 22:33:42 +04:00
|
|
|
if (mProxyConfig != PROXYCONFIG_MANUAL) return NS_OK;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2013-04-10 23:48:17 +04:00
|
|
|
// proxy info values for manual configuration mode
|
2012-07-30 18:20:58 +04:00
|
|
|
const char* type = nullptr;
|
|
|
|
const nsACString* host = nullptr;
|
2012-09-15 00:27:46 +04:00
|
|
|
int32_t port = -1;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t proxyFlags = 0;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2010-06-17 22:33:42 +04:00
|
|
|
if ((flags & RESOLVE_PREFER_SOCKS_PROXY) && !mSOCKSProxyTarget.IsEmpty() &&
|
2016-09-01 10:48:39 +03:00
|
|
|
(IsHostLocalTarget(mSOCKSProxyTarget) || mSOCKSProxyPort > 0)) {
|
2016-06-30 06:23:40 +03:00
|
|
|
host = &mSOCKSProxyTarget;
|
2021-06-04 15:35:16 +03:00
|
|
|
if (mSOCKSProxyVersion == 4) {
|
2010-06-17 22:33:42 +04:00
|
|
|
type = kProxyType_SOCKS4;
|
2021-06-04 15:35:16 +03:00
|
|
|
} else {
|
2010-06-17 22:33:42 +04:00
|
|
|
type = kProxyType_SOCKS;
|
2021-06-04 15:35:16 +03:00
|
|
|
}
|
2010-06-17 22:33:42 +04:00
|
|
|
port = mSOCKSProxyPort;
|
2021-06-04 15:35:16 +03:00
|
|
|
if (mSOCKSProxyRemoteDNS) {
|
2010-06-17 22:33:42 +04:00
|
|
|
proxyFlags |= nsIProxyInfo::TRANSPARENT_PROXY_RESOLVES_HOST;
|
2021-06-04 15:35:16 +03:00
|
|
|
}
|
2010-06-17 22:33:42 +04:00
|
|
|
} 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;
|
2016-06-30 06:23:40 +03:00
|
|
|
} else if (!mSOCKSProxyTarget.IsEmpty() &&
|
2016-09-01 10:48:39 +03:00
|
|
|
(IsHostLocalTarget(mSOCKSProxyTarget) || mSOCKSProxyPort > 0)) {
|
2016-06-30 06:23:40 +03:00
|
|
|
host = &mSOCKSProxyTarget;
|
2021-06-04 15:35:16 +03:00
|
|
|
if (mSOCKSProxyVersion == 4) {
|
2005-03-25 06:41:33 +03:00
|
|
|
type = kProxyType_SOCKS4;
|
2021-06-04 15:35:16 +03:00
|
|
|
} else {
|
2005-03-25 06:41:33 +03:00
|
|
|
type = kProxyType_SOCKS;
|
2021-06-04 15:35:16 +03:00
|
|
|
}
|
2005-03-25 06:41:33 +03:00
|
|
|
port = mSOCKSProxyPort;
|
2021-06-04 15:35:16 +03:00
|
|
|
if (mSOCKSProxyRemoteDNS) {
|
2005-03-25 06:41:33 +03:00
|
|
|
proxyFlags |= nsIProxyInfo::TRANSPARENT_PROXY_RESOLVES_HOST;
|
2021-06-04 15:35:16 +03:00
|
|
|
}
|
2005-03-25 06:41:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (type) {
|
2020-09-23 18:17:15 +03:00
|
|
|
rv = NewProxyInfo_Internal(type, *host, port, ""_ns, ""_ns, ""_ns, ""_ns,
|
2019-05-06 10:22:18 +03:00
|
|
|
proxyFlags, UINT32_MAX, nullptr, flags, 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;
|
|
|
|
|
2021-11-29 18:19:15 +03:00
|
|
|
// To avoid getting DNS service recursively, we directly use
|
|
|
|
// GetXPCOMSingleton().
|
|
|
|
nsCOMPtr<nsIDNSService> dns = nsDNSService::GetXPCOMSingleton();
|
2012-09-15 00:27:46 +04:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2018-02-08 08:18:00 +03:00
|
|
|
void nsProtocolProxyService::CopyFilters(nsTArray<RefPtr<FilterLink>>& aCopy) {
|
|
|
|
MOZ_ASSERT(aCopy.Length() == 0);
|
|
|
|
aCopy.AppendElements(mFilters);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool nsProtocolProxyService::ApplyFilter(
|
|
|
|
FilterLink const* filterLink, nsIChannel* channel,
|
|
|
|
const nsProtocolInfo& info, nsCOMPtr<nsIProxyInfo> list,
|
|
|
|
nsIProxyProtocolFilterResult* callback) {
|
|
|
|
nsresult rv;
|
2005-03-25 06:41:33 +03:00
|
|
|
|
2018-02-08 08:18:00 +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.
|
|
|
|
PruneProxyInfo(info, list);
|
2005-03-25 06:41:33 +03:00
|
|
|
|
2018-02-08 08:18:00 +03:00
|
|
|
if (filterLink->filter) {
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
Unused << GetProxyURI(channel, getter_AddRefs(uri));
|
|
|
|
if (!uri) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-04-06 23:21:03 +03:00
|
|
|
rv = filterLink->filter->ApplyFilter(uri, list, callback);
|
2018-02-08 08:18:00 +03:00
|
|
|
return NS_SUCCEEDED(rv);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2018-02-08 08:18:00 +03:00
|
|
|
if (filterLink->channelFilter) {
|
2020-04-06 23:21:03 +03:00
|
|
|
rv = filterLink->channelFilter->ApplyFilter(channel, list, callback);
|
2018-02-08 08:18:00 +03:00
|
|
|
return NS_SUCCEEDED(rv);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2018-02-08 08:18:00 +03:00
|
|
|
return false;
|
2005-03-25 06:41:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsProtocolProxyService::PruneProxyInfo(const nsProtocolInfo& info,
|
|
|
|
nsIProxyInfo** list) {
|
|
|
|
if (!*list) return;
|
2018-02-08 08:18:00 +03:00
|
|
|
|
|
|
|
LOG(("nsProtocolProxyService::PruneProxyInfo ENTER list=%p", *list));
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
nsProxyInfo* head = nullptr;
|
2005-03-25 06:41:33 +03:00
|
|
|
CallQueryInterface(*list, &head);
|
|
|
|
if (!head) {
|
2018-06-18 08:43:11 +03:00
|
|
|
MOZ_ASSERT_UNREACHABLE("nsIProxyInfo must QI to nsProxyInfo");
|
2004-07-31 21:39:29 +04:00
|
|
|
return;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2005-03-25 06:41:33 +03:00
|
|
|
NS_RELEASE(*list);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2005-03-25 06:41:33 +03:00
|
|
|
// Pruning of disabled proxies works like this:
|
|
|
|
// - If all proxies are disabled, return the full list
|
|
|
|
// - Otherwise, remove the disabled proxies.
|
2018-11-30 13:46:48 +03:00
|
|
|
//
|
2005-03-25 06:41:33 +03:00
|
|
|
// Pruning of disallowed proxies works like this:
|
|
|
|
// - If the protocol handler disallows the proxy, then we disallow it.
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2005-03-25 06:41:33 +03:00
|
|
|
// 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!
|
2021-06-04 15:35:16 +03:00
|
|
|
if (last) {
|
2005-03-25 06:41:33 +03:00
|
|
|
last->mNext = iter->mNext;
|
2021-06-04 15:35:16 +03:00
|
|
|
} else {
|
2005-03-25 06:41:33 +03:00
|
|
|
head = iter->mNext;
|
2021-06-04 15:35:16 +03:00
|
|
|
}
|
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;
|
2018-11-30 13:46:48 +03:00
|
|
|
} else {
|
2005-03-29 00:11:16 +04:00
|
|
|
last = iter;
|
|
|
|
iter = iter->mNext;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2004-07-31 21:39:29 +04:00
|
|
|
}
|
2005-03-25 06:41:33 +03:00
|
|
|
if (!head) {
|
|
|
|
return;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2005-03-25 06:41:33 +03:00
|
|
|
|
2018-11-05 10:12:54 +03:00
|
|
|
// Scan to see if all remaining non-direct proxies are disabled. If so, then
|
2015-12-10 09:21:00 +03:00
|
|
|
// 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
|
|
|
|
2018-11-05 10:12:54 +03:00
|
|
|
bool allNonDirectProxiesDisabled = 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) {
|
2018-11-05 10:12:54 +03:00
|
|
|
if (!IsProxyDisabled(iter) && iter->mType != kProxyType_DIRECT) {
|
|
|
|
allNonDirectProxiesDisabled = false;
|
2015-12-10 09:21:00 +03:00
|
|
|
break;
|
2015-11-10 17:27:45 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2005-03-25 06:41:33 +03:00
|
|
|
|
2018-11-05 10:12:54 +03:00
|
|
|
if (allNonDirectProxiesDisabled) {
|
2015-11-10 17:27:45 +03:00
|
|
|
LOG(("All proxies are disabled, so trying all again"));
|
2018-02-08 08:18: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;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-11-10 17:27:45 +03:00
|
|
|
iter = iter->mNext;
|
2021-06-04 15:35:16 +03:00
|
|
|
if (last) {
|
2015-11-10 17:27:45 +03:00
|
|
|
last->mNext = iter;
|
2021-06-04 15:35:16 +03:00
|
|
|
} else {
|
2015-12-10 09:21:00 +03:00
|
|
|
head = iter;
|
2021-06-04 15:35:16 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-11-10 17:27:45 +03:00
|
|
|
reject->mNext = nullptr;
|
|
|
|
NS_RELEASE(reject);
|
|
|
|
continue;
|
|
|
|
}
|
2018-11-30 13:46:48 +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);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-11-10 17:27:45 +03:00
|
|
|
last = iter;
|
|
|
|
iter = iter->mNext;
|
2015-10-09 02:59:00 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
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.
|
2021-06-04 15:35:16 +03:00
|
|
|
if (head && !head->mNext && head->mType == kProxyType_DIRECT) {
|
2005-03-25 06:41:33 +03:00
|
|
|
NS_RELEASE(head);
|
2021-06-04 15:35:16 +03:00
|
|
|
}
|
2005-03-25 06:41:33 +03:00
|
|
|
|
|
|
|
*list = head; // Transfer ownership
|
2018-02-08 08:18:00 +03:00
|
|
|
|
|
|
|
LOG(("nsProtocolProxyService::PruneProxyInfo LEAVE list=%p", *list));
|
2004-07-31 21:39:29 +04:00
|
|
|
}
|
2016-05-19 05:02:57 +03:00
|
|
|
|
2018-11-20 04:17:53 +03:00
|
|
|
bool nsProtocolProxyService::GetIsPACLoading() {
|
|
|
|
return mPACMan && mPACMan->IsLoading();
|
2018-10-22 12:07:51 +03:00
|
|
|
}
|
|
|
|
|
2021-11-29 18:19:15 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsProtocolProxyService::AddProxyConfigCallback(
|
|
|
|
nsIProxyConfigChangedCallback* aCallback) {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
if (!aCallback) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
mProxyConfigChangedCallbacks.AppendElement(aCallback);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsProtocolProxyService::RemoveProxyConfigCallback(
|
|
|
|
nsIProxyConfigChangedCallback* aCallback) {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
mProxyConfigChangedCallbacks.RemoveElement(aCallback);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsProtocolProxyService::NotifyProxyConfigChangedInternal() {
|
|
|
|
LOG(("nsProtocolProxyService::NotifyProxyConfigChangedInternal"));
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
for (const auto& callback : mProxyConfigChangedCallbacks) {
|
|
|
|
callback->OnProxyConfigChanged();
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-05-19 05:02:57 +03:00
|
|
|
} // namespace net
|
2018-11-20 04:17:53 +03:00
|
|
|
} // namespace mozilla
|