Sun Apr 1 02:00:28 Środkowoeuropejski czas stand. 2007 Maciej Niedzielski * XEP-0076 scanner diff -rN old-psi1a/options/default.xml new-psi1a/options/default.xml 52a53,55 > > true > diff -rN old-psi1a/src/antievil.cpp new-psi1a/src/antievil.cpp 0a1,74 > /* > * antievil.cpp - anti evil scanner task > * Copyright (C) 2007-04-01 Maciej Niedzielski > * > * This program is free software; you can redistribute it and/or > * modify it under the terms of the GNU General Public > * License as published by the Free Software Foundation; either > * version 2 of the License, or (at your option) any later version. > * > * This program is distributed in the hope that it will be useful, > * but WITHOUT ANY WARRANTY; without even the implied warranty of > * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU > * Lesser General Public License for more details. > * > * You should have received a copy of the GNU General Public > * License along with this library; if not, write to the Free Software > * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA > * > */ > > #include "antievil.h" > #include "psioptions.h" > #include "xmpp_xmlcommon.h" > > using namespace XMPP; > > > /** > * \class AntiEvil > * \brief XEP-0076 implementation > * > * This tasks protects from evil > */ > > > AntiEvil::Stats AntiEvil::s; > > AntiEvil::AntiEvil(Task *parent) > :Task(parent) > { > } > > AntiEvil::~AntiEvil() > { > } > > bool AntiEvil::take(const QDomElement &e) > { > if (!PsiOptions::instance()->getOption("options.anti-evil.enable").toBool()) > return false; > > bool evil = false; > for (QDomNode n = e.firstChild(); !n.isNull(); n = n.nextSibling()) { > QDomElement i = n.toElement(); > if (!i.isNull() && i.tagName() == "evil" && i.attribute("xmlns") == "http://jabber.org/protocol/evil") { > //qDebug("evil stanza received"); > evil = true; > break; > } > } > > ++s.scanned; > emit s.scannedNext(s.scanned); > > if (!evil) > return false; > > ++s.blocked; > s.lastBlockedFrom = e.attribute("from"); > s.lastBlockedTime = QDateTime::currentDateTime(); > emit s.blockedNext(s.blocked, s.lastBlockedFrom, s.lastBlockedTime); > > return true; > } diff -rN old-psi1a/src/antievil.h new-psi1a/src/antievil.h 0a1,59 > /* > * antievil.h - anti evil scanner task > * Copyright (C) 2007-04-01 Maciej Niedzielski > * > * This program is free software; you can redistribute it and/or > * modify it under the terms of the GNU General Public > * License as published by the Free Software Foundation; either > * version 2 of the License, or (at your option) any later version. > * > * This program is distributed in the hope that it will be useful, > * but WITHOUT ANY WARRANTY; without even the implied warranty of > * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU > * Lesser General Public License for more details. > * > * You should have received a copy of the GNU General Public > * License along with this library; if not, write to the Free Software > * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA > * > */ > > #ifndef ANTIEVIL_H > #define ANTIEVIL_H > > #include "xmpp_task.h" > #include > > class AntiEvil : public XMPP::Task > { > public: > AntiEvil(Task *); > ~AntiEvil(); > bool take(const QDomElement &); > > class Stats; > static const Stats* stats() { return &s; } > > private: > static Stats s; > > }; > > class AntiEvil::Stats : public QObject > { > Q_OBJECT > public: > int scanned; > int blocked; > > QString lastBlockedFrom; > QDateTime lastBlockedTime; > > signals: > void scannedNext(int); > void blockedNext(int, const QString&, const QDateTime&); > > friend AntiEvil; > }; > > #endif diff -rN old-psi1a/src/options/opt_antievil.cpp new-psi1a/src/options/opt_antievil.cpp 0a1,80 > #include "opt_antievil.h" > > #include "antievil.h" > #include "psioptions.h" > #include "ui_opt_antievil.h" > > #include > #include > > class OptAntiEvilUI : public QWidget, public Ui::OptAntiEvil > { > public: > OptAntiEvilUI() : QWidget() { setupUi(this); } > }; > > //---------------------------------------------------------------------------- > // OptionsTabAntiEvil > //---------------------------------------------------------------------------- > > OptionsTabAntiEvil::OptionsTabAntiEvil(QObject *parent) > : OptionsTab(parent, "antievil", "", tr("AntiEvil"), tr("Anti evil scanner"), "psi/advanced") > { > w = 0; > } > > OptionsTabAntiEvil::~OptionsTabAntiEvil() > { > } > > QWidget *OptionsTabAntiEvil::widget() > { > if ( w ) > return 0; > > w = new OptAntiEvilUI(); > OptAntiEvilUI *d = (OptAntiEvilUI *)w; > > QWhatsThis::add(d->ck_enable, > tr("Check this option to protect you Psi from evil stanzas.")); > > > const AntiEvil::Stats *s = AntiEvil::stats(); > d->lb_statsScanned->setNum(s->scanned); > if (s->blocked) { > blockedNext(s->blocked, s->lastBlockedFrom, s->lastBlockedTime) > } > > connect(AntiEvil::stats(), SIGNAL(scannedNext(int)), d->lb_statsScanned, SLOT(setNum(int))); > connect(AntiEvil::stats(), SIGNAL(blockedNext(int, QString, QDateTime)), this, SLOT(blockedNext(int, QString, QDateTime))); > > return w; > } > > void OptionsTabAntiEvil::applyOptions(Options *opt) > { > if ( !w ) > return; > > OptAntiEvilUI *d = (OptAntiEvilUI *)w; > > PsiOptions::instance()->setOption("options.anti-evil.enable" ,d->ck_enable->isChecked()); > } > > void OptionsTabAntiEvil::restoreOptions(const Options *opt) > { > if ( !w ) > return; > > OptAntiEvilUI *d = (OptAntiEvilUI *)w; > > d->ck_enable->setChecked(PsiOptions::instance()->getOption("options.anti-evil.enable").toBool()); > } > > void OptionsTabAntiEvil::blockedNext(int n, const QString &j, const QDateTime &dt) > { > OptAntiEvilUI *d = (OptAntiEvilUI *)w; > d->lb_statsBlocked->setNum(n); > d->lb_lastFrom->setText(j); > d->lb_lastTime->setText(dt.toString(Qt::TextDate)); > } diff -rN old-psi1a/src/options/opt_antievil.h new-psi1a/src/options/opt_antievil.h 0a1,28 > #ifndef OPT_ANTIEVIL_H > #define OPT_ANTIEVIL_H > > #include "optionstab.h" > #include > > class QWidget; > struct Options; > > class OptionsTabAntiEvil : public OptionsTab > { > Q_OBJECT > public: > OptionsTabAntiEvil(QObject *parent); > ~OptionsTabAntiEvil(); > > QWidget *widget(); > void applyOptions(Options *opt); > void restoreOptions(const Options *opt); > > private: > QWidget *w; > > private slots: > void blockedNext(int, const QString&, const QDateTime&); > }; > > #endif diff -rN old-psi1a/src/options/opt_antievil.ui new-psi1a/src/options/opt_antievil.ui 0a1,135 > > OptAntiEvil > > > > 0 > 0 > 295 > 255 > > > > OptAntiEvil > > > > 9 > > > 6 > > > > > Protect me from evil > > > > > > > Stats > > > > 9 > > > 6 > > > > > 0 > > > > > > > 0 > > > > > > > Evil stanzas blocked: > > > > > > > Stanzas scanned: > > > > > > > > > > Last evil stanza > > > > 9 > > > 6 > > > > > - > > > > > > > - > > > > > > > Time: > > > > > > > From: > > > > > > > > > > Qt::Vertical > > > > 20 > 40 > > > > > > > > ck_enable > > > > diff -rN old-psi1a/src/options/options.pri new-psi1a/src/options/options.pri 63a64,69 > psi_antievil { > INTERFACES += $$PWD/opt_antievil.ui > SOURCES += $$PWD/opt_antievil.cpp > HEADERS += $$PWD/opt_antievil.h > } > diff -rN old-psi1a/src/options/optionsdlg.cpp new-psi1a/src/options/optionsdlg.cpp 36a37,40 > #ifdef PSI_ANTIEVIL > #include "opt_antievil.h" > #endif > 329a334,336 > #ifdef PSI_ANTIEVIL > tabs.append( new OptionsTabAntiEvil(this) ); > #endif diff -rN old-psi1a/src/psiaccount.cpp new-psi1a/src/psiaccount.cpp 123a124,127 > #ifdef PSI_ANTIEVIL > #include "antievil.h" > #endif > 512a517,520 > #ifdef PSI_ANTIEVIL > new AntiEvil(d->client->rootTask()); > #endif > diff -rN old-psi1a/src/src.pri new-psi1a/src/src.pri 397a398,405 > # AntiEvil > CONFIG += psi_antievil > psi_antievil { > DEFINES += PSI_ANTIEVIL > HEADERS += $$PWD/antievil.h > SOURCES += $$PWD/antievil.cpp > } >