1 /***************************************************************************
2 * Copyright (C) 2005-2018 by the Quassel Project *
3 * devel@quassel-irc.org *
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. *
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. *
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 ***************************************************************************/
27 #include <QCoreApplication>
32 #include <QStringList>
34 #include "abstractcliparser.h"
38 class Quassel : public QObject
40 // TODO Qt5: Use Q_GADGET
51 QString fancyVersionString; // clickable rev
52 QString plainVersionString; // no <a> tag
55 QString generatedVersion;
59 uint protocolVersion; // deprecated
61 QString applicationName;
62 QString coreApplicationName;
63 QString clientApplicationName;
64 QString organizationName;
65 QString organizationDomain;
69 * This enum defines the optional features supported by cores/clients prior to version 0.13.
71 * Since the number of features declared this way is limited to 16 (due to the enum not having a defined
72 * width in cores/clients prior to 0.13), and for more robustness when negotiating features on connect,
73 * the bitfield-based representation was replaced by a string-based representation in 0.13, support for
74 * which is indicated by having the ExtendedFeatures flag set. Extended features are defined in the Feature
77 * @warning Do not alter this enum; new features must be added (only) to the @a Feature enum.
81 enum class LegacyFeature : quint32 {
82 SynchronizedMarkerLine = 0x0001,
83 SaslAuthentication = 0x0002,
84 SaslExternal = 0x0004,
85 HideInactiveNetworks = 0x0008,
86 PasswordChange = 0x0010,
87 CapNegotiation = 0x0020,
88 VerifyServerSSL = 0x0040,
89 CustomRateLimits = 0x0080,
90 // DccFileTransfer = 0x0100, // never in use
91 AwayFormatTimestamp = 0x0200,
92 Authenticators = 0x0400,
93 BufferActivitySync = 0x0800,
94 CoreSideHighlights = 0x1000,
95 SenderPrefixes = 0x2000,
96 RemoteDisconnect = 0x4000,
97 ExtendedFeatures = 0x8000,
99 Q_FLAGS(LegacyFeature)
100 Q_DECLARE_FLAGS(LegacyFeatures, LegacyFeature)
103 * A list of features that are optional in core and/or client, but need runtime checking.
105 * Some features require an uptodate counterpart, but don't justify a protocol break.
106 * This is what we use this enum for. Add such features to it and check at runtime on the other
107 * side for their existence.
109 * For feature negotiation, these enum values are serialized as strings, so order does not matter. However,
110 * do not rename existing enum values to avoid breaking compatibility.
112 * This list should be cleaned up after every protocol break, as we can assume them to be present then.
114 #if QT_VERSION >= 0x050000
115 enum class Feature : uint32_t {
119 SynchronizedMarkerLine,
122 HideInactiveNetworks,
123 PasswordChange, ///< Remote password change
124 CapNegotiation, ///< IRCv3 capability negotiation, account tracking
125 VerifyServerSSL, ///< IRC server SSL validation
126 CustomRateLimits, ///< IRC server custom message rate limits
127 AwayFormatTimestamp, ///< Timestamp formatting in away (e.g. %%hh:mm%%)
128 Authenticators, ///< Whether or not the core supports auth backends
129 BufferActivitySync, ///< Sync buffer activity status
130 CoreSideHighlights, ///< Core-Side highlight configuration and matching
131 SenderPrefixes, ///< Show prefixes for senders in backlog
132 RemoteDisconnect, ///< Allow this peer to be remotely disconnected
133 ExtendedFeatures, ///< Extended features
134 LongTime, ///< Serialize time as 64-bit values
135 RichMessages, ///< Real Name and Avatar URL in backlog
136 BacklogFilterType, ///< BacklogManager supports filtering backlog by MessageType
137 #if QT_VERSION >= 0x050500
138 EcdsaCertfpKeys, ///< ECDSA keys for CertFP in identities
140 LongMessageId, ///< 64-bit IDs for messages
146 static Quassel *instance();
148 static void setupBuildInfo();
149 static const BuildInfo &buildInfo();
150 static RunMode runMode();
152 static QString configDirPath();
154 //! Returns a list of data directory paths
155 /** There are several locations for applications to install their data files in. On Unix,
156 * a common location is /usr/share; others include $PREFIX/share and additional directories
157 * specified in the env variable XDG_DATA_DIRS.
158 * \return A list of directory paths to look for data files in
160 static QStringList dataDirPaths();
162 //! Searches for a data file in the possible data directories
163 /** Data files can reside in $DATA_DIR/apps/quassel, where $DATA_DIR is one of the directories
164 * returned by \sa dataDirPaths().
165 * \Note With KDE integration enabled, files are searched (only) in KDE's appdata dirs.
166 * \return The full path to the data file if found; a null QString else
168 static QString findDataFilePath(const QString &filename);
170 static QString translationDirPath();
172 //! Returns a list of directories we look for scripts in
173 /** We look for a subdirectory named "scripts" in the configdir and in all datadir paths.
174 * \return A list of directory paths containing executable scripts for /exec
176 static QStringList scriptDirPaths();
178 static void loadTranslation(const QLocale &locale);
180 static void setCliParser(std::shared_ptr<AbstractCliParser> cliParser);
181 static QString optionValue(const QString &option);
182 static bool isOptionSet(const QString &option);
191 static LogLevel logLevel();
192 static void setLogLevel(LogLevel logLevel);
193 static QFile *logFile();
194 static bool logToSyslog();
196 static void logFatalMessage(const char *msg);
198 using ReloadHandler = std::function<bool()>;
200 static void registerReloadHandler(ReloadHandler handler);
202 using QuitHandler = std::function<void()>;
204 static void registerQuitHandler(QuitHandler quitHandler);
208 static void destroy();
210 static void setRunMode(Quassel::RunMode runMode);
212 static void setDataDirPaths(const QStringList &paths);
213 static QStringList findDataDirPaths();
214 static void disableCrashHandler();
216 friend class CoreApplication;
217 friend class QtUiApplication;
218 friend class MonolithicApplication;
222 void setupEnvironment();
223 void registerMetaTypes();
225 const QString &coreDumpFileName();
228 * Requests a reload of relevant runtime configuration.
230 * Calls any registered reload handlers, and returns the cumulative result. If no handlers are registered,
231 * does nothing and returns true.
233 * @returns True if configuration reload successful, otherwise false
238 * Requests to quit the application.
240 * Calls any registered quit handlers. If no handlers are registered, calls QCoreApplication::quit().
244 void logBacktrace(const QString &filename);
246 static void handleSignal(int signal);
249 BuildInfo _buildInfo;
251 bool _initialized{false};
252 bool _handleCrashes{true};
254 QString _coreDumpFileName;
255 QString _configDirPath;
256 QStringList _dataDirPaths;
257 QString _translationDirPath;
259 LogLevel _logLevel{InfoLevel};
260 bool _logToSyslog{false};
261 std::unique_ptr<QFile> _logFile;
263 std::shared_ptr<AbstractCliParser> _cliParser;
265 std::vector<ReloadHandler> _reloadHandlers;
266 std::vector<QuitHandler> _quitHandlers;
269 // --------------------------------------------------------------------------------------------------------------------
272 * Class representing a set of supported core/client features.
274 * @sa Quassel::Feature
276 class Quassel::Features
280 * Default constructor.
282 * Creates a Feature instance with all known features (i.e., all values declared in the Quassel::Feature enum) set.
283 * This is useful for easily creating a Feature instance that represent the current version's capabilities.
288 * Constructs a Feature instance holding the given list of features.
290 * Both the @a features and the @a legacyFeatures arguments are considered (additively).
291 * This is useful when receiving a list of features from another peer.
293 * @param features A list of strings matching values in the Quassel::Feature enum. Strings that don't match are
294 * can be accessed after construction via unknownFeatures(), but are otherwise ignored.
295 * @param legacyFeatures Holds a bit-wise combination of LegacyFeature flag values, which are each added to the list of
296 * features represented by this Features instance.
298 Features(const QStringList &features, LegacyFeatures legacyFeatures);
301 * Check if a given feature is marked as enabled in this Features instance.
303 * @param feature The feature to be queried
304 * @returns Whether the given feature is marked as enabled
306 bool isEnabled(Feature feature) const;
309 * Provides a list of all features marked as either enabled or disabled (as indicated by the @a enabled argument) as strings.
311 * @param enabled Whether to return the enabled or the disabled features
312 * @return A string list containing all enabled or disabled features
314 QStringList toStringList(bool enabled = true) const;
317 * Provides a list of all enabled legacy features (i.e. features defined prior to v0.13) as bit-wise combination in a
318 * LegacyFeatures type.
320 * @note Extended features cannot be represented this way, and are thus ignored even if set.
321 * @return A LegacyFeatures type holding the bit-wise combination of all legacy features enabled in this Features instance
323 LegacyFeatures toLegacyFeatures() const;
326 * Provides the list of strings that could not be mapped to Quassel::Feature enum values on construction.
328 * Useful for debugging/logging purposes.
330 * @returns A list of strings that could not be mapped to the Feature enum on construction of this Features instance, if any
332 QStringList unknownFeatures() const;
335 std::vector<bool> _features;
336 QStringList _unknownFeatures;