blob: 1bd523f8dba7278966cc84f233c100a9880e9dc0 [file] [log] [blame]
henrike@webrtc.orgf0488722014-05-13 18:00:261/*
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
22namespace rtc {
23
24///////////////////////////////////////////////////////////////////////////////
25// AutoDetectProxy
26///////////////////////////////////////////////////////////////////////////////
27
28class AsyncResolverInterface;
29class AsyncSocket;
30
31class 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.
kwiberg@webrtc.org67186fe2015-03-09 22:21:5353 virtual bool GetProxyForUrl(const char* agent,
54 const char* url,
55 rtc::ProxyInfo* proxy);
henrike@webrtc.orgf0488722014-05-13 18:00:2656 enum { MSG_TIMEOUT = SignalThread::ST_MSG_FIRST_AVAILABLE,
57 MSG_UNRESOLVABLE,
58 ADP_MSG_FIRST_AVAILABLE};
59
60 protected:
kwiberg@webrtc.org67186fe2015-03-09 22:21:5361 ~AutoDetectProxy() override;
henrike@webrtc.orgf0488722014-05-13 18:00:2662
63 // SignalThread Interface
kwiberg@webrtc.org67186fe2015-03-09 22:21:5364 void DoWork() override;
65 void OnMessage(Message* msg) override;
henrike@webrtc.orgf0488722014-05-13 18:00:2666
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 OnResolveResult(AsyncResolverInterface* resolver);
74 bool DoConnect();
75
76 private:
77 std::string agent_;
78 std::string server_url_;
79 ProxyInfo proxy_;
80 AsyncResolverInterface* resolver_;
81 AsyncSocket* socket_;
82 int next_;
83
henrikg3c089d72015-09-16 12:37:4484 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(AutoDetectProxy);
henrike@webrtc.orgf0488722014-05-13 18:00:2685};
86
87} // namespace rtc
88
89#endif // WEBRTC_BASE_AUTODETECTPROXY_H_