| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #if defined(OS_WIN) | 10 #if defined(OS_WIN) |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 } | 41 } |
| 42 | 42 |
| 43 namespace net { | 43 namespace net { |
| 44 | 44 |
| 45 class AddressList; | 45 class AddressList; |
| 46 | 46 |
| 47 // This is a "forward declaration" to avoid including ip_address_number.h | 47 // This is a "forward declaration" to avoid including ip_address_number.h |
| 48 // Keep this in sync. | 48 // Keep this in sync. |
| 49 typedef std::vector<unsigned char> IPAddressNumber; | 49 typedef std::vector<unsigned char> IPAddressNumber; |
| 50 | 50 |
| 51 // Used by FormatUrl to specify handling of certain parts of the url. |
| 52 typedef uint32_t FormatUrlType; |
| 53 typedef uint32_t FormatUrlTypes; |
| 54 |
| 51 #if defined(OS_WIN) | 55 #if defined(OS_WIN) |
| 52 // Bluetooth address size. Windows Bluetooth is supported via winsock. | 56 // Bluetooth address size. Windows Bluetooth is supported via winsock. |
| 53 static const size_t kBluetoothAddressSize = 6; | 57 static const size_t kBluetoothAddressSize = 6; |
| 54 #endif | 58 #endif |
| 55 | 59 |
| 60 // Nothing is ommitted. |
| 61 NET_EXPORT extern const FormatUrlType kFormatUrlOmitNothing; |
| 62 |
| 63 // If set, any username and password are removed. |
| 64 NET_EXPORT extern const FormatUrlType kFormatUrlOmitUsernamePassword; |
| 65 |
| 66 // If the scheme is 'http://', it's removed. |
| 67 NET_EXPORT extern const FormatUrlType kFormatUrlOmitHTTP; |
| 68 |
| 69 // Omits the path if it is just a slash and there is no query or ref. This is |
| 70 // meaningful for non-file "standard" URLs. |
| 71 NET_EXPORT extern const FormatUrlType kFormatUrlOmitTrailingSlashOnBareHostname; |
| 72 |
| 73 // Convenience for omitting all unecessary types. |
| 74 NET_EXPORT extern const FormatUrlType kFormatUrlOmitAll; |
| 75 |
| 56 // Splits an input of the form <host>[":"<port>] into its consitituent parts. | 76 // Splits an input of the form <host>[":"<port>] into its consitituent parts. |
| 57 // Saves the result into |*host| and |*port|. If the input did not have | 77 // Saves the result into |*host| and |*port|. If the input did not have |
| 58 // the optional port, sets |*port| to -1. | 78 // the optional port, sets |*port| to -1. |
| 59 // Returns true if the parsing was successful, false otherwise. | 79 // Returns true if the parsing was successful, false otherwise. |
| 60 // The returned host is NOT canonicalized, and may be invalid. | 80 // The returned host is NOT canonicalized, and may be invalid. |
| 61 // | 81 // |
| 62 // IPv6 literals must be specified in a bracketed form, for instance: | 82 // IPv6 literals must be specified in a bracketed form, for instance: |
| 63 // [::1]:90 and [::1] | 83 // [::1]:90 and [::1] |
| 64 // | 84 // |
| 65 // The resultant |*host| in both cases will be "::1" (not bracketed). | 85 // The resultant |*host| in both cases will be "::1" (not bracketed). |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 | 140 |
| 121 // Extracts the unescaped username/password from |url|, saving the results | 141 // Extracts the unescaped username/password from |url|, saving the results |
| 122 // into |*username| and |*password|. | 142 // into |*username| and |*password|. |
| 123 NET_EXPORT_PRIVATE void GetIdentityFromURL(const GURL& url, | 143 NET_EXPORT_PRIVATE void GetIdentityFromURL(const GURL& url, |
| 124 base::string16* username, | 144 base::string16* username, |
| 125 base::string16* password); | 145 base::string16* password); |
| 126 | 146 |
| 127 // Returns either the host from |url|, or, if the host is empty, the full spec. | 147 // Returns either the host from |url|, or, if the host is empty, the full spec. |
| 128 NET_EXPORT std::string GetHostOrSpecFromURL(const GURL& url); | 148 NET_EXPORT std::string GetHostOrSpecFromURL(const GURL& url); |
| 129 | 149 |
| 150 // Converts the given host name to unicode characters. This can be called for |
| 151 // any host name, if the input is not IDN or is invalid in some way, we'll just |
| 152 // return the ASCII source so it is still usable. |
| 153 // |
| 154 // The input should be the canonicalized ASCII host name from GURL. This |
| 155 // function does NOT accept UTF-8! |
| 156 // |
| 157 // |languages| is a comma separated list of ISO 639 language codes. It |
| 158 // is used to determine whether a hostname is 'comprehensible' to a user |
| 159 // who understands languages listed. |host| will be converted to a |
| 160 // human-readable form (Unicode) ONLY when each component of |host| is |
| 161 // regarded as 'comprehensible'. Scipt-mixing is not allowed except that |
| 162 // Latin letters in the ASCII range can be mixed with a limited set of |
| 163 // script-language pairs (currently Han, Kana and Hangul for zh,ja and ko). |
| 164 // When |languages| is empty, even that mixing is not allowed. |
| 165 NET_EXPORT base::string16 IDNToUnicode(const std::string& host, |
| 166 const std::string& languages); |
| 167 |
| 130 // Canonicalizes |host| and returns it. Also fills |host_info| with | 168 // Canonicalizes |host| and returns it. Also fills |host_info| with |
| 131 // IP address information. |host_info| must not be NULL. | 169 // IP address information. |host_info| must not be NULL. |
| 132 NET_EXPORT std::string CanonicalizeHost(const std::string& host, | 170 NET_EXPORT std::string CanonicalizeHost(const std::string& host, |
| 133 url::CanonHostInfo* host_info); | 171 url::CanonHostInfo* host_info); |
| 134 | 172 |
| 135 // Returns true if |host| is not an IP address and is compliant with a set of | 173 // Returns true if |host| is not an IP address and is compliant with a set of |
| 136 // rules based on RFC 1738 and tweaked to be compatible with the real world. | 174 // rules based on RFC 1738 and tweaked to be compatible with the real world. |
| 137 // The rules are: | 175 // The rules are: |
| 138 // * One or more components separated by '.' | 176 // * One or more components separated by '.' |
| 139 // * Each component contains only alphanumeric characters and '-' or '_' | 177 // * Each component contains only alphanumeric characters and '-' or '_' |
| (...skipping 29 matching lines...) Expand all Loading... |
| 169 // If text starts with "www." it is removed, otherwise text is returned | 207 // If text starts with "www." it is removed, otherwise text is returned |
| 170 // unmodified. | 208 // unmodified. |
| 171 NET_EXPORT base::string16 StripWWW(const base::string16& text); | 209 NET_EXPORT base::string16 StripWWW(const base::string16& text); |
| 172 | 210 |
| 173 // Runs |url|'s host through StripWWW(). |url| must be valid. | 211 // Runs |url|'s host through StripWWW(). |url| must be valid. |
| 174 NET_EXPORT base::string16 StripWWWFromHost(const GURL& url); | 212 NET_EXPORT base::string16 StripWWWFromHost(const GURL& url); |
| 175 | 213 |
| 176 // Set socket to non-blocking mode | 214 // Set socket to non-blocking mode |
| 177 NET_EXPORT int SetNonBlocking(int fd); | 215 NET_EXPORT int SetNonBlocking(int fd); |
| 178 | 216 |
| 217 // Formats the host in |url| and appends it to |output|. The host formatter |
| 218 // takes the same accept languages component as ElideURL(). |
| 219 NET_EXPORT void AppendFormattedHost(const GURL& url, |
| 220 const std::string& languages, |
| 221 base::string16* output); |
| 222 |
| 223 // Creates a string representation of |url|. The IDN host name may be in Unicode |
| 224 // if |languages| accepts the Unicode representation. |format_type| is a bitmask |
| 225 // of FormatUrlTypes, see it for details. |unescape_rules| defines how to clean |
| 226 // the URL for human readability. You will generally want |UnescapeRule::SPACES| |
| 227 // for display to the user if you can handle spaces, or |UnescapeRule::NORMAL| |
| 228 // if not. If the path part and the query part seem to be encoded in %-encoded |
| 229 // UTF-8, decodes %-encoding and UTF-8. |
| 230 // |
| 231 // The last three parameters may be NULL. |
| 232 // |
| 233 // |new_parsed| will be set to the parsing parameters of the resultant URL. |
| 234 // |
| 235 // |prefix_end| will be the length before the hostname of the resultant URL. |
| 236 // |
| 237 // |offset[s]_for_adjustment| specifies one or more offsets into the original |
| 238 // URL, representing insertion or selection points between characters: if the |
| 239 // input is "http://foo.com/", offset 0 is before the entire URL, offset 7 is |
| 240 // between the scheme and the host, and offset 15 is after the end of the URL. |
| 241 // Valid input offsets range from 0 to the length of the input URL string. On |
| 242 // exit, each offset will have been modified to reflect any changes made to the |
| 243 // output string. For example, if |url| is "http://a:b@c.com/", |
| 244 // |omit_username_password| is true, and an offset is 12 (pointing between 'c' |
| 245 // and '.'), then on return the output string will be "http://c.com/" and the |
| 246 // offset will be 8. If an offset cannot be successfully adjusted (e.g. because |
| 247 // it points into the middle of a component that was entirely removed or into |
| 248 // the middle of an encoding sequence), it will be set to base::string16::npos. |
| 249 // For consistency, if an input offset points between the scheme and the |
| 250 // username/password, and both are removed, on output this offset will be 0 |
| 251 // rather than npos; this means that offsets at the starts and ends of removed |
| 252 // components are always transformed the same way regardless of what other |
| 253 // components are adjacent. |
| 254 NET_EXPORT base::string16 FormatUrl(const GURL& url, |
| 255 const std::string& languages, |
| 256 FormatUrlTypes format_types, |
| 257 UnescapeRule::Type unescape_rules, |
| 258 url::Parsed* new_parsed, |
| 259 size_t* prefix_end, |
| 260 size_t* offset_for_adjustment); |
| 261 NET_EXPORT base::string16 FormatUrlWithOffsets( |
| 262 const GURL& url, |
| 263 const std::string& languages, |
| 264 FormatUrlTypes format_types, |
| 265 UnescapeRule::Type unescape_rules, |
| 266 url::Parsed* new_parsed, |
| 267 size_t* prefix_end, |
| 268 std::vector<size_t>* offsets_for_adjustment); |
| 269 // This function is like those above except it takes |adjustments| rather |
| 270 // than |offset[s]_for_adjustment|. |adjustments| will be set to reflect all |
| 271 // the transformations that happened to |url| to convert it into the returned |
| 272 // value. |
| 273 NET_EXPORT base::string16 FormatUrlWithAdjustments( |
| 274 const GURL& url, |
| 275 const std::string& languages, |
| 276 FormatUrlTypes format_types, |
| 277 UnescapeRule::Type unescape_rules, |
| 278 url::Parsed* new_parsed, |
| 279 size_t* prefix_end, |
| 280 base::OffsetAdjuster::Adjustments* adjustments); |
| 281 |
| 282 // This is a convenience function for FormatUrl() with |
| 283 // format_types = kFormatUrlOmitAll and unescape = SPACES. This is the typical |
| 284 // set of flags for "URLs to display to the user". You should be cautious about |
| 285 // using this for URLs which will be parsed or sent to other applications. |
| 286 inline base::string16 FormatUrl(const GURL& url, const std::string& languages) { |
| 287 return FormatUrl(url, languages, kFormatUrlOmitAll, UnescapeRule::SPACES, |
| 288 NULL, NULL, NULL); |
| 289 } |
| 290 |
| 291 // Returns whether FormatUrl() would strip a trailing slash from |url|, given a |
| 292 // format flag including kFormatUrlOmitTrailingSlashOnBareHostname. |
| 293 NET_EXPORT bool CanStripTrailingSlash(const GURL& url); |
| 294 |
| 179 // Strip the portions of |url| that aren't core to the network request. | 295 // Strip the portions of |url| that aren't core to the network request. |
| 180 // - user name / password | 296 // - user name / password |
| 181 // - reference section | 297 // - reference section |
| 182 NET_EXPORT_PRIVATE GURL SimplifyUrlForRequest(const GURL& url); | 298 NET_EXPORT_PRIVATE GURL SimplifyUrlForRequest(const GURL& url); |
| 183 | 299 |
| 184 // Returns true if it can determine that only loopback addresses are configured. | 300 // Returns true if it can determine that only loopback addresses are configured. |
| 185 // i.e. if only 127.0.0.1 and ::1 are routable. | 301 // i.e. if only 127.0.0.1 and ::1 are routable. |
| 186 // Also returns false if it cannot determine this. | 302 // Also returns false if it cannot determine this. |
| 187 bool HaveOnlyLoopbackAddresses(); | 303 bool HaveOnlyLoopbackAddresses(); |
| 188 | 304 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 DSCP_CS5 = 40, // Video | 383 DSCP_CS5 = 40, // Video |
| 268 DSCP_EF = 46, // Voice | 384 DSCP_EF = 46, // Voice |
| 269 DSCP_CS6 = 48, // Voice | 385 DSCP_CS6 = 48, // Voice |
| 270 DSCP_CS7 = 56, // Control messages | 386 DSCP_CS7 = 56, // Control messages |
| 271 DSCP_LAST = DSCP_CS7 | 387 DSCP_LAST = DSCP_CS7 |
| 272 }; | 388 }; |
| 273 | 389 |
| 274 } // namespace net | 390 } // namespace net |
| 275 | 391 |
| 276 #endif // NET_BASE_NET_UTIL_H_ | 392 #endif // NET_BASE_NET_UTIL_H_ |
| OLD | NEW |