1
#ifndef _KVI_IRCMASK_H_
2
#define _KVI_IRCMASK_H_
4
//=============================================================================
7
// Creation date : Fri Jan 8 1999 19:50:35 by Szymon Stefanek
9
// This file is part of the KVIrc irc client distribution
10
// Copyright (C) 1999-2010 Szymon Stefanek (pragma at kvirc dot net)
12
// This program is FREE software. You can redistribute it and/or
13
// modify it under the terms of the GNU General Public License
14
// as published by the Free Software Foundation; either version 2
15
// of the License, or (at your opinion) any later version.
17
// This program is distributed in the HOPE that it will be USEFUL,
18
// but WITHOUT ANY WARRANTY; without even the implied warranty of
19
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20
// See the GNU General Public License for more details.
22
// You should have received a copy of the GNU General Public License
23
// along with this program. If not, write to the Free Software Foundation,
24
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26
//=============================================================================
27
// originally this file was named kvi_ircuser.h and the class was KviIrcUser
28
// ported to UNICODE on 2004.10.28 1:50 am
29
//=============================================================================
33
* \author Szymon Stefanek
34
* \brief Irc user mask abstraction
37
#include "kvi_settings.h"
38
#include "KviHeapObject.h"
39
#include "KviQString.h"
43
* \brief Irc user mask handling
45
class KVILIB_API KviIrcMask : public KviHeapObject
47
friend class KviIrcUserList;
48
friend class KviIrcUserChanList;
53
static QString m_szWild;
56
* \brief Constructs an empty mask (*!*@*)
62
* \brief Constructs this KviIrcMask object from a string mask
63
* \param szMask The mask of the user
66
KviIrcMask(const QString & szMask);
70
* \param ircUser The mask of the user
73
KviIrcMask(const KviIrcMask & ircUser)
74
: m_szNick(ircUser.m_szNick), m_szUser(ircUser.m_szUser), m_szHost(ircUser.m_szHost) {};
78
* \param nick The nickname of the user
79
* \param user The username of the user
80
* \param host The hostname of the user
83
KviIrcMask(const QString & nick, const QString & user, const QString & host)
84
: m_szNick(nick), m_szUser(user), m_szHost(host) {};
88
* \brief Defines the type of the masks
92
NickUserHost = 0, /**< 0 : nick!~user\@machine.host.top (default) */
93
NickUserNet = 1, /**< 1 : nick!~user@*.abc.host.top */
94
NickUser = 2, /**< 2 : nick!~user@* */
95
NickHost = 3, /**< 3 : nick!*\@machine.host.top */
96
NickNet = 4, /**< 4 : nick!*@*.abc.host.top */
97
Nick = 5, /**< 5 : nick!*@* */
98
UserHost = 6, /**< 6 : *!~user\@machine.host.top */
99
UserNet = 7, /**< 7 : *!~user@*.abc.host.top */
100
User = 8, /**< 8 : *!~user@* */
101
Host = 9, /**< 9 : *!*\@machine.host.top */
102
Net = 10, /**< 10 : *!*@*.abc.host.top */
103
NickCleanUserHost = 11, /**< 11 : nick!*user\@machine.host.top */
104
NickCleanUserNet = 12, /**< 12 : nick!*user@*.abc.host.top */
105
NickCleanUser = 13, /**< 13 : nick!*user@* */
106
CleanUserHost = 14, /**< 14 : *!*user\@machine.host.top */
107
CleanUserNet = 15, /**< 15 : *!*user@*.abc.host.top */
108
CleanUser = 16, /**< 16 : *!*user@* */
109
NickUserLargeNet = 17, /**< 17 : nick!~user@*.host.top */
110
NickLargeNet = 18, /**< 18 : nick!*@*.host.top */
111
UserLargeNet = 19, /**< 19 : *!~user@*.host.top */
112
NickCleanUserLargeNet = 20, /**< 20 : nick!*user@*.host.top */
113
CleanUserLargeNet = 21, /**< 21 : *!*user@*.host.top */
114
NickUserSmartNet = 22, /**< 22 : nick!~user@*.host.top */
115
NickSmartNet = 23, /**< 23 : nick!*@*.host.top */
116
UserSmartNet = 24, /**< 24 : *!~user@*.host.top */
117
NickCleanUserSmartNet = 25, /**< 25 : nick!*user@*.host.top */
118
CleanUserSmartNet = 26 /**< 26 : *!*user@*.host.top */
122
* \brief Sets the nick for this user.
124
* If szNick is NULL or it points to an empty string the nick is set to "*".
125
* \param szNick The nickname of the user
128
void setNick(const QString & szNick){ m_szNick = szNick.isEmpty() ? m_szWild : szNick; };
131
* \brief Sets the username for this user.
133
* If szUsername is NULL or it points to an empty string the username is set to "*".
134
* \param szUser The username of the user
137
void setUsername(const QString & szUser){ m_szUser = szUser.isEmpty() ? m_szWild : szUser; };
140
* \brief Sets the username for this user.
142
* If szUsername is NULL or it points to an empty string the username is set to "*".
143
* This is an alias of setUsername()
144
* \param szUser The username of the user
147
void setUser(const QString & szUser){ m_szUser = szUser.isEmpty() ? m_szWild : szUser; };
150
* \brief Sets the host for this user.
152
* If szHost is NULL or it points to an empty string the host is set to "*".
153
* \param szHost The hostname of the user
156
void setHost(const QString & szHost){ m_szHost = szHost.isEmpty() ? m_szWild : szHost; };
159
* \brief Returns the nickname of this user.
161
* In the worst case you get a string == "*"
162
* \return const QString &
164
const QString & nick() const { return m_szNick; };
167
* \brief Returns the username of this user.
169
* In the worst case you get a string == "*"
170
* \return const QString &
172
const QString & user() const { return m_szUser; };
175
* \brief Returns the hostname of this user.
177
* In the worst case you get a string == "*"
178
* \return const QString &
180
const QString & host() const { return m_szHost; };
183
* \brief Returns true if the username is set in the mask
186
bool hasUser() const { return !(m_szUser.isEmpty() || (m_szUser == m_szWild)); };
189
* \brief Returns true if the hostname is set in the mask
192
bool hasHost() const { return !(m_szHost.isEmpty() || (m_szHost == m_szWild)); };
195
* \brief Returns true if the hostname is a numeric IP
198
bool hasNumericHost() const;
201
* \brief Returns in szMask the specified (if possible) mask of this user.
203
* If the host or username are not known, the mask may contain less
204
* information than requested.
207
* 0: nick!user@\machine.host.top (nick!user@\XXX.XXX.XXX.XXX) (default)
208
* 1: nick!user@*.host.top (nick!user@\XXX.XXX.XXX.*)
210
* 3: nick!*@\machine.host.top (nick!user@\XXX.XXX.XXX.XXX)
211
* 4: nick!*@*.host.top (nick!user@\XXX.XXX.XXX.*)
213
* 6: *!user@\machine.host.top (*!user@\XXX.XXX.XXX.XX)
214
* 7: *!user@*.host.top (*!user@\XXX.XXX.XXX.*)
216
* 9: *!*@\machine.host.top (*!*@\XXX.XXX.XXX.XXX)
217
* 10: *!*@*.host.top (*!*@\XXX.XXX.XXX.*)
218
* 11: nick!*user@\machine.host.top (nick!*user@\machine.host.top)
219
* 12: nick!*user@*.host.top (nick!*user@*.host.top)
221
* 14: *!*user@\machine.host.top (*!*user@\machine.host.top)
222
* 15: *!*user@*.host.top (*!*user@*.host.top)
224
* 17: nick!~user@*.host.top (nick!~user@\XXX.XXX.*)
225
* 18: nick!*@*.host.top (nick!*@\XXX.XXX.*)
226
* 19: *!~user@*.host.top (*!~user@\XXX.XXX.*)
227
* 20: nick!*user@*.host.top (nick!*user@\XXX.XXX.*)
228
* 21: *!*user@*.host.top (*!user@*XXX.XXX.*)
230
* Smart versions of the masks 17-21 that try take care of masked ip addresses
231
* in the form xxx.xxx.INVALID-TOP-MASK
232
* 22: nick!~user@*.host.top (nick!~user@\XXX.XXX.*)
233
* 23: nick!*@*.host.top (nick!*@\XXX.XXX.*)
234
* 24: *!~user@*.host.top (*!~user@\XXX.XXX.*)
235
* 25: nick!*user@*.host.top (nick!*user@\XXX.XXX.*)
236
* 26: *!*user@*.host.top (*!user@*XXX.XXX.*)
238
* If some data is missing, these types may change:
239
* For example, if hostname is missing, the mask type 3 or 4 may be reduced to type 5
241
* ident is fun.. ahem
243
* none I line with ident
244
* ^ I line with OTHER type ident
246
* + i line with ident
247
* = i line with OTHER type ident
249
* \param szMask The mask of the user
250
* \param eMaskType The mask type
253
void mask(QString & szMask, MaskType eMaskType = NickCleanUserHost) const;
256
* \brief Returns true if the nickname contains wildcards (* and ?)
262
* \brief Wild external matches (this and external are wild)
263
* \param mask The mask of the user
266
bool matches(const KviIrcMask & mask) const;
269
* \brief Fixed external matches (this is wild, external is fixed)
270
* \param szNick The nickname of the user
271
* \param szUser The username of the user
272
* \param szHost The hostname of the user
275
bool matchesFixed(const QString & szNick, const QString & szUser, const QString & szHost) const;
278
* \brief Fixed external matches (this is wild, external is fixed)
279
* \param mask The make of the user
282
bool matchesFixed(const KviIrcMask & mask) const;
285
* \brief Fixed internal matches (this is fixed, external is wild)
286
* \param mask The mask of the user
289
bool matchedBy(const KviIrcMask & mask) const { return mask.matchesFixed(*this); };
292
* \brief Returns the number of non-wildcards characters in the mask
299
* \param user The username of the user
302
bool operator==(const KviIrcMask & user);
305
* \brief Returns the number of characters which are parts of the IP
307
* The IP is in the form xxx.xxx.xxx.*
310
int getIpDomainMaskLen() const;
313
* \brief Returns the number of characters which are parts of the IP
315
* The IP is in the form xxx.xxx.*
318
int getLargeIpDomainMaskLen() const;
321
* \brief Returns the ip in the form xxx.xxx.xxx.*
324
QString getHostDomainMask() const;
327
* \brief Returns the ip in the form xxx.xxx.*
330
QString getLargeHostDomainMask() const;
333
* \brief Returns true if the user has the ip in the mask
335
* \warning This is just a GUESS and must be called AFTER making sure that it is NOT a plain numeric IP
337
bool hasMaskedIp() const;
340
#endif //_KVI_IRCMASK_H_