| 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 "remoting/jingle_glue/xmpp_socket_adapter.h" | 5 #include "jingle/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 "remoting/jingle_glue/ssl_adapter.h" | 11 #include "jingle/notifier/base/ssl_adapter.h" |
| 12 #include "jingle/notifier/communicator/product_info.h" |
| 12 #include "talk/base/byteorder.h" | 13 #include "talk/base/byteorder.h" |
| 13 #include "talk/base/common.h" | 14 #include "talk/base/common.h" |
| 14 #include "talk/base/firewallsocketserver.h" | 15 #include "talk/base/firewallsocketserver.h" |
| 15 #include "talk/base/logging.h" | 16 #include "talk/base/logging.h" |
| 16 #include "talk/base/socketadapters.h" | 17 #include "talk/base/socketadapters.h" |
| 17 #include "talk/base/ssladapter.h" | 18 #include "talk/base/ssladapter.h" |
| 18 #include "talk/base/thread.h" | 19 #include "talk/base/thread.h" |
| 19 #include "talk/xmpp/xmppengine.h" | 20 #include "talk/xmpp/xmppengine.h" |
| 20 | 21 |
| 21 namespace remoting { | 22 namespace notifier { |
| 22 | 23 |
| 23 XmppSocketAdapter::XmppSocketAdapter(const buzz::XmppClientSettings& xcs, | 24 XmppSocketAdapter::XmppSocketAdapter(const buzz::XmppClientSettings& xcs, |
| 24 bool allow_unverified_certs) | 25 bool allow_unverified_certs) |
| 25 : state_(STATE_CLOSED), | 26 : state_(STATE_CLOSED), |
| 26 error_(ERROR_NONE), | 27 error_(ERROR_NONE), |
| 27 wsa_error_(0), | 28 wsa_error_(0), |
| 28 socket_(NULL), | 29 socket_(NULL), |
| 29 protocol_(xcs.protocol()), | 30 protocol_(xcs.protocol()), |
| 30 firewall_(false), | 31 firewall_(false), |
| 31 write_buffer_(NULL), | 32 write_buffer_(NULL), |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 } | 104 } |
| 104 | 105 |
| 105 if (proxy_.type) { | 106 if (proxy_.type) { |
| 106 talk_base::AsyncSocket* proxy_socket = 0; | 107 talk_base::AsyncSocket* proxy_socket = 0; |
| 107 if (proxy_.type == talk_base::PROXY_SOCKS5) { | 108 if (proxy_.type == talk_base::PROXY_SOCKS5) { |
| 108 proxy_socket = new talk_base::AsyncSocksProxySocket( | 109 proxy_socket = new talk_base::AsyncSocksProxySocket( |
| 109 socket, proxy_.address, proxy_.username, proxy_.password); | 110 socket, proxy_.address, proxy_.username, proxy_.password); |
| 110 } else { | 111 } else { |
| 111 // Note: we are trying unknown proxies as HTTPS currently. | 112 // Note: we are trying unknown proxies as HTTPS currently. |
| 112 proxy_socket = new talk_base::AsyncHttpsProxySocket(socket, | 113 proxy_socket = new talk_base::AsyncHttpsProxySocket(socket, |
| 113 "chromoting", proxy_.address, proxy_.username, | 114 GetUserAgentString(), proxy_.address, proxy_.username, |
| 114 proxy_.password); | 115 proxy_.password); |
| 115 } | 116 } |
| 116 if (!proxy_socket) { | 117 if (!proxy_socket) { |
| 117 SetWSAError(WSA_NOT_ENOUGH_MEMORY); | 118 SetWSAError(WSA_NOT_ENOUGH_MEMORY); |
| 118 delete socket; | 119 delete socket; |
| 119 return false; | 120 return false; |
| 120 } | 121 } |
| 121 socket = proxy_socket; // For our purposes the proxy is now the socket. | 122 socket = proxy_socket; // For our purposes the proxy is now the socket. |
| 122 } | 123 } |
| 123 | 124 |
| 124 if (protocol_ == cricket::PROTO_SSLTCP) { | 125 if (protocol_ == cricket::PROTO_SSLTCP) { |
| 125 talk_base::AsyncSocket *fake_ssl_socket = | 126 talk_base::AsyncSocket *fake_ssl_socket = |
| 126 new talk_base::AsyncSSLSocket(socket); | 127 new talk_base::AsyncSSLSocket(socket); |
| 127 if (!fake_ssl_socket) { | 128 if (!fake_ssl_socket) { |
| 128 SetWSAError(WSA_NOT_ENOUGH_MEMORY); | 129 SetWSAError(WSA_NOT_ENOUGH_MEMORY); |
| 129 delete socket; | 130 delete socket; |
| 130 return false; | 131 return false; |
| 131 } | 132 } |
| 132 socket = fake_ssl_socket; // For our purposes the SSL socket is the socket. | 133 socket = fake_ssl_socket; // For our purposes the SSL socket is the socket. |
| 133 } | 134 } |
| 134 | 135 |
| 135 #if defined(FEATURE_ENABLE_SSL) | 136 #if defined(FEATURE_ENABLE_SSL) |
| 136 talk_base::SSLAdapter* ssl_adapter = remoting::CreateSSLAdapter(socket); | 137 talk_base::SSLAdapter* ssl_adapter = notifier::CreateSSLAdapter(socket); |
| 137 socket = ssl_adapter; // For our purposes the SSL adapter is the socket. | 138 socket = ssl_adapter; // For our purposes the SSL adapter is the socket. |
| 138 #endif | 139 #endif |
| 139 | 140 |
| 140 socket->SignalReadEvent.connect(this, &XmppSocketAdapter::OnReadEvent); | 141 socket->SignalReadEvent.connect(this, &XmppSocketAdapter::OnReadEvent); |
| 141 socket->SignalWriteEvent.connect(this, &XmppSocketAdapter::OnWriteEvent); | 142 socket->SignalWriteEvent.connect(this, &XmppSocketAdapter::OnWriteEvent); |
| 142 socket->SignalConnectEvent.connect(this, &XmppSocketAdapter::OnConnectEvent); | 143 socket->SignalConnectEvent.connect(this, &XmppSocketAdapter::OnConnectEvent); |
| 143 socket->SignalCloseEvent.connect(this, &XmppSocketAdapter::OnCloseEvent); | 144 socket->SignalCloseEvent.connect(this, &XmppSocketAdapter::OnCloseEvent); |
| 144 | 145 |
| 145 // The linux implementation of socket::Connect returns an error when the | 146 // The linux implementation of socket::Connect returns an error when the |
| 146 // connect didn't complete yet. This can be distinguished from a failure | 147 // connect didn't complete yet. This can be distinguished from a failure |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 Error error = ERROR_NONE; | 419 Error error = ERROR_NONE; |
| 419 int wsa_error = 0; | 420 int wsa_error = 0; |
| 420 FlushWriteQueue(&error, &wsa_error); | 421 FlushWriteQueue(&error, &wsa_error); |
| 421 if (error != ERROR_NONE) { | 422 if (error != ERROR_NONE) { |
| 422 Close(); | 423 Close(); |
| 423 return false; | 424 return false; |
| 424 } | 425 } |
| 425 return true; | 426 return true; |
| 426 } | 427 } |
| 427 | 428 |
| 428 } // namespace remoting | 429 } // namespace notifier |
| OLD | NEW |