From d2e2fba6d8de6cd2e36d26d93df6ceeee4c694d8 Mon Sep 17 00:00:00 2001 From: Peter Snyder Date: Thu, 31 Jan 2019 19:43:24 -0800 Subject: [PATCH 01/13] init --- .gitignore | 2 + binding.gyp | 3 ++ etld/domain.cc | 21 ++++++++++ etld/domain.h | 45 +++++++++++++++++++++ etld/etld.cc | 81 ++++++++++++++++++++++++++++++++++++++ etld/etld.h | 64 ++++++++++++++++++++++++++++++ etld/public_suffix_rule.cc | 0 etld/public_suffix_rule.h | 40 +++++++++++++++++++ etld/types.h | 19 +++++++++ test/binding.gyp | 5 +++ test/etld_test.cc | 31 +++++++++++++++ test/js/matchingTest.js | 31 +++++++++++++++ test/protocol_test.cc | 2 +- 13 files changed, 343 insertions(+), 1 deletion(-) create mode 100644 etld/domain.cc create mode 100644 etld/domain.h create mode 100644 etld/etld.cc create mode 100644 etld/etld.h create mode 100644 etld/public_suffix_rule.cc create mode 100644 etld/public_suffix_rule.h create mode 100644 etld/types.h create mode 100644 test/etld_test.cc diff --git a/.gitignore b/.gitignore index 71d702c..28dd025 100644 --- a/.gitignore +++ b/.gitignore @@ -48,3 +48,5 @@ out # VIM temp files *.swp + +.vscode diff --git a/binding.gyp b/binding.gyp index fe26fc8..e68ca6d 100644 --- a/binding.gyp +++ b/binding.gyp @@ -19,6 +19,9 @@ "no_fingerprint_domain.h", "protocol.cc", "protocol.h", + "etld/domain.cc", + "etld/domain.h", + "etld/types.h", "./node_modules/bloom-filter-cpp/BloomFilter.cpp", "./node_modules/bloom-filter-cpp/BloomFilter.h", "./node_modules/bloom-filter-cpp/hashFn.cpp", diff --git a/etld/domain.cc b/etld/domain.cc new file mode 100644 index 0000000..367b739 --- /dev/null +++ b/etld/domain.cc @@ -0,0 +1,21 @@ +/* Copyright (c) 2015 Brian R. Bondy. Distributed under the MPL2 license. + * 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 +#include "./domain.h" + +namespace Brave { +namespace eTLD { + +std::string Domain::toString() const { + std::stringstream asString; + for (auto &&str : labels_) { + asString << str; + } + return asString.str(); +} + +} +} \ No newline at end of file diff --git a/etld/domain.h b/etld/domain.h new file mode 100644 index 0000000..3af9ba4 --- /dev/null +++ b/etld/domain.h @@ -0,0 +1,45 @@ +/* Copyright (c) 2015 Brian R. Bondy. Distributed under the MPL2 license. + * 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 BRAVE_ETLD_DOMAIN_H_ +#define BRAVE_ETLD_DOMAIN_H_ + +#include +#include +#include +#include "./types.h" + +namespace Brave { +namespace eTLD { + +class Domain { + public: + Domain(const std::string &domain) { + std::size_t current, previous = 0; + current = domain.find("."); + while (current != std::string::npos) { + labels_.push_back(domain.substr(previous, current - previous)); + previous = current + 1; + current = domain.find(".", previous); + } + if (previous != 0) { + labels_.push_back(domain.substr(previous, current - previous)); + } + }; + + int length() const { + return labels_.size(); + } + + std::string toString() const; + + protected: + std::vector