~ubuntu-branches/ubuntu/trusty/kvirc/trusty

« back to all changes in this revision

Viewing changes to src/kvilib/irc/KviIrcMask.h

  • Committer: Bazaar Package Importer
  • Author(s): Kai Wasserbäch, Kai Wasserbäch, Raúl Sánchez Siles
  • Date: 2011-02-12 10:40:21 UTC
  • mfrom: (14.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20110212104021-5mh4f75jlku20mnt
The combined "Twisted Experiment" and "Nocturnal Raid" release.

[ Kai Wasserbäch ]
* Synced to upstream's SVN revision 5467.
* debian/rules:
  - Added .PHONY line.
  - Resurrect -DMANUAL_REVISION, got lost somewhere and we build SVN
    revisions again.
  - Replace "-DWITH_NO_EMBEDDED_CODE=YES" with "-DWANT_CRYPTOPP=YES".
  - Change the remaining -DWITH/-DWITHOUT to the new -DWANT syntax.
* debian/control:
  - Removed DMUA, I'm a DD now.
  - Changed my e-mail address.
  - Removed unneeded relationships (no upgrades over two releases are
    supported).
  - Fix Suggests for kvirc-dbg.
  - kvirc-data: Make the "Suggests: kvirc" a Recommends, doesn't make much
    sense to install the -data package without the program.
* debian/source/local-options: Added with "unapply-patches".
* debian/kvirc.lintian-overrides: Updated to work for 4.1.1.
* debian/patches/21_make_shared-mime-info_B-D_superfluous.patch: Updated.
* debian/kvirc-data.install: Added .notifyrc.

[ Raúl Sánchez Siles ]
* Stating the right version where kvirc-data break and replace should happen.
* Fixing link to license file.
* Added French and Portuguese man pages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 opinion) 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
 
 
31
/**
 
32
* \file KviIrcMask.h
 
33
* \author Szymon Stefanek
 
34
* \brief Irc user mask abstraction
 
35
*/
 
36
 
 
37
#include "kvi_settings.h"
 
38
#include "KviHeapObject.h"
 
39
#include "KviQString.h"
 
40
 
 
41
/**
 
42
* \class KviIrcMask
 
43
* \brief Irc user mask handling
 
44
*/
 
45
class KVILIB_API KviIrcMask : public KviHeapObject
 
