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