summaryrefslogtreecommitdiff
path: root/chromium/net/dns/dns_alias_utility.h
blob: 421bc270d83d181858e84737e69af9dc296ca7f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef NET_DNS_DNS_ALIAS_UTILITY_H_
#define NET_DNS_DNS_ALIAS_UTILITY_H_

#include <set>
#include <string>

#include "base/strings/string_piece.h"
#include "net/base/net_export.h"

namespace net::dns_alias_utility {

// Validates that `alias` represents a valid DNS alias name, e.g. CNAME, and
// then URL-canonicalizes the name. Returns empty string if not valid or unable
// to canonicalize.
NET_EXPORT_PRIVATE std::string ValidateAndCanonicalizeAlias(
    base::StringPiece alias);

// Returns a fixed up set of canonicalized aliases (i.e. aliases that are
// written as hostnames for canonical URLs). The set is stripped of "localhost",
// IP addresses, duplicates, the empty string, strings longer than
// `dns_protocol::kMaxCharNameLength` characters (with one extra character
// allowed for fully-qualified hostnames, i.e. hostnames ending with '.'), and
// any strings that fail to URL-canonicalize as hosts. The remaining aliases are
// replaced with their canonicalized forms.
NET_EXPORT_PRIVATE std::set<std::string> FixUpDnsAliases(
    const std::set<std::string>& aliases);

}  // namespace net::dns_alias_utility

#endif  // NET_DNS_DNS_ALIAS_UTILITY_H_