a4c7a490b87aaea78a11d1679713d1b125a72341
[quassel.git] / src / common / protocols / legacy / legacypeer.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 LEGACYPEER_H
22 #define LEGACYPEER_H
23
24 #include <QDataStream>
25
26 #include "../../remotepeer.h"
27
28 class QDataStream;
29
30 class LegacyPeer : public RemotePeer
31 {
32     Q_OBJECT
33
34 public:
35     enum RequestType {
36         Sync = 1,
37         RpcCall,
38         InitRequest,
39         InitData,
40         HeartBeat,
41         HeartBeatReply
42     };
43
44     LegacyPeer(AuthHandler *authHandler, QTcpSocket *socket, QObject *parent = 0);
45
46     Protocol::Type protocol() const { return Protocol::LegacyProtocol; }
47     QString protocolName() const { return "the legacy protocol"; }
48
49     void setSignalProxy(SignalProxy *proxy);
50
51     void dispatch(const Protocol::RegisterClient &msg);
52     void dispatch(const Protocol::ClientDenied &msg);
53     void dispatch(const Protocol::ClientRegistered &msg);
54     void dispatch(const Protocol::SetupData &msg);
55     void dispatch(const Protocol::SetupFailed &msg);
56     void dispatch(const Protocol::SetupDone &msg);
57     void dispatch(const Protocol::Login &msg);
58     void dispatch(const Protocol::LoginFailed &msg);
59     void dispatch(const Protocol::LoginSuccess &msg);
60     void dispatch(const Protocol::SessionState &msg);
61
62     void dispatch(const Protocol::SyncMessage &msg);
63     void dispatch(const Protocol::RpcCall &msg);
64     void dispatch(const Protocol::InitRequest &msg);
65     void dispatch(const Protocol::InitData &msg);
66
67     void dispatch(const Protocol::HeartBeat &msg);
68     void dispatch(const Protocol::HeartBeatReply &msg);
69
70 signals:
71     void protocolError(const QString &errorString);
72
73     // only used in compat mode
74     void protocolVersionMismatch(int actual, int expected);
75
76 protected slots:
77     void onSocketDataAvailable();
78
79 private:
80     bool readSocketData(QVariant &item);
81     void writeSocketData(const QVariant &item);
82     void handleHandshakeMessage(const QVariant &msg);
83     void handlePackedFunc(const QVariant &packedFunc);
84     void dispatchPackedFunc(const QVariantList &packedFunc);
85
86     void toLegacyIrcUsersAndChannels(QVariantMap &initData);
87     void fromLegacyIrcUsersAndChannels(QVariantMap &initData);
88
89     QDataStream _stream;
90     quint32 _blockSize;
91     bool _useCompression;
92 };
93
94 #endif