Add support for chghost
[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      * Away change notification.
46      *
47      * http://ircv3.net/specs/extensions/away-notify-3.1.html
48      */
49     const QString AWAY_NOTIFY = "away-notify";
50
51     /**
52      * Capability added/removed notification.
53      *
54      * This is implicitly enabled via CAP LS 302, and is here for servers that only partially
55      * support IRCv3.2.
56      *
57      * http://ircv3.net/specs/extensions/cap-notify-3.2.html
58      */
59     const QString CAP_NOTIFY = "cap-notify";
60
61     /**
62      * Hostname/user changed notification.
63      *
64      * http://ircv3.net/specs/extensions/chghost-3.2.html
65      */
66     const QString CHGHOST = "chghost";
67
68     /**
69      * Extended join information.
70      *
71      * http://ircv3.net/specs/extensions/extended-join-3.1.html
72      */
73     const QString EXTENDED_JOIN = "extended-join";
74
75     /**
76      * Multiple mode prefixes in MODE and WHO replies.
77      *
78      * http://ircv3.net/specs/extensions/multi-prefix-3.1.html
79      */
80     const QString MULTI_PREFIX = "multi-prefix";
81
82     /**
83      * SASL authentication.
84      *
85      * http://ircv3.net/specs/extensions/sasl-3.2.html
86      */
87     const QString SASL = "sasl";
88
89     /**
90      * Userhost in names replies.
91      *
92      * http://ircv3.net/specs/extensions/userhost-in-names-3.2.html
93      */
94     const QString USERHOST_IN_NAMES = "userhost-in-names";
95
96     /**
97      * List of capabilities currently implemented and requested during capability negotiation.
98      */
99     const QStringList knownCaps = QStringList {
100             ACCOUNT_NOTIFY,
101             AWAY_NOTIFY,
102             CAP_NOTIFY,
103             CHGHOST,
104             EXTENDED_JOIN,
105             MULTI_PREFIX,
106             SASL,
107             USERHOST_IN_NAMES
108     };
109     // NOTE: If you modify the knownCaps list, update the constants above as needed.
110
111     /**
112      * SASL authentication mechanisms
113      *
114      * http://ircv3.net/specs/extensions/sasl-3.1.html
115      */
116     namespace SaslMech {
117
118         /**
119          * Check if the given authentication mechanism is likely to be supported.
120          *
121          * @param[in] saslCapValue   QString of SASL capability value, e.g. capValue(IrcCap::SASL)
122          * @param[in] saslMechanism  Desired SASL mechanism
123          * @return True if mechanism supported or unknown, otherwise false
124          */
125         inline bool maybeSupported(const QString &saslCapValue, const QString &saslMechanism) { return
126                     ((saslCapValue.length() == 0) || (saslCapValue.contains(saslMechanism, Qt::CaseInsensitive))); }
127         // SASL mechanisms are only specified in capability values as part of SASL 3.2.  In
128         // SASL 3.1, it's handled differently.  If we don't know via capability value, assume it's
129         // supported to reduce the risk of breaking existing setups.
130         // See: http://ircv3.net/specs/extensions/sasl-3.1.html
131         // And: http://ircv3.net/specs/extensions/sasl-3.2.html
132
133         /**
134          * PLAIN authentication, e.g. hashed password
135          */
136         const QString PLAIN = "PLAIN";
137
138         /**
139          * EXTERNAL authentication, e.g. SSL certificate and keys
140          */
141         const QString EXTERNAL = "EXTERNAL";
142     }
143 }
144
145 #endif // IRCCAP_H