File indexing completed on 2024-12-22 05:03:15
0001 /* 0002 SPDX-FileCopyrightText: 2015 Daniel Vrátil <dvratil@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include <QObject> 0010 #include <QUrl> 0011 #include <memory> 0012 0013 #include <KSslErrorUiData> 0014 #include <QSslSocket> 0015 0016 #include "response.h" 0017 #include "sasl-common.h" 0018 0019 class QTimer; 0020 0021 namespace KManageSieve 0022 { 0023 class Session; 0024 0025 class SessionThread : public QObject 0026 { 0027 Q_OBJECT 0028 0029 public: 0030 explicit SessionThread(Session *session, QObject *parent = nullptr); 0031 ~SessionThread() override; 0032 0033 void connectToHost(const QUrl &url); 0034 void disconnectFromHost(bool sendLogout); 0035 0036 void sendData(const QByteArray &data); 0037 0038 void startAuthentication(); 0039 void continueAuthentication(const Response &response, const QByteArray &data); 0040 0041 void startSsl(); 0042 0043 Q_SIGNALS: 0044 void responseReceived(const KManageSieve::Response &response, const QByteArray &data); 0045 void error(int errorCode, const QString &error); 0046 void authenticationDone(); 0047 void sslDone(); 0048 void sslError(const KSslErrorUiData &data); 0049 0050 void socketConnected(); 0051 void socketDisconnected(); 0052 0053 private Q_SLOTS: 0054 void doInit(); 0055 void doDestroy(); 0056 void doConnectToHost(const QUrl &url); 0057 void doDisconnectFromHost(bool sendLogout); 0058 void doSendData(const QByteArray &data); 0059 void doStartAuthentication(); 0060 void doContinueAuthentication(const KManageSieve::Response &response, const QByteArray &data); 0061 void doStartSsl(); 0062 0063 void slotDataReceived(); 0064 void slotSocketError(); 0065 void slotSslTimeout(); 0066 void slotEncryptedDone(); 0067 0068 private: 0069 bool saslInteract(void *in); 0070 bool saslClientStep(const QByteArray &challenge); 0071 void sslResult(bool encrypted); 0072 void handleSaslAuthError(); 0073 0074 private: 0075 Q_DISABLE_COPY(SessionThread) 0076 Session *m_session = nullptr; 0077 std::unique_ptr<QSslSocket> m_socket; 0078 0079 QUrl m_url; 0080 0081 sasl_conn_t *m_sasl_conn = nullptr; 0082 sasl_interact_t *m_sasl_client_interact = nullptr; 0083 0084 QByteArray m_data; 0085 Response m_lastResponse; 0086 qint64 m_pendingQuantity = -1; 0087 0088 QTimer *m_sslCheck = nullptr; 0089 }; 0090 } // namespace KManageSieve