OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | |
3 * | |
4 * Use of this source code is governed by a BSD-style license | |
5 * that can be found in the LICENSE file in the root of the source | |
6 * tree. An additional intellectual property rights grant can be found | |
7 * in the file PATENTS. All contributing project authors may | |
8 * be found in the AUTHORS file in the root of the source tree. | |
9 */ | |
10 | |
11 #ifndef WEBRTC_BASE_AUTODETECTPROXY_H_ | |
12 #define WEBRTC_BASE_AUTODETECTPROXY_H_ | |
13 | |
14 #include <string> | |
15 | |
16 #include "webrtc/base/constructormagic.h" | |
17 #include "webrtc/base/cryptstring.h" | |
18 #include "webrtc/base/proxydetect.h" | |
19 #include "webrtc/base/proxyinfo.h" | |
20 #include "webrtc/base/signalthread.h" | |
21 | |
22 namespace rtc { | |
23 | |
24 /////////////////////////////////////////////////////////////////////////////// | |
25 // AutoDetectProxy | |
26 /////////////////////////////////////////////////////////////////////////////// | |
27 | |
28 class AsyncResolverInterface; | |
29 class AsyncSocket; | |
30 | |
31 class AutoDetectProxy : public SignalThread { | |
32 public: | |
33 explicit AutoDetectProxy(const std::string& user_agent); | |
34 | |
35 const ProxyInfo& proxy() const { return proxy_; } | |
36 | |
37 void set_server_url(const std::string& url) { | |
38 server_url_ = url; | |
39 } | |
40 void set_proxy(const SocketAddress& proxy) { | |
41 proxy_.type = PROXY_UNKNOWN; | |
42 proxy_.address = proxy; | |
43 } | |
44 void set_auth_info(bool use_auth, const std::string& username, | |
45 const CryptString& password) { | |
46 if (use_auth) { | |
47 proxy_.username = username; | |
48 proxy_.password = password; | |
49 } | |
50 } | |
51 // Default implementation of GetProxySettingsForUrl. Override for special | |
52 // implementation. | |
53 virtual bool GetProxyForUrl(const char* agent, | |
54 const char* url, | |
55 rtc::ProxyInfo* proxy); | |
56 enum { MSG_TIMEOUT = SignalThread::ST_MSG_FIRST_AVAILABLE, | |
57 MSG_UNRESOLVABLE, | |
58 ADP_MSG_FIRST_AVAILABLE}; | |
59 | |
60 protected: | |
61 ~AutoDetectProxy() override; | |
62 | |
63 // SignalThread Interface | |
64 void DoWork() override; | |
65 void OnMessage(Message* msg) override; | |
66 | |
67 void Next(); | |
68 void Complete(ProxyType type); | |
69 | |
70 void OnConnectEvent(AsyncSocket * socket); | |
71 void OnReadEvent(AsyncSocket * socket); | |
72 void OnCloseEvent(AsyncSocket * socket, int error); | |
73 void OnTimeout(); | |
74 void OnResolveResult(AsyncResolverInterface* resolver); | |
75 bool DoConnect(); | |
76 | |
77 private: | |
78 std::string agent_; | |
79 std::string server_url_; | |
80 ProxyInfo proxy_; | |
81 AsyncResolverInterface* resolver_; | |
82 AsyncSocket* socket_; | |
83 int next_; | |
84 | |
85 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(AutoDetectProxy); | |
86 }; | |
87 | |
88 } // namespace rtc | |
89 | |
90 #endif // WEBRTC_BASE_AUTODETECTPROXY_H_ | |
OLD | NEW |