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

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

Issue 188873004: Compile src/net for PNaCl (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 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
« no previous file with comments | « no previous file | net/base/net_util_posix.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <iterator> 10 #include <iterator>
11 #include <map> 11 #include <map>
12 #include <set> 12 #include <set>
13 13
14 #include "build/build_config.h" 14 #include "build/build_config.h"
15 15
16 #if defined(OS_WIN) 16 #if defined(OS_WIN)
17 #include <windows.h> 17 #include <windows.h>
18 #include <iphlpapi.h> 18 #include <iphlpapi.h>
19 #include <winsock2.h> 19 #include <winsock2.h>
20 #pragma comment(lib, "iphlpapi.lib") 20 #pragma comment(lib, "iphlpapi.lib")
21 #elif defined(OS_POSIX) 21 #elif defined(OS_POSIX)
22 #include <fcntl.h> 22 #include <fcntl.h>
23 #include <netdb.h>
24 #include <netinet/in.h>
25 #if !defined(OS_NACL)
26 #include <net/if.h>
23 #if !defined(OS_ANDROID) 27 #if !defined(OS_ANDROID)
24 #include <ifaddrs.h> 28 #include <ifaddrs.h>
25 #endif 29 #endif // !defined(OS_NACL)
26 #include <net/if.h> 30 #endif // !defined(OS_ANDROID)
27 #include <netdb.h> 31 #endif // defined(OS_POSIX)
28 #include <netinet/in.h>
29 #endif
30 32
31 #include "base/basictypes.h" 33 #include "base/basictypes.h"
32 #include "base/i18n/time_formatting.h" 34 #include "base/i18n/time_formatting.h"
33 #include "base/json/string_escape.h" 35 #include "base/json/string_escape.h"
34 #include "base/lazy_instance.h" 36 #include "base/lazy_instance.h"
35 #include "base/logging.h" 37 #include "base/logging.h"
36 #include "base/memory/singleton.h" 38 #include "base/memory/singleton.h"
37 #include "base/message_loop/message_loop.h" 39 #include "base/message_loop/message_loop.h"
38 #include "base/metrics/histogram.h" 40 #include "base/metrics/histogram.h"
39 #include "base/stl_util.h" 41 #include "base/stl_util.h"
40 #include "base/strings/string_number_conversions.h" 42 #include "base/strings/string_number_conversions.h"
41 #include "base/strings/string_piece.h" 43 #include "base/strings/string_piece.h"
42 #include "base/strings/string_split.h" 44 #include "base/strings/string_split.h"
43 #include "base/strings/string_tokenizer.h" 45 #include "base/strings/string_tokenizer.h"
44 #include "base/strings/string_util.h" 46 #include "base/strings/string_util.h"
45 #include "base/strings/stringprintf.h" 47 #include "base/strings/stringprintf.h"
46 #include "base/strings/sys_string_conversions.h" 48 #include "base/strings/sys_string_conversions.h"
47 #include "base/strings/utf_offset_string_conversions.h" 49 #include "base/strings/utf_offset_string_conversions.h"
48 #include "base/strings/utf_string_conversions.h" 50 #include "base/strings/utf_string_conversions.h"
49 #include "base/synchronization/lock.h" 51 #include "base/synchronization/lock.h"
50 #include "base/sys_byteorder.h" 52 #include "base/sys_byteorder.h"
51 #include "base/time/time.h" 53 #include "base/time/time.h"
52 #include "base/values.h" 54 #include "base/values.h"
53 #include "grit/net_resources.h" 55 #include "grit/net_resources.h"
54 #include "url/gurl.h" 56 #include "url/gurl.h"
55 #include "url/url_canon.h" 57 #include "url/url_canon.h"
56 #include "url/url_canon_ip.h" 58 #include "url/url_canon_ip.h"
57 #include "url/url_parse.h" 59 #include "url/url_parse.h"
58 #if defined(OS_ANDROID)
59 #include "net/android/network_library.h"
60 #endif
61 #include "net/base/dns_util.h" 60 #include "net/base/dns_util.h"
62 #include "net/base/escape.h" 61 #include "net/base/escape.h"
63 #include "net/base/net_module.h" 62 #include "net/base/net_module.h"
64 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" 63 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
65 #if defined(OS_WIN)
66 #include "net/base/winsock_init.h"
67 #endif
68 #include "net/http/http_content_disposition.h" 64 #include "net/http/http_content_disposition.h"
69 #include "third_party/icu/source/common/unicode/uidna.h" 65 #include "third_party/icu/source/common/unicode/uidna.h"
70 #include "third_party/icu/source/common/unicode/uniset.h" 66 #include "third_party/icu/source/common/unicode/uniset.h"
71 #include "third_party/icu/source/common/unicode/uscript.h" 67 #include "third_party/icu/source/common/unicode/uscript.h"
72 #include "third_party/icu/source/common/unicode/uset.h" 68 #include "third_party/icu/source/common/unicode/uset.h"
73 #include "third_party/icu/source/i18n/unicode/datefmt.h" 69 #include "third_party/icu/source/i18n/unicode/datefmt.h"
74 #include "third_party/icu/source/i18n/unicode/regex.h" 70 #include "third_party/icu/source/i18n/unicode/regex.h"
75 #include "third_party/icu/source/i18n/unicode/ulocdata.h" 71 #include "third_party/icu/source/i18n/unicode/ulocdata.h"
76 72
73 #if defined(OS_ANDROID)
74 #include "net/android/network_library.h"
75 #endif
76 #if defined(OS_WIN)
77 #include "net/base/winsock_init.h"
78 #endif
79
77 using base::Time; 80 using base::Time;
78 81
79 namespace net { 82 namespace net {
80 83
81 namespace { 84 namespace {
82 85
83 typedef std::vector<size_t> Offsets; 86 typedef std::vector<size_t> Offsets;
84 87
85 // The general list of blocked ports. Will be blocked unless a specific 88 // The general list of blocked ports. Will be blocked unless a specific
86 // protocol overrides it. (Ex: ftp can use ports 20 and 21) 89 // protocol overrides it. (Ex: ftp can use ports 20 and 21)
(...skipping 1170 matching lines...) Expand 10 before | Expand all | Expand 10 after
1257 uint16 port) { 1260 uint16 port) {
1258 return IPAddressToStringWithPort(&addr.front(), addr.size(), port); 1261 return IPAddressToStringWithPort(&addr.front(), addr.size(), port);
1259 } 1262 }
1260 1263
1261 std::string IPAddressToPackedString(const IPAddressNumber& addr) { 1264 std::string IPAddressToPackedString(const IPAddressNumber& addr) {
1262 return std::string(reinterpret_cast<const char *>(&addr.front()), 1265 return std::string(reinterpret_cast<const char *>(&addr.front()),
1263 addr.size()); 1266 addr.size());
1264 } 1267 }
1265 1268
1266 std::string GetHostName() { 1269 std::string GetHostName() {
1270 #if defined(OS_NACL)
1271 NOTIMPLEMENTED();
1272 return std::string();
1273 #else // defined(OS_NACL)
1267 #if defined(OS_WIN) 1274 #if defined(OS_WIN)
1268 EnsureWinsockInit(); 1275 EnsureWinsockInit();
1269 #endif 1276 #endif
1270 1277
1271 // Host names are limited to 255 bytes. 1278 // Host names are limited to 255 bytes.
1272 char buffer[256]; 1279 char buffer[256];
1273 int result = gethostname(buffer, sizeof(buffer)); 1280 int result = gethostname(buffer, sizeof(buffer));
1274 if (result != 0) { 1281 if (result != 0) {
1275 DVLOG(1) << "gethostname() failed with " << result; 1282 DVLOG(1) << "gethostname() failed with " << result;
1276 buffer[0] = '\0'; 1283 buffer[0] = '\0';
1277 } 1284 }
1278 return std::string(buffer); 1285 return std::string(buffer);
1286 #endif // !defined(OS_NACL)
1279 } 1287 }
1280 1288
1281 void GetIdentityFromURL(const GURL& url, 1289 void GetIdentityFromURL(const GURL& url,
1282 base::string16* username, 1290 base::string16* username,
1283 base::string16* password) { 1291 base::string16* password) {
1284 UnescapeRule::Type flags = 1292 UnescapeRule::Type flags =
1285 UnescapeRule::SPACES | UnescapeRule::URL_SPECIAL_CHARS; 1293 UnescapeRule::SPACES | UnescapeRule::URL_SPECIAL_CHARS;
1286 *username = UnescapeAndDecodeUTF8URLComponent(url.username(), flags, NULL); 1294 *username = UnescapeAndDecodeUTF8URLComponent(url.username(), flags, NULL);
1287 *password = UnescapeAndDecodeUTF8URLComponent(url.password(), flags, NULL); 1295 *password = UnescapeAndDecodeUTF8URLComponent(url.password(), flags, NULL);
1288 } 1296 }
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
1534 g_explicitly_allowed_ports.Get().find(port_); 1542 g_explicitly_allowed_ports.Get().find(port_);
1535 if (it != g_explicitly_allowed_ports.Get().end()) 1543 if (it != g_explicitly_allowed_ports.Get().end())
1536 g_explicitly_allowed_ports.Get().erase(it); 1544 g_explicitly_allowed_ports.Get().erase(it);
1537 else 1545 else
1538 NOTREACHED(); 1546 NOTREACHED();
1539 } 1547 }
1540 1548
1541 bool HaveOnlyLoopbackAddresses() { 1549 bool HaveOnlyLoopbackAddresses() {
1542 #if defined(OS_ANDROID) 1550 #if defined(OS_ANDROID)
1543 return android::HaveOnlyLoopbackAddresses(); 1551 return android::HaveOnlyLoopbackAddresses();
1552 #elif defined(OS_NACL)
1553 NOTIMPLEMENTED();
1554 return false;
1544 #elif defined(OS_POSIX) 1555 #elif defined(OS_POSIX)
1545 struct ifaddrs* interface_addr = NULL; 1556 struct ifaddrs* interface_addr = NULL;
1546 int rv = getifaddrs(&interface_addr); 1557 int rv = getifaddrs(&interface_addr);
1547 if (rv != 0) { 1558 if (rv != 0) {
1548 DVLOG(1) << "getifaddrs() failed with errno = " << errno; 1559 DVLOG(1) << "getifaddrs() failed with errno = " << errno;
1549 return false; 1560 return false;
1550 } 1561 }
1551 1562
1552 bool result = true; 1563 bool result = true;
1553 for (struct ifaddrs* interface = interface_addr; 1564 for (struct ifaddrs* interface = interface_addr;
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
1818 } 1829 }
1819 return a1.size() * CHAR_BIT; 1830 return a1.size() * CHAR_BIT;
1820 } 1831 }
1821 1832
1822 unsigned MaskPrefixLength(const IPAddressNumber& mask) { 1833 unsigned MaskPrefixLength(const IPAddressNumber& mask) {
1823 IPAddressNumber all_ones(mask.size(), 0xFF); 1834 IPAddressNumber all_ones(mask.size(), 0xFF);
1824 return CommonPrefixLength(mask, all_ones); 1835 return CommonPrefixLength(mask, all_ones);
1825 } 1836 }
1826 1837
1827 } // namespace net 1838 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/base/net_util_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698