Quassel IRC  Pre-Release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
storage.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2015 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 STORAGE_H
22 #define STORAGE_H
23 
24 #include <QtCore>
25 
26 #include "types.h"
27 #include "coreidentity.h"
28 #include "message.h"
29 #include "network.h"
30 
31 class Storage : public QObject
32 {
33  Q_OBJECT
34 
35 public:
36  Storage(QObject *parent = 0);
37  virtual ~Storage() {};
38 
39  enum State {
40  IsReady, // ready to go
41  NeedsSetup, // need basic setup (ask the user for input)
42  NotAvailable // remove the storage backend from the list of avaliable backends
43  };
44 
45  enum HashVersion {
49 
50  };
51 
52 public slots:
53  /* General */
54 
56 
60  virtual bool isAvailable() const = 0;
61 
63 
64  virtual QString displayName() const = 0;
65 
67 
68  virtual QString description() const = 0;
69 
71  virtual QStringList setupKeys() const = 0;
72 
74  /* the values are QVariants with default values */
75  virtual QVariantMap setupDefaults() const = 0;
76 
78 
82  virtual bool setup(const QVariantMap &settings = QVariantMap()) = 0;
83 
85 
88  virtual State init(const QVariantMap &settings = QVariantMap()) = 0;
89 
91 
95  virtual void sync() = 0;
96 
97  // TODO: Add functions for configuring the backlog handling, i.e. defining auto-cleanup settings etc
98 
99  /* User handling */
100 
102 
106  virtual UserId addUser(const QString &user, const QString &password) = 0;
107 
109 
113  virtual bool updateUser(UserId user, const QString &password) = 0;
114 
116 
119  virtual void renameUser(UserId user, const QString &newName) = 0;
120 
122 
126  virtual UserId validateUser(const QString &user, const QString &password) = 0;
127 
129 
132  virtual UserId getUserId(const QString &username) = 0;
133 
135 
137  virtual UserId internalUser() = 0;
138 
140 
142  virtual void delUser(UserId user) = 0;
143 
145 
150  virtual void setUserSetting(UserId userId, const QString &settingName, const QVariant &data) = 0;
151 
153 
159  virtual QVariant getUserSetting(UserId userId, const QString &settingName, const QVariant &data = QVariant()) = 0;
160 
161  /* Identity handling */
162  virtual IdentityId createIdentity(UserId user, CoreIdentity &identity) = 0;
163  virtual bool updateIdentity(UserId user, const CoreIdentity &identity) = 0;
164  virtual void removeIdentity(UserId user, IdentityId identityId) = 0;
165  virtual QList<CoreIdentity> identities(UserId user) = 0;
166 
167  /* Network handling */
168 
170 
174  virtual NetworkId createNetwork(UserId user, const NetworkInfo &info) = 0;
175 
177 
182  virtual bool updateNetwork(UserId user, const NetworkInfo &info) = 0;
183 
185 
191  virtual bool removeNetwork(UserId user, const NetworkId &networkId) = 0;
192 
194 
199  virtual QList<NetworkInfo> networks(UserId user) = 0;
200 
202 
207  virtual QList<NetworkId> connectedNetworks(UserId user) = 0;
208 
210 
216  virtual void setNetworkConnected(UserId user, const NetworkId &networkId, bool isConnected) = 0;
217 
219 
225  virtual QHash<QString, QString> persistentChannels(UserId user, const NetworkId &networkId) = 0;
226 
228 
235  virtual void setChannelPersistent(UserId user, const NetworkId &networkId, const QString &channel, bool isJoined) = 0;
236 
238 
245  virtual void setPersistentChannelKey(UserId user, const NetworkId &networkId, const QString &channel, const QString &key) = 0;
246 
248 
253  virtual QString awayMessage(UserId user, NetworkId networkId) = 0;
254 
256 
262  virtual void setAwayMessage(UserId user, NetworkId networkId, const QString &awayMsg) = 0;
263 
265 
270  virtual QString userModes(UserId user, NetworkId networkId) = 0;
271 
273 
279  virtual void setUserModes(UserId user, NetworkId networkId, const QString &userModes) = 0;
280 
281  /* Buffer handling */
282 
284 
291  virtual BufferInfo bufferInfo(UserId user, const NetworkId &networkId, BufferInfo::Type type, const QString &buffer = "", bool create = true) = 0;
292 
294 
298  virtual BufferInfo getBufferInfo(UserId user, const BufferId &bufferId) = 0;
299 
301 
305  virtual QList<BufferInfo> requestBuffers(UserId user) = 0;
306 
308 
314  virtual QList<BufferId> requestBufferIdsForNetwork(UserId user, NetworkId networkId) = 0;
315 
317 
322  virtual bool removeBuffer(const UserId &user, const BufferId &bufferId) = 0;
323 
325 
331  virtual bool renameBuffer(const UserId &user, const BufferId &bufferId, const QString &newName) = 0;
332 
334 
340  virtual bool mergeBuffersPermanently(const UserId &user, const BufferId &bufferId1, const BufferId &bufferId2) = 0;
341 
343 
348  virtual void setBufferLastSeenMsg(UserId user, const BufferId &bufferId, const MsgId &msgId) = 0;
349 
351 
354  virtual QHash<BufferId, MsgId> bufferLastSeenMsgIds(UserId user) = 0;
355 
357 
364  virtual void setBufferMarkerLineMsg(UserId user, const BufferId &bufferId, const MsgId &msgId) = 0;
365 
367 
372  virtual QHash<BufferId, MsgId> bufferMarkerLineMsgIds(UserId user) = 0;
373 
374  /* Message handling */
375 
377 
380  virtual bool logMessage(Message &msg) = 0;
381 
383 
386  virtual bool logMessages(MessageList &msgs) = 0;
387 
389 
395  virtual QList<Message> requestMsgs(UserId user, BufferId bufferId, MsgId first = -1, MsgId last = -1, int limit = -1) = 0;
396 
398 
403  virtual QList<Message> requestAllMsgs(UserId user, MsgId first = -1, MsgId last = -1, int limit = -1) = 0;
404 
405 signals:
407  void bufferInfoUpdated(UserId user, const BufferInfo &);
409  void bufferRenamed(const QString &newName, const QString &oldName);
411  void userAdded(UserId, const QString &username);
413  void userRenamed(UserId, const QString &newname);
415  void userRemoved(UserId);
416 
417 protected:
418  QString hashPassword(const QString &password);
419  bool checkHashedPassword(const UserId user, const QString &password, const QString &hashedPassword, const Storage::HashVersion version);
420 
421 private:
422  QString hashPasswordSha1(const QString &password);
423  bool checkHashedPasswordSha1(const QString &password, const QString &hashedPassword);
424 
425  QString hashPasswordSha2_512(const QString &password);
426  bool checkHashedPasswordSha2_512(const QString &password, const QString &hashedPassword);
427  QString sha2_512(const QString &input);
428 };
429 
430 
431 #endif