qa: Remove lots of superfluous semicolons
[quassel.git] / src / core / core.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 #pragma once
22
23 #include <memory>
24 #include <vector>
25
26 #include <QDateTime>
27 #include <QPointer>
28 #include <QString>
29 #include <QVariant>
30 #include <QTimer>
31
32 #ifdef HAVE_SSL
33 #  include <QSslSocket>
34 #  include "sslserver.h"
35 #else
36 #  include <QTcpSocket>
37 #  include <QTcpServer>
38 #endif
39
40 #include "authenticator.h"
41 #include "bufferinfo.h"
42 #include "deferredptr.h"
43 #include "identserver.h"
44 #include "message.h"
45 #include "oidentdconfiggenerator.h"
46 #include "sessionthread.h"
47 #include "singleton.h"
48 #include "storage.h"
49 #include "types.h"
50
51 class CoreAuthHandler;
52 class CoreSession;
53 class InternalPeer;
54 class SessionThread;
55 class SignalProxy;
56
57 struct NetworkInfo;
58
59 class AbstractSqlMigrationReader;
60 class AbstractSqlMigrationWriter;
61
62 class Core : public QObject, public Singleton<Core>
63 {
64     Q_OBJECT
65
66 public:
67     Core();
68     ~Core() override;
69
70     void init();
71
72     /**
73      * Shuts down active core sessions, saves state and emits the shutdownComplete() signal afterwards.
74      */
75     void shutdown();
76
77
78     /*** Storage access ***/
79     // These methods are threadsafe.
80
81     //! Validate user
82     /**
83      * \param userName The user's login name
84      * \param password The user's uncrypted password
85      * \return The user's ID if valid; 0 otherwise
86      */
87     static inline UserId validateUser(const QString &userName, const QString &password) {
88         return instance()->_storage->validateUser(userName, password);
89     }
90
91     //! Authenticate user against auth backend
92     /**
93      * \param userName The user's login name
94      * \param password The user's uncrypted password
95      * \return The user's ID if valid; 0 otherwise
96      */
97     static inline UserId authenticateUser(const QString &userName, const QString &password) {
98         return instance()->_authenticator->validateUser(userName, password);
99     }
100
101     //! Add a new user, exposed so auth providers can call this without being the storage.
102     /**
103      * \param userName The user's login name
104      * \param password The user's uncrypted password
105      * \param authenticator The name of the auth provider service used to log the user in, defaults to "Database".
106      * \return The user's ID if valid; 0 otherwise
107      */
108     static inline UserId addUser(const QString &userName, const QString &password, const QString &authenticator = "Database") {
109         return instance()->_storage->addUser(userName, password, authenticator);
110     }
111
112     //! Does a comparison test against the authenticator in the database and the authenticator currently in use for a UserID.
113     /**
114      * \param userid The user's ID (note: not login name).
115      * \param authenticator The name of the auth provider service used to log the user in, defaults to "Database".
116      * \return True if the userid was configured with the passed authenticator, false otherwise.
117      */
118     static inline bool checkAuthProvider(const UserId userid, const QString &authenticator) {
119         return instance()->_storage->getUserAuthenticator(userid) == authenticator;
120     }
121
122     //! Change a user's password
123     /**
124      * \param userId     The user's ID
125      * \param password   The user's unencrypted new password
126      * \return true, if the password change was successful
127      */
128     static bool changeUserPassword(UserId userId, const QString &password);
129
130     //! Check if we can change a user password.
131     /**
132      * \param userID     The user's ID
133      * \return true, if we can change their password, false otherwise
134      */
135     static bool canChangeUserPassword(UserId userId);
136
137     //! Store a user setting persistently
138     /**
139      * \param userId       The users Id
140      * \param settingName  The Name of the Setting
141      * \param data         The Value
142      */
143     static inline void setUserSetting(UserId userId, const QString &settingName, const QVariant &data)
144     {
145         instance()->_storage->setUserSetting(userId, settingName, data);
146     }
147
148
149     //! Retrieve a persistent user setting
150     /**
151      * \param userId       The users Id
152      * \param settingName  The Name of the Setting
153      * \param defaultValue Value to return in case it's unset.
154      * \return the Value of the Setting or the default value if it is unset.
155      */
156     static inline QVariant getUserSetting(UserId userId, const QString &settingName, const QVariant &defaultValue = QVariant())
157     {
158         return instance()->_storage->getUserSetting(userId, settingName, defaultValue);
159     }
160
161
162     /* Identity handling */
163     static inline IdentityId createIdentity(UserId user, CoreIdentity &identity)
164     {
165         return instance()->_storage->createIdentity(user, identity);
166     }
167
168
169     static bool updateIdentity(UserId user, const CoreIdentity &identity)
170     {
171         return instance()->_storage->updateIdentity(user, identity);
172     }
173
174
175     static void removeIdentity(UserId user, IdentityId identityId)
176     {
177         instance()->_storage->removeIdentity(user, identityId);
178     }
179
180
181     static QList<CoreIdentity> identities(UserId user)
182     {
183         return instance()->_storage->identities(user);
184     }
185
186
187     //! Create a Network in the Storage and store it's Id in the given NetworkInfo
188     /** \note This method is thredsafe.
189      *
190      *  \param user        The core user
191      *  \param networkInfo a NetworkInfo definition to store the newly created ID in
192      *  \return true if successfull.
193      */
194     static bool createNetwork(UserId user, NetworkInfo &info);
195
196     //! Apply the changes to NetworkInfo info to the storage engine
197     /** \note This method is thredsafe.
198      *
199      *  \param user        The core user
200      *  \param networkInfo The Updated NetworkInfo
201      *  \return true if successfull.
202      */
203     static inline bool updateNetwork(UserId user, const NetworkInfo &info)
204     {
205         return instance()->_storage->updateNetwork(user, info);
206     }
207
208
209     //! Permanently remove a Network and all the data associated with it.
210     /** \note This method is thredsafe.
211      *
212      *  \param user        The core user
213      *  \param networkId   The network to delete
214      *  \return true if successfull.
215      */
216     static inline bool removeNetwork(UserId user, const NetworkId &networkId)
217     {
218         return instance()->_storage->removeNetwork(user, networkId);
219     }
220
221
222     //! Returns a list of all NetworkInfos for the given UserId user
223     /** \note This method is thredsafe.
224      *
225      *  \param user        The core user
226      *  \return QList<NetworkInfo>.
227      */
228     static inline QList<NetworkInfo> networks(UserId user)
229     {
230         return instance()->_storage->networks(user);
231     }
232
233
234     //! Get a list of Networks to restore
235     /** Return a list of networks the user was connected at the time of core shutdown
236      *  \note This method is threadsafe.
237      *
238      *  \param user  The User Id in question
239      */
240     static inline QList<NetworkId> connectedNetworks(UserId user)
241     {
242         return instance()->_storage->connectedNetworks(user);
243     }
244
245
246     //! Update the connected state of a network
247     /** \note This method is threadsafe
248      *
249      *  \param user        The Id of the networks owner
250      *  \param networkId   The Id of the network
251      *  \param isConnected whether the network is connected or not
252      */
253     static inline void setNetworkConnected(UserId user, const NetworkId &networkId, bool isConnected)
254     {
255         return instance()->_storage->setNetworkConnected(user, networkId, isConnected);
256     }
257
258
259     //! Get a hash of channels with their channel keys for a given network
260     /** The keys are channel names and values are passwords (possibly empty)
261      *  \note This method is threadsafe
262      *
263      *  \param user       The id of the networks owner
264      *  \param networkId  The Id of the network
265      */
266     static inline QHash<QString, QString> persistentChannels(UserId user, const NetworkId &networkId)
267     {
268         return instance()->_storage->persistentChannels(user, networkId);
269     }
270
271
272     //! Update the connected state of a channel
273     /** \note This method is threadsafe
274      *
275      *  \param user       The Id of the networks owner
276      *  \param networkId  The Id of the network
277      *  \param channel    The name of the channel
278      *  \param isJoined   whether the channel is connected or not
279      */
280     static inline void setChannelPersistent(UserId user, const NetworkId &networkId, const QString &channel, bool isJoined)
281     {
282         return instance()->_storage->setChannelPersistent(user, networkId, channel, isJoined);
283     }
284
285
286     //! Get a hash of buffers with their ciphers for a given network
287     /** The keys are channel names and values are ciphers (possibly empty)
288      *  \note This method is threadsafe
289      *
290      *  \param user       The id of the networks owner
291      *  \param networkId  The Id of the network
292      */
293     static inline QHash<QString, QByteArray> bufferCiphers(UserId user, const NetworkId &networkId)
294     {
295         return instance()->_storage->bufferCiphers(user, networkId);
296     }
297
298
299     //! Update the cipher of a buffer
300     /** \note This method is threadsafe
301      *
302      *  \param user        The Id of the networks owner
303      *  \param networkId   The Id of the network
304      *  \param bufferName The Cname of the buffer
305      *  \param cipher      The cipher for the buffer
306      */
307     static inline void setBufferCipher(UserId user, const NetworkId &networkId, const QString &bufferName, const QByteArray &cipher)
308     {
309         return instance()->_storage->setBufferCipher(user, networkId, bufferName, cipher);
310     }
311
312
313     //! Update the key of a channel
314     /** \note This method is threadsafe
315      *
316      *  \param user       The Id of the networks owner
317      *  \param networkId  The Id of the network
318      *  \param channel    The name of the channel
319      *  \param key        The key of the channel (possibly empty)
320      */
321     static inline void setPersistentChannelKey(UserId user, const NetworkId &networkId, const QString &channel, const QString &key)
322     {
323         return instance()->_storage->setPersistentChannelKey(user, networkId, channel, key);
324     }
325
326
327     //! retrieve last known away message for session restore
328     /** \note This method is threadsafe
329      *
330      *  \param user       The Id of the networks owner
331      *  \param networkId  The Id of the network
332      */
333     static inline QString awayMessage(UserId user, NetworkId networkId)
334     {
335         return instance()->_storage->awayMessage(user, networkId);
336     }
337
338
339     //! Make away message persistent for session restore
340     /** \note This method is threadsafe
341      *
342      *  \param user       The Id of the networks owner
343      *  \param networkId  The Id of the network
344      *  \param awayMsg    The current away message of own user
345      */
346     static inline void setAwayMessage(UserId user, NetworkId networkId, const QString &awayMsg)
347     {
348         return instance()->_storage->setAwayMessage(user, networkId, awayMsg);
349     }
350
351
352     //! retrieve last known user mode for session restore
353     /** \note This method is threadsafe
354      *
355      *  \param user       The Id of the networks owner
356      *  \param networkId  The Id of the network
357      */
358     static inline QString userModes(UserId user, NetworkId networkId)
359     {
360         return instance()->_storage->userModes(user, networkId);
361     }
362
363
364     //! Make our user modes persistent for session restore
365     /** \note This method is threadsafe
366      *
367      *  \param user       The Id of the networks owner
368      *  \param networkId  The Id of the network
369      *  \param userModes  The current user modes of own user
370      */
371     static inline void setUserModes(UserId user, NetworkId networkId, const QString &userModes)
372     {
373         return instance()->_storage->setUserModes(user, networkId, userModes);
374     }
375
376
377     //! Get the unique BufferInfo for the given combination of network and buffername for a user.
378     /** \note This method is threadsafe.
379      *
380      *  \param user      The core user who owns this buffername
381      *  \param networkId The network id
382      *  \param type      The type of the buffer (StatusBuffer, Channel, etc.)
383      *  \param buffer    The buffer name (if empty, the net's status buffer is returned)
384      *  \param create    Whether or not the buffer should be created if it doesnt exist
385      *  \return The BufferInfo corresponding to the given network and buffer name, or 0 if not found
386      */
387     static inline BufferInfo bufferInfo(UserId user, const NetworkId &networkId, BufferInfo::Type type, const QString &buffer = "", bool create = true)
388     {
389         return instance()->_storage->bufferInfo(user, networkId, type, buffer, create);
390     }
391
392
393     //! Get the unique BufferInfo for a bufferId
394     /** \note This method is threadsafe
395      *  \param user      The core user who owns this buffername
396      *  \param bufferId  The id of the buffer
397      *  \return The BufferInfo corresponding to the given buffer id, or an invalid BufferInfo if not found.
398      */
399     static inline BufferInfo getBufferInfo(UserId user, const BufferId &bufferId)
400     {
401         return instance()->_storage->getBufferInfo(user, bufferId);
402     }
403
404
405     //! Store a Message in the storage backend and set it's unique Id.
406     /** \note This method is threadsafe.
407      *
408      *  \param message The message object to be stored
409      *  \return true on success
410      */
411     static inline bool storeMessage(Message &message)
412     {
413         return instance()->_storage->logMessage(message);
414     }
415
416
417     //! Store a list of Messages in the storage backend and set their unique Id.
418     /** \note This method is threadsafe.
419      *
420      *  \param messages The list message objects to be stored
421      *  \return true on success
422      */
423     static inline bool storeMessages(MessageList &messages)
424     {
425         return instance()->_storage->logMessages(messages);
426     }
427
428
429     //! Request a certain number messages stored in a given buffer.
430     /** \param buffer   The buffer we request messages from
431      *  \param first    if != -1 return only messages with a MsgId >= first
432      *  \param last     if != -1 return only messages with a MsgId < last
433      *  \param limit    if != -1 limit the returned list to a max of \limit entries
434      *  \return The requested list of messages
435      */
436     static inline QList<Message> requestMsgs(UserId user, BufferId bufferId, MsgId first = -1, MsgId last = -1, int limit = -1)
437     {
438         return instance()->_storage->requestMsgs(user, bufferId, first, last, limit);
439     }
440
441
442     //! Request a certain number messages stored in a given buffer, matching certain filters
443     /** \param buffer   The buffer we request messages from
444      *  \param first    if != -1 return only messages with a MsgId >= first
445      *  \param last     if != -1 return only messages with a MsgId < last
446      *  \param limit    if != -1 limit the returned list to a max of \limit entries
447      *  \param type     The Message::Types that should be returned
448      *  \return The requested list of messages
449      */
450     static inline QList<Message> requestMsgsFiltered(UserId user, BufferId bufferId, MsgId first = -1, MsgId last = -1,
451                                                      int limit = -1, Message::Types type = Message::Types{-1},
452                                                      Message::Flags flags = Message::Flags{-1})
453     {
454         return instance()->_storage->requestMsgsFiltered(user, bufferId, first, last, limit, type, flags);
455     }
456
457
458     //! Request a certain number of messages across all buffers
459     /** \param first    if != -1 return only messages with a MsgId >= first
460      *  \param last     if != -1 return only messages with a MsgId < last
461      *  \param limit    Max amount of messages
462      *  \return The requested list of messages
463      */
464     static inline QList<Message> requestAllMsgs(UserId user, MsgId first = -1, MsgId last = -1, int limit = -1)
465     {
466         return instance()->_storage->requestAllMsgs(user, first, last, limit);
467     }
468
469
470     //! Request a certain number of messages across all buffers, matching certain filters
471     /** \param first    if != -1 return only messages with a MsgId >= first
472      *  \param last     if != -1 return only messages with a MsgId < last
473      *  \param limit    Max amount of messages
474      *  \param type     The Message::Types that should be returned
475      *  \return The requested list of messages
476      */
477     static inline QList<Message> requestAllMsgsFiltered(UserId user, MsgId first = -1, MsgId last = -1, int limit = -1,
478                                                         Message::Types type = Message::Types{-1},
479                                                         Message::Flags flags = Message::Flags{-1})
480     {
481         return instance()->_storage->requestAllMsgsFiltered(user, first, last, limit, type, flags);
482     }
483
484
485     //! Request a list of all buffers known to a user.
486     /** This method is used to get a list of all buffers we have stored a backlog from.
487      *  \note This method is threadsafe.
488      *
489      *  \param user  The user whose buffers we request
490      *  \return A list of the BufferInfos for all buffers as requested
491      */
492     static inline QList<BufferInfo> requestBuffers(UserId user)
493     {
494         return instance()->_storage->requestBuffers(user);
495     }
496
497
498     //! Request a list of BufferIds for a given NetworkId
499     /** \note This method is threadsafe.
500      *
501      *  \param user  The user whose buffers we request
502      *  \param networkId  The NetworkId of the network in question
503      *  \return List of BufferIds belonging to the Network
504      */
505     static inline QList<BufferId> requestBufferIdsForNetwork(UserId user, NetworkId networkId)
506     {
507         return instance()->_storage->requestBufferIdsForNetwork(user, networkId);
508     }
509
510
511     //! Remove permanently a buffer and it's content from the storage backend
512     /** This call cannot be reverted!
513      *  \note This method is threadsafe.
514      *
515      *  \param user      The user who is the owner of the buffer
516      *  \param bufferId  The bufferId
517      *  \return true if successfull
518      */
519     static inline bool removeBuffer(const UserId &user, const BufferId &bufferId)
520     {
521         return instance()->_storage->removeBuffer(user, bufferId);
522     }
523
524
525     //! Rename a Buffer
526     /** \note This method is threadsafe.
527      *  \param user      The id of the buffer owner
528      *  \param bufferId  The bufferId
529      *  \param newName   The new name of the buffer
530      *  \return true if successfull
531      */
532     static inline bool renameBuffer(const UserId &user, const BufferId &bufferId, const QString &newName)
533     {
534         return instance()->_storage->renameBuffer(user, bufferId, newName);
535     }
536
537
538     //! Merge the content of two Buffers permanently. This cannot be reversed!
539     /** \note This method is threadsafe.
540      *  \param user      The id of the buffer owner
541      *  \param bufferId1 The bufferId of the remaining buffer
542      *  \param bufferId2 The buffer that is about to be removed
543      *  \return true if successfulln
544      */
545     static inline bool mergeBuffersPermanently(const UserId &user, const BufferId &bufferId1, const BufferId &bufferId2)
546     {
547         return instance()->_storage->mergeBuffersPermanently(user, bufferId1, bufferId2);
548     }
549
550
551     //! Update the LastSeenDate for a Buffer
552     /** This Method is used to make the LastSeenDate of a Buffer persistent
553      *  \note This method is threadsafe.
554      *
555      * \param user      The Owner of that Buffer
556      * \param bufferId  The buffer id
557      * \param MsgId     The Message id of the message that has been just seen
558      */
559     static inline void setBufferLastSeenMsg(UserId user, const BufferId &bufferId, const MsgId &msgId)
560     {
561         return instance()->_storage->setBufferLastSeenMsg(user, bufferId, msgId);
562     }
563
564
565     //! Get a usable sysident for the given user in oidentd-strict mode
566     /** \param user    The user to retrieve the sysident for
567      *  \return The authusername
568      */
569     QString strictSysIdent(UserId user) const;
570
571
572     //! Get a Hash of all last seen message ids
573     /** This Method is called when the Quassel Core is started to restore the lastSeenMsgIds
574      *  \note This method is threadsafe.
575      *
576      * \param user      The Owner of the buffers
577      */
578     static inline QHash<BufferId, MsgId> bufferLastSeenMsgIds(UserId user)
579     {
580         return instance()->_storage->bufferLastSeenMsgIds(user);
581     }
582
583
584     //! Update the MarkerLineMsgId for a Buffer
585     /** This Method is used to make the marker line position of a Buffer persistent
586      *  \note This method is threadsafe.
587      *
588      * \param user      The Owner of that Buffer
589      * \param bufferId  The buffer id
590      * \param MsgId     The Message id where the marker line should be placed
591      */
592     static inline void setBufferMarkerLineMsg(UserId user, const BufferId &bufferId, const MsgId &msgId)
593     {
594         return instance()->_storage->setBufferMarkerLineMsg(user, bufferId, msgId);
595     }
596
597
598     //! Get a Hash of all marker line message ids
599     /** This Method is called when the Quassel Core is started to restore the MarkerLineMsgIds
600      *  \note This method is threadsafe.
601      *
602      * \param user      The Owner of the buffers
603      */
604     static inline QHash<BufferId, MsgId> bufferMarkerLineMsgIds(UserId user)
605     {
606         return instance()->_storage->bufferMarkerLineMsgIds(user);
607     }
608
609     //! Update the BufferActivity for a Buffer
610     /** This Method is used to make the activity state of a Buffer persistent
611      *  \note This method is threadsafe.
612      *
613      * \param user      The Owner of that Buffer
614      * \param bufferId  The buffer id
615      * \param MsgId     The Message id where the marker line should be placed
616      */
617     static inline void setBufferActivity(UserId user, BufferId bufferId, Message::Types activity) {
618         return instance()->_storage->setBufferActivity(user, bufferId, activity);
619     }
620
621
622     //! Get a Hash of all buffer activity states
623     /** This Method is called when the Quassel Core is started to restore the BufferActivity
624      *  \note This method is threadsafe.
625      *
626      * \param user      The Owner of the buffers
627      */
628     static inline QHash<BufferId, Message::Types> bufferActivities(UserId user) {
629         return instance()->_storage->bufferActivities(user);
630     }
631
632     //! Get the bitset of buffer activity states for a buffer
633     /** This method is used to load the activity state of a buffer when its last seen message changes.
634      *  \note This method is threadsafe.
635      *
636      * \param bufferId The buffer
637      * \param lastSeenMsgId     The last seen message
638      */
639     static inline Message::Types bufferActivity(BufferId bufferId, MsgId lastSeenMsgId) {
640         return instance()->_storage->bufferActivity(bufferId, lastSeenMsgId);
641     }
642
643     //! Update the highlight count for a Buffer
644     /** This Method is used to make the highlight count state of a Buffer persistent
645      *  \note This method is threadsafe.
646      *
647      * \param user      The Owner of that Buffer
648      * \param bufferId  The buffer id
649      * \param MsgId     The Message id where the marker line should be placed
650      */
651     static inline void setHighlightCount(UserId user, BufferId bufferId, int highlightCount) {
652         return instance()->_storage->setHighlightCount(user, bufferId, highlightCount);
653     }
654
655
656     //! Get a Hash of all highlight count states
657     /** This Method is called when the Quassel Core is started to restore the highlight count
658      *  \note This method is threadsafe.
659      *
660      * \param user      The Owner of the buffers
661      */
662     static inline QHash<BufferId, int> highlightCounts(UserId user) {
663         return instance()->_storage->highlightCounts(user);
664     }
665     //! Get the highlight count states for a buffer
666     /** This method is used to load the highlight count of a buffer when its last seen message changes.
667      *  \note This method is threadsafe.
668      *
669      * \param bufferId The buffer
670      * \param lastSeenMsgId     The last seen message
671      */
672     static inline int highlightCount(BufferId bufferId, MsgId lastSeenMsgId) {
673         return instance()->_storage->highlightCount(bufferId, lastSeenMsgId);
674     }
675
676     static inline QDateTime startTime() { return instance()->_startTime; }
677     static inline bool isConfigured() { return instance()->_configured; }
678
679     /**
680      * Whether or not strict ident mode is enabled, locking users' idents to Quassel username
681      *
682      * @return True if strict mode enabled, otherwise false
683      */
684     static inline bool strictIdentEnabled() { return instance()->_strictIdentEnabled; }
685
686     static bool sslSupported();
687
688     static QVariantList backendInfo();
689     static QVariantList authenticatorInfo();
690
691     static QString setup(const QString &adminUser, const QString &adminPassword, const QString &backend, const QVariantMap &setupData, const QString &authenticator, const QVariantMap &authSetupMap);
692
693     static inline QTimer *syncTimer() { return &instance()->_storageSyncTimer; }
694
695     inline OidentdConfigGenerator *oidentdConfigGenerator() const { return _oidentdConfigGenerator; }
696     inline IdentServer *identServer() const { return _identServer; }
697
698     static const int AddClientEventId;
699
700 signals:
701     //! Sent when a BufferInfo is updated in storage.
702     void bufferInfoUpdated(UserId user, const BufferInfo &info);
703
704     //! Relay from CoreSession::sessionState(). Used for internal connection only
705     void sessionState(const Protocol::SessionState &sessionState);
706
707     //! Emitted when database schema upgrade starts or ends
708     void dbUpgradeInProgress(bool inProgress);
709
710     //! Emitted when a fatal error was encountered during async initialization
711     void exitRequested(int exitCode, const QString &reason);
712
713     //! Emitted once core shutdown is complete
714     void shutdownComplete();
715
716 public slots:
717     void initAsync();
718
719     /** Persist storage.
720      *
721      * @note This method is threadsafe.
722      */
723     void syncStorage();
724
725     /**
726      * Reload SSL certificates used for connection with clients.
727      *
728      * @return True if certificates reloaded successfully, otherwise false.
729      */
730     bool reloadCerts();
731
732     void cacheSysIdent();
733
734     QString setupCore(const QString &adminUser, const QString &adminPassword, const QString &backend, const QVariantMap &setupData, const QString &authenticator, const QVariantMap &authSetupMap);
735
736     void connectInternalPeer(QPointer<InternalPeer> peer);
737
738 protected:
739     void customEvent(QEvent *event) override;
740
741 private slots:
742     bool startListening();
743     void stopListening(const QString &msg = QString());
744     void incomingConnection();
745     void clientDisconnected();
746
747     bool initStorage(const QString &backend, const QVariantMap &settings,
748                      const QProcessEnvironment &environment, bool loadFromEnvironment,
749                      bool setup = false);
750     bool initAuthenticator(const QString &backend, const QVariantMap &settings,
751                            const QProcessEnvironment &environment, bool loadFromEnvironment,
752                            bool setup = false);
753
754     void socketError(QAbstractSocket::SocketError err, const QString &errorString);
755     void setupClientSession(RemotePeer *, UserId);
756
757     bool changeUserPass(const QString &username);
758
759     void onSessionShutdown(SessionThread *session);
760
761 private:
762     SessionThread *sessionForUser(UserId userId, bool restoreState = false);
763     void addClientHelper(RemotePeer *peer, UserId uid);
764     //void processCoreSetup(QTcpSocket *socket, QVariantMap &msg);
765     QString setupCoreForInternalUsage();
766     void setupInternalClientSession(QPointer<InternalPeer> peer);
767
768     bool createUser();
769
770     template<typename Storage>
771     void registerStorageBackend();
772
773     template<typename Authenticator>
774     void registerAuthenticator();
775
776     void registerStorageBackends();
777     void registerAuthenticators();
778
779     DeferredSharedPtr<Storage>       storageBackend(const QString& backendId) const;
780     DeferredSharedPtr<Authenticator> authenticator(const QString& authenticatorId) const;
781
782     bool selectBackend(const QString &backend);
783     bool selectAuthenticator(const QString &backend);
784
785     bool saveBackendSettings(const QString &backend, const QVariantMap &settings);
786     void saveAuthenticatorSettings(const QString &backend, const QVariantMap &settings);
787
788     void saveState();
789     void restoreState();
790
791     template<typename Backend>
792     QVariantMap promptForSettings(const Backend *backend);
793
794 private:
795     static Core *_instance;
796     QSet<CoreAuthHandler *> _connectingClients;
797     QHash<UserId, SessionThread *> _sessions;
798     DeferredSharedPtr<Storage>       _storage;        ///< Active storage backend
799     DeferredSharedPtr<Authenticator> _authenticator;  ///< Active authenticator
800     QMap<UserId, QString> _authUserNames;
801
802     QTimer _storageSyncTimer;
803
804 #ifdef HAVE_SSL
805     SslServer _server, _v6server;
806 #else
807     QTcpServer _server, _v6server;
808 #endif
809
810     OidentdConfigGenerator *_oidentdConfigGenerator {nullptr};
811
812     std::vector<DeferredSharedPtr<Storage>>       _registeredStorageBackends;
813     std::vector<DeferredSharedPtr<Authenticator>> _registeredAuthenticators;
814
815     QDateTime _startTime;
816
817     IdentServer *_identServer {nullptr};
818
819     bool _initialized{false};
820     bool _configured{false};
821
822     QPointer<InternalPeer> _pendingInternalConnection;
823
824     /// Whether or not strict ident mode is enabled, locking users' idents to Quassel username
825     bool _strictIdentEnabled;
826
827     static std::unique_ptr<AbstractSqlMigrationReader> getMigrationReader(Storage *storage);
828     static std::unique_ptr<AbstractSqlMigrationWriter> getMigrationWriter(Storage *storage);
829     static void stdInEcho(bool on);
830     static inline void enableStdInEcho() { stdInEcho(true); }
831     static inline void disableStdInEcho() { stdInEcho(false); }
832 };