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