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, const char* url, 54 rtc::ProxyInfo* proxy) { 55 return GetProxySettingsForUrl(agent, url, proxy, true); 56 } 57 enum { MSG_TIMEOUT = SignalThread::ST_MSG_FIRST_AVAILABLE, 58 MSG_UNRESOLVABLE, 59 ADP_MSG_FIRST_AVAILABLE}; 60 61 protected: 62 virtual ~AutoDetectProxy(); 63 64 // SignalThread Interface 65 virtual void DoWork(); 66 virtual void OnMessage(Message *msg); 67 68 void Next(); 69 void Complete(ProxyType type); 70 71 void OnConnectEvent(AsyncSocket * socket); 72 void OnReadEvent(AsyncSocket * socket); 73 void OnCloseEvent(AsyncSocket * socket, int error); 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 DISALLOW_IMPLICIT_CONSTRUCTORS(AutoDetectProxy); 86 }; 87 88 } // namespace rtc 89 90 #endif // WEBRTC_BASE_AUTODETECTPROXY_H_ 91