14c0ed7c9568715507d7dd62ee9d6d1128b595c6
[quassel.git] / src / common / irccap.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 IRCCAP_H
22 #define IRCCAP_H
23
24 #include <QString>
25 #include <QStringList>
26
27 // Why a namespace instead of a class?  Seems to be a better fit for C++ than a 'static' class, as
28 // compared to C# or Java.  However, feel free to change if needed.
29 // See https://stackoverflow.com/questions/482745/namespaces-for-enum-types-best-practices
30 /**
31  * IRCv3 capability names and values
32  */
33 namespace IrcCap {
34
35     // NOTE: If you add or modify the constants below, update the knownCaps list.
36
37     /**
38      * Account change notification.
39      *
40      * http://ircv3.net/specs/extensions/account-notify-3.1.html
41      */
42     const QString ACCOUNT_NOTIFY = "account-notify";
43
44     /**
45      * Magic number for WHOX, used to ignore user-requested WHOX replies from servers
46      *
47      * If a user initiates a WHOX, there's no easy way to tell what fields were requested.  It's
48      * simpler to not attempt to parse data from user-requested WHOX replies.
49      */
50     const uint ACCOUNT_NOTIFY_WHOX_NUM = 369;
51
52     /**
53      * Away change notification.
54      *
55      * http://ircv3.net/specs/extensions/away-notify-3.1.html
56      */
57     const QString AWAY_NOTIFY = "away-notify";
58
59     /**
60      * Capability added/removed notification.
61      *
62      * This is implicitly enabled via CAP LS 302, and is here for servers that only partially
63      * support IRCv3.2.
64      *
65      * http://ircv3.net/specs/extensions/cap-notify-3.2.html
66      */
67     const QString CAP_NOTIFY = "cap-notify";
68
69     /**
70      * Hostname/user changed notification.
71      *
72      * http://ircv3.net/specs/extensions/chghost-3.2.html
73      */
74     const QString CHGHOST = "chghost";
75
76     /**
77      * Extended join information.
78      *
79      * http://ircv3.net/specs/extensions/extended-join-3.1.html
80      */
81     const QString EXTENDED_JOIN = "extended-join";
82
83     /**
84      * Multiple mode prefixes in MODE and WHO replies.
85      *
86      * http://ircv3.net/specs/extensions/multi-prefix-3.1.html
87      */
88     const QString MULTI_PREFIX = "multi-prefix";
89
90     /**
91      * SASL authentication.
92      *
93      * http://ircv3.net/specs/extensions/sasl-3.2.html
94      */
95     const QString SASL = "sasl";
96
97     /**
98      * Userhost in names replies.
99      *
100      * http://ircv3.net/specs/extensions/userhost-in-names-3.2.html
101      */
102     const QString USERHOST_IN_NAMES = "userhost-in-names";
103
104     /**
105      * List of capabilities currently implemented and requested during capability negotiation.
106      */
107     const QStringList knownCaps = QStringList {
108             ACCOUNT_NOTIFY,
109             AWAY_NOTIFY,
110             CAP_NOTIFY,
111             CHGHOST,
112             EXTENDED_JOIN,
113             MULTI_PREFIX,
114             SASL,
115             USERHOST_IN_NAMES
116     };
117     // NOTE: If you modify the knownCaps list, update the constants above as needed.
118
119     /**
120      * SASL authentication mechanisms
121      *
122      * http://ircv3.net/specs/extensions/sasl-3.1.html
123      */
124     namespace SaslMech {
125
126         /**
127          * Check if the given authentication mechanism is likely to be supported.
128          *
129          * @param[in] saslCapValue   QString of SASL capability value, e.g. capValue(IrcCap::SASL)
130          * @param[in] saslMechanism  Desired SASL mechanism
131          * @return True if mechanism supported or unknown, otherwise false
132          */
133         inline bool maybeSupported(const QString &saslCapValue, const QString &saslMechanism) { return
134                     ((saslCapValue.length() == 0) || (saslCapValue.contains(saslMechanism, Qt::CaseInsensitive))); }
135         // SASL mechanisms are only specified in capability values as part of SASL 3.2.  In
136         // SASL 3.1, it's handled differently.  If we don't know via capability value, assume it's
137         // supported to reduce the risk of breaking existing setups.
138         // See: http://ircv3.net/specs/extensions/sasl-3.1.html
139         // And: http://ircv3.net/specs/extensions/sasl-3.2.html
140
141         /**
142          * PLAIN authentication, e.g. hashed password
143          */
144         const QString PLAIN = "PLAIN";
145
146         /**
147          * EXTERNAL authentication, e.g. SSL certificate and keys
148          */
149         const QString EXTERNAL = "EXTERNAL";
150     }
151 }
152
153 #endif // IRCCAP_H