-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ruslan Nigmatullin
committed
Mar 24, 2012
1 parent
adad27d
commit 8bf9e59
Showing
6 changed files
with
264 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/**************************************************************************** | ||
** | ||
** Jreen | ||
** | ||
** Copyright © 2012 Ruslan Nigmatullin <euroelessar@yandex.ru> | ||
** | ||
***************************************************************************** | ||
** | ||
** $JREEN_BEGIN_LICENSE$ | ||
** 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 General Public License for more details. | ||
** | ||
** You should have received a copy of the GNU General Public License | ||
** along with this program. If not, see http://www.gnu.org/licenses/. | ||
** $JREEN_END_LICENSE$ | ||
** | ||
****************************************************************************/ | ||
|
||
#include "captcha.h" | ||
|
||
namespace Jreen { | ||
|
||
class CaptchaPrivate | ||
{ | ||
public: | ||
DataForm::Ptr form; | ||
}; | ||
|
||
Captcha::Captcha(DataForm::Ptr form) : d_ptr(new CaptchaPrivate) | ||
{ | ||
d_func()->form = form; | ||
} | ||
|
||
Captcha::~Captcha() | ||
{ | ||
} | ||
|
||
DataForm::Ptr Captcha::form() const | ||
{ | ||
return d_func()->form; | ||
} | ||
|
||
void Captcha::setForm(const DataForm::Ptr &form) | ||
{ | ||
d_func()->form = form; | ||
} | ||
|
||
} // namespace Jreen |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/**************************************************************************** | ||
** | ||
** Jreen | ||
** | ||
** Copyright © 2012 Ruslan Nigmatullin <euroelessar@yandex.ru> | ||
** | ||
***************************************************************************** | ||
** | ||
** $JREEN_BEGIN_LICENSE$ | ||
** 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 General Public License for more details. | ||
** | ||
** You should have received a copy of the GNU General Public License | ||
** along with this program. If not, see http://www.gnu.org/licenses/. | ||
** $JREEN_END_LICENSE$ | ||
** | ||
****************************************************************************/ | ||
|
||
#ifndef JREEN_CAPTCHA_H | ||
#define JREEN_CAPTCHA_H | ||
|
||
#include "dataform.h" | ||
|
||
namespace Jreen { | ||
|
||
class CaptchaPrivate; | ||
|
||
class JREEN_EXPORT Captcha : public Payload | ||
{ | ||
J_PAYLOAD(Jreen::Captcha) | ||
Q_DECLARE_PRIVATE(Captcha) | ||
public: | ||
Captcha(DataForm::Ptr form = DataForm::Ptr()); | ||
~Captcha(); | ||
|
||
DataForm::Ptr form() const; | ||
void setForm(const DataForm::Ptr &form); | ||
|
||
private: | ||
QScopedPointer<CaptchaPrivate> d_ptr; | ||
}; | ||
|
||
} // namespace Jreen | ||
|
||
#endif // JREEN_CAPTCHA_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/**************************************************************************** | ||
** | ||
** Jreen | ||
** | ||
** Copyright © 2012 Ruslan Nigmatullin <euroelessar@yandex.ru> | ||
** | ||
***************************************************************************** | ||
** | ||
** $JREEN_BEGIN_LICENSE$ | ||
** 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 General Public License for more details. | ||
** | ||
** You should have received a copy of the GNU General Public License | ||
** along with this program. If not, see http://www.gnu.org/licenses/. | ||
** $JREEN_END_LICENSE$ | ||
** | ||
****************************************************************************/ | ||
|
||
#include "captchafactory_p.h" | ||
|
||
#define NS_CAPTCHA QLatin1String("urn:xmpp:captcha") | ||
|
||
namespace Jreen { | ||
|
||
CaptchaFactory::CaptchaFactory() : m_depth(0), m_atFactory(0) | ||
{ | ||
} | ||
|
||
QStringList CaptchaFactory::features() const | ||
{ | ||
return QStringList(); | ||
} | ||
|
||
bool CaptchaFactory::canParse(const QStringRef &name, const QStringRef &uri, const QXmlStreamAttributes &attributes) | ||
{ | ||
Q_UNUSED(attributes); | ||
return name == QLatin1String("captcha") && uri == NS_CAPTCHA; | ||
} | ||
|
||
void CaptchaFactory::handleStartElement(const QStringRef &name, const QStringRef &uri, const QXmlStreamAttributes &attributes) | ||
{ | ||
++m_depth; | ||
|
||
if (m_depth == 1) | ||
m_captcha.reset(new Captcha); | ||
else if (m_depth == 2 && m_factory.canParse(name, uri, attributes)) | ||
m_atFactory = true; | ||
|
||
if (m_atFactory) | ||
m_factory.handleStartElement(name, uri, attributes); | ||
} | ||
|
||
void CaptchaFactory::handleEndElement(const QStringRef &name, const QStringRef &uri) | ||
{ | ||
if (m_atFactory) { | ||
m_factory.handleEndElement(name, uri); | ||
if (m_depth == 2) { | ||
DataForm::Ptr form = m_factory.createPayload().staticCast<DataForm>(); | ||
if (form->typeName() == NS_CAPTCHA) | ||
m_captcha->setForm(form); | ||
m_atFactory = false; | ||
} | ||
} | ||
|
||
--m_depth; | ||
} | ||
|
||
void CaptchaFactory::handleCharacterData(const QStringRef &text) | ||
{ | ||
if (m_atFactory) | ||
m_factory.handleCharacterData(text); | ||
} | ||
|
||
void CaptchaFactory::serialize(Payload *extension, QXmlStreamWriter *writer) | ||
{ | ||
Captcha *captcha = payload_cast<Captcha*>(extension); | ||
writer->writeStartElement(QLatin1String("captcha")); | ||
writer->writeDefaultNamespace(NS_CAPTCHA); | ||
if (captcha->form()) | ||
m_factory.serialize(captcha->form().data(), writer); | ||
writer->writeEndElement(); | ||
} | ||
|
||
Payload::Ptr CaptchaFactory::createPayload() | ||
{ | ||
return Payload::Ptr(m_captcha.take()); | ||
} | ||
|
||
} // namespace Jreen |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/**************************************************************************** | ||
** | ||
** Jreen | ||
** | ||
** Copyright © 2012 Ruslan Nigmatullin <euroelessar@yandex.ru> | ||
** | ||
***************************************************************************** | ||
** | ||
** $JREEN_BEGIN_LICENSE$ | ||
** 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 General Public License for more details. | ||
** | ||
** You should have received a copy of the GNU General Public License | ||
** along with this program. If not, see http://www.gnu.org/licenses/. | ||
** $JREEN_END_LICENSE$ | ||
** | ||
****************************************************************************/ | ||
|
||
#ifndef JREEN_CAPTCHAFACTORY_P_H | ||
#define JREEN_CAPTCHAFACTORY_P_H | ||
|
||
#include "captcha.h" | ||
#include "dataformfactory_p.h" | ||
|
||
namespace Jreen { | ||
|
||
class JREEN_AUTOTEST_EXPORT CaptchaFactory : public PayloadFactory<Captcha> | ||
{ | ||
public: | ||
CaptchaFactory(); | ||
|
||
QStringList features() const; | ||
bool canParse(const QStringRef &name, const QStringRef &uri, const QXmlStreamAttributes &attributes); | ||
void handleStartElement(const QStringRef &name, const QStringRef &uri, const QXmlStreamAttributes &attributes); | ||
void handleEndElement(const QStringRef &name, const QStringRef &uri); | ||
void handleCharacterData(const QStringRef &text); | ||
void serialize(Payload *extension, QXmlStreamWriter *writer); | ||
Payload::Ptr createPayload(); | ||
|
||
private: | ||
int m_depth : 31; | ||
int m_atFactory : 1; | ||
DataFormFactory m_factory; | ||
QScopedPointer<Captcha> m_captcha; | ||
}; | ||
|
||
} // namespace Jreen | ||
|
||
#endif // JREEN_CAPTCHAFACTORY_P_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters