OLD | NEW |
| (Empty) |
1 // Copyright 2007-2010 Google Inc. | |
2 // | |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | |
4 // you may not use this file except in compliance with the License. | |
5 // You may obtain a copy of the License at | |
6 // | |
7 // http://www.apache.org/licenses/LICENSE-2.0 | |
8 // | |
9 // Unless required by applicable law or agreed to in writing, software | |
10 // distributed under the License is distributed on an "AS IS" BASIS, | |
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 // See the License for the specific language governing permissions and | |
13 // limitations under the License. | |
14 // ======================================================================== | |
15 | |
16 #ifndef OMAHA_NET_DETECTOR_H__ | |
17 #define OMAHA_NET_DETECTOR_H__ | |
18 | |
19 #include <windows.h> | |
20 #include <atlstr.h> | |
21 #include "base/basictypes.h" | |
22 #include "base/scoped_ptr.h" | |
23 | |
24 namespace omaha { | |
25 | |
26 struct ProxyConfig; | |
27 | |
28 class ProxyDetectorInterface { | |
29 public: | |
30 // Detects proxy information. | |
31 virtual HRESULT Detect(ProxyConfig* config) = 0; | |
32 virtual const TCHAR* source() = 0; | |
33 virtual ~ProxyDetectorInterface() {} | |
34 }; | |
35 | |
36 // Detects proxy override information in the specified registry key. | |
37 class RegistryOverrideProxyDetector : public ProxyDetectorInterface { | |
38 public: | |
39 explicit RegistryOverrideProxyDetector(const CString& reg_path) | |
40 : reg_path_(reg_path) {} | |
41 | |
42 virtual HRESULT Detect(ProxyConfig* config); | |
43 virtual const TCHAR* source() { return _T("RegistryOverride"); } | |
44 private: | |
45 CString reg_path_; | |
46 DISALLOW_EVIL_CONSTRUCTORS(RegistryOverrideProxyDetector); | |
47 }; | |
48 | |
49 class UpdateDevProxyDetector : public ProxyDetectorInterface { | |
50 public: | |
51 UpdateDevProxyDetector(); | |
52 virtual HRESULT Detect(ProxyConfig* config) { | |
53 return registry_detector_.Detect(config); | |
54 } | |
55 virtual const TCHAR* source() { return _T("UpdateDev"); } | |
56 private: | |
57 RegistryOverrideProxyDetector registry_detector_; | |
58 DISALLOW_EVIL_CONSTRUCTORS(UpdateDevProxyDetector); | |
59 }; | |
60 | |
61 // Detects winhttp proxy information. This is what the winhttp proxy | |
62 // configuration utility (proxycfg.exe) has set. | |
63 // The winhttp proxy settings are under: | |
64 // HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\Connections | |
65 class DefaultProxyDetector : public ProxyDetectorInterface { | |
66 public: | |
67 DefaultProxyDetector() {} | |
68 virtual HRESULT Detect(ProxyConfig* config); | |
69 virtual const TCHAR* source() { return _T("winhttp"); } | |
70 private: | |
71 DISALLOW_EVIL_CONSTRUCTORS(DefaultProxyDetector); | |
72 }; | |
73 | |
74 // Detects proxy information for Firefox. | |
75 // http://www.mozilla.org/quality/networking/docs/netprefs.html | |
76 // It works only when the calling code runs as or it impersonates a user. | |
77 class FirefoxProxyDetector : public ProxyDetectorInterface { | |
78 public: | |
79 enum ProxyType { | |
80 PROXY_TYPE_NO_PROXY = 0, | |
81 PROXY_TYPE_NAMED_PROXY = 1, | |
82 PROXY_TYPE_AUTO_CONFIG_URL = 2, | |
83 PROXY_TYPE_AUTO_DETECT = 4 | |
84 }; | |
85 | |
86 FirefoxProxyDetector(); | |
87 | |
88 virtual HRESULT Detect(ProxyConfig* config); | |
89 virtual const TCHAR* source() { return _T("Firefox"); } | |
90 private: | |
91 // Parses the prefs.js file. | |
92 HRESULT ParsePrefsFile(const TCHAR* name, | |
93 const TCHAR* file_path, | |
94 ProxyConfig* config); | |
95 | |
96 // Parse one line of the prefs file. | |
97 void ParsePrefsLine(const char* ansi_line, | |
98 CString* proxy_type, | |
99 CString* proxy_config_url, | |
100 CString* proxy_http_host, | |
101 CString* proxy_http_port, | |
102 CString* proxy_ssl_host, | |
103 CString* proxy_ssl_port); | |
104 | |
105 // Builds a proxy string out of individual components. | |
106 HRESULT BuildProxyString(const CString& http_host, | |
107 const CString& http_port, | |
108 const CString& ssl_host, | |
109 const CString& ssl_port, | |
110 CString* proxy); | |
111 | |
112 // Cached configuration values for the current FF profile. | |
113 CString cached_prefs_name_; | |
114 CString cached_prefs_file_path_; | |
115 int64 cached_prefs_last_modified_; | |
116 scoped_ptr<ProxyConfig> cached_config_; | |
117 | |
118 friend class FirefoxProxyDetectorTest; | |
119 DISALLOW_EVIL_CONSTRUCTORS(FirefoxProxyDetector); | |
120 }; | |
121 | |
122 // Detects wininet proxy information for the current user. The caller must | |
123 // run as user to retrieve the correct information. | |
124 // It works only when the calling code runs as or it impersonates a user. | |
125 class IEProxyDetector : public ProxyDetectorInterface { | |
126 public: | |
127 IEProxyDetector() {} | |
128 virtual HRESULT Detect(ProxyConfig* config); | |
129 virtual const TCHAR* source() { return _T("IE"); } | |
130 private: | |
131 DISALLOW_EVIL_CONSTRUCTORS(IEProxyDetector); | |
132 }; | |
133 | |
134 } // namespace omaha | |
135 | |
136 #endif // OMAHA_NET_DETECTOR_H__ | |
137 | |
OLD | NEW |