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