OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 #ifdef OS_WIN | 10 #ifdef OS_WIN |
11 #include <windows.h> | 11 #include <windows.h> |
12 #endif | 12 #endif |
13 | 13 |
14 #include <string> | 14 #include <string> |
| 15 #include <set> |
15 | 16 |
16 #include "base/basictypes.h" | 17 #include "base/basictypes.h" |
17 #include "base/string16.h" | 18 #include "base/string16.h" |
18 #include "net/base/escape.h" | 19 #include "net/base/escape.h" |
19 | 20 |
20 struct addrinfo; | 21 struct addrinfo; |
21 class FilePath; | 22 class FilePath; |
22 class GURL; | 23 class GURL; |
23 | 24 |
24 namespace base { | 25 namespace base { |
25 class Time; | 26 class Time; |
26 } | 27 } |
27 | 28 |
28 namespace url_canon { | 29 namespace url_canon { |
29 struct CanonHostInfo; | 30 struct CanonHostInfo; |
30 } | 31 } |
31 | 32 |
32 namespace url_parse { | 33 namespace url_parse { |
33 struct Parsed; | 34 struct Parsed; |
34 } | 35 } |
35 | 36 |
36 namespace net { | 37 namespace net { |
37 | 38 |
| 39 // Holds a list of ports that should be accepted despite bans. |
| 40 extern std::set<int> explicitly_allowed_ports; |
| 41 |
38 // Given the full path to a file name, creates a file: URL. The returned URL | 42 // Given the full path to a file name, creates a file: URL. The returned URL |
39 // may not be valid if the input is malformed. | 43 // may not be valid if the input is malformed. |
40 GURL FilePathToFileURL(const FilePath& path); | 44 GURL FilePathToFileURL(const FilePath& path); |
41 | 45 |
42 // Converts a file: URL back to a filename that can be passed to the OS. The | 46 // Converts a file: URL back to a filename that can be passed to the OS. The |
43 // file URL must be well-formed (GURL::is_valid() must return true); we don't | 47 // file URL must be well-formed (GURL::is_valid() must return true); we don't |
44 // handle degenerate cases here. Returns true on success, false if it isn't a | 48 // handle degenerate cases here. Returns true on success, false if it isn't a |
45 // valid file URL. On failure, *file_path will be empty. | 49 // valid file URL. On failure, *file_path will be empty. |
46 bool FileURLToFilePath(const GURL& url, FilePath* file_path); | 50 bool FileURLToFilePath(const GURL& url, FilePath* file_path); |
47 | 51 |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 | 188 |
185 // Checks the given port against a list of ports which are restricted by | 189 // Checks the given port against a list of ports which are restricted by |
186 // default. Returns true if the port is allowed, false if it is restricted. | 190 // default. Returns true if the port is allowed, false if it is restricted. |
187 bool IsPortAllowedByDefault(int port); | 191 bool IsPortAllowedByDefault(int port); |
188 | 192 |
189 // Checks the given port against a list of ports which are restricted by the | 193 // Checks the given port against a list of ports which are restricted by the |
190 // FTP protocol. Returns true if the port is allowed, false if it is | 194 // FTP protocol. Returns true if the port is allowed, false if it is |
191 // restricted. | 195 // restricted. |
192 bool IsPortAllowedByFtp(int port); | 196 bool IsPortAllowedByFtp(int port); |
193 | 197 |
| 198 // Check if banned |port| has been overriden by an entry in |
| 199 // |explicitly_allowed_ports_|. |
| 200 bool IsPortAllowedByOverride(int port); |
| 201 |
194 // Set socket to non-blocking mode | 202 // Set socket to non-blocking mode |
195 int SetNonBlocking(int fd); | 203 int SetNonBlocking(int fd); |
196 | 204 |
197 // Appends the given part of the original URL to the output string formatted for | 205 // Appends the given part of the original URL to the output string formatted for |
198 // the user. The given parsed structure will be updated. The host name formatter | 206 // the user. The given parsed structure will be updated. The host name formatter |
199 // also takes the same accept languages component as ElideURL. |new_parsed| may | 207 // also takes the same accept languages component as ElideURL. |new_parsed| may |
200 // be null. | 208 // be null. |
201 void AppendFormattedHost(const GURL& url, const std::wstring& languages, | 209 void AppendFormattedHost(const GURL& url, const std::wstring& languages, |
202 std::wstring* output, url_parse::Parsed* new_parsed); | 210 std::wstring* output, url_parse::Parsed* new_parsed); |
203 | 211 |
(...skipping 19 matching lines...) Expand all Loading... |
223 // unescape=SPACES, new_parsed=NULL, and prefix_end=NULL. | 231 // unescape=SPACES, new_parsed=NULL, and prefix_end=NULL. |
224 inline std::wstring FormatUrl(const GURL& url, const std::wstring& languages) { | 232 inline std::wstring FormatUrl(const GURL& url, const std::wstring& languages) { |
225 return FormatUrl(url, languages, true, UnescapeRule::SPACES, NULL, NULL); | 233 return FormatUrl(url, languages, true, UnescapeRule::SPACES, NULL, NULL); |
226 } | 234 } |
227 | 235 |
228 // Strip the portions of |url| that aren't core to the network request. | 236 // Strip the portions of |url| that aren't core to the network request. |
229 // - user name / password | 237 // - user name / password |
230 // - reference section | 238 // - reference section |
231 GURL SimplifyUrlForRequest(const GURL& url); | 239 GURL SimplifyUrlForRequest(const GURL& url); |
232 | 240 |
| 241 void SetExplicitlyAllowedPorts(const std::wstring& allowed_ports); |
| 242 |
233 } // namespace net | 243 } // namespace net |
234 | 244 |
235 #endif // NET_BASE_NET_UTIL_H__ | 245 #endif // NET_BASE_NET_UTIL_H__ |
OLD | NEW |