clazy: Convert many old-style connects into function pointer based
[quassel.git] / src / client / clientauthhandler.h
1 /***************************************************************************
2  *   Copyright (C) 2005-2018 by the Quassel Project                        *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) version 3.                                           *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
19  ***************************************************************************/
20
21 #pragma once
22
23 #include "compressor.h"
24 #include "authhandler.h"
25 #include "coreaccount.h"
26
27 class QSslSocket;
28
29 class RemotePeer;
30
31 class ClientAuthHandler : public AuthHandler
32 {
33     Q_OBJECT
34
35 public:
36     enum DigestVersion {
37         Md5,
38         Sha2_512,
39         Latest=Sha2_512
40     };
41
42     ClientAuthHandler(CoreAccount account, QObject *parent = nullptr);
43
44     Peer *peer() const;
45
46 public slots:
47     void connectToCore();
48
49     void login(const QString &previousError = QString());
50     void login(const QString &user, const QString &password, bool remember);
51     void setupCore(const Protocol::SetupData &setupData);
52
53 signals:
54     void statusMessage(const QString &message);
55     void errorMessage(const QString &message);
56     void errorPopup(const QString &message);
57     void transferProgress(int current, int max);
58
59     void requestDisconnect(const QString &errorString = QString(), bool wantReconnect = false);
60
61     void connectionReady();
62     void loginSuccessful(const CoreAccount &account);
63     void handshakeComplete(RemotePeer *peer, const Protocol::SessionState &sessionState);
64
65     // These signals MUST be handled synchronously!
66     void userAuthenticationRequired(CoreAccount *account, bool *valid, const QString &errorMessage = QString());
67     void handleNoSslInClient(bool *accepted);
68     void handleNoSslInCore(bool *accepted);
69 #ifdef HAVE_SSL
70     void handleSslErrors(const QSslSocket *socket, bool *accepted, bool *permanently);
71 #endif
72
73     void encrypted(bool isEncrypted = true);
74     void startCoreSetup(const QVariantList &backendInfo, const QVariantList &authenticatorInfo);
75     void coreSetupSuccessful();
76     void coreSetupFailed(const QString &error);
77
78 private:
79     using AuthHandler::handle;
80
81     void handle(const Protocol::ClientDenied &msg) override;
82     void handle(const Protocol::ClientRegistered &msg) override;
83     void handle(const Protocol::SetupFailed &msg) override;
84     void handle(const Protocol::SetupDone &msg) override;
85     void handle(const Protocol::LoginFailed &msg) override;
86     void handle(const Protocol::LoginSuccess &msg) override;
87     void handle(const Protocol::SessionState &msg) override;
88
89     void setPeer(RemotePeer *peer);
90     void checkAndEnableSsl(bool coreSupportsSsl);
91     void startRegistration();
92
93 private slots:
94     void onSocketConnected();
95     void onSocketStateChanged(QAbstractSocket::SocketState state);
96     void onSocketError(QAbstractSocket::SocketError) override;
97     void onSocketDisconnected() override;
98     void onReadyRead();
99
100 #ifdef HAVE_SSL
101     void onSslSocketEncrypted();
102     void onSslErrors();
103 #endif
104
105     void onProtocolVersionMismatch(int actual, int expected);
106
107     void onConnectionReady();
108
109 private:
110     RemotePeer *_peer;
111     bool _coreConfigured;
112     QVariantList _backendInfo;
113     QVariantList _authenticatorInfo;
114     CoreAccount _account;
115     bool _probing;
116     bool _legacy;
117     quint8 _connectionFeatures;
118 };