OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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_PROXY_PROXY_SERVER_H_ | 5 #ifndef NET_PROXY_PROXY_SERVER_H_ |
6 #define NET_PROXY_PROXY_SERVER_H_ | 6 #define NET_PROXY_PROXY_SERVER_H_ |
7 | 7 |
8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
9 | 9 |
10 #if defined(OS_MACOSX) | 10 #if defined(OS_MACOSX) |
(...skipping 11 matching lines...) Expand all Loading... |
22 public: | 22 public: |
23 // The type of proxy. These are defined as bit flags so they can be ORed | 23 // The type of proxy. These are defined as bit flags so they can be ORed |
24 // together to pass as the |scheme_bit_field| argument to | 24 // together to pass as the |scheme_bit_field| argument to |
25 // ProxyService::RemoveProxiesWithoutScheme(). | 25 // ProxyService::RemoveProxiesWithoutScheme(). |
26 enum Scheme { | 26 enum Scheme { |
27 SCHEME_INVALID = 1 << 0, | 27 SCHEME_INVALID = 1 << 0, |
28 SCHEME_DIRECT = 1 << 1, | 28 SCHEME_DIRECT = 1 << 1, |
29 SCHEME_HTTP = 1 << 2, | 29 SCHEME_HTTP = 1 << 2, |
30 SCHEME_SOCKS4 = 1 << 3, | 30 SCHEME_SOCKS4 = 1 << 3, |
31 SCHEME_SOCKS5 = 1 << 4, | 31 SCHEME_SOCKS5 = 1 << 4, |
| 32 SCHEME_HTTPS = 1 << 5, |
32 }; | 33 }; |
33 | 34 |
34 // Default copy-constructor and assignment operator are OK! | 35 // Default copy-constructor and assignment operator are OK! |
35 | 36 |
36 // Constructs an invalid ProxyServer. | 37 // Constructs an invalid ProxyServer. |
37 ProxyServer() : scheme_(SCHEME_INVALID), port_(-1) {} | 38 ProxyServer() : scheme_(SCHEME_INVALID), port_(-1) {} |
38 | 39 |
39 // If |host| is an IPv6 literal address, it must include the square | 40 // If |host| is an IPv6 literal address, it must include the square |
40 // brackets. | 41 // brackets. |
41 ProxyServer(Scheme scheme, const std::string& host, int port) | 42 ProxyServer(Scheme scheme, const std::string& host, int port) |
42 : scheme_(scheme), host_(host), port_(port) {} | 43 : scheme_(scheme), host_(host), port_(port) {} |
43 | 44 |
44 bool is_valid() const { return scheme_ != SCHEME_INVALID; } | 45 bool is_valid() const { return scheme_ != SCHEME_INVALID; } |
45 | 46 |
46 // Gets the proxy's scheme (i.e. SOCKS4, SOCKS5, HTTP} | 47 // Gets the proxy's scheme (i.e. SOCKS4, SOCKS5, HTTP} |
47 Scheme scheme() const { return scheme_; } | 48 Scheme scheme() const { return scheme_; } |
48 | 49 |
49 // Returns true if this ProxyServer is actually just a DIRECT connection. | 50 // Returns true if this ProxyServer is actually just a DIRECT connection. |
50 bool is_direct() const { return scheme_ == SCHEME_DIRECT; } | 51 bool is_direct() const { return scheme_ == SCHEME_DIRECT; } |
51 | 52 |
52 // Returns true if this ProxyServer is an HTTP proxy. | 53 // Returns true if this ProxyServer is an HTTP proxy. |
53 bool is_http() const { return scheme_ == SCHEME_HTTP; } | 54 bool is_http() const { return scheme_ == SCHEME_HTTP; } |
54 | 55 |
| 56 // Returns true if this ProxyServer is an HTTPS proxy. |
| 57 bool is_https() const { return scheme_ == SCHEME_HTTPS; } |
| 58 |
55 // Returns true if this ProxyServer is a SOCKS proxy. | 59 // Returns true if this ProxyServer is a SOCKS proxy. |
56 bool is_socks() const { | 60 bool is_socks() const { |
57 return scheme_ == SCHEME_SOCKS4 || scheme_ == SCHEME_SOCKS5; | 61 return scheme_ == SCHEME_SOCKS4 || scheme_ == SCHEME_SOCKS5; |
58 } | 62 } |
59 | 63 |
60 // Gets the host portion of the proxy server. If the host portion is an | 64 // Gets the host portion of the proxy server. If the host portion is an |
61 // IPv6 literal address, the return value does not include the square | 65 // IPv6 literal address, the return value does not include the square |
62 // brackets ([]) used to separate it from the port portion. | 66 // brackets ([]) used to separate it from the port portion. |
63 std::string HostNoBrackets() const; | 67 std::string HostNoBrackets() const; |
64 | 68 |
(...skipping 15 matching lines...) Expand all Loading... |
80 // assumed as |default_scheme|. If <port> is omitted, it will be assumed as | 84 // assumed as |default_scheme|. If <port> is omitted, it will be assumed as |
81 // the default port for the chosen scheme (80 for "http", 1080 for "socks"). | 85 // the default port for the chosen scheme (80 for "http", 1080 for "socks"). |
82 // | 86 // |
83 // If parsing fails the instance will be set to invalid. | 87 // If parsing fails the instance will be set to invalid. |
84 // | 88 // |
85 // Examples (for |default_scheme| = SCHEME_HTTP ): | 89 // Examples (for |default_scheme| = SCHEME_HTTP ): |
86 // "foopy" {scheme=HTTP, host="foopy", port=80} | 90 // "foopy" {scheme=HTTP, host="foopy", port=80} |
87 // "socks4://foopy" {scheme=SOCKS4, host="foopy", port=1080} | 91 // "socks4://foopy" {scheme=SOCKS4, host="foopy", port=1080} |
88 // "socks5://foopy" {scheme=SOCKS5, host="foopy", port=1080} | 92 // "socks5://foopy" {scheme=SOCKS5, host="foopy", port=1080} |
89 // "http://foopy:17" {scheme=HTTP, host="foopy", port=17} | 93 // "http://foopy:17" {scheme=HTTP, host="foopy", port=17} |
| 94 // "https://foopy:17" {scheme=HTTPS, host="foopy", port=17} |
90 // "direct://" {scheme=DIRECT} | 95 // "direct://" {scheme=DIRECT} |
91 // "foopy:X" INVALID -- bad port. | 96 // "foopy:X" INVALID -- bad port. |
92 static ProxyServer FromURI(const std::string& uri, Scheme default_scheme); | 97 static ProxyServer FromURI(const std::string& uri, Scheme default_scheme); |
93 static ProxyServer FromURI(std::string::const_iterator uri_begin, | 98 static ProxyServer FromURI(std::string::const_iterator uri_begin, |
94 std::string::const_iterator uri_end, | 99 std::string::const_iterator uri_end, |
95 Scheme default_scheme); | 100 Scheme default_scheme); |
96 | 101 |
97 // Formats as a URI string. This does the reverse of FromURI. | 102 // Formats as a URI string. This does the reverse of FromURI. |
98 std::string ToURI() const; | 103 std::string ToURI() const; |
99 | 104 |
100 // Parses from a PAC string result. | 105 // Parses from a PAC string result. |
101 // | 106 // |
102 // If <port> is omitted, it will be assumed as the default port for the | 107 // If <port> is omitted, it will be assumed as the default port for the |
103 // chosen scheme (80 for "http", 1080 for "socks"). | 108 // chosen scheme (80 for "http", 1080 for "socks"). |
104 // | 109 // |
105 // If parsing fails the instance will be set to invalid. | 110 // If parsing fails the instance will be set to invalid. |
106 // | 111 // |
107 // Examples: | 112 // Examples: |
108 // "PROXY foopy:19" {scheme=HTTP, host="foopy", port=19} | 113 // "PROXY foopy:19" {scheme=HTTP, host="foopy", port=19} |
109 // "DIRECT" {scheme=DIRECT} | 114 // "DIRECT" {scheme=DIRECT} |
110 // "SOCKS5 foopy" {scheme=SOCKS5, host="foopy", port=1080} | 115 // "SOCKS5 foopy" {scheme=SOCKS5, host="foopy", port=1080} |
| 116 // "HTTPS foopy:123" {scheme=HTTPS, host="foopy", port=123} |
111 // "BLAH xxx:xx" INVALID | 117 // "BLAH xxx:xx" INVALID |
112 static ProxyServer FromPacString(const std::string& pac_string); | 118 static ProxyServer FromPacString(const std::string& pac_string); |
113 static ProxyServer FromPacString(std::string::const_iterator pac_string_begin, | 119 static ProxyServer FromPacString(std::string::const_iterator pac_string_begin, |
114 std::string::const_iterator pac_string_end); | 120 std::string::const_iterator pac_string_end); |
115 | 121 |
116 // Returns a ProxyServer representing DIRECT connections. | 122 // Returns a ProxyServer representing DIRECT connections. |
117 static ProxyServer Direct() { | 123 static ProxyServer Direct() { |
118 return ProxyServer(SCHEME_DIRECT, std::string(), -1); | 124 return ProxyServer(SCHEME_DIRECT, std::string(), -1); |
119 } | 125 } |
120 | 126 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 std::string::const_iterator host_and_port_end); | 158 std::string::const_iterator host_and_port_end); |
153 | 159 |
154 Scheme scheme_; | 160 Scheme scheme_; |
155 std::string host_; | 161 std::string host_; |
156 int port_; | 162 int port_; |
157 }; | 163 }; |
158 | 164 |
159 } // namespace net | 165 } // namespace net |
160 | 166 |
161 #endif // NET_PROXY_PROXY_SERVER_H_ | 167 #endif // NET_PROXY_PROXY_SERVER_H_ |
OLD | NEW |