OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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_BASE_NET_UTIL_H_ | 5 #ifndef NET_BASE_NET_UTIL_H_ |
6 #define NET_BASE_NET_UTIL_H_ | 6 #define NET_BASE_NET_UTIL_H_ |
7 | 7 |
8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
9 | 9 |
10 #ifdef OS_WIN | 10 #ifdef OS_WIN |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 // escaping 'unsafe' characters (e.g. (back)slash, colon) as they see fit. | 122 // escaping 'unsafe' characters (e.g. (back)slash, colon) as they see fit. |
123 // | 123 // |
124 // TODO(jungshik): revisit this issue. At the moment, the only caller | 124 // TODO(jungshik): revisit this issue. At the moment, the only caller |
125 // net_util::GetSuggestedFilename and it calls ReplaceIllegalCharacters. The | 125 // net_util::GetSuggestedFilename and it calls ReplaceIllegalCharacters. The |
126 // other caller is a unit test. Need to figure out expose this function only to | 126 // other caller is a unit test. Need to figure out expose this function only to |
127 // net_util_unittest. | 127 // net_util_unittest. |
128 // | 128 // |
129 std::string GetFileNameFromCD(const std::string& header, | 129 std::string GetFileNameFromCD(const std::string& header, |
130 const std::string& referrer_charset); | 130 const std::string& referrer_charset); |
131 | 131 |
132 // Converts the given host name to unicode characters, APPENDING them to the | 132 // Converts the given host name to unicode characters. This can be called for |
133 // the given output string. This can be called for any host name, if the | 133 // any host name, if the input is not IDN or is invalid in some way, we'll just |
134 // input is not IDN or is invalid in some way, we'll just append the ASCII | 134 // return the ASCII source so it is still usable. |
135 // source to the output so it is still usable. | |
136 // | 135 // |
137 // The input should be the canonicalized ASCII host name from GURL. This | 136 // The input should be the canonicalized ASCII host name from GURL. This |
138 // function does NOT accept UTF-8! Its length must also be given (this is | 137 // function does NOT accept UTF-8! Its length must also be given (this is |
139 // designed to work on the substring of the host out of a URL spec). | 138 // designed to work on the substring of the host out of a URL spec). |
140 // | 139 // |
141 // |languages| is a comma separated list of ISO 639 language codes. It | 140 // |languages| is a comma separated list of ISO 639 language codes. It |
142 // is used to determine whether a hostname is 'comprehensible' to a user | 141 // is used to determine whether a hostname is 'comprehensible' to a user |
143 // who understands languages listed. |host| will be converted to a | 142 // who understands languages listed. |host| will be converted to a |
144 // human-readable form (Unicode) ONLY when each component of |host| is | 143 // human-readable form (Unicode) ONLY when each component of |host| is |
145 // regarded as 'comprehensible'. Scipt-mixing is not allowed except that | 144 // regarded as 'comprehensible'. Scipt-mixing is not allowed except that |
146 // Latin letters in the ASCII range can be mixed with a limited set of | 145 // Latin letters in the ASCII range can be mixed with a limited set of |
147 // script-language pairs (currently Han, Kana and Hangul for zh,ja and ko). | 146 // script-language pairs (currently Han, Kana and Hangul for zh,ja and ko). |
148 // When |languages| is empty, even that mixing is not allowed. | 147 // When |languages| is empty, even that mixing is not allowed. |
149 void IDNToUnicode(const char* host, | 148 // |
150 int host_len, | 149 // |offset_for_adjustment| is an offset into |host|, which will be adjusted to |
151 const std::wstring& languages, | 150 // point at the same logical place in the output string. If this isn't possible |
152 std::wstring* out); | 151 // because it points past the end of |host| or into the middle of a punycode |
| 152 // sequence, it will be set to std::wstring::npos. |offset_for_adjustment| may |
| 153 // be NULL. |
| 154 std::wstring IDNToUnicode(const char* host, |
| 155 size_t host_len, |
| 156 const std::wstring& languages, |
| 157 size_t* offset_for_adjustment); |
153 | 158 |
154 // Canonicalizes |host| and returns it. Also fills |host_info| with | 159 // Canonicalizes |host| and returns it. Also fills |host_info| with |
155 // IP address information. |host_info| must not be NULL. | 160 // IP address information. |host_info| must not be NULL. |
156 std::string CanonicalizeHost(const std::string& host, | 161 std::string CanonicalizeHost(const std::string& host, |
157 url_canon::CanonHostInfo* host_info); | 162 url_canon::CanonHostInfo* host_info); |
158 std::string CanonicalizeHost(const std::wstring& host, | 163 std::string CanonicalizeHost(const std::wstring& host, |
159 url_canon::CanonHostInfo* host_info); | 164 url_canon::CanonHostInfo* host_info); |
160 | 165 |
161 // Returns true if |host| is not an IP address and is compliant with a set of | 166 // Returns true if |host| is not an IP address and is compliant with a set of |
162 // rules based on RFC 1738 and tweaked to be compatible with the real world. | 167 // rules based on RFC 1738 and tweaked to be compatible with the real world. |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 // |explicitly_allowed_ports_|. | 226 // |explicitly_allowed_ports_|. |
222 bool IsPortAllowedByOverride(int port); | 227 bool IsPortAllowedByOverride(int port); |
223 | 228 |
224 // Set socket to non-blocking mode | 229 // Set socket to non-blocking mode |
225 int SetNonBlocking(int fd); | 230 int SetNonBlocking(int fd); |
226 | 231 |
227 // Appends the given part of the original URL to the output string formatted for | 232 // Appends the given part of the original URL to the output string formatted for |
228 // the user. The given parsed structure will be updated. The host name formatter | 233 // the user. The given parsed structure will be updated. The host name formatter |
229 // also takes the same accept languages component as ElideURL. |new_parsed| may | 234 // also takes the same accept languages component as ElideURL. |new_parsed| may |
230 // be null. | 235 // be null. |
231 void AppendFormattedHost(const GURL& url, const std::wstring& languages, | 236 void AppendFormattedHost(const GURL& url, |
232 std::wstring* output, url_parse::Parsed* new_parsed); | 237 const std::wstring& languages, |
| 238 std::wstring* output, |
| 239 url_parse::Parsed* new_parsed, |
| 240 size_t* offset_for_adjustment); |
233 | 241 |
234 // Creates a string representation of |url|. The IDN host name may | 242 // Creates a string representation of |url|. The IDN host name may be in Unicode |
235 // be in Unicode if |languages| accepts the Unicode representation. | 243 // if |languages| accepts the Unicode representation. If |
236 // If |omit_username_password| is true, the username and the password are | 244 // |omit_username_password| is true, any username and password are removed. |
237 // omitted. |unescape_rules| defines how to clean the URL for human readability. | 245 // |unescape_rules| defines how to clean the URL for human readability. |
238 // You will generally want |UnescapeRule::SPACES| for display to the user if you | 246 // You will generally want |UnescapeRule::SPACES| for display to the user if you |
239 // can handle spaces, or |UnescapeRule::NORMAL| if not. If the path part and the | 247 // can handle spaces, or |UnescapeRule::NORMAL| if not. If the path part and the |
240 // query part seem to be encoded in %-encoded UTF-8, decodes %-encoding and | 248 // query part seem to be encoded in %-encoded UTF-8, decodes %-encoding and |
241 // UTF-8. |new_parsed| will have parsing parameters of the resultant URL. | 249 // UTF-8. |
| 250 // |
| 251 // The last three parameters may be NULL. |
| 252 // |new_parsed| will be set to the parsing parameters of the resultant URL. |
242 // |prefix_end| will be the length before the hostname of the resultant URL. | 253 // |prefix_end| will be the length before the hostname of the resultant URL. |
243 // |new_parsed| and |prefix_end| may be NULL. | 254 // |offset_for_adjustment| is an offset into the original |url|'s spec(), which |
| 255 // will be modified to reflect changes this function makes to the output string; |
| 256 // for example, if |url| is "http://a:b@c.com/", |omit_username_password| is |
| 257 // true, and |offset_for_adjustment| is 12 (the offset of '.'), then on return |
| 258 // the output string will be "http://c.com/" and |offset_for_adjustment| will be |
| 259 // 8. If the offset cannot be successfully adjusted (e.g. because it points |
| 260 // into the middle of a component that was entirely removed, past the end of the |
| 261 // string, or into the middle of an encoding sequence), it will be set to |
| 262 // std::wstring::npos. |
244 std::wstring FormatUrl(const GURL& url, | 263 std::wstring FormatUrl(const GURL& url, |
245 const std::wstring& languages, | 264 const std::wstring& languages, |
246 bool omit_username_password, | 265 bool omit_username_password, |
247 UnescapeRule::Type unescape_rules, | 266 UnescapeRule::Type unescape_rules, |
248 url_parse::Parsed* new_parsed, | 267 url_parse::Parsed* new_parsed, |
249 size_t* prefix_end); | 268 size_t* prefix_end, |
| 269 size_t* offset_for_adjustment); |
250 | 270 |
251 // Creates a string representation of |url| for display to the user. | 271 // Creates a string representation of |url| for display to the user. |
252 // This is a shorthand of the above function with omit_username_password=true, | 272 // This is a shorthand of the above function with omit_username_password=true, |
253 // unescape=SPACES, new_parsed=NULL, and prefix_end=NULL. | 273 // unescape=SPACES, new_parsed=NULL, and prefix_end=NULL. |
254 inline std::wstring FormatUrl(const GURL& url, const std::wstring& languages) { | 274 inline std::wstring FormatUrl(const GURL& url, const std::wstring& languages) { |
255 return FormatUrl(url, languages, true, UnescapeRule::SPACES, NULL, NULL); | 275 return FormatUrl(url, languages, true, UnescapeRule::SPACES, NULL, NULL, |
| 276 NULL); |
256 } | 277 } |
257 | 278 |
258 // Strip the portions of |url| that aren't core to the network request. | 279 // Strip the portions of |url| that aren't core to the network request. |
259 // - user name / password | 280 // - user name / password |
260 // - reference section | 281 // - reference section |
261 GURL SimplifyUrlForRequest(const GURL& url); | 282 GURL SimplifyUrlForRequest(const GURL& url); |
262 | 283 |
263 void SetExplicitlyAllowedPorts(const std::wstring& allowed_ports); | 284 void SetExplicitlyAllowedPorts(const std::wstring& allowed_ports); |
264 | 285 |
265 } // namespace net | 286 } // namespace net |
266 | 287 |
267 #endif // NET_BASE_NET_UTIL_H_ | 288 #endif // NET_BASE_NET_UTIL_H_ |
OLD | NEW |