1 /*
2 Copyright (C) 2008-2020 The Communi Project
3
4 You may use this file under the terms of BSD license as follows:
5
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are met:
8 * Redistributions of source code must retain the above copyright
9 notice, this list of conditions and the following disclaimer.
10 * Redistributions in binary form must reproduce the above copyright
11 notice, this list of conditions and the following disclaimer in the
12 documentation and/or other materials provided with the distribution.
13 * Neither the name of the copyright holder nor the names of its
14 contributors may be used to endorse or promote products derived
15 from this software without specific prior written permission.
16
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR
21 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #include "irc.h"
30 #include "irccore.h"
31 #include "irccommand.h"
32 #include "ircconnection.h"
33 #include "ircmessage_p.h"
34 #include <QMetaEnum>
35 #include <QDebug>
36 #ifndef QT_NO_SSL
37 #include <QSslSocket>
38 #endif // QT_NO_SSL
39
40 IRC_BEGIN_NAMESPACE
41
42 /*!
43 \file irc.h
44 \brief \#include <Irc>
45 */
46
47 /*!
48 \class Irc
49 \ingroup core
50 \brief Miscellaneous identifiers used throughout the library.
51 */
52
53 /*!
54 \since 3.5
55 \property bool Irc::secureSupported
56 This property holds whether SSL is supported.
57
58 The value may be \c false for the following reasons:
59 \li Qt was built without SSL support (\c QT_NO_SSL is defined), or
60 \li The platform does not support SSL (QSslSocket::supportsSsl() returns \c false).
61
62 \par Access function:
63 \li static bool <b>isSecureSupported</b>()
64
65 \sa IrcConnection::secure, QSslSocket::supportsSsl()
66 */
isSecureSupported()67 bool Irc::isSecureSupported()
68 {
69 #ifdef QT_NO_SSL
70 return false;
71 #else
72 return QSslSocket::supportsSsl();
73 #endif
74 }
75
76 /*!
77 \since 3.5
78
79 This property holds the list of supported SASL (Simple Authentication and Security Layer) mechanisms.
80
81 \par Access function:
82 \li static QStringList <b>supportedSaslMechanisms</b>()
83
84 \sa IrcConnection::saslMechanism, \ref ircv3
85 */
supportedSaslMechanisms()86 QStringList Irc::supportedSaslMechanisms()
87 {
88 return QStringList() << QLatin1String("PLAIN");
89 }
90
91 /*!
92 \since 3.5
93
94 This property holds the list of supported capabilities.
95
96 These capabilities are guaranteed to be compatible with the framework. In order to
97 easily enable all possible supported capabilities, assign Irc::supportedCapabilities
98 to IrcNetwork::requestedCapabilities.
99
100 \par Access function:
101 \li static QStringList <b>supportedCapabilities</b>()
102
103 \sa \ref capabilities, \ref ircv3
104 */
supportedCapabilities()105 QStringList Irc::supportedCapabilities()
106 {
107 return QStringList() << QLatin1String("account-notify")
108 << QLatin1String("account-tag")
109 << QLatin1String("away-notify")
110 << QLatin1String("batch")
111 << QLatin1String("cap-notify")
112 << QLatin1String("chghost")
113 << QLatin1String("echo-message")
114 << QLatin1String("extended-join")
115 << QLatin1String("invite-notify")
116 << QLatin1String("multi-prefix")
117 << QLatin1String("sasl")
118 << QLatin1String("server-time")
119 << QLatin1String("userhost-in-names");
120 }
121
122 /*!
123 Returns the version number of Communi at run-time as a string (for example, "1.2.3").
124 This may be a different version than the version the application was compiled against.
125
126 \sa IRC_VERSION, IRC_VERSION_STR
127 */
version()128 QString Irc::version()
129 {
130 return QLatin1String(IRC_VERSION_STR);
131 }
132
133 /*!
134 Returns the numeric \a code as a string or a null string if the code is unknown.
135
136 \sa Irc::Code, IrcNumericMessage::code()
137 */
codeToString(int code)138 QString Irc::codeToString(int code)
139 {
140 const int index = Irc::staticMetaObject.indexOfEnumerator("Code");
141 QMetaEnum enumerator = Irc::staticMetaObject.enumerator(index);
142 return QLatin1String(enumerator.valueToKey(code));
143 }
144
145 /*!
146 Returns the nick part of the specified \a prefix.
147
148 Nick part of a prefix as specified in RFC 1459:
149 <pre>
150 <b><nick></b> [ '!' <ident> ] [ '@' <host> ]
151 </pre>
152
153 \sa IrcMessage::prefix, IrcMessage::nick
154 */
nickFromPrefix(const QString & prefix)155 QString Irc::nickFromPrefix(const QString& prefix)
156 {
157 QString nick;
158 IrcMessagePrivate::parsePrefix(prefix, &nick, nullptr, nullptr);
159 return nick;
160 }
161
162 /*!
163 Returns the ident part of the specified \a prefix.
164
165 Ident part of a prefix as specified in RFC 1459:
166 <pre>
167 <nick> [ '!' <b><ident></b> ] [ '@' <host> ]
168 </pre>
169
170 \sa IrcMessage::prefix, IrcMessage::ident
171 */
identFromPrefix(const QString & prefix)172 QString Irc::identFromPrefix(const QString& prefix)
173 {
174 QString ident;
175 IrcMessagePrivate::parsePrefix(prefix, nullptr, &ident, nullptr);
176 return ident;
177 }
178
179 /*!
180 Returns the host part of the specified \a prefix.
181
182 Host part of a prefix as specified in RFC 1459:
183 <pre>
184 <nick> [ '!' <ident> ] [ '@' <b><host></b> ]
185 </pre>
186
187 \sa IrcMessage::prefix, IrcMessage::host
188 */
hostFromPrefix(const QString & prefix)189 QString Irc::hostFromPrefix(const QString& prefix)
190 {
191 QString host;
192 IrcMessagePrivate::parsePrefix(prefix, nullptr, nullptr, &host);
193 return host;
194 }
195
196 /*!
197 \deprecated Use IrcCore::registerMetaTypes() instead.
198 */
registerMetaTypes()199 void Irc::registerMetaTypes()
200 {
201 IrcCore::registerMetaTypes();
202 }
203
204 #ifndef QT_NO_DEBUG_STREAM
operator <<(QDebug debug,Irc::Code code)205 QDebug operator<<(QDebug debug, Irc::Code code)
206 {
207 const int index = Irc::staticMetaObject.indexOfEnumerator("Code");
208 QMetaEnum enumerator = Irc::staticMetaObject.enumerator(index);
209 const char* key = enumerator.valueToKey(code);
210 debug << (key ? key : "Unknown");
211 return debug;
212 }
213
operator <<(QDebug debug,Irc::DataRole role)214 QDebug operator<<(QDebug debug, Irc::DataRole role)
215 {
216 const int index = Irc::staticMetaObject.indexOfEnumerator("DataRole");
217 QMetaEnum enumerator = Irc::staticMetaObject.enumerator(index);
218 const char* key = enumerator.valueToKey(role);
219 debug << (key ? key : "Unknown");
220 return debug;
221 }
222
operator <<(QDebug debug,Irc::Color color)223 QDebug operator<<(QDebug debug, Irc::Color color)
224 {
225 const int index = Irc::staticMetaObject.indexOfEnumerator("Color");
226 QMetaEnum enumerator = Irc::staticMetaObject.enumerator(index);
227 const char* key = enumerator.valueToKey(color);
228 debug << (key ? key : "Unknown");
229 return debug;
230 }
231
operator <<(QDebug debug,Irc::SortMethod method)232 QDebug operator<<(QDebug debug, Irc::SortMethod method)
233 {
234 const int index = Irc::staticMetaObject.indexOfEnumerator("SortMethod");
235 QMetaEnum enumerator = Irc::staticMetaObject.enumerator(index);
236 const char* key = enumerator.valueToKey(method);
237 debug << (key ? key : "Unknown");
238 return debug;
239 }
240 #endif // QT_NO_DEBUG_STREAM
241
242 #include "moc_irc.cpp"
243
244 IRC_END_NAMESPACE
245