Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(524)

Side by Side Diff: net/base/net_util.h

Issue 6898026: Eliminate wstring from base/utf_offset_string_conversions.h, net/base/escape.h, and net/base/net_... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #pragma once 7 #pragma once
8 8
9 #include "build/build_config.h" 9 #include "build/build_config.h"
10 10
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 void GetIdentityFromURL(const GURL& url, 128 void GetIdentityFromURL(const GURL& url,
129 string16* username, 129 string16* username,
130 string16* password); 130 string16* password);
131 131
132 // Returns either the host from |url|, or, if the host is empty, the full spec. 132 // Returns either the host from |url|, or, if the host is empty, the full spec.
133 std::string GetHostOrSpecFromURL(const GURL& url); 133 std::string GetHostOrSpecFromURL(const GURL& url);
134 134
135 // Return the value of the HTTP response header with name 'name'. 'headers' 135 // Return the value of the HTTP response header with name 'name'. 'headers'
136 // should be in the format that URLRequest::GetResponseHeaders() returns. 136 // should be in the format that URLRequest::GetResponseHeaders() returns.
137 // Returns the empty string if the header is not found. 137 // Returns the empty string if the header is not found.
138 std::wstring GetSpecificHeader(const std::wstring& headers,
139 const std::wstring& name);
140 std::string GetSpecificHeader(const std::string& headers, 138 std::string GetSpecificHeader(const std::string& headers,
141 const std::string& name); 139 const std::string& name);
142 140
143 // Return the value of the HTTP response header field's parameter named 141 // Return the value of the HTTP response header field's parameter named
144 // 'param_name'. Returns the empty string if the parameter is not found or is 142 // 'param_name'. Returns the empty string if the parameter is not found or is
145 // improperly formatted. 143 // improperly formatted.
146 std::wstring GetHeaderParamValue(const std::wstring& field, 144 std::string GetHeaderParamValue(const std::string& header,
147 const std::wstring& param_name,
148 QuoteRule::Type quote_rule);
149 std::string GetHeaderParamValue(const std::string& field,
150 const std::string& param_name, 145 const std::string& param_name,
151 QuoteRule::Type quote_rule); 146 QuoteRule::Type quote_rule);
152 147
153 // Return the filename extracted from Content-Disposition header. The following 148 // Return the filename extracted from Content-Disposition header. The following
154 // formats are tried in order listed below: 149 // formats are tried in order listed below:
155 // 150 //
156 // 1. RFC 5987 151 // 1. RFC 5987
157 // 2. RFC 2047 152 // 2. RFC 2047
158 // 3. Raw-8bit-characters : 153 // 3. Raw-8bit-characters :
159 // a. UTF-8, b. referrer_charset, c. default os codepage. 154 // a. UTF-8, b. referrer_charset, c. default os codepage.
(...skipping 19 matching lines...) Expand all
179 // net_util_unittest. 174 // net_util_unittest.
180 // 175 //
181 std::string GetFileNameFromCD(const std::string& header, 176 std::string GetFileNameFromCD(const std::string& header,
182 const std::string& referrer_charset); 177 const std::string& referrer_charset);
183 178
184 // Converts the given host name to unicode characters. This can be called for 179 // Converts the given host name to unicode characters. This can be called for
185 // any host name, if the input is not IDN or is invalid in some way, we'll just 180 // any host name, if the input is not IDN or is invalid in some way, we'll just
186 // return the ASCII source so it is still usable. 181 // return the ASCII source so it is still usable.
187 // 182 //
188 // The input should be the canonicalized ASCII host name from GURL. This 183 // The input should be the canonicalized ASCII host name from GURL. This
189 // function does NOT accept UTF-8! Its length must also be given (this is 184 // function does NOT accept UTF-8!
190 // designed to work on the substring of the host out of a URL spec).
191 // 185 //
192 // |languages| is a comma separated list of ISO 639 language codes. It 186 // |languages| is a comma separated list of ISO 639 language codes. It
193 // is used to determine whether a hostname is 'comprehensible' to a user 187 // is used to determine whether a hostname is 'comprehensible' to a user
194 // who understands languages listed. |host| will be converted to a 188 // who understands languages listed. |host| will be converted to a
195 // human-readable form (Unicode) ONLY when each component of |host| is 189 // human-readable form (Unicode) ONLY when each component of |host| is
196 // regarded as 'comprehensible'. Scipt-mixing is not allowed except that 190 // regarded as 'comprehensible'. Scipt-mixing is not allowed except that
197 // Latin letters in the ASCII range can be mixed with a limited set of 191 // Latin letters in the ASCII range can be mixed with a limited set of
198 // script-language pairs (currently Han, Kana and Hangul for zh,ja and ko). 192 // script-language pairs (currently Han, Kana and Hangul for zh,ja and ko).
199 // When |languages| is empty, even that mixing is not allowed. 193 // When |languages| is empty, even that mixing is not allowed.
200 // 194 string16 IDNToUnicode(const std::string& host,
201 // (|offset[s]_for_adjustment|) specifies one or more offsets into the original 195 const std::string& languages);
202 // |url|'s spec(); each offset will be adjusted to point at the same logical
203 // place in the result strings during decoding. If this isn't possible because
204 // an offset points past the end of |host| or into the middle of a punycode
205 // sequence, the offending offset will be set to std::wstring::npos.
206 // |offset[s]_for_adjustment| may be NULL.
207 std::wstring IDNToUnicode(const char* host,
208 size_t host_len,
209 const std::wstring& languages,
210 size_t* offset_for_adjustment);
211 std::wstring IDNToUnicodeWithOffsets(
212 const char* host,
213 size_t host_len,
214 const std::wstring& languages,
215 std::vector<size_t>* offsets_for_adjustment);
216 196
217 // Canonicalizes |host| and returns it. Also fills |host_info| with 197 // Canonicalizes |host| and returns it. Also fills |host_info| with
218 // IP address information. |host_info| must not be NULL. 198 // IP address information. |host_info| must not be NULL.
219 std::string CanonicalizeHost(const std::string& host, 199 std::string CanonicalizeHost(const std::string& host,
220 url_canon::CanonHostInfo* host_info); 200 url_canon::CanonHostInfo* host_info);
221 std::string CanonicalizeHost(const std::wstring& host,
222 url_canon::CanonHostInfo* host_info);
223 201
224 // Returns true if |host| is not an IP address and is compliant with a set of 202 // Returns true if |host| is not an IP address and is compliant with a set of
225 // rules based on RFC 1738 and tweaked to be compatible with the real world. 203 // rules based on RFC 1738 and tweaked to be compatible with the real world.
226 // The rules are: 204 // The rules are:
227 // * One or more components separated by '.' 205 // * One or more components separated by '.'
228 // * Each component begins and ends with an alphanumeric character 206 // * Each component begins and ends with an alphanumeric character
229 // * Each component contains only alphanumeric characters and '-' or '_' 207 // * Each component contains only alphanumeric characters and '-' or '_'
230 // * The last component does not begin with a digit 208 // * The last component does not begin with a digit
231 // * Optional trailing dot after last component (means "treat as FQDN") 209 // * Optional trailing dot after last component (means "treat as FQDN")
232 // If |desired_tld| is non-NULL, the host will only be considered invalid if 210 // If |desired_tld| is non-NULL, the host will only be considered invalid if
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 // restricted. 265 // restricted.
288 bool IsPortAllowedByFtp(int port); 266 bool IsPortAllowedByFtp(int port);
289 267
290 // Check if banned |port| has been overriden by an entry in 268 // Check if banned |port| has been overriden by an entry in
291 // |explicitly_allowed_ports_|. 269 // |explicitly_allowed_ports_|.
292 bool IsPortAllowedByOverride(int port); 270 bool IsPortAllowedByOverride(int port);
293 271
294 // Set socket to non-blocking mode 272 // Set socket to non-blocking mode
295 int SetNonBlocking(int fd); 273 int SetNonBlocking(int fd);
296 274
297 // Appends the given part of the original URL to the output string formatted for 275 // Formats the host in |url| and appends it to |output|. The host formatter
298 // the user. The given parsed structure will be updated. The host name formatter 276 // takes the same accept languages component as ElideURL().
299 // also takes the same accept languages component as ElideURL. |new_parsed| may
300 // be null.
301 //
302 // (|offset[s]_for_adjustment|) specifies one or more offsets into the original
303 // |url|'s spec(); each offset will be adjusted to point at the same logical
304 // place in the result strings after reformatting of the host. If this isn't
305 // possible because an offset points past the end of the host or into the middle
306 // of a multi-character sequence, the offending offset will be set to
307 // std::wstring::npos. |offset[s]_for_adjustment| may be NULL.
308 void AppendFormattedHost(const GURL& url, 277 void AppendFormattedHost(const GURL& url,
309 const std::wstring& languages, 278 const std::string& languages,
310 std::wstring* output, 279 string16* output);
311 url_parse::Parsed* new_parsed,
312 size_t* offset_for_adjustment);
313 void AppendFormattedHostWithOffsets(
314 const GURL& url,
315 const std::wstring& languages,
316 std::wstring* output,
317 url_parse::Parsed* new_parsed,
318 std::vector<size_t>* offsets_for_adjustment);
319 280
320 // Creates a string representation of |url|. The IDN host name may be in Unicode 281 // Creates a string representation of |url|. The IDN host name may be in Unicode
321 // if |languages| accepts the Unicode representation. |format_type| is a bitmask 282 // if |languages| accepts the Unicode representation. |format_type| is a bitmask
322 // of FormatUrlTypes, see it for details. |unescape_rules| defines how to clean 283 // of FormatUrlTypes, see it for details. |unescape_rules| defines how to clean
323 // the URL for human readability. You will generally want |UnescapeRule::SPACES| 284 // the URL for human readability. You will generally want |UnescapeRule::SPACES|
324 // for display to the user if you can handle spaces, or |UnescapeRule::NORMAL| 285 // for display to the user if you can handle spaces, or |UnescapeRule::NORMAL|
325 // if not. If the path part and the query part seem to be encoded in %-encoded 286 // if not. If the path part and the query part seem to be encoded in %-encoded
326 // UTF-8, decodes %-encoding and UTF-8. 287 // UTF-8, decodes %-encoding and UTF-8.
327 // 288 //
328 // The last three parameters may be NULL. 289 // The last three parameters may be NULL.
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 }; 435 };
475 436
476 typedef std::vector<NetworkInterface> NetworkInterfaceList; 437 typedef std::vector<NetworkInterface> NetworkInterfaceList;
477 438
478 // Returns list of network interfaces except loopback interface. If an 439 // Returns list of network interfaces except loopback interface. If an
479 // interface has more than one address, a separate entry is added to 440 // interface has more than one address, a separate entry is added to
480 // the list for each address. 441 // the list for each address.
481 // Can be called only on a thread that allows IO. 442 // Can be called only on a thread that allows IO.
482 bool GetNetworkList(NetworkInterfaceList* networks); 443 bool GetNetworkList(NetworkInterfaceList* networks);
483 444
484 // Private adjustment function called by std::transform which sets the offset
485 // to npos if the offset occurs at or before |component_start|, otherwise don't
486 // alter the offset. Exposed here for unit testing.
487 struct ClampComponentOffset {
488 explicit ClampComponentOffset(size_t component_start);
489 size_t operator()(size_t offset);
490
491 const size_t component_start;
492 };
493
494 } // namespace net 445 } // namespace net
495 446
496 #endif // NET_BASE_NET_UTIL_H_ 447 #endif // NET_BASE_NET_UTIL_H_
OLDNEW
« no previous file with comments | « net/base/escape_unittest.cc ('k') | net/base/net_util.cc » ('j') | net/base/net_util.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698