| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 // TODO(ajwong): Unfork with | |
| 6 // chrome/common/net/notifier/communicator/xmpp_socket_adapter.h | |
| 7 | |
| 8 #ifndef REMOTING_JINGLE_GLUE_XMPP_SOCKET_ADAPTER_H_ | |
| 9 #define REMOTING_JINGLE_GLUE_XMPP_SOCKET_ADAPTER_H_ | |
| 10 | |
| 11 #include <string> | |
| 12 | |
| 13 #include "talk/base/asyncsocket.h" | |
| 14 #include "talk/xmpp/asyncsocket.h" | |
| 15 #include "talk/xmpp/xmppclientsettings.h" | |
| 16 #include "talk/xmpp/xmppengine.h" | |
| 17 | |
| 18 #ifndef _WIN32 | |
| 19 // Additional errors used by us from Win32 headers. | |
| 20 #define SEC_E_CERT_EXPIRED static_cast<int>(0x80090328L) | |
| 21 #define WSA_NOT_ENOUGH_MEMORY ENOMEM | |
| 22 #endif | |
| 23 | |
| 24 namespace remoting { | |
| 25 | |
| 26 class XmppSocketAdapter : public buzz::AsyncSocket, | |
| 27 public sigslot::has_slots<> { | |
| 28 public: | |
| 29 XmppSocketAdapter(const buzz::XmppClientSettings& xcs, | |
| 30 bool allow_unverified_certs); | |
| 31 virtual ~XmppSocketAdapter(); | |
| 32 | |
| 33 virtual State state() { return state_; } | |
| 34 virtual Error error() { return error_; } | |
| 35 virtual int GetError() { return wsa_error_; } | |
| 36 | |
| 37 void set_firewall(bool firewall) { firewall_ = firewall; } | |
| 38 | |
| 39 virtual bool Connect(const talk_base::SocketAddress& addr); | |
| 40 virtual bool Read(char* data, size_t len, size_t* len_read); | |
| 41 virtual bool Write(const char* data, size_t len); | |
| 42 virtual bool Close(); | |
| 43 | |
| 44 #if defined(FEATURE_ENABLE_SSL) | |
| 45 bool StartTls(const std::string& domainname); | |
| 46 bool IsOpen() const { return state_ == STATE_OPEN | |
| 47 || state_ == STATE_TLS_OPEN; } | |
| 48 #else | |
| 49 bool IsOpen() const { return state_ == STATE_OPEN; } | |
| 50 #endif | |
| 51 | |
| 52 sigslot::signal0<> SignalAuthenticationError; | |
| 53 | |
| 54 private: | |
| 55 // Return false if the socket is closed. | |
| 56 bool HandleReadable(); | |
| 57 bool HandleWritable(); | |
| 58 | |
| 59 State state_; | |
| 60 Error error_; | |
| 61 int wsa_error_; | |
| 62 | |
| 63 talk_base::AsyncSocket* socket_; | |
| 64 cricket::ProtocolType protocol_; | |
| 65 talk_base::ProxyInfo proxy_; | |
| 66 bool firewall_; | |
| 67 char* write_buffer_; | |
| 68 size_t write_buffer_length_; | |
| 69 size_t write_buffer_capacity_; | |
| 70 bool allow_unverified_certs_; | |
| 71 | |
| 72 bool FreeState(); | |
| 73 void NotifyClose(); | |
| 74 | |
| 75 void OnReadEvent(talk_base::AsyncSocket* socket); | |
| 76 void OnWriteEvent(talk_base::AsyncSocket* socket); | |
| 77 void OnConnectEvent(talk_base::AsyncSocket* socket); | |
| 78 void OnCloseEvent(talk_base::AsyncSocket* socket, int error); | |
| 79 | |
| 80 void QueueWriteData(const char* data, size_t len); | |
| 81 void FlushWriteQueue(Error* error, int* wsa_error); | |
| 82 | |
| 83 void SetError(Error error); | |
| 84 void SetWSAError(int error); | |
| 85 DISALLOW_COPY_AND_ASSIGN(XmppSocketAdapter); | |
| 86 }; | |
| 87 | |
| 88 } // namespace remoting | |
| 89 | |
| 90 #endif // REMOTING_JINGLE_GLUE_XMPP_SOCKET_ADAPTER_H_ | |
| OLD | NEW |