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