OLD | NEW |
1 // Copyright 2008, Google Inc. | 1 // Copyright 2008, Google Inc. |
2 // All rights reserved. | 2 // All rights reserved. |
3 // | 3 // |
4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
6 // met: | 6 // met: |
7 // | 7 // |
8 // * Redistributions of source code must retain the above copyright | 8 // * Redistributions of source code must retain the above copyright |
9 // notice, this list of conditions and the following disclaimer. | 9 // notice, this list of conditions and the following disclaimer. |
10 // * Redistributions in binary form must reproduce the above | 10 // * Redistributions in binary form must reproduce the above |
(...skipping 14 matching lines...) Expand all Loading... |
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 | 29 |
30 #ifndef GOOGLEURL_SRC_URL_CANON_IP_H__ | 30 #ifndef GOOGLEURL_SRC_URL_CANON_IP_H__ |
31 #define GOOGLEURL_SRC_URL_CANON_IP_H__ | 31 #define GOOGLEURL_SRC_URL_CANON_IP_H__ |
32 | 32 |
33 #include "base/string16.h" | 33 #include "base/string16.h" |
34 #include "googleurl/src/url_canon.h" | 34 #include "googleurl/src/url_canon.h" |
| 35 #include "googleurl/src/url_common.h" |
35 #include "googleurl/src/url_parse.h" | 36 #include "googleurl/src/url_parse.h" |
36 | 37 |
37 namespace url_canon { | 38 namespace url_canon { |
38 | 39 |
39 // Searches the host name for the portions of the IPv4 address. On success, | 40 // Searches the host name for the portions of the IPv4 address. On success, |
40 // each component will be placed into |components| and it will return true. | 41 // each component will be placed into |components| and it will return true. |
41 // It will return false if the host can not be separated as an IPv4 address | 42 // It will return false if the host can not be separated as an IPv4 address |
42 // or if there are any non-7-bit characters or other characters that can not | 43 // or if there are any non-7-bit characters or other characters that can not |
43 // be in an IP address. (This is important so we fail as early as possible for | 44 // be in an IP address. (This is important so we fail as early as possible for |
44 // common non-IP hostnames.) | 45 // common non-IP hostnames.) |
45 // | 46 // |
46 // Not all components may exist. If there are only 3 components, for example, | 47 // Not all components may exist. If there are only 3 components, for example, |
47 // the last one will have a length of -1 or 0 to indicate it does not exist. | 48 // the last one will have a length of -1 or 0 to indicate it does not exist. |
48 // | 49 // |
49 // Note that many platform's inet_addr will ignore everything after a space | 50 // Note that many platform's inet_addr will ignore everything after a space |
50 // in certain curcumstances if the stuff before the space looks like an IP | 51 // in certain curcumstances if the stuff before the space looks like an IP |
51 // address. IE6 is included in this. We do NOT handle this case. In many cases, | 52 // address. IE6 is included in this. We do NOT handle this case. In many cases, |
52 // the browser's canonicalization will get run before this which converts | 53 // the browser's canonicalization will get run before this which converts |
53 // spaces to %20 (in the case of IE7) or rejects them (in the case of | 54 // spaces to %20 (in the case of IE7) or rejects them (in the case of |
54 // Mozilla), so this code path never gets hit. Our host canonicalization will | 55 // Mozilla), so this code path never gets hit. Our host canonicalization will |
55 // notice these spaces and escape them, which will make IP address finding | 56 // notice these spaces and escape them, which will make IP address finding |
56 // fail. This seems like better behavior than stripping after a space. | 57 // fail. This seems like better behavior than stripping after a space. |
57 bool FindIPv4Components(const char* spec, | 58 GURL_API bool FindIPv4Components(const char* spec, |
58 const url_parse::Component& host, | 59 const url_parse::Component& host, |
59 url_parse::Component components[4]); | 60 url_parse::Component components[4]); |
60 bool FindIPv4Components(const char16* spec, | 61 GURL_API bool FindIPv4Components(const char16* spec, |
61 const url_parse::Component& host, | 62 const url_parse::Component& host, |
62 url_parse::Component components[4]); | 63 url_parse::Component components[4]); |
63 | 64 |
64 // Converts an IPv4 address to a 32-bit number (network byte order). | 65 // Converts an IPv4 address to a 32-bit number (network byte order). |
65 // | 66 // |
66 // Possible return values: | 67 // Possible return values: |
67 // IPV4 - IPv4 address was successfully parsed. | 68 // IPV4 - IPv4 address was successfully parsed. |
68 // BROKEN - Input was formatted like an IPv4 address, but overflow occurred | 69 // BROKEN - Input was formatted like an IPv4 address, but overflow occurred |
69 // during parsing. | 70 // during parsing. |
70 // NEUTRAL - Input couldn't possibly be interpreted as an IPv4 address. | 71 // NEUTRAL - Input couldn't possibly be interpreted as an IPv4 address. |
71 // It might be an IPv6 address, or a hostname. | 72 // It might be an IPv6 address, or a hostname. |
72 // | 73 // |
73 // On success, |num_ipv4_components| will be populated with the number of | 74 // On success, |num_ipv4_components| will be populated with the number of |
74 // components in the IPv4 address. | 75 // components in the IPv4 address. |
75 CanonHostInfo::Family IPv4AddressToNumber(const char* spec, | 76 GURL_API CanonHostInfo::Family IPv4AddressToNumber( |
76 const url_parse::Component& host, | 77 const char* spec, |
77 unsigned char address[4], | 78 const url_parse::Component& host, |
78 int* num_ipv4_components); | 79 unsigned char address[4], |
79 CanonHostInfo::Family IPv4AddressToNumber(const char16* spec, | 80 int* num_ipv4_components); |
80 const url_parse::Component& host, | 81 GURL_API CanonHostInfo::Family IPv4AddressToNumber( |
81 unsigned char address[4], | 82 const char16* spec, |
82 int* num_ipv4_components); | 83 const url_parse::Component& host, |
| 84 unsigned char address[4], |
| 85 int* num_ipv4_components); |
83 | 86 |
84 // Converts an IPv6 address to a 128-bit number (network byte order), returning | 87 // Converts an IPv6 address to a 128-bit number (network byte order), returning |
85 // true on success. False means that the input was not a valid IPv6 address. | 88 // true on success. False means that the input was not a valid IPv6 address. |
86 // | 89 // |
87 // NOTE that |host| is expected to be surrounded by square brackets. | 90 // NOTE that |host| is expected to be surrounded by square brackets. |
88 // i.e. "[::1]" rather than "::1". | 91 // i.e. "[::1]" rather than "::1". |
89 bool IPv6AddressToNumber(const char* spec, | 92 GURL_API bool IPv6AddressToNumber(const char* spec, |
90 const url_parse::Component& host, | 93 const url_parse::Component& host, |
91 unsigned char address[16]); | 94 unsigned char address[16]); |
92 bool IPv6AddressToNumber(const char16* spec, | 95 GURL_API bool IPv6AddressToNumber(const char16* spec, |
93 const url_parse::Component& host, | 96 const url_parse::Component& host, |
94 unsigned char address[16]); | 97 unsigned char address[16]); |
95 | 98 |
96 } // namespace url_canon | 99 } // namespace url_canon |
97 | 100 |
98 #endif // GOOGLEURL_SRC_URL_CANON_IP_H__ | 101 #endif // GOOGLEURL_SRC_URL_CANON_IP_H__ |
OLD | NEW |