Semi-yearly copyright bump
[quassel.git] / src / common / protocol.h
1 /***************************************************************************
2  *   Copyright (C) 2005-2018 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 Handler {
46     SignalProxy,
47     AuthHandler
48 };
49
50
51 /*** Handshake, handled by AuthHandler ***/
52
53 struct HandshakeMessage {
54     inline Handler handler() const { return 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)
85     : coreFeatures(coreFeatures)
86     , coreConfigured(coreConfigured)
87     , backendInfo(backendInfo)
88     , sslSupported(sslSupported)
89     {}
90
91     quint32 coreFeatures;
92     bool coreConfigured;
93     QVariantList backendInfo; // TODO: abstract this better
94
95     // this is only used by the LegacyProtocol in compat mode
96     bool sslSupported;
97 };
98
99
100 struct SetupData : public HandshakeMessage
101 {
102     inline SetupData(const QString &adminUser, const QString &adminPassword, const QString &backend, const QVariantMap &setupData)
103     : adminUser(adminUser), adminPassword(adminPassword), backend(backend), setupData(setupData) {}
104
105     QString adminUser;
106     QString adminPassword;
107     QString backend;
108     QVariantMap setupData;
109 };
110
111
112 struct SetupFailed : public HandshakeMessage
113 {
114     inline SetupFailed(const QString &errorString)
115     : errorString(errorString) {}
116
117     QString errorString;
118 };
119
120
121 struct SetupDone : public HandshakeMessage
122 {
123     inline SetupDone() {}
124 };
125
126
127 struct Login : public HandshakeMessage
128 {
129     inline Login(const QString &user, const QString &password)
130     : user(user), password(password) {}
131
132     QString user;
133     QString password;
134 };
135
136
137 struct LoginFailed : public HandshakeMessage
138 {
139     inline LoginFailed(const QString &errorString)
140     : errorString(errorString) {}
141
142     QString errorString;
143 };
144
145
146 struct LoginSuccess : public HandshakeMessage
147 {
148     inline LoginSuccess() {}
149 };
150
151
152 // TODO: more generic format
153 struct SessionState : public HandshakeMessage
154 {
155     inline SessionState() {} // needed for QMetaType (for the mono client)
156     inline SessionState(const QVariantList &identities, const QVariantList &bufferInfos, const QVariantList &networkIds)
157     : identities(identities), bufferInfos(bufferInfos), networkIds(networkIds) {}
158
159     QVariantList identities;
160     QVariantList bufferInfos;
161     QVariantList networkIds;
162 };
163
164 /*** handled by SignalProxy ***/
165
166 struct SignalProxyMessage
167 {
168     inline Handler handler() const { return SignalProxy; }
169 };
170
171
172 struct SyncMessage : public SignalProxyMessage
173 {
174     inline SyncMessage(const QByteArray &className, const QString &objectName, const QByteArray &slotName, const QVariantList &params)
175     : className(className), objectName(objectName), slotName(slotName), params(params) {}
176
177     QByteArray className;
178     QString objectName;
179     QByteArray slotName;
180     QVariantList params;
181 };
182
183
184 struct RpcCall : public SignalProxyMessage
185 {
186     inline RpcCall(const QByteArray &slotName, const QVariantList &params)
187     : slotName(slotName), params(params) {}
188
189     QByteArray slotName;
190     QVariantList params;
191 };
192
193
194 struct InitRequest : public SignalProxyMessage
195 {
196     inline InitRequest(const QByteArray &className, const QString &objectName)
197     : className(className), objectName(objectName) {}
198
199     QByteArray className;
200     QString objectName;
201 };
202
203
204 struct InitData : public SignalProxyMessage
205 {
206     inline InitData(const QByteArray &className, const QString &objectName, const QVariantMap &initData)
207     : className(className), objectName(objectName), initData(initData) {}
208
209     QByteArray className;
210     QString objectName;
211     QVariantMap initData;
212 };
213
214
215 /*** handled by RemoteConnection ***/
216
217 struct HeartBeat
218 {
219     inline HeartBeat(const QDateTime &timestamp) : timestamp(timestamp) {}
220
221     QDateTime timestamp;
222 };
223
224
225 struct HeartBeatReply
226 {
227     inline HeartBeatReply(const QDateTime &timestamp) : timestamp(timestamp) {}
228
229     QDateTime timestamp;
230 };
231
232
233 };
234
235 #endif