Files
tubestation/toolkit/system/windowsproxy/ProxyUtils.cpp
Liang-Heng Chen 79df15ca74 Bug 1258977 - Part 1: separate match function; r=bagder
MozReview-Commit-ID: J4DVAzI0bZm
2016-05-26 14:34:51 +08:00

53 lines
1.5 KiB
C++

/* -*- 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