Add credits for Marek
[trojita.git] / src / Streams / Socket.h
blob024fd17fee63511908ca9b903989456947ec4092
1 /* Copyright (C) 2006 - 2014 Jan Kundrát <jkt@flaska.net>
3 This file is part of the Trojita Qt IMAP e-mail client,
4 http://trojita.flaska.net/
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License as
8 published by the Free Software Foundation; either version 2 of
9 the License or (at your option) version 3 or any later version
10 accepted by the membership of KDE e.V. (or its successor approved
11 by the membership of KDE e.V.), which shall act as a proxy
12 defined in Section 14 of version 3 of the license.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #ifndef STREAMS_SOCKET_H
23 #define STREAMS_SOCKET_H
25 #include <memory>
26 #include <QAbstractSocket>
27 #include <QSslError>
28 #include "../Imap/ConnectionState.h"
30 namespace Streams {
32 /** @short A common wrapepr class for implementing remote sockets
34 This class extends the basic QIODevice-like API by a few handy methods,
35 so that the upper layers do not have to worry about low-level socket details.
37 class Socket: public QObject
39 Q_OBJECT
40 public:
41 virtual ~Socket();
43 /** @short Returns true if there's enough data to read, including the CR-LF pair */
44 virtual bool canReadLine() = 0;
46 /** @short Read at most @arg maxSize bytes from the socket */
47 virtual QByteArray read(qint64 maxSize) = 0;
49 /** @short Read a line from the socket (up to the @arg maxSize bytes) */
50 virtual QByteArray readLine(qint64 maxSize = 0) = 0;
52 /** @short Write the contents of the @arg byteArray buffer to the socket */
53 virtual qint64 write(const QByteArray &byteArray) = 0;
55 /** @short Negotiate and start encryption with the remote peer
57 Please note that this function can throw an exception if the
58 underlying socket implementation does not support TLS (an example of
59 such an implementation is QProcess-backed socket).
61 virtual void startTls() = 0;
63 /** @short Return true if the socket is no longer usable */
64 virtual bool isDead() = 0;
66 /** @short Return complete SSL certificate chain of the peer */
67 virtual QList<QSslCertificate> sslChain() const;
69 /** @short Return a list of SSL errors encountered during this connection */
70 virtual QList<QSslError> sslErrors() const;
72 /** @short Is this socket starting ecnryption from the very start? */
73 virtual bool isConnectingEncryptedSinceStart() const;
75 /** @short Close the connection */
76 virtual void close() = 0;
78 /** @short Start the DEFLATE algorithm on both directions of this stream */
79 virtual void startDeflate() = 0;
80 signals:
81 /** @short The socket got disconnected */
82 void disconnected(const QString);
84 /** @short Some data could be read from the socket */
85 void readyRead();
87 /** @short Low-level state of the connection has changed */
88 void stateChanged(Imap::ConnectionState state, const QString &message);
90 /** @short The socket is now encrypted */
91 void encrypted();
96 #endif