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