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
142 inline SetupDone() {}
146 struct Login : public HandshakeMessage
148 inline Login(QString user, QString password)
149 : user(std::move(user)), password(std::move(password)) {}
156 struct LoginFailed : public HandshakeMessage
158 inline LoginFailed(QString errorString)
159 : errorString(std::move(errorString)) {}
165 struct LoginSuccess : public HandshakeMessage
167 inline LoginSuccess() {}
171 // TODO: more generic format
172 struct SessionState : public HandshakeMessage
174 inline SessionState() {} // needed for QMetaType (for the mono client)
175 inline SessionState(QVariantList identities, QVariantList bufferInfos, QVariantList networkIds)
176 : identities(std::move(identities)), bufferInfos(std::move(bufferInfos)), networkIds(std::move(networkIds)) {}
178 QVariantList identities;
179 QVariantList bufferInfos;
180 QVariantList networkIds;
183 /*** handled by SignalProxy ***/
185 struct SignalProxyMessage
187 inline Handler handler() const { return Handler::SignalProxy; }
191 struct SyncMessage : public SignalProxyMessage
193 SyncMessage() = default;
194 SyncMessage(QByteArray className, QString objectName, QByteArray slotName, QVariantList params)
195 : className(std::move(className)), objectName(std::move(objectName)), slotName(std::move(slotName)), params(std::move(params)) {}
197 QByteArray className;
204 struct RpcCall : public SignalProxyMessage
207 RpcCall(QByteArray slotName, QVariantList params)
208 : slotName(std::move(slotName)), params(std::move(params)) {}
215 struct InitRequest : public SignalProxyMessage
217 InitRequest() = default;
218 InitRequest(QByteArray className, QString objectName)
219 : className(std::move(className)), objectName(std::move(objectName)) {}
221 QByteArray className;
226 struct InitData : public SignalProxyMessage
228 InitData() = default;
229 InitData(QByteArray className, QString objectName, QVariantMap initData)
230 : className(std::move(className)), objectName(std::move(objectName)), initData(std::move(initData)) {}
232 QByteArray className;
234 QVariantMap initData;
238 /*** handled by RemoteConnection ***/
242 inline HeartBeat(QDateTime timestamp) : timestamp(std::move(timestamp)) {}
248 struct HeartBeatReply
250 inline HeartBeatReply(QDateTime timestamp) : timestamp(std::move(timestamp)) {}
258 // Required for InternalPeer
259 Q_DECLARE_METATYPE(Protocol::SyncMessage)
260 Q_DECLARE_METATYPE(Protocol::RpcCall)
261 Q_DECLARE_METATYPE(Protocol::InitRequest)
262 Q_DECLARE_METATYPE(Protocol::InitData)