1 /***************************************************************************
2 * Copyright (C) 2005-2018 by the Quassel Project *
3 * devel@quassel-irc.org *
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. *
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. *
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 ***************************************************************************/
25 #include <QVariantList>
32 const quint32 magic = 0x42b33f00;
35 InternalProtocol = 0x00,
36 LegacyProtocol = 0x01,
37 DataStreamProtocol = 0x02
53 /*** Handshake, handled by AuthHandler ***/
55 struct HandshakeMessage {
56 inline Handler handler() const { return Handler::AuthHandler; }
60 struct RegisterClient : public HandshakeMessage
62 inline RegisterClient(Quassel::Features clientFeatures, QString clientVersion, QString buildDate, bool sslSupported = false)
63 : features(std::move(clientFeatures))
64 , clientVersion(std::move(clientVersion))
65 , buildDate(std::move(buildDate))
66 , sslSupported(sslSupported)
69 Quassel::Features features;
70 QString clientVersion;
73 // this is only used by the LegacyProtocol in compat mode
78 struct ClientDenied : public HandshakeMessage
80 inline ClientDenied(QString errorString)
81 : errorString(std::move(errorString)) {}
87 struct ClientRegistered : public HandshakeMessage
89 inline ClientRegistered(Quassel::Features coreFeatures, bool coreConfigured, QVariantList backendInfo, QVariantList authenticatorInfo, bool sslSupported)
90 : features(std::move(coreFeatures))
91 , coreConfigured(coreConfigured)
92 , backendInfo(std::move(backendInfo))
93 , authenticatorInfo(std::move(authenticatorInfo))
94 , sslSupported(sslSupported)
97 Quassel::Features features;
99 QVariantList backendInfo; // TODO: abstract this better
101 // The authenticatorInfo should be optional!
102 QVariantList authenticatorInfo;
104 // this is only used by the LegacyProtocol in compat mode
109 struct SetupData : public HandshakeMessage
111 inline SetupData(QString adminUser, QString adminPassword, QString backend,
112 QVariantMap setupData, QString authenticator = QString(),
113 QVariantMap authSetupData = QVariantMap())
114 : adminUser(std::move(adminUser))
115 , adminPassword(std::move(adminPassword))
116 , backend(std::move(backend))
117 , setupData(std::move(setupData))
118 , authenticator(std::move(authenticator))
119 , authSetupData(std::move(authSetupData))
123 QString adminPassword;
125 QVariantMap setupData;
126 QString authenticator;
127 QVariantMap authSetupData;
131 struct SetupFailed : public HandshakeMessage
133 inline SetupFailed(QString errorString)
134 : errorString(std::move(errorString)) {}
140 struct SetupDone : public HandshakeMessage
145 struct Login : public HandshakeMessage
147 inline Login(QString user, QString password)
148 : user(std::move(user)), password(std::move(password)) {}
155 struct LoginFailed : public HandshakeMessage
157 inline LoginFailed(QString errorString)
158 : errorString(std::move(errorString)) {}
164 struct LoginSuccess : public HandshakeMessage
169 // TODO: more generic format
170 struct SessionState : public HandshakeMessage
172 inline SessionState() = default; // needed for QMetaType (for the mono client)
173 inline SessionState(QVariantList identities, QVariantList bufferInfos, QVariantList networkIds)
174 : identities(std::move(identities)), bufferInfos(std::move(bufferInfos)), networkIds(std::move(networkIds)) {}
176 QVariantList identities;
177 QVariantList bufferInfos;
178 QVariantList networkIds;
181 /*** handled by SignalProxy ***/
183 struct SignalProxyMessage
185 inline Handler handler() const { return Handler::SignalProxy; }
189 struct SyncMessage : public SignalProxyMessage
191 SyncMessage() = default;
192 SyncMessage(QByteArray className, QString objectName, QByteArray slotName, QVariantList params)
193 : className(std::move(className)), objectName(std::move(objectName)), slotName(std::move(slotName)), params(std::move(params)) {}
195 QByteArray className;
202 struct RpcCall : public SignalProxyMessage
205 RpcCall(QByteArray slotName, QVariantList params)
206 : slotName(std::move(slotName)), params(std::move(params)) {}
213 struct InitRequest : public SignalProxyMessage
215 InitRequest() = default;
216 InitRequest(QByteArray className, QString objectName)
217 : className(std::move(className)), objectName(std::move(objectName)) {}
219 QByteArray className;
224 struct InitData : public SignalProxyMessage
226 InitData() = default;
227 InitData(QByteArray className, QString objectName, QVariantMap initData)
228 : className(std::move(className)), objectName(std::move(objectName)), initData(std::move(initData)) {}
230 QByteArray className;
232 QVariantMap initData;
236 /*** handled by RemoteConnection ***/
240 inline HeartBeat(QDateTime timestamp) : timestamp(std::move(timestamp)) {}
246 struct HeartBeatReply
248 inline HeartBeatReply(QDateTime timestamp) : timestamp(std::move(timestamp)) {}
256 // Required for InternalPeer
257 Q_DECLARE_METATYPE(Protocol::SyncMessage)
258 Q_DECLARE_METATYPE(Protocol::RpcCall)
259 Q_DECLARE_METATYPE(Protocol::InitRequest)
260 Q_DECLARE_METATYPE(Protocol::InitData)