Happy New Year!
[quassel.git] / src / client / clientauthhandler.h
1 /***************************************************************************
2  *   Copyright (C) 2005-2014 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 "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     ClientAuthHandler(CoreAccount account, QObject *parent = 0);
37
38 public slots:
39     void connectToCore();
40
41     void login(const QString &previousError = QString());
42     void login(const QString &user, const QString &password, bool remember);
43     void setupCore(const Protocol::SetupData &setupData);
44
45 signals:
46     void statusMessage(const QString &message);
47     void errorMessage(const QString &message);
48     void errorPopup(const QString &message);
49     void transferProgress(int current, int max);
50
51     void requestDisconnect(const QString &errorString = QString(), bool wantReconnect = false);
52
53     void connectionReady();
54     void loginSuccessful(const CoreAccount &account);
55     void handshakeComplete(RemotePeer *peer, const Protocol::SessionState &sessionState);
56
57     // These signals MUST be handled synchronously!
58     void userAuthenticationRequired(CoreAccount *account, bool *valid, const QString &errorMessage = QString());
59     void handleNoSslInClient(bool *accepted);
60     void handleNoSslInCore(bool *accepted);
61 #ifdef HAVE_SSL
62     void handleSslErrors(const QSslSocket *socket, bool *accepted, bool *permanently);
63 #endif
64
65     void encrypted(bool isEncrypted = true);
66     void startCoreSetup(const QVariantList &backendInfo);
67     void coreSetupSuccessful();
68     void coreSetupFailed(const QString &error);
69
70 private:
71     using AuthHandler::handle;
72
73     void handle(const Protocol::ClientDenied &msg);
74     void handle(const Protocol::ClientRegistered &msg);
75     void handle(const Protocol::SetupFailed &msg);
76     void handle(const Protocol::SetupDone &msg);
77     void handle(const Protocol::LoginFailed &msg);
78     void handle(const Protocol::LoginSuccess &msg);
79     void handle(const Protocol::SessionState &msg);
80
81 private slots:
82     void onSocketConnected();
83     //void onSocketStateChanged(QAbstractSocket::SocketState state);
84     //void onSocketError(QAbstractSocket::SocketError);
85 #ifdef HAVE_SSL
86     void onSslSocketEncrypted();
87     void onSslErrors();
88 #endif
89
90     void onProtocolVersionMismatch(int actual, int expected);
91
92     void onConnectionReady();
93
94 private:
95     RemotePeer *_peer;
96     bool _coreConfigured;
97     QVariantList _backendInfo;
98     CoreAccount _account;
99
100 };
101
102 #endif