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