OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <unicode/regex.h> | 7 #include <unicode/regex.h> |
8 #include <unicode/ucnv.h> | 8 #include <unicode/ucnv.h> |
9 #include <unicode/uidna.h> | 9 #include <unicode/uidna.h> |
10 #include <unicode/ulocdata.h> | 10 #include <unicode/ulocdata.h> |
(...skipping 1022 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1033 // Adjust new_parsed. | 1033 // Adjust new_parsed. |
1034 DCHECK(new_parsed->scheme.is_valid()); | 1034 DCHECK(new_parsed->scheme.is_valid()); |
1035 int delta = -(new_parsed->scheme.len + 3); // +3 for ://. | 1035 int delta = -(new_parsed->scheme.len + 3); // +3 for ://. |
1036 new_parsed->scheme.reset(); | 1036 new_parsed->scheme.reset(); |
1037 AdjustComponents(delta, new_parsed); | 1037 AdjustComponents(delta, new_parsed); |
1038 } | 1038 } |
1039 | 1039 |
1040 return url_string; | 1040 return url_string; |
1041 } | 1041 } |
1042 | 1042 |
| 1043 char* do_strdup(const char* src) { |
| 1044 #if defined(OS_WIN) |
| 1045 return _strdup(src); |
| 1046 #else |
| 1047 return strdup(src); |
| 1048 #endif |
| 1049 } |
| 1050 |
1043 } // namespace | 1051 } // namespace |
1044 | 1052 |
1045 const FormatUrlType kFormatUrlOmitNothing = 0; | 1053 const FormatUrlType kFormatUrlOmitNothing = 0; |
1046 const FormatUrlType kFormatUrlOmitUsernamePassword = 1 << 0; | 1054 const FormatUrlType kFormatUrlOmitUsernamePassword = 1 << 0; |
1047 const FormatUrlType kFormatUrlOmitHTTP = 1 << 1; | 1055 const FormatUrlType kFormatUrlOmitHTTP = 1 << 1; |
1048 const FormatUrlType kFormatUrlOmitTrailingSlashOnBareHostname = 1 << 2; | 1056 const FormatUrlType kFormatUrlOmitTrailingSlashOnBareHostname = 1 << 2; |
1049 const FormatUrlType kFormatUrlOmitAll = kFormatUrlOmitUsernamePassword | | 1057 const FormatUrlType kFormatUrlOmitAll = kFormatUrlOmitUsernamePassword | |
1050 kFormatUrlOmitHTTP | kFormatUrlOmitTrailingSlashOnBareHostname; | 1058 kFormatUrlOmitHTTP | kFormatUrlOmitTrailingSlashOnBareHostname; |
1051 | 1059 |
1052 // TODO(viettrungluu): We don't want non-POD globals; change this. | 1060 // TODO(viettrungluu): We don't want non-POD globals; change this. |
(...skipping 986 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2039 if (remaining_bits != 0) { | 2047 if (remaining_bits != 0) { |
2040 unsigned char mask = 0xFF << (8 - remaining_bits); | 2048 unsigned char mask = 0xFF << (8 - remaining_bits); |
2041 int i = num_entire_bytes_in_prefix; | 2049 int i = num_entire_bytes_in_prefix; |
2042 if ((ip_number[i] & mask) != (ip_prefix[i] & mask)) | 2050 if ((ip_number[i] & mask) != (ip_prefix[i] & mask)) |
2043 return false; | 2051 return false; |
2044 } | 2052 } |
2045 | 2053 |
2046 return true; | 2054 return true; |
2047 } | 2055 } |
2048 | 2056 |
| 2057 struct addrinfo* CreateCopyOfAddrinfo(const struct addrinfo* info, |
| 2058 bool recursive) { |
| 2059 DCHECK(info); |
| 2060 struct addrinfo* copy = new addrinfo; |
| 2061 |
| 2062 // Copy all the fields (some of these are pointers, we will fix that next). |
| 2063 memcpy(copy, info, sizeof(addrinfo)); |
| 2064 |
| 2065 // ai_canonname is a NULL-terminated string. |
| 2066 if (info->ai_canonname) { |
| 2067 copy->ai_canonname = do_strdup(info->ai_canonname); |
| 2068 } |
| 2069 |
| 2070 // ai_addr is a buffer of length ai_addrlen. |
| 2071 if (info->ai_addr) { |
| 2072 copy->ai_addr = reinterpret_cast<sockaddr *>(new char[info->ai_addrlen]); |
| 2073 memcpy(copy->ai_addr, info->ai_addr, info->ai_addrlen); |
| 2074 } |
| 2075 |
| 2076 // Recursive copy. |
| 2077 if (recursive && info->ai_next) |
| 2078 copy->ai_next = CreateCopyOfAddrinfo(info->ai_next, recursive); |
| 2079 else |
| 2080 copy->ai_next = NULL; |
| 2081 |
| 2082 return copy; |
| 2083 } |
| 2084 |
| 2085 void FreeCopyOfAddrinfo(struct addrinfo* info) { |
| 2086 DCHECK(info); |
| 2087 if (info->ai_canonname) |
| 2088 free(info->ai_canonname); // Allocated by strdup. |
| 2089 |
| 2090 if (info->ai_addr) |
| 2091 delete [] reinterpret_cast<char*>(info->ai_addr); |
| 2092 |
| 2093 struct addrinfo* next = info->ai_next; |
| 2094 |
| 2095 delete info; |
| 2096 |
| 2097 // Recursive free. |
| 2098 if (next) |
| 2099 FreeCopyOfAddrinfo(next); |
| 2100 } |
| 2101 |
2049 // Returns the port field of the sockaddr in |info|. | 2102 // Returns the port field of the sockaddr in |info|. |
2050 uint16* GetPortFieldFromAddrinfo(struct addrinfo* info) { | 2103 uint16* GetPortFieldFromAddrinfo(struct addrinfo* info) { |
2051 const struct addrinfo* const_info = info; | 2104 const struct addrinfo* const_info = info; |
2052 const uint16* port_field = GetPortFieldFromAddrinfo(const_info); | 2105 const uint16* port_field = GetPortFieldFromAddrinfo(const_info); |
2053 return const_cast<uint16*>(port_field); | 2106 return const_cast<uint16*>(port_field); |
2054 } | 2107 } |
2055 | 2108 |
2056 const uint16* GetPortFieldFromAddrinfo(const struct addrinfo* info) { | 2109 const uint16* GetPortFieldFromAddrinfo(const struct addrinfo* info) { |
2057 DCHECK(info); | 2110 DCHECK(info); |
2058 const struct sockaddr* address = info->ai_addr; | 2111 const struct sockaddr* address = info->ai_addr; |
(...skipping 28 matching lines...) Expand all Loading... |
2087 } | 2140 } |
2088 | 2141 |
2089 int GetPortFromSockaddr(const struct sockaddr* address, socklen_t address_len) { | 2142 int GetPortFromSockaddr(const struct sockaddr* address, socklen_t address_len) { |
2090 const uint16* port_field = GetPortFieldFromSockaddr(address, address_len); | 2143 const uint16* port_field = GetPortFieldFromSockaddr(address, address_len); |
2091 if (!port_field) | 2144 if (!port_field) |
2092 return -1; | 2145 return -1; |
2093 return ntohs(*port_field); | 2146 return ntohs(*port_field); |
2094 } | 2147 } |
2095 | 2148 |
2096 } // namespace net | 2149 } // namespace net |
OLD | NEW |