blob: 02d645383c3b9774a291d0b43f0bdb70d485ac71 [file] [log] [blame]
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +00001/*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11#ifndef WEBRTC_LIBJINGLE_XMPP_XMPPSOCKET_H_
12#define WEBRTC_LIBJINGLE_XMPP_XMPPSOCKET_H_
13
14#include "webrtc/libjingle/xmpp/asyncsocket.h"
15#include "webrtc/libjingle/xmpp/xmppengine.h"
16#include "webrtc/base/asyncsocket.h"
jbauchf1f87202016-03-30 06:43:37 -070017#include "webrtc/base/buffer.h"
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000018#include "webrtc/base/sigslot.h"
19
20// The below define selects the SSLStreamAdapter implementation for
21// SSL, as opposed to the SSLAdapter socket adapter.
Stefan Holmer9131efd2016-05-23 18:19:26 +020022// #define USE_SSLSTREAM
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000023
24namespace rtc {
25 class StreamInterface;
26 class SocketAddress;
27};
28extern rtc::AsyncSocket* cricket_socket_;
29
30namespace buzz {
31
32class XmppSocket : public buzz::AsyncSocket, public sigslot::has_slots<> {
33public:
34 XmppSocket(buzz::TlsOptions tls);
35 ~XmppSocket();
36
37 virtual buzz::AsyncSocket::State state();
38 virtual buzz::AsyncSocket::Error error();
39 virtual int GetError();
40
41 virtual bool Connect(const rtc::SocketAddress& addr);
42 virtual bool Read(char * data, size_t len, size_t* len_read);
43 virtual bool Write(const char * data, size_t len);
44 virtual bool Close();
45 virtual bool StartTls(const std::string & domainname);
46
47 sigslot::signal1<int> SignalCloseEvent;
48
49private:
50 void CreateCricketSocket(int family);
51#ifndef USE_SSLSTREAM
52 void OnReadEvent(rtc::AsyncSocket * socket);
53 void OnWriteEvent(rtc::AsyncSocket * socket);
54 void OnConnectEvent(rtc::AsyncSocket * socket);
55 void OnCloseEvent(rtc::AsyncSocket * socket, int error);
56#else // USE_SSLSTREAM
57 void OnEvent(rtc::StreamInterface* stream, int events, int err);
58#endif // USE_SSLSTREAM
59
60 rtc::AsyncSocket * cricket_socket_;
61#ifdef USE_SSLSTREAM
62 rtc::StreamInterface *stream_;
63#endif // USE_SSLSTREAM
64 buzz::AsyncSocket::State state_;
jbauchf1f87202016-03-30 06:43:37 -070065 rtc::Buffer buffer_;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000066 buzz::TlsOptions tls_;
67};
68
69} // namespace buzz
70
71#endif // WEBRTC_LIBJINGLE_XMPP_XMPPSOCKET_H_
72