| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/sync/notifier/communicator/xmpp_socket_adapter.h" | 5 #include "chrome/browser/sync/notifier/communicator/xmpp_socket_adapter.h" |
| 6 | 6 |
| 7 #include <iomanip> | 7 #include <iomanip> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "chrome/browser/sync/notifier/communicator/product_info.h" | 11 #include "chrome/browser/sync/notifier/communicator/product_info.h" |
| 12 #if defined(OS_LINUX) || defined(OS_MACOSX) |
| 13 #include "chrome/browser/sync/notifier/communicator/ssl_socket_adapter.h" |
| 14 #endif |
| 12 #include "talk/base/byteorder.h" | 15 #include "talk/base/byteorder.h" |
| 13 #include "talk/base/common.h" | 16 #include "talk/base/common.h" |
| 14 #include "talk/base/firewallsocketserver.h" | 17 #include "talk/base/firewallsocketserver.h" |
| 15 #include "talk/base/logging.h" | 18 #include "talk/base/logging.h" |
| 16 #include "talk/base/socketadapters.h" | 19 #include "talk/base/socketadapters.h" |
| 20 #if defined(OS_WIN) |
| 17 #include "talk/base/ssladapter.h" | 21 #include "talk/base/ssladapter.h" |
| 22 #endif |
| 18 #include "talk/xmpp/xmppengine.h" | 23 #include "talk/xmpp/xmppengine.h" |
| 19 | 24 |
| 20 namespace notifier { | 25 namespace notifier { |
| 21 | 26 |
| 22 XmppSocketAdapter::XmppSocketAdapter(const buzz::XmppClientSettings& xcs, | 27 XmppSocketAdapter::XmppSocketAdapter(const buzz::XmppClientSettings& xcs, |
| 23 bool allow_unverified_certs) | 28 bool allow_unverified_certs) |
| 24 : state_(STATE_CLOSED), | 29 : state_(STATE_CLOSED), |
| 25 error_(ERROR_NONE), | 30 error_(ERROR_NONE), |
| 26 wsa_error_(0), | 31 wsa_error_(0), |
| 27 socket_(NULL), | 32 socket_(NULL), |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 new talk_base::AsyncSSLSocket(socket); | 130 new talk_base::AsyncSSLSocket(socket); |
| 126 if (!fake_ssl_socket) { | 131 if (!fake_ssl_socket) { |
| 127 SetWSAError(WSA_NOT_ENOUGH_MEMORY); | 132 SetWSAError(WSA_NOT_ENOUGH_MEMORY); |
| 128 delete socket; | 133 delete socket; |
| 129 return false; | 134 return false; |
| 130 } | 135 } |
| 131 socket = fake_ssl_socket; // For our purposes the SSL socket is the socket. | 136 socket = fake_ssl_socket; // For our purposes the SSL socket is the socket. |
| 132 } | 137 } |
| 133 | 138 |
| 134 #if defined(FEATURE_ENABLE_SSL) | 139 #if defined(FEATURE_ENABLE_SSL) |
| 140 #if defined(OS_WIN) |
| 135 talk_base::SSLAdapter* ssl = talk_base::SSLAdapter::Create(socket); | 141 talk_base::SSLAdapter* ssl = talk_base::SSLAdapter::Create(socket); |
| 142 #else |
| 143 notifier::SSLSocketAdapter* ssl = notifier::SSLSocketAdapter::Create(socket); |
| 144 #endif |
| 136 socket = ssl; | 145 socket = ssl; |
| 137 #endif | 146 #endif |
| 138 | 147 |
| 139 socket->SignalReadEvent.connect(this, &XmppSocketAdapter::OnReadEvent); | 148 socket->SignalReadEvent.connect(this, &XmppSocketAdapter::OnReadEvent); |
| 140 socket->SignalWriteEvent.connect(this, &XmppSocketAdapter::OnWriteEvent); | 149 socket->SignalWriteEvent.connect(this, &XmppSocketAdapter::OnWriteEvent); |
| 141 socket->SignalConnectEvent.connect(this, &XmppSocketAdapter::OnConnectEvent); | 150 socket->SignalConnectEvent.connect(this, &XmppSocketAdapter::OnConnectEvent); |
| 142 socket->SignalCloseEvent.connect(this, &XmppSocketAdapter::OnCloseEvent); | 151 socket->SignalCloseEvent.connect(this, &XmppSocketAdapter::OnCloseEvent); |
| 143 | 152 |
| 144 // The linux implementation of socket::Connect returns an error when the | 153 // The linux implementation of socket::Connect returns an error when the |
| 145 // connect didn't complete yet. This can be distinguished from a failure | 154 // connect didn't complete yet. This can be distinguished from a failure |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 bool XmppSocketAdapter::StartTls(const std::string& verify_host_name) { | 322 bool XmppSocketAdapter::StartTls(const std::string& verify_host_name) { |
| 314 if (state_ != STATE_OPEN) { | 323 if (state_ != STATE_OPEN) { |
| 315 SetError(ERROR_WRONGSTATE); | 324 SetError(ERROR_WRONGSTATE); |
| 316 return false; | 325 return false; |
| 317 } | 326 } |
| 318 | 327 |
| 319 state_ = STATE_TLS_CONNECTING; | 328 state_ = STATE_TLS_CONNECTING; |
| 320 | 329 |
| 321 ASSERT(write_buffer_length_ == 0); | 330 ASSERT(write_buffer_length_ == 0); |
| 322 | 331 |
| 332 #if defined(OS_WIN) |
| 323 talk_base::SSLAdapter* ssl_adapter = | 333 talk_base::SSLAdapter* ssl_adapter = |
| 324 static_cast<talk_base::SSLAdapter*>(socket_); | 334 static_cast<talk_base::SSLAdapter*>(socket_); |
| 335 #else |
| 336 notifier::SSLSocketAdapter* ssl_adapter = |
| 337 static_cast<notifier::SSLSocketAdapter*>(socket_); |
| 338 #endif |
| 325 | 339 |
| 326 if (allow_unverified_certs_) { | 340 if (allow_unverified_certs_) { |
| 327 ssl_adapter->set_ignore_bad_cert(true); | 341 ssl_adapter->set_ignore_bad_cert(true); |
| 328 } | 342 } |
| 329 | 343 |
| 330 if (ssl_adapter->StartSSL(verify_host_name.c_str(), false) != 0) { | 344 if (ssl_adapter->StartSSL(verify_host_name.c_str(), false) != 0) { |
| 331 state_ = STATE_OPEN; | 345 state_ = STATE_OPEN; |
| 332 SetError(ERROR_SSL); | 346 SetError(ERROR_SSL); |
| 333 return false; | 347 return false; |
| 334 } | 348 } |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 int wsa_error = 0; | 431 int wsa_error = 0; |
| 418 FlushWriteQueue(&error, &wsa_error); | 432 FlushWriteQueue(&error, &wsa_error); |
| 419 if (error != ERROR_NONE) { | 433 if (error != ERROR_NONE) { |
| 420 Close(); | 434 Close(); |
| 421 return false; | 435 return false; |
| 422 } | 436 } |
| 423 return true; | 437 return true; |
| 424 } | 438 } |
| 425 | 439 |
| 426 } // namespace notifier | 440 } // namespace notifier |
| OLD | NEW |