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