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