Semi-yearly copyright bump
[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 #ifndef CLIENTAUTHHANDLER_H
22 #define CLIENTAUTHHANDLER_H
23
24 #include "compressor.h"
25 #include "authhandler.h"
26 #include "coreaccount.h"
27
28 class QSslSocket;
29
30 class RemotePeer;
31
32 class ClientAuthHandler : public AuthHandler
33 {
34     Q_OBJECT
35
36 public:
37     ClientAuthHandler(CoreAccount account, QObject *parent = 0);
38
39     enum DigestVersion {
40         Md5,
41         Sha2_512,
42         Latest=Sha2_512
43     };
44
45 public slots:
46     void connectToCore();
47
48     void login(const QString &previousError = QString());
49     void login(const QString &user, const QString &password, bool remember);
50     void setupCore(const Protocol::SetupData &setupData);
51
52 signals:
53     void statusMessage(const QString &message);
54     void errorMessage(const QString &message);
55     void errorPopup(const QString &message);
56     void transferProgress(int current, int max);
57
58     void requestDisconnect(const QString &errorString = QString(), bool wantReconnect = false);
59
60     void connectionReady();
61     void loginSuccessful(const CoreAccount &account);
62     void handshakeComplete(RemotePeer *peer, const Protocol::SessionState &sessionState);
63
64     // These signals MUST be handled synchronously!
65     void userAuthenticationRequired(CoreAccount *account, bool *valid, const QString &errorMessage = QString());
66     void handleNoSslInClient(bool *accepted);
67     void handleNoSslInCore(bool *accepted);
68 #ifdef HAVE_SSL
69     void handleSslErrors(const QSslSocket *socket, bool *accepted, bool *permanently);
70 #endif
71
72     void encrypted(bool isEncrypted = true);
73     void startCoreSetup(const QVariantList &backendInfo);
74     void coreSetupSuccessful();
75     void coreSetupFailed(const QString &error);
76
77 private:
78     using AuthHandler::handle;
79
80     void handle(const Protocol::ClientDenied &msg);
81     void handle(const Protocol::ClientRegistered &msg);
82     void handle(const Protocol::SetupFailed &msg);
83     void handle(const Protocol::SetupDone &msg);
84     void handle(const Protocol::LoginFailed &msg);
85     void handle(const Protocol::LoginSuccess &msg);
86     void handle(const Protocol::SessionState &msg);
87
88     void setPeer(RemotePeer *peer);
89     void checkAndEnableSsl(bool coreSupportsSsl);
90     void startRegistration();
91
92 #if QT_VERSION < 0x050000
93     QByteArray sha2_512(const QByteArray &input);
94 #endif
95
96 private slots:
97     void onSocketConnected();
98     void onSocketStateChanged(QAbstractSocket::SocketState state);
99     void onSocketError(QAbstractSocket::SocketError);
100     void onSocketDisconnected();
101     void onReadyRead();
102
103 #ifdef HAVE_SSL
104     void onSslSocketEncrypted();
105     void onSslErrors();
106 #endif
107
108     void onProtocolVersionMismatch(int actual, int expected);
109
110     void onConnectionReady();
111
112 private:
113     RemotePeer *_peer;
114     bool _coreConfigured;
115     QVariantList _backendInfo;
116     CoreAccount _account;
117     bool _probing;
118     bool _legacy;
119     quint8 _connectionFeatures;
120 };
121
122 #endif