| 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" |
| 9 |
| 10 #if defined(OS_MACOSX) |
| 11 #include <CoreFoundation/CoreFoundation.h> |
| 12 #endif |
| 13 |
| 8 #include <string> | 14 #include <string> |
| 9 | 15 |
| 10 namespace net { | 16 namespace net { |
| 11 | 17 |
| 12 // ProxyServer encodes the {type, host, port} of a proxy server. | 18 // ProxyServer encodes the {type, host, port} of a proxy server. |
| 13 // ProxyServer is immutable. | 19 // ProxyServer is immutable. |
| 14 class ProxyServer { | 20 class ProxyServer { |
| 15 public: | 21 public: |
| 16 // The type of proxy. These are defined as bit flags so they can be ORed | 22 // The type of proxy. These are defined as bit flags so they can be ORed |
| 17 // together to pass as the |scheme_bit_field| argument to | 23 // together to pass as the |scheme_bit_field| argument to |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 // | 100 // |
| 95 // Examples: | 101 // Examples: |
| 96 // "PROXY foopy:19" {scheme=HTTP, host="foopy", port=19} | 102 // "PROXY foopy:19" {scheme=HTTP, host="foopy", port=19} |
| 97 // "DIRECT" {scheme=DIRECT} | 103 // "DIRECT" {scheme=DIRECT} |
| 98 // "SOCKS5 foopy" {scheme=SOCKS5, host="foopy", port=1080} | 104 // "SOCKS5 foopy" {scheme=SOCKS5, host="foopy", port=1080} |
| 99 // "BLAH xxx:xx" INVALID | 105 // "BLAH xxx:xx" INVALID |
| 100 static ProxyServer FromPacString(const std::string& pac_string); | 106 static ProxyServer FromPacString(const std::string& pac_string); |
| 101 static ProxyServer FromPacString(std::string::const_iterator pac_string_begin, | 107 static ProxyServer FromPacString(std::string::const_iterator pac_string_begin, |
| 102 std::string::const_iterator pac_string_end); | 108 std::string::const_iterator pac_string_end); |
| 103 | 109 |
| 110 #if defined(OS_MACOSX) |
| 111 // Utility function to pull out a host/port pair from a dictionary and return |
| 112 // it as a ProxyServer object. Pass in a dictionary that has a value for the |
| 113 // host key and optionally a value for the port key. In the error condition |
| 114 // where the host value is especially malformed, returns an invalid |
| 115 // ProxyServer. |
| 116 static ProxyServer FromDictionary(Scheme scheme, |
| 117 CFDictionaryRef dict, |
| 118 CFStringRef host_key, |
| 119 CFStringRef port_key); |
| 120 #endif |
| 121 |
| 122 |
| 104 // Format as a PAC result entry. This does the reverse of FromPacString(). | 123 // Format as a PAC result entry. This does the reverse of FromPacString(). |
| 105 std::string ToPacString() const; | 124 std::string ToPacString() const; |
| 106 | 125 |
| 107 // Returns the default port number for a proxy server with the specified | 126 // Returns the default port number for a proxy server with the specified |
| 108 // scheme. Returns -1 if unknown. | 127 // scheme. Returns -1 if unknown. |
| 109 static int GetDefaultPortForScheme(Scheme scheme); | 128 static int GetDefaultPortForScheme(Scheme scheme); |
| 110 | 129 |
| 111 bool operator==(const ProxyServer& other) const { | 130 bool operator==(const ProxyServer& other) const { |
| 112 return scheme_ == other.scheme_ && | 131 return scheme_ == other.scheme_ && |
| 113 host_ == other.host_ && | 132 host_ == other.host_ && |
| 114 port_ == other.port_; | 133 port_ == other.port_; |
| 115 } | 134 } |
| 116 | 135 |
| 117 private: | 136 private: |
| 118 // Create a ProxyServer given a scheme, and host/port string. If parsing the | 137 // Create a ProxyServer given a scheme, and host/port string. If parsing the |
| 119 // host/port string fails, the returned instance will be invalid. | 138 // host/port string fails, the returned instance will be invalid. |
| 120 static ProxyServer FromSchemeHostAndPort( | 139 static ProxyServer FromSchemeHostAndPort( |
| 121 Scheme scheme, | 140 Scheme scheme, |
| 122 std::string::const_iterator host_and_port_begin, | 141 std::string::const_iterator host_and_port_begin, |
| 123 std::string::const_iterator host_and_port_end); | 142 std::string::const_iterator host_and_port_end); |
| 124 | 143 |
| 125 Scheme scheme_; | 144 Scheme scheme_; |
| 126 std::string host_; | 145 std::string host_; |
| 127 int port_; | 146 int port_; |
| 128 }; | 147 }; |
| 129 | 148 |
| 130 } // namespace net | 149 } // namespace net |
| 131 | 150 |
| 132 #endif // NET_PROXY_PROXY_SERVER_H_ | 151 #endif // NET_PROXY_PROXY_SERVER_H_ |
| OLD | NEW |