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