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 #include "net/base/net_util.h" | 5 #include "net/base/net_util.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <limits> | 10 #include <limits> |
11 #include <string> | 11 #include <string> |
12 | 12 |
13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
14 | 14 |
15 #if defined(OS_WIN) | 15 #if defined(OS_WIN) |
16 #include <windows.h> | 16 #include <windows.h> |
17 #include <iphlpapi.h> | 17 #include <iphlpapi.h> |
18 #include <winsock2.h> | 18 #include <winsock2.h> |
19 #pragma comment(lib, "iphlpapi.lib") | 19 #pragma comment(lib, "iphlpapi.lib") |
20 #elif defined(OS_POSIX) | 20 #elif defined(OS_POSIX) |
21 #include <fcntl.h> | 21 #include <fcntl.h> |
22 #include <netdb.h> | 22 #include <netdb.h> |
23 #include <unistd.h> | 23 #include <unistd.h> |
24 #endif // defined(OS_POSIX) | 24 #endif // defined(OS_POSIX) |
25 | 25 |
26 #include "base/json/string_escape.h" | |
27 #include "base/logging.h" | 26 #include "base/logging.h" |
28 #include "base/strings/string_split.h" | 27 #include "base/strings/string_split.h" |
29 #include "base/strings/string_util.h" | 28 #include "base/strings/string_util.h" |
30 #include "base/strings/stringprintf.h" | 29 #include "base/strings/stringprintf.h" |
31 #include "base/strings/utf_string_conversions.h" | 30 #include "base/strings/utf_string_conversions.h" |
32 #include "base/sys_byteorder.h" | 31 #include "base/sys_byteorder.h" |
33 #include "base/values.h" | 32 #include "base/values.h" |
34 #include "net/base/address_list.h" | 33 #include "net/base/address_list.h" |
35 #include "net/base/escape.h" | 34 #include "net/base/escape.h" |
36 #include "net/base/ip_address_number.h" | 35 #include "net/base/ip_address_number.h" |
37 #include "net/base/net_module.h" | |
38 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 36 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
39 #include "net/base/url_util.h" | 37 #include "net/base/url_util.h" |
40 #include "net/grit/net_resources.h" | |
41 #include "url/gurl.h" | 38 #include "url/gurl.h" |
42 #include "url/third_party/mozilla/url_parse.h" | 39 #include "url/third_party/mozilla/url_parse.h" |
43 #include "url/url_canon.h" | 40 #include "url/url_canon.h" |
44 #include "url/url_canon_ip.h" | 41 #include "url/url_canon_ip.h" |
45 | 42 |
46 #if defined(OS_WIN) | 43 #if defined(OS_WIN) |
47 #include "net/base/winsock_init.h" | 44 #include "net/base/winsock_init.h" |
48 #endif | 45 #endif |
49 | 46 |
50 namespace net { | 47 namespace net { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 canon_host_output.Complete(); | 87 canon_host_output.Complete(); |
91 DCHECK_EQ(host_info->out_host.len, static_cast<int>(canon_host.length())); | 88 DCHECK_EQ(host_info->out_host.len, static_cast<int>(canon_host.length())); |
92 } else { | 89 } else { |
93 // Empty host, or canonicalization failed. We'll return empty. | 90 // Empty host, or canonicalization failed. We'll return empty. |
94 canon_host.clear(); | 91 canon_host.clear(); |
95 } | 92 } |
96 | 93 |
97 return canon_host; | 94 return canon_host; |
98 } | 95 } |
99 | 96 |
100 std::string GetDirectoryListingHeader(const base::string16& title) { | |
101 static const base::StringPiece header( | |
102 NetModule::GetResource(IDR_DIR_HEADER_HTML)); | |
103 // This can be null in unit tests. | |
104 DLOG_IF(WARNING, header.empty()) << | |
105 "Missing resource: directory listing header"; | |
106 | |
107 std::string result; | |
108 if (!header.empty()) | |
109 result.assign(header.data(), header.size()); | |
110 | |
111 result.append("<script>start("); | |
112 base::EscapeJSONString(title, true, &result); | |
113 result.append(");</script>\n"); | |
114 | |
115 return result; | |
116 } | |
117 | |
118 inline bool IsHostCharAlphanumeric(char c) { | 97 inline bool IsHostCharAlphanumeric(char c) { |
119 // We can just check lowercase because uppercase characters have already been | 98 // We can just check lowercase because uppercase characters have already been |
120 // normalized. | 99 // normalized. |
121 return ((c >= 'a') && (c <= 'z')) || ((c >= '0') && (c <= '9')); | 100 return ((c >= 'a') && (c <= 'z')) || ((c >= '0') && (c <= '9')); |
122 } | 101 } |
123 | 102 |
124 bool IsCanonicalizedHostCompliant(const std::string& host) { | 103 bool IsCanonicalizedHostCompliant(const std::string& host) { |
125 if (host.empty()) | 104 if (host.empty()) |
126 return false; | 105 return false; |
127 | 106 |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 // Here it's possible to get away with faster case-sensitive comparisons | 393 // Here it's possible to get away with faster case-sensitive comparisons |
415 // because the list above is all lowercase, and a GURL's host name will | 394 // because the list above is all lowercase, and a GURL's host name will |
416 // always be canonicalized to lowercase as well. | 395 // always be canonicalized to lowercase as well. |
417 if (base::EndsWith(host, suffix, base::CompareCase::SENSITIVE)) | 396 if (base::EndsWith(host, suffix, base::CompareCase::SENSITIVE)) |
418 return true; | 397 return true; |
419 } | 398 } |
420 return false; | 399 return false; |
421 } | 400 } |
422 | 401 |
423 } // namespace net | 402 } // namespace net |
OLD | NEW |