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