1 // Copyright 2013 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef NET_TOOLS_TLD_CLEANUP_TLD_CLEANUP_UTIL_H_ 6 #define NET_TOOLS_TLD_CLEANUP_TLD_CLEANUP_UTIL_H_ 7 8 #include <map> 9 #include <string> 10 #include <tuple> 11 12 namespace base { 13 class FilePath; 14 } // namespace base 15 16 namespace net::tld_cleanup { 17 18 struct Rule { 19 bool exception; 20 bool wildcard; 21 bool is_private; 22 23 bool operator==(const Rule& other) const { 24 return std::tie(exception, wildcard, is_private) == 25 std::tie(other.exception, other.wildcard, other.is_private); 26 } 27 }; 28 29 typedef std::map<std::string, Rule> RuleMap; 30 31 // These result codes should be in increasing order of severity. 32 enum class NormalizeResult { 33 kSuccess, 34 kWarning, 35 kError, 36 }; 37 38 // Converts the list of domain rules contained in the `rules` map to string. 39 // Rule lines all have trailing LF in the output. 40 std::string RulesToGperf(const RuleMap& rules); 41 42 // Loads the file described by |in_filename|, converts it to the desired format 43 // (see the file comments in tld_cleanup.cc), and saves it into |out_filename|. 44 // Returns the most severe of the result codes encountered when normalizing the 45 // rules. 46 NormalizeResult NormalizeFile(const base::FilePath& in_filename, 47 const base::FilePath& out_filename); 48 49 // Parses |data|, and converts it to the internal data format RuleMap. Returns 50 // the most severe of the result codes encountered when normalizing the rules. 51 NormalizeResult NormalizeDataToRuleMap(const std::string& data, RuleMap& rules); 52 53 } // namespace net::tld_cleanup 54 55 #endif // NET_TOOLS_TLD_CLEANUP_TLD_CLEANUP_UTIL_H_ 56