46
{
 
47
        friend class KviIrcUserList;
 
48
        friend class KviIrcUserChanList;
 
49
private:
 
50
        QString m_szNick;
 
51
        QString m_szUser;
 
52
        QString m_szHost;
 
53
        static QString m_szWild;
 
54
public:
 
55
        /**
 
56
        * \brief Constructs an empty mask (*!*@*)
 
57
        * \return KviIrcMask
 
58
        */
 
59
        KviIrcMask();
 
60
 
 
61
        /**
 
62
        * \brief Constructs this KviIrcMask object from a string mask
 
63
        * \param szMask The mask of the user
 
64
        * \return KviIrcMask
 
65
        */
 
66
        KviIrcMask(const QString & szMask);
 
67
 
 
68
        /**
 
69
        * \brief Carbon copy
 
70
        * \param ircUser The mask of the user
 
71
        * \return KviIrcMask
 
72
        */
 
73
        KviIrcMask(const KviIrcMask & ircUser)
 
74
        : m_szNick(ircUser.m_szNick), m_szUser(ircUser.m_szUser), m_szHost(ircUser.m_szHost) {};
 
75
 
 
76
        /**
 
77
        * \brief Carbon copy
 
78
        * \param nick The nickname of the user
 
79
        * \param user The username of the user
 
80
        * \param host The hostname of the user
 
81
        * \return KviIrcMask
 
82
        */
 
83
        KviIrcMask(const QString & nick, const QString & user, const QString & host)
 
84
        : m_szNick(nick), m_szUser(user), m_szHost(host) {};
 
85
 
 
86
        /**
 
87
        * \enum MaskType
 
88
        * \brief Defines the type of the masks
 
89
        */
 
90
        enum MaskType
 
91
        {
 
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 */
 
119
        };
 
120
public:
 
121
        /**
 
122
        * \brief Sets the nick for this user.
 
123
        *
 
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
 
126
        * \return void
 
127
        */
 
128
        void setNick(const QString & szNick){ m_szNick = szNick.isEmpty() ? m_szWild : szNick; };
 
129
 
 
130
        /**
 
131
        * \brief Sets the username for this user.
 
132
        *
 
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
 
135
        * \return void
 
136
        */
 
137
        void setUsername(const QString & szUser){ m_szUser = szUser.isEmpty() ? m_szWild : szUser; };
 
138
 
 
139
        /**
 
140
        * \brief Sets the username for this user.
 
141
        *
 
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
 
145
        * \return void
 
146
        */
 
147
        void setUser(const QString & szUser){ m_szUser = szUser.isEmpty() ? m_szWild : szUser; };
 
148
 
 
149
        /**
 
150
        * \brief Sets the host for this user.
 
151
        *
 
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
 
154
        * \return void
 
155
        */
 
156
        void setHost(const QString & szHost){ m_szHost = szHost.isEmpty() ? m_szWild : szHost; };
 
157
 
 
158
        /**
 
159
        * \brief Returns the nickname of this user.
 
160
        *
 
161
        * In the worst case you get a string == "*"
 
162
        * \return const QString &
 
163
        */
 
164
        const QString & nick() const { return m_szNick; };
 
165
 
 
166
        /**
 
167
        * \brief Returns the username of this user.
 
168
        *
 
169
        * In the worst case you get a string == "*"
 
170
        * \return const QString &
 
171
        */
 
172
        const QString & user() const { return m_szUser; };
 
173
 
 
174
        /**
 
175
        * \brief Returns the hostname of this user.
 
176
        *
 
177
        * In the worst case you get a string == "*"
 
178
        * \return const QString &
 
179
        */
 
180
        const QString & host() const { return m_szHost; };
 
181
 
 
182
        /**
 
183
        * \brief Returns true if the username is set in the mask
 
184
        * \return bool
 
185
        */
 
186
        bool hasUser() const { return !(m_szUser.isEmpty() || (m_szUser == m_szWild)); };
 
187
 
 
188
        /**
 
189
        * \brief Returns true if the hostname is set in the mask
 
190
        * \return bool
 
191
        */
 
192
        bool hasHost() const { return !(m_szHost.isEmpty() || (m_szHost == m_szWild)); };
 
193
 
 
194
        /**
 
195
        * \brief Returns true if the hostname is a numeric IP
 
196
        * \return bool
 
197
        */
 
198
        bool hasNumericHost() const;
 
199
 
 
200
        /**
 
201
        * \brief Returns in szMask the specified (if possible) mask of this user.
 
202
        *
 
203
        * If the host or username are not known, the mask may contain less
 
204
        * information than requested.
 
205
        * 
 
206
        * Mask types:
 
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.*)
 
209
        *  2: nick!user@*
 
210
        *  3: nick!*@\machine.host.top     (nick!user@\XXX.XXX.XXX.XXX)
 
211
        *  4: nick!*@*.host.top           (nick!user@\XXX.XXX.XXX.*)
 
212
        *  5: nick!*@*
 
213
        *  6: *!user@\machine.host.top     (*!user@\XXX.XXX.XXX.XX)
 
214
        *  7: *!user@*.host.top           (*!user@\XXX.XXX.XXX.*)
 
215
        *  8: *!user@*
 
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)
 
220
        * 13: nick!*user@*
 
221
        * 14: *!*user@\machine.host.top    (*!*user@\machine.host.top)
 
222
        * 15: *!*user@*.host.top          (*!*user@*.host.top)
 
223
        * 16: *!*user@*
 
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.*)
 
229
        * 
 
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.*)
 
237
        * 
 
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
 
240
        * 
 
241
        * ident is fun.. ahem
 
242
        * prefixes used:
 
243
        * none   I line with ident
 
244
        * ^      I line with OTHER type ident
 
245
        * ~      I line, no ident
 
246
        * +      i line with ident
 
247
        * =      i line with OTHER type ident
 
248
        * -      i line, no ident
 
249
        * \param szMask The mask of the user
 
250
        * \param eMaskType The mask type
 
251
        * \return void
 
252
        */
 
253
        void mask(QString & szMask, MaskType eMaskType = NickCleanUserHost) const;
 
254
 
 
255
        /**
 
256
        * \brief Returns true if the nickname contains wildcards (* and ?)
 
257
        * \return bool
 
258
        */
 
259
        bool hasWildNick();
 
260
 
 
261
        /**
 
262
        * \brief Wild external matches (this and external are wild)
 
263
        * \param mask The mask of the user
 
264
        * \return bool
 
265
        */
 
266
        bool matches(const KviIrcMask & mask) const;
 
267
 
 
268
        /**
 
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
 
273
        * \return bool
 
274
        */
 
275
        bool matchesFixed(const QString & szNick, const QString & szUser, const QString & szHost) const;
 
276
 
 
277
        /**
 
278
        * \brief Fixed external matches (this is wild, external is fixed)
 
279
        * \param mask The make of the user
 
280
        * \return bool
 
281
        */
 
282
        bool matchesFixed(const KviIrcMask & mask) const;
 
283
 
 
284
        /**
 
285
        * \brief Fixed internal matches (this is fixed, external is wild)
 
286
        * \param mask The mask of the user
 
287
        * \return bool
 
288
        */
 
289
        bool matchedBy(const KviIrcMask & mask) const { return mask.matchesFixed(*this); };
 
290
 
 
291
        /**
 
292
        * \brief Returns the number of non-wildcards characters in the mask
 
293
        * \return int
 
294
        */
 
295
        int nonWildChars();
 
296
 
 
297
        /**
 
298
        * \brief Comparison
 
299
        * \param user The username of the user
 
300
        * \return bool
 
301
        */
 
302
        bool operator==(const KviIrcMask & user);
 
303
private:
 
304
        /**
 
305
        * \brief Returns the number of characters which are parts of the IP
 
306
        *
 
307
        * The IP is in the form xxx.xxx.xxx.*
 
308
        * \return int
 
309
        */
 
310
        int getIpDomainMaskLen() const;
 
311
 
 
312
        /**
 
313
        * \brief Returns the number of characters which are parts of the IP
 
314
        *
 
315
        * The IP is in the form xxx.xxx.*
 
316
        * \return int
 
317
        */
 
318
        int getLargeIpDomainMaskLen() const;
 
319
 
 
320
        /**
 
321
        * \brief Returns the ip in the form xxx.xxx.xxx.*
 
322
        * \return QString
 
323
        */
 
324
        QString getHostDomainMask() const;
 
325
 
 
326
        /**
 
327
        * \brief Returns the ip in the form xxx.xxx.*
 
328
        * \return QString
 
329
        */
 
330
        QString getLargeHostDomainMask() const;
 
331
 
 
332
        /**
 
333
        * \brief Returns true if the user has the ip in the mask
 
334
        * \return bool
 
335
        * \warning This is just a GUESS and must be called AFTER making sure that it is NOT a plain numeric IP
 
336
        */
 
337
        bool hasMaskedIp() const;
 
338
};
 
339
 
 
340
#endif //_KVI_IRCMASK_H_