Bug 1258977 - Part 1: separate match function; r=bagder
authorLiang-Heng Chen <xeonchen@mozilla.com>
Thu, 26 May 2016 14:34:51 +0800
changeset 340860 d264fcc9f04ad7bfc213140303019d788ef44c40
parent 340859 7d46836853cd3bc69986f012bcc9466a8c00853a
child 340861 fd981e994ec94e20bcf4251b7920bc36f9ca697e
push id1183
push userraliiev@mozilla.com
push dateMon, 05 Sep 2016 20:01:49 +0000
treeherdermozilla-release@3148731bed45 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbagder
bugs1258977
milestone49.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1258977 - Part 1: separate match function; r=bagder MozReview-Commit-ID: J4DVAzI0bZm
toolkit/system/windowsproxy/ProxyUtils.cpp
toolkit/system/windowsproxy/ProxyUtils.h
toolkit/system/windowsproxy/moz.build
toolkit/system/windowsproxy/nsWindowsSystemProxySettings.cpp
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;