OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef NET_DNS_DNS_UTIL_H_ | 5 #ifndef NET_DNS_DNS_UTIL_H_ |
6 #define NET_DNS_DNS_UTIL_H_ | 6 #define NET_DNS_DNS_UTIL_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/strings/string_piece.h" | 10 #include "base/strings/string_piece.h" |
11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
12 #include "net/base/net_export.h" | 12 #include "net/base/net_export.h" |
13 #include "net/base/network_change_notifier.h" | 13 #include "net/base/network_change_notifier.h" |
14 | 14 |
15 namespace net { | 15 namespace net { |
16 | 16 |
17 class AddressList; | 17 class AddressList; |
18 | 18 |
19 // DNSDomainFromDot - convert a domain string to DNS format. From DJB's | 19 // DNSDomainFromDot - convert a domain string to DNS format. From DJB's |
20 // public domain DNS library. | 20 // public domain DNS library. |
21 // | 21 // |
22 // dotted: a string in dotted form: "www.google.com" | 22 // dotted: a string in dotted form: "www.google.com" |
23 // out: a result in DNS form: "\x03www\x06google\x03com\x00" | 23 // out: a result in DNS form: "\x03www\x06google\x03com\x00" |
24 NET_EXPORT_PRIVATE bool DNSDomainFromDot(const base::StringPiece& dotted, | 24 NET_EXPORT_PRIVATE bool DNSDomainFromDot(const base::StringPiece& dotted, |
25 std::string* out); | 25 std::string* out); |
26 | 26 |
27 // Checks that a hostname is valid. Simple wrapper around DNSDomainFromDot. | 27 // Checks that a hostname is valid. Simple wrapper around DNSDomainFromDot. |
28 NET_EXPORT_PRIVATE bool IsValidDNSDomain(const base::StringPiece& dotted); | 28 NET_EXPORT_PRIVATE bool IsValidDNSDomain(const base::StringPiece& dotted); |
29 | 29 |
| 30 // Returns true if the character is valid in a DNS hostname label, whether in |
| 31 // the first position or later in the label. |
| 32 // |
| 33 // This function asserts a looser form of the restrictions in RFC 7719 (section |
| 34 // 2; https://tools.ietf.org/html/rfc7719#section-2): hostnames can include |
| 35 // characters a-z, A-Z, 0-9, -, and _, and any of those characters (except -) |
| 36 // are legal in the first position. The looser rules are necessary to support |
| 37 // service records (initial _), and non-compliant but attested hostnames that |
| 38 // include _. These looser rules also allow Punycode and hence IDN. |
| 39 // |
| 40 // TODO(palmer): In the future, when we can remove support for invalid names, |
| 41 // this can be a private implementation detail of |DNSDomainFromDot|, and need |
| 42 // not be NET_EXPORT_PRIVATE. |
| 43 NET_EXPORT_PRIVATE bool IsValidHostLabelCharacter(char c, bool is_first_char); |
| 44 |
30 // DNSDomainToString converts a domain in DNS format to a dotted string. | 45 // DNSDomainToString converts a domain in DNS format to a dotted string. |
31 // Excludes the dot at the end. | 46 // Excludes the dot at the end. |
32 NET_EXPORT_PRIVATE std::string DNSDomainToString( | 47 NET_EXPORT_PRIVATE std::string DNSDomainToString( |
33 const base::StringPiece& domain); | 48 const base::StringPiece& domain); |
34 | 49 |
35 #if !defined(OS_NACL) | 50 #if !defined(OS_NACL) |
36 NET_EXPORT_PRIVATE | 51 NET_EXPORT_PRIVATE |
37 base::TimeDelta GetTimeDeltaForConnectionTypeFromFieldTrialOrDefault( | 52 base::TimeDelta GetTimeDeltaForConnectionTypeFromFieldTrialOrDefault( |
38 const char* field_trial_name, | 53 const char* field_trial_name, |
39 base::TimeDelta default_delta, | 54 base::TimeDelta default_delta, |
(...skipping 15 matching lines...) Expand all Loading... |
55 }; | 70 }; |
56 | 71 |
57 // Compares two AddressLists to see how similar or different their addresses | 72 // Compares two AddressLists to see how similar or different their addresses |
58 // are. (See |AddressListDeltaType| for details of exactly what's checked.) | 73 // are. (See |AddressListDeltaType| for details of exactly what's checked.) |
59 AddressListDeltaType FindAddressListDeltaType(const AddressList& a, | 74 AddressListDeltaType FindAddressListDeltaType(const AddressList& a, |
60 const AddressList& b); | 75 const AddressList& b); |
61 | 76 |
62 } // namespace net | 77 } // namespace net |
63 | 78 |
64 #endif // NET_DNS_DNS_UTIL_H_ | 79 #endif // NET_DNS_DNS_UTIL_H_ |
OLD | NEW |