Warning, file /pim/trojita/src/Streams/Socket.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /* Copyright (C) 2006 - 2014 Jan Kundrát <jkt@flaska.net>
0002 
0003    This file is part of the Trojita Qt IMAP e-mail client,
0004    http://trojita.flaska.net/
0005 
0006    This program is free software; you can redistribute it and/or
0007    modify it under the terms of the GNU General Public License as
0008    published by the Free Software Foundation; either version 2 of
0009    the License or (at your option) version 3 or any later version
0010    accepted by the membership of KDE e.V. (or its successor approved
0011    by the membership of KDE e.V.), which shall act as a proxy
0012    defined in Section 14 of version 3 of the license.
0013 
0014    This program is distributed in the hope that it will be useful,
0015    but WITHOUT ANY WARRANTY; without even the implied warranty of
0016    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0017    GNU General Public License for more details.
0018 
0019    You should have received a copy of the GNU General Public License
0020    along with this program.  If not, see <http://www.gnu.org/licenses/>.
0021 */
0022 #ifndef STREAMS_SOCKET_H
0023 #define STREAMS_SOCKET_H
0024 
0025 #include <memory>
0026 #include <QAbstractSocket>
0027 #include <QSslError>
0028 #include "../Imap/ConnectionState.h"
0029 
0030 namespace Streams {
0031 
0032 /** @short A common wrapepr class for implementing remote sockets
0033 
0034   This class extends the basic QIODevice-like API by a few handy methods,
0035 so that the upper layers do not have to worry about low-level socket details.
0036 */
0037 class Socket: public QObject
0038 {
0039     Q_OBJECT
0040 public:
0041     virtual ~Socket();
0042 
0043     /** @short Returns true if there's enough data to read, including the CR-LF pair */
0044     virtual bool canReadLine() = 0;
0045 
0046     /** @short Read at most @arg maxSize bytes from the socket */
0047     virtual QByteArray read(qint64 maxSize) = 0;
0048 
0049     /** @short Read a line from the socket (up to the @arg maxSize bytes) */
0050     virtual QByteArray readLine(qint64 maxSize = 0) = 0;
0051 
0052     /** @short Write the contents of the @arg byteArray buffer to the socket */
0053     virtual qint64 write(const QByteArray &byteArray) = 0;
0054 
0055     /** @short Negotiate and start encryption with the remote peer
0056 
0057       Please note that this function can throw an exception if the
0058     underlying socket implementation does not support TLS (an example of
0059     such an implementation is QProcess-backed socket).
0060     */
0061     virtual void startTls() = 0;
0062 
0063     /** @short Return true if the socket is no longer usable */
0064     virtual bool isDead() = 0;
0065 
0066     /** @short Return complete SSL certificate chain of the peer */
0067     virtual QList<QSslCertificate> sslChain() const;
0068 
0069     /** @short Return a list of SSL errors encountered during this connection */
0070     virtual QList<QSslError> sslErrors() const;
0071 
0072     /** @short Is this socket starting ecnryption from the very start? */
0073     virtual bool isConnectingEncryptedSinceStart() const;
0074 
0075     /** @short Close the connection */
0076     virtual void close() = 0;
0077 
0078     /** @short Start the DEFLATE algorithm on both directions of this stream */
0079     virtual void startDeflate() = 0;
0080 signals:
0081     /** @short The socket got disconnected */
0082     void disconnected(const QString);
0083 
0084     /** @short Some data could be read from the socket */
0085     void readyRead();
0086 
0087     /** @short Low-level state of the connection has changed */
0088     void stateChanged(Imap::ConnectionState state, const QString &message);
0089 
0090     /** @short The socket is now encrypted */
0091     void encrypted();
0092 };
0093 
0094 }
0095 
0096 #endif