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