OLD | NEW |
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 #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 1102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1113 // Adjust new_parsed. | 1113 // Adjust new_parsed. |
1114 DCHECK(new_parsed->scheme.is_valid()); | 1114 DCHECK(new_parsed->scheme.is_valid()); |
1115 int delta = -(new_parsed->scheme.len + 3); // +3 for ://. | 1115 int delta = -(new_parsed->scheme.len + 3); // +3 for ://. |
1116 new_parsed->scheme.reset(); | 1116 new_parsed->scheme.reset(); |
1117 AdjustComponents(delta, new_parsed); | 1117 AdjustComponents(delta, new_parsed); |
1118 } | 1118 } |
1119 | 1119 |
1120 return url_string; | 1120 return url_string; |
1121 } | 1121 } |
1122 | 1122 |
| 1123 char* do_strdup(const char* src) { |
| 1124 #if defined(OS_WIN) |
| 1125 return _strdup(src); |
| 1126 #else |
| 1127 return strdup(src); |
| 1128 #endif |
| 1129 } |
| 1130 |
1123 } // namespace | 1131 } // namespace |
1124 | 1132 |
1125 const FormatUrlType kFormatUrlOmitNothing = 0; | 1133 const FormatUrlType kFormatUrlOmitNothing = 0; |
1126 const FormatUrlType kFormatUrlOmitUsernamePassword = 1 << 0; | 1134 const FormatUrlType kFormatUrlOmitUsernamePassword = 1 << 0; |
1127 const FormatUrlType kFormatUrlOmitHTTP = 1 << 1; | 1135 const FormatUrlType kFormatUrlOmitHTTP = 1 << 1; |
1128 const FormatUrlType kFormatUrlOmitTrailingSlashOnBareHostname = 1 << 2; | 1136 const FormatUrlType kFormatUrlOmitTrailingSlashOnBareHostname = 1 << 2; |
1129 const FormatUrlType kFormatUrlOmitAll = kFormatUrlOmitUsernamePassword | | 1137 const FormatUrlType kFormatUrlOmitAll = kFormatUrlOmitUsernamePassword | |
1130 kFormatUrlOmitHTTP | kFormatUrlOmitTrailingSlashOnBareHostname; | 1138 kFormatUrlOmitHTTP | kFormatUrlOmitTrailingSlashOnBareHostname; |
1131 | 1139 |
1132 // TODO(viettrungluu): We don't want non-POD globals; change this. | 1140 // TODO(viettrungluu): We don't want non-POD globals; change this. |
(...skipping 1042 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2175 if (remaining_bits != 0) { | 2183 if (remaining_bits != 0) { |
2176 unsigned char mask = 0xFF << (8 - remaining_bits); | 2184 unsigned char mask = 0xFF << (8 - remaining_bits); |
2177 int i = num_entire_bytes_in_prefix; | 2185 int i = num_entire_bytes_in_prefix; |
2178 if ((ip_number[i] & mask) != (ip_prefix[i] & mask)) | 2186 if ((ip_number[i] & mask) != (ip_prefix[i] & mask)) |
2179 return false; | 2187 return false; |
2180 } | 2188 } |
2181 | 2189 |
2182 return true; | 2190 return true; |
2183 } | 2191 } |
2184 | 2192 |
| 2193 struct addrinfo* CreateCopyOfAddrinfo(const struct addrinfo* info, |
| 2194 bool recursive) { |
| 2195 DCHECK(info); |
| 2196 struct addrinfo* copy = new addrinfo; |
| 2197 |
| 2198 // Copy all the fields (some of these are pointers, we will fix that next). |
| 2199 memcpy(copy, info, sizeof(addrinfo)); |
| 2200 |
| 2201 // ai_canonname is a NULL-terminated string. |
| 2202 if (info->ai_canonname) { |
| 2203 copy->ai_canonname = do_strdup(info->ai_canonname); |
| 2204 } |
| 2205 |
| 2206 // ai_addr is a buffer of length ai_addrlen. |
| 2207 if (info->ai_addr) { |
| 2208 copy->ai_addr = reinterpret_cast<sockaddr *>(new char[info->ai_addrlen]); |
| 2209 memcpy(copy->ai_addr, info->ai_addr, info->ai_addrlen); |
| 2210 } |
| 2211 |
| 2212 // Recursive copy. |
| 2213 if (recursive && info->ai_next) |
| 2214 copy->ai_next = CreateCopyOfAddrinfo(info->ai_next, recursive); |
| 2215 else |
| 2216 copy->ai_next = NULL; |
| 2217 |
| 2218 return copy; |
| 2219 } |
| 2220 |
| 2221 void FreeCopyOfAddrinfo(struct addrinfo* info) { |
| 2222 DCHECK(info); |
| 2223 if (info->ai_canonname) |
| 2224 free(info->ai_canonname); // Allocated by strdup. |
| 2225 |
| 2226 if (info->ai_addr) |
| 2227 delete [] reinterpret_cast<char*>(info->ai_addr); |
| 2228 |
| 2229 struct addrinfo* next = info->ai_next; |
| 2230 |
| 2231 delete info; |
| 2232 |
| 2233 // Recursive free. |
| 2234 if (next) |
| 2235 FreeCopyOfAddrinfo(next); |
| 2236 } |
| 2237 |
2185 // Returns the port field of the sockaddr in |info|. | 2238 // Returns the port field of the sockaddr in |info|. |
2186 uint16* GetPortFieldFromAddrinfo(struct addrinfo* info) { | 2239 uint16* GetPortFieldFromAddrinfo(struct addrinfo* info) { |
2187 const struct addrinfo* const_info = info; | 2240 const struct addrinfo* const_info = info; |
2188 const uint16* port_field = GetPortFieldFromAddrinfo(const_info); | 2241 const uint16* port_field = GetPortFieldFromAddrinfo(const_info); |
2189 return const_cast<uint16*>(port_field); | 2242 return const_cast<uint16*>(port_field); |
2190 } | 2243 } |
2191 | 2244 |
2192 const uint16* GetPortFieldFromAddrinfo(const struct addrinfo* info) { | 2245 const uint16* GetPortFieldFromAddrinfo(const struct addrinfo* info) { |
2193 DCHECK(info); | 2246 DCHECK(info); |
2194 const struct sockaddr* address = info->ai_addr; | 2247 const struct sockaddr* address = info->ai_addr; |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2276 | 2329 |
2277 ClampComponentOffset::ClampComponentOffset(size_t component_start) | 2330 ClampComponentOffset::ClampComponentOffset(size_t component_start) |
2278 : component_start(component_start) {} | 2331 : component_start(component_start) {} |
2279 | 2332 |
2280 size_t ClampComponentOffset::operator()(size_t offset) { | 2333 size_t ClampComponentOffset::operator()(size_t offset) { |
2281 return (offset >= component_start) ? | 2334 return (offset >= component_start) ? |
2282 offset : std::wstring::npos; | 2335 offset : std::wstring::npos; |
2283 } | 2336 } |
2284 | 2337 |
2285 } // namespace net | 2338 } // namespace net |
OLD | NEW |