OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 URL_URL_CANON_IP_H_ | 5 #ifndef URL_URL_CANON_IP_H_ |
6 #define URL_URL_CANON_IP_H_ | 6 #define URL_URL_CANON_IP_H_ |
7 | 7 |
8 #include "base/string16.h" | 8 #include "base/string16.h" |
9 #include "url/url_canon.h" | 9 #include "url/url_canon.h" |
10 #include "url/url_export.h" | |
11 #include "url/url_parse.h" | 10 #include "url/url_parse.h" |
12 | 11 |
13 namespace url_canon { | 12 namespace url_canon { |
14 | 13 |
15 // Writes the given IPv4 address to |output|. | 14 // Writes the given IPv4 address to |output|. |
16 URL_EXPORT void AppendIPv4Address(const unsigned char address[4], | 15 void AppendIPv4Address(const unsigned char address[4], |
17 CanonOutput* output); | 16 CanonOutput* output); |
18 | 17 |
19 // Writes the given IPv6 address to |output|. | 18 // Writes the given IPv6 address to |output|. |
20 URL_EXPORT void AppendIPv6Address(const unsigned char address[16], | 19 void AppendIPv6Address(const unsigned char address[16], |
21 CanonOutput* output); | 20 CanonOutput* output); |
22 | 21 |
23 // Searches the host name for the portions of the IPv4 address. On success, | 22 // Searches the host name for the portions of the IPv4 address. On success, |
24 // each component will be placed into |components| and it will return true. | 23 // each component will be placed into |components| and it will return true. |
25 // It will return false if the host can not be separated as an IPv4 address | 24 // It will return false if the host can not be separated as an IPv4 address |
26 // or if there are any non-7-bit characters or other characters that can not | 25 // or if there are any non-7-bit characters or other characters that can not |
27 // be in an IP address. (This is important so we fail as early as possible for | 26 // be in an IP address. (This is important so we fail as early as possible for |
28 // common non-IP hostnames.) | 27 // common non-IP hostnames.) |
29 // | 28 // |
30 // Not all components may exist. If there are only 3 components, for example, | 29 // Not all components may exist. If there are only 3 components, for example, |
31 // the last one will have a length of -1 or 0 to indicate it does not exist. | 30 // the last one will have a length of -1 or 0 to indicate it does not exist. |
32 // | 31 // |
33 // Note that many platform's inet_addr will ignore everything after a space | 32 // Note that many platform's inet_addr will ignore everything after a space |
34 // in certain curcumstances if the stuff before the space looks like an IP | 33 // in certain curcumstances if the stuff before the space looks like an IP |
35 // address. IE6 is included in this. We do NOT handle this case. In many cases, | 34 // address. IE6 is included in this. We do NOT handle this case. In many cases, |
36 // the browser's canonicalization will get run before this which converts | 35 // the browser's canonicalization will get run before this which converts |
37 // spaces to %20 (in the case of IE7) or rejects them (in the case of | 36 // spaces to %20 (in the case of IE7) or rejects them (in the case of |
38 // Mozilla), so this code path never gets hit. Our host canonicalization will | 37 // Mozilla), so this code path never gets hit. Our host canonicalization will |
39 // notice these spaces and escape them, which will make IP address finding | 38 // notice these spaces and escape them, which will make IP address finding |
40 // fail. This seems like better behavior than stripping after a space. | 39 // fail. This seems like better behavior than stripping after a space. |
41 URL_EXPORT bool FindIPv4Components(const char* spec, | 40 bool FindIPv4Components(const char* spec, |
42 const url_parse::Component& host, | 41 const url_parse::Component& host, |
43 url_parse::Component components[4]); | 42 url_parse::Component components[4]); |
44 URL_EXPORT bool FindIPv4Components(const char16* spec, | 43 bool FindIPv4Components(const char16* spec, |
45 const url_parse::Component& host, | 44 const url_parse::Component& host, |
46 url_parse::Component components[4]); | 45 url_parse::Component components[4]); |
47 | 46 |
48 // Converts an IPv4 address to a 32-bit number (network byte order). | 47 // Converts an IPv4 address to a 32-bit number (network byte order). |
49 // | 48 // |
50 // Possible return values: | 49 // Possible return values: |
51 // IPV4 - IPv4 address was successfully parsed. | 50 // IPV4 - IPv4 address was successfully parsed. |
52 // BROKEN - Input was formatted like an IPv4 address, but overflow occurred | 51 // BROKEN - Input was formatted like an IPv4 address, but overflow occurred |
53 // during parsing. | 52 // during parsing. |
54 // NEUTRAL - Input couldn't possibly be interpreted as an IPv4 address. | 53 // NEUTRAL - Input couldn't possibly be interpreted as an IPv4 address. |
55 // It might be an IPv6 address, or a hostname. | 54 // It might be an IPv6 address, or a hostname. |
56 // | 55 // |
57 // On success, |num_ipv4_components| will be populated with the number of | 56 // On success, |num_ipv4_components| will be populated with the number of |
58 // components in the IPv4 address. | 57 // components in the IPv4 address. |
59 URL_EXPORT CanonHostInfo::Family IPv4AddressToNumber( | 58 CanonHostInfo::Family IPv4AddressToNumber( |
60 const char* spec, | 59 const char* spec, |
61 const url_parse::Component& host, | 60 const url_parse::Component& host, |
62 unsigned char address[4], | 61 unsigned char address[4], |
63 int* num_ipv4_components); | 62 int* num_ipv4_components); |
64 URL_EXPORT CanonHostInfo::Family IPv4AddressToNumber( | 63 CanonHostInfo::Family IPv4AddressToNumber( |
65 const char16* spec, | 64 const char16* spec, |
66 const url_parse::Component& host, | 65 const url_parse::Component& host, |
67 unsigned char address[4], | 66 unsigned char address[4], |
68 int* num_ipv4_components); | 67 int* num_ipv4_components); |
69 | 68 |
70 // Converts an IPv6 address to a 128-bit number (network byte order), returning | 69 // Converts an IPv6 address to a 128-bit number (network byte order), returning |
71 // true on success. False means that the input was not a valid IPv6 address. | 70 // true on success. False means that the input was not a valid IPv6 address. |
72 // | 71 // |
73 // NOTE that |host| is expected to be surrounded by square brackets. | 72 // NOTE that |host| is expected to be surrounded by square brackets. |
74 // i.e. "[::1]" rather than "::1". | 73 // i.e. "[::1]" rather than "::1". |
75 URL_EXPORT bool IPv6AddressToNumber(const char* spec, | 74 bool IPv6AddressToNumber(const char* spec, |
76 const url_parse::Component& host, | 75 const url_parse::Component& host, |
77 unsigned char address[16]); | 76 unsigned char address[16]); |
78 URL_EXPORT bool IPv6AddressToNumber(const char16* spec, | 77 bool IPv6AddressToNumber(const char16* spec, |
79 const url_parse::Component& host, | 78 const url_parse::Component& host, |
80 unsigned char address[16]); | 79 unsigned char address[16]); |
81 | 80 |
82 } // namespace url_canon | 81 } // namespace url_canon |
83 | 82 |
84 #endif // URL_URL_CANON_IP_H_ | 83 #endif // URL_URL_CANON_IP_H_ |
OLD | NEW |