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