1
//=============================================================================
3
// File : KviNickServRuleSet.cpp
4
// Creation date : Thu Aug 09 2001 17:44:56 by Szymon Stefanek
6
// This file is part of the KVIrc irc client distribution
7
// Copyright (C) 2001-2010 Szymon Stefanek (pragma at kvirc dot net)
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.
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.
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.
23
//=============================================================================
26
#include "KviNickServRuleSet.h"
27
#include "KviConfigurationFile.h"
28
#include "KviIrcMask.h"
35
Authentication with NickServ
37
NickServ, automatic authentication with NickServ
41
Automatic authentication with NickServ
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]
63
// FIXME: The doc above is a bit outdated, fix it
65
KviNickServRuleSet::KviNickServRuleSet()
72
KviNickServRuleSet::KviNickServRuleSet(const KviNickServRuleSet &s)
79
KviNickServRuleSet::~KviNickServRuleSet()
81
if(m_pRules)delete m_pRules;
84
void KviNickServRuleSet::save(KviConfigurationFile * pCfg, const QString & szPrefix)
87
return; // nothing to save
88
if(m_pRules->isEmpty())
89
return; // should never happen anyway
93
szTmp = QString("%1NSEnabled").arg(szPrefix);
94
pCfg->writeEntry(szTmp,m_bEnabled);
96
szTmp = QString("%1NSRules").arg(szPrefix);
97
pCfg->writeEntry(szTmp,m_pRules->count());
99
for(KviNickServRule * pRule = m_pRules->first(); pRule; pRule = m_pRules->next())
101
szTmp = QString("%1NSRule%2_").arg(szPrefix).arg(i);
102
pRule->save(pCfg,szTmp);
107
KviNickServRuleSet * KviNickServRuleSet::load(KviConfigurationFile * pCfg, const QString & szPrefix)
110
szTmp = QString("%1NSRules").arg(szPrefix);
111
unsigned int uCount = pCfg->readUIntEntry(szTmp,0);
114
KviNickServRuleSet * pSet = new KviNickServRuleSet();
115
if(pSet->loadPrivate(pCfg,szPrefix,uCount))
121
void KviNickServRuleSet::load(const QString & szConfigFile)
124
KviConfigurationFile cfg(szConfigFile,KviConfigurationFile::Read);
126
QString szTmp = "NSRules";
127
unsigned int uCount = cfg.readUIntEntry(szTmp,0);
130
loadPrivate(&cfg,QString(""),uCount);
133
void KviNickServRuleSet::save(const QString & szConfigFile)
135
KviConfigurationFile cfg(szConfigFile,KviConfigurationFile::Write);
137
save(&cfg,QString(""));
140
bool KviNickServRuleSet::loadPrivate(KviConfigurationFile * pCfg, const QString & szPrefix, unsigned int uEntries)
145
m_pRules = new KviPointerList<KviNickServRule>;
146
m_pRules->setAutoDelete(true);
152
szTmp = QString("%1NSEnabled").arg(szPrefix);
153
m_bEnabled = pCfg->readBoolEntry(szTmp,false);
154
for(unsigned int u=0; u < uEntries; u++)
156
szTmp = QString("%1NSRule%2_").arg(szPrefix).arg(u);
157
KviNickServRule * pRule = new KviNickServRule();
158
if(!pRule->load(pCfg,szTmp))
160
else m_pRules->append(pRule);
164
if(m_pRules->isEmpty())
174
void KviNickServRuleSet::clear()
184
void KviNickServRuleSet::addRule(KviNickServRule * r)
188
m_pRules = new KviPointerList<KviNickServRule>;
189
m_pRules->setAutoDelete(true);
194
KviNickServRuleSet * KviNickServRuleSet::createInstance()
196
return new KviNickServRuleSet();
200
KviNickServRule * KviNickServRuleSet::matchRule(const QString & szNick, const KviIrcMask * pNickServ, const QString & szMsg, const QString & szServer)
202
if(!m_pRules) return 0;
204
for(KviNickServRule *r = m_pRules->first();r;r = m_pRules->next())
206
if(!KviQString::matchString(r->registeredNick(),szNick,false,true))
209
if(!szServer.isEmpty())
211
QRegExp res(r->serverMask(),Qt::CaseInsensitive,QRegExp::Wildcard);
212
if(!res.exactMatch(szServer))
215
if(!pNickServ->matchedBy(KviIrcMask(r->nickServMask())))
217
QRegExp re(r->messageRegexp(),Qt::CaseInsensitive,QRegExp::Wildcard);
218
if(re.exactMatch(szMsg)) return r;
223
void KviNickServRuleSet::copyFrom(const KviNickServRuleSet &src)
227
if(m_pRules)m_pRules->clear();
229
m_pRules = new KviPointerList<KviNickServRule>;
230
m_pRules->setAutoDelete(true);
232
for(KviNickServRule * r = src.m_pRules->first();r;r = src.m_pRules->next())
234
KviNickServRule * c = new KviNickServRule();
238
if(m_pRules->isEmpty())
244
m_bEnabled = src.m_bEnabled;