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

« back to all changes in this revision

Viewing changes to src/kvilib/irc/KviNickServRuleSet.cpp

  • 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
//=============================================================================
 
2
//
 
3
//   File : KviNickServRuleSet.cpp
 
4
//   Creation date : Thu Aug 09 2001 17:44:56 by Szymon Stefanek
 
5
//
 
6
//   This file is part of the KVIrc irc client distribution
 
7
//   Copyright (C) 2001-2010 Szymon Stefanek (pragma at kvirc dot net)
 
8
//
 
9
//   This program is FREE software. You can redistribute it and/or
 
10
//   modify it under the terms of the GNU General Public License
 
11
//   as published by the Free Software Foundation; either version 2
 
12
//   of the License, or (at your opinion) any later version.
 
13
//
 
14
//   This program is distributed in the HOPE that it will be USEFUL,
 
15
//   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
17
//   See the GNU General Public License for more details.
 
18
//
 
19
//   You should have received a copy of the GNU General Public License
 
20
//   along with this program. If not, write to the Free Software Foundation,
 
21
//   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 
22
//
 
23
//=============================================================================
 
24
 
 
25
 
 
26
#include "KviNickServRuleSet.h"
 
27
#include "KviConfigurationFile.h"
 
28
#include "KviIrcMask.h"
 
29
 
 
30
#include <QRegExp>
 
31
 
 
32
/*
 
33
        @doc: nickserv_proto
 
34
        @title:
 
35
                Authentication with NickServ
 
36
        @keyterms:
 
37
                NickServ, automatic authentication with NickServ
 
38
        @type:
 
39
                generic
 
40
        @short:
 
41
                Automatic authentication with NickServ
 
42
        @body:
 
43
                KVIrc supports automatic authentication with the NickServ service.[br]
 
44
                This service is commonly implemented on major IRC networks: basically
 
45
                it is a program that allows users to register their nickname and protect
 
46
                it from being stolen by others.[br] The NickServ protocol is
 
47
                not standardized (at the time that I'm writing this doc) and automatic
 
48
                authentication is a pure experimental protocol.[br]
 
49
                Once you get on IRC with a registered nickname, the NickServ will
 
50
                ask you for identification by sending you a NOTICE.[br]
 
51
                The message will look in a way similar to the following:[br]
 
52
                <b>You're using a registered nickname: if this is your nick,
 
53
                please type /msg NickServ IDENTIFY password, otherwise please
 
54
                choose another nickname</b>.[br]
 
55
                The message is often broken in two or three lines of text.[br]
 
56
                Please note that many network policies suggest to avoid automatic authentication
 
57
                with NickServ.[br]I have implemented it because I know that it works on the networks
 
58
                that I'm usually on.[br]You have to check that this protocol works on your network and
 
59
                then eventually use it at your own risk.[br]
 
60
*/
 
61
 
 
62
 
 
63
// FIXME: The doc above is a bit outdated, fix it
 
64
 
 
65
KviNickServRuleSet::KviNickServRuleSet()
 
66
: KviHeapObject()
 
67
{
 
68
        m_bEnabled = false;
 
69
        m_pRules = 0;
 
70
}
 
71
 
 
72
KviNickServRuleSet::KviNickServRuleSet(const KviNickServRuleSet &s)
 
73
{
 
74
        m_pRules = 0;
 
75
        copyFrom(s);
 
76
}
 
77
 
 
78
 
 
79
KviNickServRuleSet::~KviNickServRuleSet()
 
80
{
 
81
        if(m_pRules)delete m_pRules;
 
82
}
 
83
 
 
84
void KviNickServRuleSet::save(KviConfigurationFile * pCfg, const QString & szPrefix)
 
85
{
 
86
        if(!m_pRules)
 
87
                return; // nothing to save
 
88
        if(m_pRules->isEmpty())
 
89
                return; // should never happen anyway
 
90
        QString szTmp;
 
91
        if(m_bEnabled)
 
92
        {
 
93
                szTmp = QString("%1NSEnabled").arg(szPrefix);
 
94
                pCfg->writeEntry(szTmp,m_bEnabled);
 
95
        }
 
96
        szTmp = QString("%1NSRules").arg(szPrefix);
 
97
        pCfg->writeEntry(szTmp,m_pRules->count());
 
98
        int i = 0;
 
99
        for(KviNickServRule * pRule = m_pRules->first(); pRule; pRule = m_pRules->next())
 
100
        {
 
101
                szTmp = QString("%1NSRule%2_").arg(szPrefix).arg(i);
 
102
                pRule->save(pCfg,szTmp);
 
103
                i++;
 
104
        }
 
105
}
 
106
 
 
107
KviNickServRuleSet * KviNickServRuleSet::load(KviConfigurationFile * pCfg, const QString & szPrefix)
 
108
{
 
109
        QString szTmp;
 
110
        szTmp = QString("%1NSRules").arg(szPrefix);
 
111
        unsigned int uCount = pCfg->readUIntEntry(szTmp,0);
 
112
        if(uCount == 0)
 
113
                return 0;
 
114
        KviNickServRuleSet * pSet = new KviNickServRuleSet();
 
115
        if(pSet->loadPrivate(pCfg,szPrefix,uCount))
 
116
                return pSet;
 
117
        delete pSet;
 
118
        return 0;
 
119
}
 
120
 
 
121
void KviNickServRuleSet::load(const QString & szConfigFile)
 
