Bug 1258977 - Part 1: separate match function; r=bagder
MozReview-Commit-ID: J4DVAzI0bZm
new file mode 100644
--- /dev/null
+++ b/toolkit/system/windowsproxy/ProxyUtils.cpp
@@ -0,0 +1,52 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* 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/. */
+
+#include "ProxyUtils.h"
+
+namespace mozilla {
+namespace toolkit {
+namespace system {
+
+bool IsHostProxyEntry(const nsACString& aHost, const nsACString& aOverride)
+{
+ nsAutoCString host(aHost);
+ nsAutoCString override(aOverride);
+ int32_t overrideLength = override.Length();
+ int32_t tokenStart = 0;
+ int32_t offset = 0;
+ bool star = false;
+
+ while (tokenStart < overrideLength) {
+ int32_t tokenEnd = override.FindChar('*', tokenStart);
+ if (tokenEnd == tokenStart) {
+ star = true;
+ tokenStart++;
+ // If the character following the '*' is a '.' character then skip
+ // it so that "*.foo.com" allows "foo.com".
+ if (override.FindChar('.', tokenStart) == tokenStart) {
+ tokenStart++;
+ }
+ } else {
+ if (tokenEnd == -1) {
+ tokenEnd = overrideLength;
+ }
+ nsAutoCString token(Substring(override, tokenStart,
+ tokenEnd - tokenStart));
+ offset = host.Find(token, offset);
+ if (offset == -1 || (!star && offset)) {
+ return false;
+ }
+ star = false;
+ tokenStart = tokenEnd;
+ offset += token.Length();
+ }
+ }
+
+ return (star || (offset == host.Length()));
+}
+
+} // namespace system
+} // namespace toolkit
+} // namespace mozilla
new file mode 100644
--- /dev/null
+++ b/toolkit/system/windowsproxy/ProxyUtils.h
@@ -0,0 +1,21 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* 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/. */
+
+#ifndef mozilla_toolkit_system_windowsproxy_ProxyUtils_h
+#define mozilla_toolkit_system_windowsproxy_ProxyUtils_h
+
+#include "nsStringGlue.h"
+
+namespace mozilla {
+namespace toolkit {
+namespace system {
+
+bool IsHostProxyEntry(const nsACString& aHost, const nsACString& aOverride);
+
+} // namespace system
+} // namespace toolkit
+} // namespace mozilla
+
+#endif // mozilla_toolkit_system_windowsproxy_ProxyUtils_h
--- a/toolkit/system/windowsproxy/moz.build
+++ b/toolkit/system/windowsproxy/moz.build
@@ -1,11 +1,12 @@
# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# 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/.
SOURCES += [
'nsWindowsSystemProxySettings.cpp',
+ 'ProxyUtils.cpp'
]
FINAL_LIBRARY = 'xul'
--- a/toolkit/system/windowsproxy/nsWindowsSystemProxySettings.cpp
+++ b/toolkit/system/windowsproxy/nsWindowsSystemProxySettings.cpp
@@ -12,16 +12,17 @@
#include "nsISystemProxySettings.h"
#include "nsIServiceManager.h"
#include "mozilla/ModuleUtils.h"
#include "nsPrintfCString.h"
#include "nsNetCID.h"
#include "nsISupportsPrimitives.h"
#include "nsIURI.h"
#include "GeckoProfiler.h"
+#include "ProxyUtils.h"
class nsWindowsSystemProxySettings final : public nsISystemProxySettings
{
public:
NS_DECL_THREADSAFE_ISUPPORTS
NS_DECL_NSISYSTEMPROXYSETTINGS
nsWindowsSystemProxySettings() {};
@@ -163,47 +164,17 @@ nsWindowsSystemProxySettings::MatchOverr
return false;
}
bool
nsWindowsSystemProxySettings::PatternMatch(const nsACString& aHost,
const nsACString& aOverride)
{
- nsAutoCString host(aHost);
- nsAutoCString override(aOverride);
- int32_t overrideLength = override.Length();
- int32_t tokenStart = 0;
- int32_t offset = 0;
- bool star = false;
-
- while (tokenStart < overrideLength) {
- int32_t tokenEnd = override.FindChar('*', tokenStart);
- if (tokenEnd == tokenStart) {
- star = true;
- tokenStart++;
- // If the character following the '*' is a '.' character then skip
- // it so that "*.foo.com" allows "foo.com".
- if (override.FindChar('.', tokenStart) == tokenStart)
- tokenStart++;
- } else {
- if (tokenEnd == -1)
- tokenEnd = overrideLength;
- nsAutoCString token(Substring(override, tokenStart,
- tokenEnd - tokenStart));
- offset = host.Find(token, offset);
- if (offset == -1 || (!star && offset))
- return false;
- star = false;
- tokenStart = tokenEnd;
- offset += token.Length();
- }
- }
-
- return (star || (offset == host.Length()));
+ return mozilla::toolkit::system::IsHostProxyEntry(aHost, aOverride);
}
nsresult
nsWindowsSystemProxySettings::GetPACURI(nsACString& aResult)
{
PROFILER_LABEL_FUNC(js::ProfileEntry::Category::STORAGE);
nsresult rv;
uint32_t flags = 0;