Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(81)

Side by Side Diff: webrtc/base/sslsocketfactory.cc

Issue 2685783014: Replace NULL with nullptr in all C++ files. (Closed)
Patch Set: Fixing android. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2007 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2007 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 12 matching lines...) Expand all
23 /////////////////////////////////////////////////////////////////////////////// 23 ///////////////////////////////////////////////////////////////////////////////
24 // ProxySocketAdapter 24 // ProxySocketAdapter
25 // TODO: Consider combining AutoDetectProxy and ProxySocketAdapter. I think 25 // TODO: Consider combining AutoDetectProxy and ProxySocketAdapter. I think
26 // the socket adapter is the more appropriate idiom for automatic proxy 26 // the socket adapter is the more appropriate idiom for automatic proxy
27 // detection. We may or may not want to combine proxydetect.* as well. 27 // detection. We may or may not want to combine proxydetect.* as well.
28 /////////////////////////////////////////////////////////////////////////////// 28 ///////////////////////////////////////////////////////////////////////////////
29 29
30 class ProxySocketAdapter : public AsyncSocketAdapter { 30 class ProxySocketAdapter : public AsyncSocketAdapter {
31 public: 31 public:
32 ProxySocketAdapter(SslSocketFactory* factory, int family, int type) 32 ProxySocketAdapter(SslSocketFactory* factory, int family, int type)
33 : AsyncSocketAdapter(NULL), factory_(factory), family_(family), 33 : AsyncSocketAdapter(nullptr),
34 type_(type), detect_(NULL) { 34 factory_(factory),
35 } 35 family_(family),
36 type_(type),
37 detect_(nullptr) {}
36 ~ProxySocketAdapter() override { 38 ~ProxySocketAdapter() override {
37 Close(); 39 Close();
38 } 40 }
39 41
40 int Connect(const SocketAddress& addr) override { 42 int Connect(const SocketAddress& addr) override {
41 RTC_DCHECK(NULL == detect_); 43 RTC_DCHECK(nullptr == detect_);
42 RTC_DCHECK(NULL == socket_); 44 RTC_DCHECK(nullptr == socket_);
43 remote_ = addr; 45 remote_ = addr;
44 if (remote_.IsAnyIP() && remote_.hostname().empty()) { 46 if (remote_.IsAnyIP() && remote_.hostname().empty()) {
45 LOG_F(LS_ERROR) << "Empty address"; 47 LOG_F(LS_ERROR) << "Empty address";
46 return SOCKET_ERROR; 48 return SOCKET_ERROR;
47 } 49 }
48 Url<char> url("/", remote_.HostAsURIString(), remote_.port()); 50 Url<char> url("/", remote_.HostAsURIString(), remote_.port());
49 detect_ = new AutoDetectProxy(factory_->agent_); 51 detect_ = new AutoDetectProxy(factory_->agent_);
50 detect_->set_server_url(url.url()); 52 detect_->set_server_url(url.url());
51 detect_->SignalWorkDone.connect(this, 53 detect_->SignalWorkDone.connect(this,
52 &ProxySocketAdapter::OnProxyDetectionComplete); 54 &ProxySocketAdapter::OnProxyDetectionComplete);
53 detect_->Start(); 55 detect_->Start();
54 return SOCKET_ERROR; 56 return SOCKET_ERROR;
55 } 57 }
56 int GetError() const override { 58 int GetError() const override {
57 if (socket_) { 59 if (socket_) {
58 return socket_->GetError(); 60 return socket_->GetError();
59 } 61 }
60 return detect_ ? EWOULDBLOCK : EADDRNOTAVAIL; 62 return detect_ ? EWOULDBLOCK : EADDRNOTAVAIL;
61 } 63 }
62 int Close() override { 64 int Close() override {
63 if (socket_) { 65 if (socket_) {
64 return socket_->Close(); 66 return socket_->Close();
65 } 67 }
66 if (detect_) { 68 if (detect_) {
67 detect_->Destroy(false); 69 detect_->Destroy(false);
68 detect_ = NULL; 70 detect_ = nullptr;
69 } 71 }
70 return 0; 72 return 0;
71 } 73 }
72 ConnState GetState() const override { 74 ConnState GetState() const override {
73 if (socket_) { 75 if (socket_) {
74 return socket_->GetState(); 76 return socket_->GetState();
75 } 77 }
76 return detect_ ? CS_CONNECTING : CS_CLOSED; 78 return detect_ ? CS_CONNECTING : CS_CLOSED;
77 } 79 }
78 80
79 private: 81 private:
80 // AutoDetectProxy Slots 82 // AutoDetectProxy Slots
81 void OnProxyDetectionComplete(SignalThread* thread) { 83 void OnProxyDetectionComplete(SignalThread* thread) {
82 RTC_DCHECK(detect_ == thread); 84 RTC_DCHECK(detect_ == thread);
83 Attach(factory_->CreateProxySocket(detect_->proxy(), family_, type_)); 85 Attach(factory_->CreateProxySocket(detect_->proxy(), family_, type_));
84 detect_->Release(); 86 detect_->Release();
85 detect_ = NULL; 87 detect_ = nullptr;
86 if (0 == AsyncSocketAdapter::Connect(remote_)) { 88 if (0 == AsyncSocketAdapter::Connect(remote_)) {
87 SignalConnectEvent(this); 89 SignalConnectEvent(this);
88 } else if (!IsBlockingError(socket_->GetError())) { 90 } else if (!IsBlockingError(socket_->GetError())) {
89 SignalCloseEvent(this, socket_->GetError()); 91 SignalCloseEvent(this, socket_->GetError());
90 } 92 }
91 } 93 }
92 94
93 SslSocketFactory* factory_; 95 SslSocketFactory* factory_;
94 int family_; 96 int family_;
95 int type_; 97 int type_;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 return CreateProxySocket(proxy_, family, type); 135 return CreateProxySocket(proxy_, family, type);
134 } 136 }
135 } 137 }
136 138
137 139
138 AsyncSocket* SslSocketFactory::CreateProxySocket(const ProxyInfo& proxy, 140 AsyncSocket* SslSocketFactory::CreateProxySocket(const ProxyInfo& proxy,
139 int family, 141 int family,
140 int type) { 142 int type) {
141 AsyncSocket* socket = factory_->CreateAsyncSocket(family, type); 143 AsyncSocket* socket = factory_->CreateAsyncSocket(family, type);
142 if (!socket) 144 if (!socket)
143 return NULL; 145 return nullptr;
144 146
145 // Binary logging happens at the lowest level 147 // Binary logging happens at the lowest level
146 if (!logging_label_.empty() && binary_mode_) { 148 if (!logging_label_.empty() && binary_mode_) {
147 socket = new LoggingSocketAdapter(socket, logging_level_, 149 socket = new LoggingSocketAdapter(socket, logging_level_,
148 logging_label_.c_str(), binary_mode_); 150 logging_label_.c_str(), binary_mode_);
149 } 151 }
150 152
151 if (proxy.type) { 153 if (proxy.type) {
152 AsyncSocket* proxy_socket = 0; 154 AsyncSocket* proxy_socket = 0;
153 if (proxy_.type == PROXY_SOCKS5) { 155 if (proxy_.type == PROXY_SOCKS5) {
154 proxy_socket = new AsyncSocksProxySocket(socket, proxy.address, 156 proxy_socket = new AsyncSocksProxySocket(socket, proxy.address,
155 proxy.username, proxy.password); 157 proxy.username, proxy.password);
156 } else { 158 } else {
157 // Note: we are trying unknown proxies as HTTPS currently 159 // Note: we are trying unknown proxies as HTTPS currently
158 AsyncHttpsProxySocket* http_proxy = 160 AsyncHttpsProxySocket* http_proxy =
159 new AsyncHttpsProxySocket(socket, agent_, proxy.address, 161 new AsyncHttpsProxySocket(socket, agent_, proxy.address,
160 proxy.username, proxy.password); 162 proxy.username, proxy.password);
161 http_proxy->SetForceConnect(force_connect_ || !hostname_.empty()); 163 http_proxy->SetForceConnect(force_connect_ || !hostname_.empty());
162 proxy_socket = http_proxy; 164 proxy_socket = http_proxy;
163 } 165 }
164 if (!proxy_socket) { 166 if (!proxy_socket) {
165 delete socket; 167 delete socket;
166 return NULL; 168 return nullptr;
167 } 169 }
168 socket = proxy_socket; // for our purposes the proxy is now the socket 170 socket = proxy_socket; // for our purposes the proxy is now the socket
169 } 171 }
170 172
171 if (!hostname_.empty()) { 173 if (!hostname_.empty()) {
172 std::unique_ptr<SSLAdapter> ssl_adapter(SSLAdapter::Create(socket)); 174 std::unique_ptr<SSLAdapter> ssl_adapter(SSLAdapter::Create(socket));
173 if (!ssl_adapter) { 175 if (!ssl_adapter) {
174 LOG_F(LS_ERROR) << "SSL unavailable"; 176 LOG_F(LS_ERROR) << "SSL unavailable";
175 delete socket; 177 delete socket;
176 return NULL; 178 return nullptr;
177 } 179 }
178 180
179 ssl_adapter->set_ignore_bad_cert(ignore_bad_cert_); 181 ssl_adapter->set_ignore_bad_cert(ignore_bad_cert_);
180 if (ssl_adapter->StartSSL(hostname_.c_str(), true) != 0) { 182 if (ssl_adapter->StartSSL(hostname_.c_str(), true) != 0) {
181 LOG_F(LS_ERROR) << "SSL failed to start."; 183 LOG_F(LS_ERROR) << "SSL failed to start.";
182 return NULL; 184 return nullptr;
183 } 185 }
184 socket = ssl_adapter.release(); 186 socket = ssl_adapter.release();
185 } 187 }
186 188
187 // Regular logging occurs at the highest level 189 // Regular logging occurs at the highest level
188 if (!logging_label_.empty() && !binary_mode_) { 190 if (!logging_label_.empty() && !binary_mode_) {
189 socket = new LoggingSocketAdapter(socket, logging_level_, 191 socket = new LoggingSocketAdapter(socket, logging_level_,
190 logging_label_.c_str(), binary_mode_); 192 logging_label_.c_str(), binary_mode_);
191 } 193 }
192 return socket; 194 return socket;
193 } 195 }
194 196
195 /////////////////////////////////////////////////////////////////////////////// 197 ///////////////////////////////////////////////////////////////////////////////
196 198
197 } // namespace rtc 199 } // namespace rtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698