122
{
 
123
        clear();
 
124
        KviConfigurationFile cfg(szConfigFile,KviConfigurationFile::Read);
 
125
 
 
126
        QString szTmp = "NSRules";
 
127
        unsigned int uCount = cfg.readUIntEntry(szTmp,0);
 
128
        if(uCount == 0)
 
129
                return;
 
130
        loadPrivate(&cfg,QString(""),uCount);
 
131
}
 
132
 
 
133
void KviNickServRuleSet::save(const QString & szConfigFile)
 
134
{
 
135
        KviConfigurationFile cfg(szConfigFile,KviConfigurationFile::Write);
 
136
        cfg.clear();
 
137
        save(&cfg,QString(""));
 
138
}
 
139
 
 
140
bool KviNickServRuleSet::loadPrivate(KviConfigurationFile * pCfg, const QString & szPrefix, unsigned int uEntries)
 
141
{
 
142
        if(m_pRules)
 
143
                m_pRules->clear();
 
144
        else {
 
145
                m_pRules = new KviPointerList<KviNickServRule>;
 
146
                m_pRules->setAutoDelete(true);
 
147
        }
 
148
 
 
149
        if(uEntries != 0)
 
150
        {
 
151
                QString szTmp;
 
152
                szTmp = QString("%1NSEnabled").arg(szPrefix);
 
153
                m_bEnabled = pCfg->readBoolEntry(szTmp,false);
 
154
                for(unsigned int u=0; u < uEntries; u++)
 
155
                {
 
156
                        szTmp = QString("%1NSRule%2_").arg(szPrefix).arg(u);
 
157
                        KviNickServRule * pRule = new KviNickServRule();
 
158
                        if(!pRule->load(pCfg,szTmp))
 
159
                                delete pRule;
 
160
                        else m_pRules->append(pRule);
 
161
                }
 
162
        }
 
163
 
 
164
        if(m_pRules->isEmpty())
 
165
        {
 
166
                m_bEnabled = false;
 
167
                delete m_pRules;
 
168
                m_pRules = 0;
 
169
                return false;
 
170
        }
 
171
        return true;
 
172
}
 
173
 
 
174
void KviNickServRuleSet::clear()
 
175
{
 
176
        if(m_pRules)
 
177
        {
 
178
                delete m_pRules;
 
179
                m_pRules = 0;
 
180
        }
 
181
        m_bEnabled = false;
 
182
}
 
183
 
 
184
void KviNickServRuleSet::addRule(KviNickServRule * r)
 
185
{
 
186
        if(!m_pRules)
 
187
        {
 
188
                m_pRules = new KviPointerList<KviNickServRule>;
 
189
                m_pRules->setAutoDelete(true);
 
190
        }
 
191
        m_pRules->append(r);
 
192
}
 
193
 
 
194
KviNickServRuleSet * KviNickServRuleSet::createInstance()
 
195
{
 
196
        return new KviNickServRuleSet();
 
197
}
 
198
 
 
199
 
 
200
KviNickServRule * KviNickServRuleSet::matchRule(const QString & szNick, const KviIrcMask * pNickServ, const QString & szMsg, const QString & szServer)
 
201
{
 
202
        if(!m_pRules) return 0;
 
203
        
 
204
        for(KviNickServRule *r = m_pRules->first();r;r = m_pRules->next())
 
205
        {
 
206
                if(!KviQString::matchString(r->registeredNick(),szNick,false,true))
 
207
                        continue;
 
208
                
 
209
                if(!szServer.isEmpty())
 
210
                {
 
211
                        QRegExp res(r->serverMask(),Qt::CaseInsensitive,QRegExp::Wildcard);
 
212
                        if(!res.exactMatch(szServer))
 
213
                                continue;
 
214
                }
 
215
                if(!pNickServ->matchedBy(KviIrcMask(r->nickServMask())))
 
216
                        continue;
 
217
                QRegExp re(r->messageRegexp(),Qt::CaseInsensitive,QRegExp::Wildcard);
 
218
                if(re.exactMatch(szMsg)) return r;
 
219
        }
 
220
        return 0;
 
221
}
 
222
 
 
223
void KviNickServRuleSet::copyFrom(const KviNickServRuleSet &src)
 
224
{
 
225
        if(src.m_pRules)
 
226
        {
 
227
                if(m_pRules)m_pRules->clear();
 
228
                else {
 
229
                        m_pRules = new KviPointerList<KviNickServRule>;
 
230
                        m_pRules->setAutoDelete(true);
 
231
                }
 
232
                for(KviNickServRule * r = src.m_pRules->first();r;r = src.m_pRules->next())
 
233
                {
 
234
                        KviNickServRule * c = new KviNickServRule();
 
235
                        c->copyFrom(*r);
 
236
                        m_pRules->append(c);
 
237
                }
 
238
                if(m_pRules->isEmpty())
 
239
                {
 
240
                        m_bEnabled = false;
 
241
                        delete m_pRules;
 
242
                        m_pRules = 0;
 
243
                } else {
 
244
                        m_bEnabled = src.m_bEnabled;
 
245
                }
 
246
        } else {
 
247
                m_bEnabled = false;
 
248
                if(m_pRules)
 
249
                {
 
250
                        delete m_pRules;
 
251
                        m_pRules = 0;
 
252
                }
 
253
        }
 
254
}
 
255