KVIrc  4.9.2
DeveloperAPIs
KviIrcMask.h
Go to the documentation of this file.
1 #ifndef _KVI_IRCMASK_H_
2 #define _KVI_IRCMASK_H_
3 
4 //=============================================================================
5 //
6 // File : KviIrcMask.h
7 // Creation date : Fri Jan 8 1999 19:50:35 by Szymon Stefanek
8 //
9 // This file is part of the KVIrc IRC client distribution
10 // Copyright (C) 1999-2010 Szymon Stefanek (pragma at kvirc dot net)
11 //
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 option) any later version.
16 //
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.
21 //
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.
25 //
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 //=============================================================================
30 
37 #include "kvi_settings.h"
38 #include "KviHeapObject.h"
39 #include "KviQString.h"
40 
46 {
47  friend class KviIrcUserList;
48  friend class KviIrcUserChanList;
49 
50 private:
51  QString m_szNick;
52  QString m_szUser;
53  QString m_szHost;
54  static QString m_szWild;
55 
56 public:
61  KviIrcMask();
62 
68  KviIrcMask(const QString & szMask);
69 
75  KviIrcMask(const KviIrcMask & ircUser)
76  : m_szNick(ircUser.m_szNick), m_szUser(ircUser.m_szUser), m_szHost(ircUser.m_szHost){};
77 
85  KviIrcMask(const QString & nick, const QString & user, const QString & host)
86  : m_szNick(nick), m_szUser(user), m_szHost(host){};
87 
92  enum MaskType
93  {
94  NickUserHost = 0,
95  NickUserNet = 1,
96  NickUser = 2,
97  NickHost = 3,
98  NickNet = 4,
99  Nick = 5,
100  UserHost = 6,
101  UserNet = 7,
102  User = 8,
103  Host = 9,
104  Net = 10,
105  NickCleanUserHost = 11,
106  NickCleanUserNet = 12,
107  NickCleanUser = 13,
108  CleanUserHost = 14,
109  CleanUserNet = 15,
110  CleanUser = 16,
111  NickUserLargeNet = 17,
112  NickLargeNet = 18,
113  UserLargeNet = 19,
114  NickCleanUserLargeNet = 20,
115  CleanUserLargeNet = 21,
116  NickUserSmartNet = 22,
117  NickSmartNet = 23,
118  UserSmartNet = 24,
119  NickCleanUserSmartNet = 25,
120  CleanUserSmartNet = 26
121  };
122 
123 public:
131  void setNick(const QString & szNick) { m_szNick = szNick.isEmpty() ? m_szWild : szNick; };
132 
140  void setUsername(const QString & szUser) { m_szUser = szUser.isEmpty() ? m_szWild : szUser; };
141 
150  void setUser(const QString & szUser) { m_szUser = szUser.isEmpty() ? m_szWild : szUser; };
151 
159  void setHost(const QString & szHost) { m_szHost = szHost.isEmpty() ? m_szWild : szHost; };
160 
167  const QString & nick() const { return m_szNick; };
168 
175  const QString & user() const { return m_szUser; };
176 
183  const QString & host() const { return m_szHost; };
184 
189  bool hasUser() const { return !(m_szUser.isEmpty() || (m_szUser == m_szWild)); };
190 
195  bool hasHost() const { return !(m_szHost.isEmpty() || (m_szHost == m_szWild)); };
196 
201  bool hasNumericHost() const;
202 
256  void mask(QString & szMask, MaskType eMaskType = NickCleanUserHost) const;
257 
262  bool hasWildNick();
263 
269  bool matches(const KviIrcMask & mask) const;
270 
278  bool matchesFixed(const QString & szNick, const QString & szUser, const QString & szHost) const;
279 
285  bool matchesFixed(const KviIrcMask & mask) const;
286 
292  bool matchedBy(const KviIrcMask & mask) const { return mask.matchesFixed(*this); };
293 
300  bool matchWildString(const QString & szExp, const QString & szStr) const;
301 
306  int nonWildChars();
307 
313  bool operator==(const KviIrcMask & user);
314 
315 private:
322  int getIpDomainMaskLen() const;
323 
330  int getLargeIpDomainMaskLen() const;
331 
336  QString getHostDomainMask() const;
337 
342  QString getLargeHostDomainMask() const;
343 
349  bool hasMaskedIp() const;
350 };
351 
352 #endif //_KVI_IRCMASK_H_
bool matchesFixed(const QString &szNick, const QString &szUser, const QString &szHost) const
Fixed external matches (this is wild, external is fixed)
Definition: KviIrcMask.cpp:357
__KVI_EXTERN bool operator==(const KviCString &left, const KviCString &right)
Definition: KviCString.h:552
QString m_szHost
Definition: KviIrcMask.h:53
Definition: KviHeapObject.h:124
bool hasUser() const
Returns true if the username is set in the mask.
Definition: KviIrcMask.h:189
void setNick(const QString &szNick)
Sets the nick for this user.
Definition: KviIrcMask.h:131
const QString & user() const
Returns the username of this user.
Definition: KviIrcMask.h:175
Irc user mask handling.
Definition: KviIrcMask.h:45
QString szHost
Definition: libkvisetup.cpp:45
void setHost(const QString &szHost)
Sets the host for this user.
Definition: KviIrcMask.h:159
QString m_szUser
Definition: KviIrcMask.h:52
const QString & nick() const
Returns the nickname of this user.
Definition: KviIrcMask.h:167
MaskType
Defines the type of the masks.
Definition: KviIrcMask.h:92
KviIrcMask(const QString &nick, const QString &user, const QString &host)
Carbon copy.
Definition: KviIrcMask.h:85
Heap Object.
QString m_szNick
Definition: KviIrcMask.h:51
void setUsername(const QString &szUser)
Sets the username for this user.
Definition: KviIrcMask.h:140
This file contains compile time settings.
KviIrcMask(const KviIrcMask &ircUser)
Carbon copy.
Definition: KviIrcMask.h:75
bool hasHost() const
Returns true if the hostname is set in the mask.
Definition: KviIrcMask.h:195
bool matchedBy(const KviIrcMask &mask) const
Fixed internal matches (this is fixed, external is wild)
Definition: KviIrcMask.h:292
#define KVILIB_API
Definition: kvi_settings.h:125
static QString m_szWild
Definition: KviIrcMask.h:54
Helper functions for the QString class.
void setUser(const QString &szUser)
Sets the username for this user.
Definition: KviIrcMask.h:150
const QString & host() const
Returns the hostname of this user.
Definition: KviIrcMask.h:183