Semi-yearly copyright bump
[quassel.git] / src / common / protocol.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 <QByteArray>
24 #include <QDateTime>
25 #include <QVariantList>
26
27 #include "quassel.h"
28
29 namespace Protocol {
30
31 const quint32 magic = 0x42b33f00;
32
33 enum Type {
34     InternalProtocol = 0x00,
35     LegacyProtocol = 0x01,
36     DataStreamProtocol = 0x02
37 };
38
39
40 enum Feature {
41     Encryption = 0x01,
42     Compression = 0x02
43 };
44
45
46 enum class Handler {
47     SignalProxy,
48     AuthHandler
49 };
50
51
52 /*** Handshake, handled by AuthHandler ***/
53
54 struct HandshakeMessage {
55     inline Handler handler() const { return Handler::AuthHandler; }
56 };
57
58
59 struct RegisterClient : public HandshakeMessage
60 {
61     inline RegisterClient(Quassel::Features clientFeatures, const QString &clientVersion, const QString &buildDate, bool sslSupported = false)
62         : features(std::move(clientFeatures))
63         , clientVersion(clientVersion)
64         , buildDate(buildDate)
65         , sslSupported(sslSupported)
66     {}
67
68     Quassel::Features features;
69     QString clientVersion;
70     QString buildDate;
71
72     // this is only used by the LegacyProtocol in compat mode
73     bool sslSupported;
74 };
75
76
77 struct ClientDenied : public HandshakeMessage
78 {
79     inline ClientDenied(const QString &errorString)
80     : errorString(errorString) {}
81
82     QString errorString;
83 };
84
85
86 struct ClientRegistered : public HandshakeMessage
87 {
88     inline ClientRegistered(Quassel::Features coreFeatures, bool coreConfigured, const QVariantList &backendInfo, const QVariantList &authenticatorInfo, bool sslSupported)
89         : features(std::move(coreFeatures))
90         , coreConfigured(coreConfigured)
91         , backendInfo(backendInfo)
92         , authenticatorInfo(authenticatorInfo)
93         , sslSupported(sslSupported)
94     {}
95
96     Quassel::Features features;
97     bool coreConfigured;
98     QVariantList backendInfo; // TODO: abstract this better
99
100     // The authenticatorInfo should be optional!
101     QVariantList authenticatorInfo;
102
103     // this is only used by the LegacyProtocol in compat mode
104     bool sslSupported;
105 };
106
107
108 struct SetupData : public HandshakeMessage
109 {
110     inline SetupData(const QString &adminUser, const QString &adminPassword, const QString &backend,
111                      const QVariantMap &setupData, const QString &authenticator = QString(),
112                      const QVariantMap &authSetupData = QVariantMap())
113     : adminUser(adminUser)
114     , adminPassword(adminPassword)
115     , backend(backend)
116     , setupData(setupData)
117     , authenticator(authenticator)
118     , authSetupData(authSetupData)
119     {}
120
121     QString adminUser;
122     QString adminPassword;
123     QString backend;
124     QVariantMap setupData;
125     QString authenticator;
126     QVariantMap authSetupData;
127 };
128
129
130 struct SetupFailed : public HandshakeMessage
131 {
132     inline SetupFailed(const QString &errorString)
133     : errorString(errorString) {}
134
135     QString errorString;
136 };
137
138
139 struct SetupDone : public HandshakeMessage
140 {
141     inline SetupDone() {}
142 };
143
144
145 struct Login : public HandshakeMessage
146 {
147     inline Login(const QString &user, const QString &password)
148     : user(user), password(password) {}
149
150     QString user;
151     QString password;
152 };
153
154
155 struct LoginFailed : public HandshakeMessage
156 {
157     inline LoginFailed(const QString &errorString)
158     : errorString(errorString) {}
159
160     QString errorString;
161 };
162
163
164 struct LoginSuccess : public HandshakeMessage
165 {
166     inline LoginSuccess() {}
167 };
168
169
170 // TODO: more generic format
171 struct SessionState : public HandshakeMessage
172 {
173     inline SessionState() {} // needed for QMetaType (for the mono client)
174     inline SessionState(const QVariantList &identities, const QVariantList &bufferInfos, const QVariantList &networkIds)
175     : identities(identities), bufferInfos(bufferInfos), networkIds(networkIds) {}
176
177     QVariantList identities;
178     QVariantList bufferInfos;
179     QVariantList networkIds;
180 };
181
182 /*** handled by SignalProxy ***/
183
184 struct SignalProxyMessage
185 {
186     inline Handler handler() const { return Handler::SignalProxy; }
187 };
188
189
190 struct SyncMessage : public SignalProxyMessage
191 {
192     inline SyncMessage(const QByteArray &className, const QString &objectName, const QByteArray &slotName, const QVariantList &params)
193     : className(className), objectName(objectName), slotName(slotName), params(params) {}
194
195     QByteArray className;
196     QString objectName;
197     QByteArray slotName;
198     QVariantList params;
199 };
200
201
202 struct RpcCall : public SignalProxyMessage
203 {
204     inline RpcCall(const QByteArray &slotName, const QVariantList &params)
205     : slotName(slotName), params(params) {}
206
207     QByteArray slotName;
208     QVariantList params;
209 };
210
211
212 struct InitRequest : public SignalProxyMessage
213 {
214     inline InitRequest(const QByteArray &className, const QString &objectName)
215     : className(className), objectName(objectName) {}
216
217     QByteArray className;
218     QString objectName;
219 };
220
221
222 struct InitData : public SignalProxyMessage
223 {
224     inline InitData(const QByteArray &className, const QString &objectName, const QVariantMap &initData)
225     : className(className), objectName(objectName), initData(initData) {}
226
227     QByteArray className;
228     QString objectName;
229     QVariantMap initData;
230 };
231
232
233 /*** handled by RemoteConnection ***/
234
235 struct HeartBeat
236 {
237     inline HeartBeat(const QDateTime &timestamp) : timestamp(timestamp) {}
238
239     QDateTime timestamp;
240 };
241
242
243 struct HeartBeatReply
244 {
245     inline HeartBeatReply(const QDateTime &timestamp) : timestamp(timestamp) {}
246
247     QDateTime timestamp;
248 };
249
250
251 };