summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Parser/PayloadParsers')
-rw-r--r--Swiften/Parser/PayloadParsers/BlockParser.h3
-rw-r--r--Swiften/Parser/PayloadParsers/BytestreamsParser.h2
-rw-r--r--Swiften/Parser/PayloadParsers/FormParser.cpp155
-rw-r--r--Swiften/Parser/PayloadParsers/FormParser.h86
-rw-r--r--Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp16
-rw-r--r--Swiften/Parser/PayloadParsers/IBBParser.h2
-rw-r--r--Swiften/Parser/PayloadParsers/IdleParser.cpp32
-rw-r--r--Swiften/Parser/PayloadParsers/IdleParser.h24
-rw-r--r--Swiften/Parser/PayloadParsers/InBandRegistrationPayloadParser.h2
-rw-r--r--Swiften/Parser/PayloadParsers/JingleFileTransferDescriptionParser.h2
-rw-r--r--Swiften/Parser/PayloadParsers/JingleIBBTransportMethodPayloadParser.cpp15
-rw-r--r--Swiften/Parser/PayloadParsers/JingleParser.h2
-rw-r--r--Swiften/Parser/PayloadParsers/MUCInvitationPayloadParser.cpp1
-rw-r--r--Swiften/Parser/PayloadParsers/PubSubAffiliationParser.cpp64
-rw-r--r--Swiften/Parser/PayloadParsers/PubSubAffiliationParser.h34
-rw-r--r--Swiften/Parser/PayloadParsers/PubSubAffiliationsParser.cpp65
-rw-r--r--Swiften/Parser/PayloadParsers/PubSubAffiliationsParser.h34
-rw-r--r--Swiften/Parser/PayloadParsers/PubSubConfigureParser.cpp61
-rw-r--r--Swiften/Parser/PayloadParsers/PubSubConfigureParser.h34
-rw-r--r--Swiften/Parser/PayloadParsers/PubSubCreateParser.cpp59
-rw-r--r--Swiften/Parser/PayloadParsers/PubSubCreateParser.h34
-rw-r--r--Swiften/Parser/PayloadParsers/PubSubDefaultParser.cpp64
-rw-r--r--Swiften/Parser/PayloadParsers/PubSubDefaultParser.h34
-rw-r--r--Swiften/Parser/PayloadParsers/PubSubErrorParser.cpp104
-rw-r--r--Swiften/Parser/PayloadParsers/PubSubErrorParser.h35
-rw-r--r--Swiften/Parser/PayloadParsers/PubSubErrorParserFactory.cpp12
-rw-r--r--Swiften/Parser/PayloadParsers/PubSubErrorParserFactory.h29
-rw-r--r--Swiften/Parser/PayloadParsers/PubSubEventAssociateParser.cpp59
-rw-r--r--Swiften/Parser/PayloadParsers/PubSubEventAssociateParser.h34
-rw-r--r--Swiften/Parser/PayloadParsers/PubSubEventCollectionParser.cpp72
-rw-r--r--Swiften/Parser/PayloadParsers/PubSubEventCollectionParser.h34
-rw-r--r--Swiften/Parser/PayloadParsers/PubSubEventConfigurationParser.cpp65
-rw-r--r--Swiften/Parser/PayloadParsers/PubSubEventConfigurationParser.h34
-rw-r--r--Swiften/Parser/PayloadParsers/PubSubEventDeleteParser.cpp65
-rw-r--r--Swiften/Parser/PayloadParsers/PubSubEventDeleteParser.h34
-rw-r--r--Swiften/Parser/PayloadParsers/PubSubEventDisassociateParser.cpp59
-rw-r--r--Swiften/Parser/PayloadParsers/PubSubEventDisassociateParser.h34
-rw-r--r--Swiften/Parser/PayloadParsers/PubSubEventItemParser.cpp69
-rw-r--r--Swiften/Parser/PayloadParsers/PubSubEventItemParser.h34
-rw-r--r--Swiften/Parser/PayloadParsers/PubSubEventItemsParser.cpp72
-rw-r--r--Swiften/Parser/PayloadParsers/PubSubEventItemsParser.h34
-rw-r--r--Swiften/Parser/PayloadParsers/PubSubEventParser.cpp81
-rw-r--r--Swiften/Parser/PayloadParsers/PubSubEventParser.h34
-rw-r--r--Swiften/Parser/PayloadParsers/PubSubEventPurgeParser.cpp59
-rw-r--r--Swiften/Parser/PayloadParsers/PubSubEventPurgeParser.h34
-rw-r--r--Swiften/Parser/PayloadParsers/PubSubEventRedirectParser.cpp59
-rw-r--r--Swiften/Parser/PayloadParsers/PubSubEventRedirectParser.h34
-rw-r--r--Swiften/Parser/PayloadParsers/PubSubEventRetractParser.cpp59
-rw-r--r--Swiften/Parser/PayloadParsers/PubSubEventRetractParser.h34
-rw-r--r--Swiften/Parser/PayloadParsers/PubSubEventSubscriptionParser.cpp76
-rw-r--r--Swiften/Parser/PayloadParsers/PubSubEventSubscriptionParser.h34
-rw-r--r--Swiften/Parser/PayloadParsers/PubSubItemParser.cpp63
-rw-r--r--Swiften/Parser/PayloadParsers/PubSubItemParser.h34
-rw-r--r--Swiften/Parser/PayloadParsers/PubSubItemsParser.cpp75
-rw-r--r--Swiften/Parser/PayloadParsers/PubSubItemsParser.h34
-rw-r--r--Swiften/Parser/PayloadParsers/PubSubOptionsParser.cpp73
-rw-r--r--Swiften/Parser/PayloadParsers/PubSubOptionsParser.h34
-rw-r--r--Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationParser.cpp66
-rw-r--r--Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationParser.h34
-rw-r--r--Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationsParser.cpp65
-rw-r--r--Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationsParser.h34
-rw-r--r--Swiften/Parser/PayloadParsers/PubSubOwnerConfigureParser.cpp65
-rw-r--r--Swiften/Parser/PayloadParsers/PubSubOwnerConfigureParser.h34
-rw-r--r--Swiften/Parser/PayloadParsers/PubSubOwnerDefaultParser.cpp61
-rw-r--r--Swiften/Parser/PayloadParsers/PubSubOwnerDefaultParser.h34
-rw-r--r--Swiften/Parser/PayloadParsers/PubSubOwnerDeleteParser.cpp65
-rw-r--r--Swiften/Parser/PayloadParsers/PubSubOwnerDeleteParser.h34
-rw-r--r--Swiften/Parser/PayloadParsers/PubSubOwnerPubSubParser.cpp81
-rw-r--r--Swiften/Parser/PayloadParsers/PubSubOwnerPubSubParser.h34
-rw-r--r--Swiften/Parser/PayloadParsers/PubSubOwnerPurgeParser.cpp59
-rw-r--r--Swiften/Parser/PayloadParsers/PubSubOwnerPurgeParser.h34
-rw-r--r--Swiften/Parser/PayloadParsers/PubSubOwnerRedirectParser.cpp59
-rw-r--r--Swiften/Parser/PayloadParsers/PubSubOwnerRedirectParser.h34
-rw-r--r--Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionParser.cpp66
-rw-r--r--Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionParser.h34
-rw-r--r--Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionsParser.cpp65
-rw-r--r--Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionsParser.h34
-rw-r--r--Swiften/Parser/PayloadParsers/PubSubParser.cpp125
-rw-r--r--Swiften/Parser/PayloadParsers/PubSubParser.h38
-rw-r--r--Swiften/Parser/PayloadParsers/PubSubPublishParser.cpp65
-rw-r--r--Swiften/Parser/PayloadParsers/PubSubPublishParser.h34
-rw-r--r--Swiften/Parser/PayloadParsers/PubSubRetractParser.cpp68
-rw-r--r--Swiften/Parser/PayloadParsers/PubSubRetractParser.h34
-rw-r--r--Swiften/Parser/PayloadParsers/PubSubSubscribeOptionsParser.cpp57
-rw-r--r--Swiften/Parser/PayloadParsers/PubSubSubscribeOptionsParser.h34
-rw-r--r--Swiften/Parser/PayloadParsers/PubSubSubscribeParser.cpp64
-rw-r--r--Swiften/Parser/PayloadParsers/PubSubSubscribeParser.h34
-rw-r--r--Swiften/Parser/PayloadParsers/PubSubSubscriptionParser.cpp79
-rw-r--r--Swiften/Parser/PayloadParsers/PubSubSubscriptionParser.h34
-rw-r--r--Swiften/Parser/PayloadParsers/PubSubSubscriptionsParser.cpp65
-rw-r--r--Swiften/Parser/PayloadParsers/PubSubSubscriptionsParser.h34
-rw-r--r--Swiften/Parser/PayloadParsers/PubSubUnsubscribeParser.cpp67
-rw-r--r--Swiften/Parser/PayloadParsers/PubSubUnsubscribeParser.h34
-rw-r--r--Swiften/Parser/PayloadParsers/SearchPayloadParser.h2
-rw-r--r--Swiften/Parser/PayloadParsers/StreamInitiationFileInfoParser.cpp2
-rw-r--r--Swiften/Parser/PayloadParsers/StreamInitiationParser.cpp8
-rw-r--r--Swiften/Parser/PayloadParsers/StreamInitiationParser.h2
-rw-r--r--Swiften/Parser/PayloadParsers/UnitTest/BlockParserTest.cpp72
-rw-r--r--Swiften/Parser/PayloadParsers/UnitTest/FormParserTest.cpp53
-rw-r--r--Swiften/Parser/PayloadParsers/UnitTest/IdleParserTest.cpp38
-rw-r--r--Swiften/Parser/PayloadParsers/UnitTest/JingleParserTest.cpp8
-rw-r--r--Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h8
-rw-r--r--Swiften/Parser/PayloadParsers/UnitTest/SearchPayloadParserTest.cpp18
-rw-r--r--Swiften/Parser/PayloadParsers/UnitTest/VCardParserTest.cpp98
-rw-r--r--Swiften/Parser/PayloadParsers/UserLocationParser.cpp106
-rw-r--r--Swiften/Parser/PayloadParsers/UserLocationParser.h31
-rw-r--r--Swiften/Parser/PayloadParsers/VCardParser.cpp168
-rw-r--r--Swiften/Parser/PayloadParsers/VCardParser.h4
-rw-r--r--Swiften/Parser/PayloadParsers/WhiteboardParser.cpp8
109 files changed, 4776 insertions, 229 deletions
diff --git a/Swiften/Parser/PayloadParsers/BlockParser.h b/Swiften/Parser/PayloadParsers/BlockParser.h
index cd727ad..6ee47a2 100644
--- a/Swiften/Parser/PayloadParsers/BlockParser.h
+++ b/Swiften/Parser/PayloadParsers/BlockParser.h
@@ -7,13 +7,14 @@
#pragma once
#include <Swiften/Elements/Nickname.h>
+#include <Swiften/JID/JID.h>
#include <Swiften/Parser/GenericPayloadParser.h>
namespace Swift {
template<typename BLOCK_ELEMENT>
class BlockParser : public GenericPayloadParser<BLOCK_ELEMENT> {
public:
- BlockParser() : GenericPayloadParser<BLOCK_ELEMENT>() {
+ BlockParser() : GenericPayloadParser<BLOCK_ELEMENT>(), level(0) {
}
virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) {
diff --git a/Swiften/Parser/PayloadParsers/BytestreamsParser.h b/Swiften/Parser/PayloadParsers/BytestreamsParser.h
index 4785913..5c151c2 100644
--- a/Swiften/Parser/PayloadParsers/BytestreamsParser.h
+++ b/Swiften/Parser/PayloadParsers/BytestreamsParser.h
@@ -24,7 +24,7 @@ namespace Swift {
private:
enum Level {
TopLevel = 0,
- PayloadLevel = 1,
+ PayloadLevel = 1
};
int level;
};
diff --git a/Swiften/Parser/PayloadParsers/FormParser.cpp b/Swiften/Parser/PayloadParsers/FormParser.cpp
index 2df0a85..7c29189 100644
--- a/Swiften/Parser/PayloadParsers/FormParser.cpp
+++ b/Swiften/Parser/PayloadParsers/FormParser.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010 Remko Tronçon
+ * Copyright (c) 2010-2013 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
@@ -10,7 +10,7 @@
namespace Swift {
-FormParser::FormParser() : level_(TopLevel), parsingItem_(false), parsingReported_(false) {
+FormParser::FormParser() : level_(TopLevel), parsingItem_(false), parsingReported_(false), parsingOption_(false) {
}
void FormParser::handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) {
@@ -36,67 +36,62 @@ void FormParser::handleStartElement(const std::string& element, const std::strin
else if (element == "instructions") {
currentText_.clear();
}
- else if (element == "field") {
- std::string type;
- FormField::ref correspondingReportedField;
- if (!parsingItem_) {
- type = attributes.getAttribute("type");
- } else {
- foreach(FormField::ref field, getPayloadInternal()->getReportedFields()) {
- if (field->getName() == attributes.getAttribute("var")) {
- correspondingReportedField = field;
- break;
- }
- }
- }
- if (type == "boolean" || boost::dynamic_pointer_cast<BooleanFormField>(correspondingReportedField)) {
- currentFieldParseHelper_ = BooleanFormFieldParseHelper::create();
- }
- else if (type == "fixed" || boost::dynamic_pointer_cast<FixedFormField>(correspondingReportedField)) {
- currentFieldParseHelper_ = FixedFormFieldParseHelper::create();
+ else if (element == "reported") {
+ parsingReported_ = true;
+ }
+ else if (element == "item") {
+ parsingItem_ = true;
+ }
+ }
+ else if (level_ == FieldLevel && currentField_) {
+ currentText_.clear();
+ if (element == "option") {
+ currentOptionLabel_ = attributes.getAttribute("label");
+ currentOptionValue_ = "";
+ parsingOption_ = true;
+ }
+ }
+ if (level_ >= PayloadLevel) {
+ if (element == "field") {
+ currentField_ = boost::make_shared<FormField>();
+ std::string type = attributes.getAttribute("type");
+ FormField::Type fieldType = FormField::UnknownType;
+ if (type == "boolean") {
+ fieldType = FormField::BooleanType;
}
- else if (type == "hidden" || boost::dynamic_pointer_cast<HiddenFormField>(correspondingReportedField)) {
- currentFieldParseHelper_ = HiddenFormFieldParseHelper::create();
+ if (type == "fixed") {
+ fieldType = FormField::FixedType;
}
- else if (type == "jid-multi" || boost::dynamic_pointer_cast<JIDMultiFormField>(correspondingReportedField)) {
- currentFieldParseHelper_ = JIDMultiFormFieldParseHelper::create();
+ if (type == "hidden") {
+ fieldType = FormField::HiddenType;
}
- else if (type == "jid-single" || boost::dynamic_pointer_cast<JIDSingleFormField>(correspondingReportedField)) {
- currentFieldParseHelper_ = JIDSingleFormFieldParseHelper::create();
+ if (type == "list-single") {
+ fieldType = FormField::ListSingleType;
}
- else if (type == "list-multi" || boost::dynamic_pointer_cast<ListMultiFormField>(correspondingReportedField)) {
- currentFieldParseHelper_ = ListMultiFormFieldParseHelper::create();
+ if (type == "text-multi") {
+ fieldType = FormField::TextMultiType;
}
- else if (type == "list-single" || boost::dynamic_pointer_cast<ListSingleFormField>(correspondingReportedField)) {
- currentFieldParseHelper_ = ListSingleFormFieldParseHelper::create();
+ if (type == "text-private") {
+ fieldType = FormField::TextPrivateType;
}
- else if (type == "text-multi" || boost::dynamic_pointer_cast<TextMultiFormField>(correspondingReportedField)) {
- currentFieldParseHelper_ = TextMultiFormFieldParseHelper::create();
+ if (type == "text-single") {
+ fieldType = FormField::TextSingleType;
}
- else if (type == "text-private" || boost::dynamic_pointer_cast<TextPrivateFormField>(correspondingReportedField)) {
- currentFieldParseHelper_ = TextPrivateFormFieldParseHelper::create();
+ if (type == "jid-single") {
+ fieldType = FormField::JIDSingleType;
}
- else /*if (type == "text-single") || undefined */ {
- currentFieldParseHelper_ = TextSingleFormFieldParseHelper::create();
+ if (type == "jid-multi") {
+ fieldType = FormField::JIDMultiType;
}
- if (currentFieldParseHelper_) {
- currentFieldParseHelper_->getField()->setName(attributes.getAttribute("var"));
- currentFieldParseHelper_->getField()->setLabel(attributes.getAttribute("label"));
+ if (type == "list-multi") {
+ fieldType = FormField::ListMultiType;
}
+ currentField_->setType(fieldType);
+ currentField_->setName(attributes.getAttribute("var"));
+ currentField_->setLabel(attributes.getAttribute("label"));
}
- else if (element == "reported") {
- parsingReported_ = true;
- level_ = PayloadLevel - 1;
- }
- else if (element == "item") {
- parsingItem_ = true;
- level_ = PayloadLevel - 1;
- }
- }
- else if (level_ == FieldLevel && currentFieldParseHelper_) {
- currentText_.clear();
- if (element == "option") {
- currentOptionLabel_ = attributes.getAttribute("label");
+ else if (element == "value") {
+ currentText_.clear();
}
}
++level_;
@@ -123,42 +118,48 @@ void FormParser::handleEndElement(const std::string& element, const std::string&
getPayloadInternal()->setInstructions(currentInstructions + "\n" + currentText_);
}
}
- else if (element == "field") {
- if (currentFieldParseHelper_) {
- if (parsingReported_) {
- getPayloadInternal()->addReportedField(currentFieldParseHelper_->getField());
- } else if (parsingItem_) {
- currentFields_.push_back(currentFieldParseHelper_->getField());
- } else {
- getPayloadInternal()->addField(currentFieldParseHelper_->getField());
- }
- currentFieldParseHelper_.reset();
- }
+ else if (element == "reported") {
+ parsingReported_ = false;
+ }
+ else if (element == "item") {
+ parsingItem_ = false;
+ getPayloadInternal()->addItem(currentFields_);
+ currentFields_.clear();
}
}
- else if (level_ == FieldLevel && currentFieldParseHelper_) {
+ else if (currentField_) {
if (element == "required") {
- currentFieldParseHelper_->getField()->setRequired(true);
+ currentField_->setRequired(true);
}
else if (element == "desc") {
- currentFieldParseHelper_->getField()->setDescription(currentText_);
+ currentField_->setDescription(currentText_);
}
else if (element == "option") {
- currentFieldParseHelper_->getField()->addOption(FormField::Option(currentOptionLabel_, currentText_));
+ currentField_->addOption(FormField::Option(currentOptionLabel_, currentOptionValue_));
+ parsingOption_ = false;
}
else if (element == "value") {
- currentFieldParseHelper_->addValue(currentText_);
+ if (parsingOption_) {
+ currentOptionValue_ = currentText_;
+ }
+ else {
+ currentField_->addValue(currentText_);
+ }
}
}
- if (element == "reported") {
- parsingReported_ = false;
- level_++;
- }
- else if (element == "item") {
- parsingItem_ = false;
- level_++;
- getPayloadInternal()->addItem(currentFields_);
- currentFields_.clear();
+ if (level_ >= PayloadLevel && currentField_) {
+ if (element == "field") {
+ if (parsingReported_) {
+ getPayloadInternal()->addReportedField(currentField_);
+ }
+ else if (parsingItem_) {
+ currentFields_.push_back(currentField_);
+ }
+ else {
+ getPayloadInternal()->addField(currentField_);
+ }
+ currentField_.reset();
+ }
}
}
diff --git a/Swiften/Parser/PayloadParsers/FormParser.h b/Swiften/Parser/PayloadParsers/FormParser.h
index a3e2524..0b23a81 100644
--- a/Swiften/Parser/PayloadParsers/FormParser.h
+++ b/Swiften/Parser/PayloadParsers/FormParser.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010 Remko Tronçon
+ * Copyright (c) 2010-2013 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
@@ -18,86 +18,6 @@ namespace Swift {
virtual void handleEndElement(const std::string& element, const std::string&);
virtual void handleCharacterData(const std::string& data);
- private:
- class FieldParseHelper {
- public:
- virtual ~FieldParseHelper() {}
- virtual void addValue(const std::string&) = 0;
- virtual boost::shared_ptr<FormField> getField() const {
- return field;
- }
- protected:
- boost::shared_ptr<FormField> field;
- };
- class BoolFieldParseHelper : public FieldParseHelper {
- virtual void addValue(const std::string& s) {
- boost::dynamic_pointer_cast< GenericFormField<bool> >(getField())->setValue(s == "1" || s == "true");
- getField()->addRawValue(s);
- }
- };
- class StringFieldParseHelper : public FieldParseHelper {
- virtual void addValue(const std::string& s) {
- boost::shared_ptr<GenericFormField<std::string> > field = boost::dynamic_pointer_cast< GenericFormField<std::string> >(getField());
- if (field->getValue().empty()) {
- field->setValue(s);
- }
- else {
- field->setValue(field->getValue() + "\n" + s);
- }
- getField()->addRawValue(s);
- }
- };
- class JIDFieldParseHelper : public FieldParseHelper {
- virtual void addValue(const std::string& s) {
- getField()->addRawValue(s);
- boost::dynamic_pointer_cast< GenericFormField<JID> >(getField())->setValue(JID(s));
- }
- };
- class StringListFieldParseHelper : public FieldParseHelper {
- virtual void addValue(const std::string& s) {
- // FIXME: Inefficient, but too much hassle to do efficiently
- boost::shared_ptr<GenericFormField< std::vector<std::string> > > field = boost::dynamic_pointer_cast< GenericFormField<std::vector<std::string > > >(getField());
- std::vector<std::string> l = field->getValue();
- l.push_back(s);
- field->setValue(l);
- getField()->addRawValue(s);
- }
- };
- class JIDListFieldParseHelper : public FieldParseHelper {
- virtual void addValue(const std::string& s) {
- // FIXME: Inefficient, but too much hassle to do efficiently
- boost::shared_ptr< GenericFormField< std::vector<JID> > > field = boost::dynamic_pointer_cast< GenericFormField<std::vector<JID > > >(getField());
- std::vector<JID> l = field->getValue();
- l.push_back(JID(s));
- field->setValue(l);
- getField()->addRawValue(s);
- }
- };
-
-#define SWIFTEN_DECLARE_FORM_FIELD_PARSE_HELPER(name, baseParser) \
- class name##FormFieldParseHelper : public baseParser##FieldParseHelper { \
- public: \
- typedef boost::shared_ptr<name##FormFieldParseHelper> ref; \
- static ref create() { \
- return ref(new name##FormFieldParseHelper()); \
- } \
- private: \
- name##FormFieldParseHelper() : baseParser##FieldParseHelper() { \
- field = name##FormField::create(); \
- } \
- };
-
- SWIFTEN_DECLARE_FORM_FIELD_PARSE_HELPER(Boolean, Bool);
- SWIFTEN_DECLARE_FORM_FIELD_PARSE_HELPER(Fixed, String);
- SWIFTEN_DECLARE_FORM_FIELD_PARSE_HELPER(Hidden, String);
- SWIFTEN_DECLARE_FORM_FIELD_PARSE_HELPER(ListSingle, String);
- SWIFTEN_DECLARE_FORM_FIELD_PARSE_HELPER(TextMulti, String);
- SWIFTEN_DECLARE_FORM_FIELD_PARSE_HELPER(TextPrivate, String);
- SWIFTEN_DECLARE_FORM_FIELD_PARSE_HELPER(TextSingle, String);
- SWIFTEN_DECLARE_FORM_FIELD_PARSE_HELPER(JIDSingle, JID);
- SWIFTEN_DECLARE_FORM_FIELD_PARSE_HELPER(JIDMulti, JIDList);
- SWIFTEN_DECLARE_FORM_FIELD_PARSE_HELPER(ListMulti, StringList);
-
enum Level {
TopLevel = 0,
PayloadLevel = 1,
@@ -106,9 +26,11 @@ namespace Swift {
int level_;
std::string currentText_;
std::string currentOptionLabel_;
- boost::shared_ptr<FieldParseHelper> currentFieldParseHelper_;
+ std::string currentOptionValue_;
bool parsingItem_;
bool parsingReported_;
+ bool parsingOption_;
+ FormField::ref currentField_;
std::vector<FormField::ref> currentFields_;
};
}
diff --git a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp
index a40e8f6..3ec5a7a 100644
--- a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp
+++ b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010-2012 Remko Tronçon
+ * Copyright (c) 2010-2013 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
@@ -10,6 +10,8 @@
#include <Swiften/Elements/UnblockPayload.h>
#include <Swiften/Elements/BlockListPayload.h>
#include <Swiften/Parser/GenericPayloadParser.h>
+#include <Swiften/Parser/GenericPayloadParserFactory.h>
+#include <Swiften/Parser/GenericPayloadParserFactory2.h>
#include <Swiften/Parser/PayloadParserFactory.h>
#include <Swiften/Parser/PayloadParsers/ErrorParser.h>
#include <Swiften/Parser/PayloadParsers/ErrorParserFactory.h>
@@ -67,6 +69,12 @@
#include <Swiften/Parser/PayloadParsers/DeliveryReceiptParserFactory.h>
#include <Swiften/Parser/PayloadParsers/DeliveryReceiptRequestParserFactory.h>
#include <Swiften/Parser/PayloadParsers/WhiteboardParser.h>
+#include <Swiften/Parser/PayloadParsers/IdleParser.h>
+#include <Swiften/Parser/PayloadParsers/PubSubParser.h>
+#include <Swiften/Parser/PayloadParsers/PubSubOwnerPubSubParser.h>
+#include <Swiften/Parser/PayloadParsers/PubSubEventParser.h>
+#include <Swiften/Parser/PayloadParsers/PubSubErrorParserFactory.h>
+#include <Swiften/Parser/PayloadParsers/UserLocationParser.h>
using namespace boost;
@@ -126,8 +134,14 @@ FullPayloadParserFactoryCollection::FullPayloadParserFactoryCollection() {
factories_.push_back(boost::make_shared<GenericPayloadParserFactory<JingleFileTransferHashParser> >("checksum"));
factories_.push_back(boost::make_shared<GenericPayloadParserFactory<S5BProxyRequestParser> >("query", "http://jabber.org/protocol/bytestreams"));
factories_.push_back(boost::make_shared<GenericPayloadParserFactory<WhiteboardParser> >("wb", "http://swift.im/whiteboard"));
+ factories_.push_back(boost::make_shared<GenericPayloadParserFactory<UserLocationParser> >("geoloc", "http://jabber.org/protocol/geoloc"));
factories_.push_back(boost::make_shared<DeliveryReceiptParserFactory>());
factories_.push_back(boost::make_shared<DeliveryReceiptRequestParserFactory>());
+ factories_.push_back(boost::make_shared<GenericPayloadParserFactory<IdleParser> >("idle", "urn:xmpp:idle:1"));
+ factories_.push_back(boost::make_shared<GenericPayloadParserFactory2<PubSubParser> >("pubsub", "http://jabber.org/protocol/pubsub", this));
+ factories_.push_back(boost::make_shared<GenericPayloadParserFactory2<PubSubOwnerPubSubParser> >("pubsub", "http://jabber.org/protocol/pubsub#owner", this));
+ factories_.push_back(boost::make_shared<GenericPayloadParserFactory2<PubSubEventParser> >("event", "http://jabber.org/protocol/pubsub#event", this));
+ factories_.push_back(boost::make_shared<PubSubErrorParserFactory>());
foreach(shared_ptr<PayloadParserFactory> factory, factories_) {
addFactory(factory.get());
diff --git a/Swiften/Parser/PayloadParsers/IBBParser.h b/Swiften/Parser/PayloadParsers/IBBParser.h
index d899475..59011b4 100644
--- a/Swiften/Parser/PayloadParsers/IBBParser.h
+++ b/Swiften/Parser/PayloadParsers/IBBParser.h
@@ -23,7 +23,7 @@ namespace Swift {
private:
enum Level {
- TopLevel = 0,
+ TopLevel = 0
};
int level;
std::string currentText;
diff --git a/Swiften/Parser/PayloadParsers/IdleParser.cpp b/Swiften/Parser/PayloadParsers/IdleParser.cpp
new file mode 100644
index 0000000..51aa34b
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/IdleParser.cpp
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2013 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#include <Swiften/Parser/PayloadParsers/IdleParser.h>
+
+#include <Swiften/Base/DateTime.h>
+
+namespace Swift {
+
+IdleParser::IdleParser() : level_(0) {
+}
+
+void IdleParser::handleStartElement(const std::string& /*element*/, const std::string& /*ns*/, const AttributeMap& attributes) {
+ if (level_ == 0) {
+ boost::posix_time::ptime since = stringToDateTime(attributes.getAttribute("since"));
+ getPayloadInternal()->setSince(since);
+ }
+ ++level_;
+}
+
+void IdleParser::handleEndElement(const std::string&, const std::string&) {
+ --level_;
+}
+
+void IdleParser::handleCharacterData(const std::string&) {
+
+}
+
+}
diff --git a/Swiften/Parser/PayloadParsers/IdleParser.h b/Swiften/Parser/PayloadParsers/IdleParser.h
new file mode 100644
index 0000000..38001b2
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/IdleParser.h
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 2013 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Elements/Idle.h>
+#include <Swiften/Parser/GenericPayloadParser.h>
+
+namespace Swift {
+ class IdleParser : public GenericPayloadParser<Idle> {
+ public:
+ IdleParser();
+
+ virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes);
+ virtual void handleEndElement(const std::string& element, const std::string&);
+ virtual void handleCharacterData(const std::string& data);
+
+ private:
+ int level_;
+ };
+}
diff --git a/Swiften/Parser/PayloadParsers/InBandRegistrationPayloadParser.h b/Swiften/Parser/PayloadParsers/InBandRegistrationPayloadParser.h
index ae8d36c..1f85c85 100644
--- a/Swiften/Parser/PayloadParsers/InBandRegistrationPayloadParser.h
+++ b/Swiften/Parser/PayloadParsers/InBandRegistrationPayloadParser.h
@@ -27,7 +27,7 @@ namespace Swift {
private:
enum Level {
TopLevel = 0,
- PayloadLevel = 1,
+ PayloadLevel = 1
};
int level;
FormParserFactory* formParserFactory;
diff --git a/Swiften/Parser/PayloadParsers/JingleFileTransferDescriptionParser.h b/Swiften/Parser/PayloadParsers/JingleFileTransferDescriptionParser.h
index 93560c6..7ea22b4 100644
--- a/Swiften/Parser/PayloadParsers/JingleFileTransferDescriptionParser.h
+++ b/Swiften/Parser/PayloadParsers/JingleFileTransferDescriptionParser.h
@@ -26,7 +26,7 @@ class JingleFileTransferDescriptionParser : public GenericPayloadParser<JingleFi
enum CurrentParseElement {
UnknownElement,
RequestElement,
- OfferElement,
+ OfferElement
};
PayloadParserFactoryCollection* factories;
diff --git a/Swiften/Parser/PayloadParsers/JingleIBBTransportMethodPayloadParser.cpp b/Swiften/Parser/PayloadParsers/JingleIBBTransportMethodPayloadParser.cpp
index a3dfd12..d140368 100644
--- a/Swiften/Parser/PayloadParsers/JingleIBBTransportMethodPayloadParser.cpp
+++ b/Swiften/Parser/PayloadParsers/JingleIBBTransportMethodPayloadParser.cpp
@@ -4,6 +4,12 @@
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
#include <boost/lexical_cast.hpp>
#include <boost/optional.hpp>
@@ -18,9 +24,12 @@ namespace Swift {
void JingleIBBTransportMethodPayloadParser::handleStartElement(const std::string&, const std::string&, const AttributeMap& attributes) {
try {
- getPayloadInternal()->setBlockSize(boost::lexical_cast<int>(attributes.getAttributeValue("block-size").get_value_or("0")));
- } catch (boost::bad_lexical_cast &) {
- getPayloadInternal()->setBlockSize(0);
+ boost::optional<std::string> blockSize = attributes.getAttributeValue("block-size");
+ if (blockSize) {
+ getPayloadInternal()->setBlockSize(boost::lexical_cast<unsigned int>(*blockSize));
+ }
+ }
+ catch (boost::bad_lexical_cast &) {
}
getPayloadInternal()->setSessionID(attributes.getAttributeValue("sid").get_value_or(""));
++level;
diff --git a/Swiften/Parser/PayloadParsers/JingleParser.h b/Swiften/Parser/PayloadParsers/JingleParser.h
index 188ead9..c7bd58c 100644
--- a/Swiften/Parser/PayloadParsers/JingleParser.h
+++ b/Swiften/Parser/PayloadParsers/JingleParser.h
@@ -29,5 +29,5 @@ class JingleParser : public GenericPayloadParser<JinglePayload> {
boost::shared_ptr<PayloadParser> currentPayloadParser;
};
-};
+}
diff --git a/Swiften/Parser/PayloadParsers/MUCInvitationPayloadParser.cpp b/Swiften/Parser/PayloadParsers/MUCInvitationPayloadParser.cpp
index fa95af7..c1cf33d 100644
--- a/Swiften/Parser/PayloadParsers/MUCInvitationPayloadParser.cpp
+++ b/Swiften/Parser/PayloadParsers/MUCInvitationPayloadParser.cpp
@@ -17,6 +17,7 @@ void MUCInvitationPayloadParser::handleTree(ParserElement::ref root) {
invite->setPassword(root->getAttributes().getAttribute("password"));
invite->setReason(root->getAttributes().getAttribute("reason"));
invite->setThread(root->getAttributes().getAttribute("thread"));
+ invite->setIsImpromptu(root->getChild("impromptu", "http://swift.im/impromptu") ? true : false);
}
}
diff --git a/Swiften/Parser/PayloadParsers/PubSubAffiliationParser.cpp b/Swiften/Parser/PayloadParsers/PubSubAffiliationParser.cpp
new file mode 100644
index 0000000..05fa119
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/PubSubAffiliationParser.cpp
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma clang diagnostic ignored "-Wunused-private-field"
+
+#include <Swiften/Parser/PayloadParsers/PubSubAffiliationParser.h>
+
+#include <boost/optional.hpp>
+
+
+#include <Swiften/Parser/PayloadParserFactoryCollection.h>
+#include <Swiften/Parser/PayloadParserFactory.h>
+#include <Swiften/Parser/EnumParser.h>
+
+using namespace Swift;
+
+PubSubAffiliationParser::PubSubAffiliationParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) {
+}
+
+PubSubAffiliationParser::~PubSubAffiliationParser() {
+}
+
+void PubSubAffiliationParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) {
+ if (level == 0) {
+ if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) {
+ getPayloadInternal()->setNode(*attributeValue);
+ }
+ if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("affiliation")) {
+ if (boost::optional<PubSubAffiliation::Type> value = EnumParser<PubSubAffiliation::Type>()(PubSubAffiliation::None, "none")(PubSubAffiliation::Member, "member")(PubSubAffiliation::Outcast, "outcast")(PubSubAffiliation::Owner, "owner")(PubSubAffiliation::Publisher, "publisher")(PubSubAffiliation::PublishOnly, "publish-only").parse(*attributeValue)) {
+ getPayloadInternal()->setType(*value);
+ }
+ }
+ }
+
+
+
+ if (level >= 1 && currentPayloadParser) {
+ currentPayloadParser->handleStartElement(element, ns, attributes);
+ }
+ ++level;
+}
+
+void PubSubAffiliationParser::handleEndElement(const std::string& element, const std::string& ns) {
+ --level;
+ if (currentPayloadParser) {
+ if (level >= 1) {
+ currentPayloadParser->handleEndElement(element, ns);
+ }
+
+ if (level == 1) {
+
+ currentPayloadParser.reset();
+ }
+ }
+}
+
+void PubSubAffiliationParser::handleCharacterData(const std::string& data) {
+ if (level > 1 && currentPayloadParser) {
+ currentPayloadParser->handleCharacterData(data);
+ }
+}
diff --git a/Swiften/Parser/PayloadParsers/PubSubAffiliationParser.h b/Swiften/Parser/PayloadParsers/PubSubAffiliationParser.h
new file mode 100644
index 0000000..43c619d
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/PubSubAffiliationParser.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <boost/shared_ptr.hpp>
+
+#include <Swiften/Base/Override.h>
+#include <Swiften/Base/API.h>
+#include <Swiften/Elements/PubSubAffiliation.h>
+#include <Swiften/Parser/GenericPayloadParser.h>
+
+namespace Swift {
+ class PayloadParserFactoryCollection;
+ class PayloadParser;
+
+ class SWIFTEN_API PubSubAffiliationParser : public GenericPayloadParser<PubSubAffiliation> {
+ public:
+ PubSubAffiliationParser(PayloadParserFactoryCollection* parsers);
+ virtual ~PubSubAffiliationParser();
+
+ virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE;
+ virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE;
+ virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE;
+
+ private:
+ PayloadParserFactoryCollection* parsers;
+ int level;
+ boost::shared_ptr<PayloadParser> currentPayloadParser;
+ };
+}
diff --git a/Swiften/Parser/PayloadParsers/PubSubAffiliationsParser.cpp b/Swiften/Parser/PayloadParsers/PubSubAffiliationsParser.cpp
new file mode 100644
index 0000000..b75e339
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/PubSubAffiliationsParser.cpp
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma clang diagnostic ignored "-Wunused-private-field"
+
+#include <Swiften/Parser/PayloadParsers/PubSubAffiliationsParser.h>
+
+#include <boost/optional.hpp>
+
+
+#include <Swiften/Parser/PayloadParserFactoryCollection.h>
+#include <Swiften/Parser/PayloadParserFactory.h>
+#include <Swiften/Parser/PayloadParsers/PubSubAffiliationParser.h>
+
+using namespace Swift;
+
+PubSubAffiliationsParser::PubSubAffiliationsParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) {
+}
+
+PubSubAffiliationsParser::~PubSubAffiliationsParser() {
+}
+
+void PubSubAffiliationsParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) {
+ if (level == 0) {
+ if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) {
+ getPayloadInternal()->setNode(*attributeValue);
+ }
+ }
+
+ if (level == 1) {
+ if (element == "affiliation" && ns == "http://jabber.org/protocol/pubsub") {
+ currentPayloadParser = boost::make_shared<PubSubAffiliationParser>(parsers);
+ }
+ }
+
+ if (level >= 1 && currentPayloadParser) {
+ currentPayloadParser->handleStartElement(element, ns, attributes);
+ }
+ ++level;
+}
+
+void PubSubAffiliationsParser::handleEndElement(const std::string& element, const std::string& ns) {
+ --level;
+ if (currentPayloadParser) {
+ if (level >= 1) {
+ currentPayloadParser->handleEndElement(element, ns);
+ }
+
+ if (level == 1) {
+ if (element == "affiliation" && ns == "http://jabber.org/protocol/pubsub") {
+ getPayloadInternal()->addAffiliation(boost::dynamic_pointer_cast<PubSubAffiliation>(currentPayloadParser->getPayload()));
+ }
+ currentPayloadParser.reset();
+ }
+ }
+}
+
+void PubSubAffiliationsParser::handleCharacterData(const std::string& data) {
+ if (level > 1 && currentPayloadParser) {
+ currentPayloadParser->handleCharacterData(data);
+ }
+}
diff --git a/Swiften/Parser/PayloadParsers/PubSubAffiliationsParser.h b/Swiften/Parser/PayloadParsers/PubSubAffiliationsParser.h
new file mode 100644
index 0000000..646e7a8
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/PubSubAffiliationsParser.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <boost/shared_ptr.hpp>
+
+#include <Swiften/Base/Override.h>
+#include <Swiften/Base/API.h>
+#include <Swiften/Elements/PubSubAffiliations.h>
+#include <Swiften/Parser/GenericPayloadParser.h>
+
+namespace Swift {
+ class PayloadParserFactoryCollection;
+ class PayloadParser;
+
+ class SWIFTEN_API PubSubAffiliationsParser : public GenericPayloadParser<PubSubAffiliations> {
+ public:
+ PubSubAffiliationsParser(PayloadParserFactoryCollection* parsers);
+ virtual ~PubSubAffiliationsParser();
+
+ virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE;
+ virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE;
+ virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE;
+
+ private:
+ PayloadParserFactoryCollection* parsers;
+ int level;
+ boost::shared_ptr<PayloadParser> currentPayloadParser;
+ };
+}
diff --git a/Swiften/Parser/PayloadParsers/PubSubConfigureParser.cpp b/Swiften/Parser/PayloadParsers/PubSubConfigureParser.cpp
new file mode 100644
index 0000000..773c1c7
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/PubSubConfigureParser.cpp
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma clang diagnostic ignored "-Wunused-private-field"
+
+#include <Swiften/Parser/PayloadParsers/PubSubConfigureParser.h>
+
+#include <boost/optional.hpp>
+
+
+#include <Swiften/Parser/PayloadParserFactoryCollection.h>
+#include <Swiften/Parser/PayloadParserFactory.h>
+#include <Swiften/Parser/PayloadParsers/FormParser.h>
+
+using namespace Swift;
+
+PubSubConfigureParser::PubSubConfigureParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) {
+}
+
+PubSubConfigureParser::~PubSubConfigureParser() {
+}
+
+void PubSubConfigureParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) {
+
+
+ if (level == 1) {
+ if (element == "x" && ns == "jabber:x:data") {
+ currentPayloadParser = boost::make_shared<FormParser>();
+ }
+ }
+
+ if (level >= 1 && currentPayloadParser) {
+ currentPayloadParser->handleStartElement(element, ns, attributes);
+ }
+ ++level;
+}
+
+void PubSubConfigureParser::handleEndElement(const std::string& element, const std::string& ns) {
+ --level;
+ if (currentPayloadParser) {
+ if (level >= 1) {
+ currentPayloadParser->handleEndElement(element, ns);
+ }
+
+ if (level == 1) {
+ if (element == "x" && ns == "jabber:x:data") {
+ getPayloadInternal()->setData(boost::dynamic_pointer_cast<Form>(currentPayloadParser->getPayload()));
+ }
+ currentPayloadParser.reset();
+ }
+ }
+}
+
+void PubSubConfigureParser::handleCharacterData(const std::string& data) {
+ if (level > 1 && currentPayloadParser) {
+ currentPayloadParser->handleCharacterData(data);
+ }
+}
diff --git a/Swiften/Parser/PayloadParsers/PubSubConfigureParser.h b/Swiften/Parser/PayloadParsers/PubSubConfigureParser.h
new file mode 100644
index 0000000..8300140
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/PubSubConfigureParser.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <boost/shared_ptr.hpp>
+
+#include <Swiften/Base/Override.h>
+#include <Swiften/Base/API.h>
+#include <Swiften/Elements/PubSubConfigure.h>
+#include <Swiften/Parser/GenericPayloadParser.h>
+
+namespace Swift {
+ class PayloadParserFactoryCollection;
+ class PayloadParser;
+
+ class SWIFTEN_API PubSubConfigureParser : public GenericPayloadParser<PubSubConfigure> {
+ public:
+ PubSubConfigureParser(PayloadParserFactoryCollection* parsers);
+ virtual ~PubSubConfigureParser();
+
+ virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE;
+ virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE;
+ virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE;
+
+ private:
+ PayloadParserFactoryCollection* parsers;
+ int level;
+ boost::shared_ptr<PayloadParser> currentPayloadParser;
+ };
+}
diff --git a/Swiften/Parser/PayloadParsers/PubSubCreateParser.cpp b/Swiften/Parser/PayloadParsers/PubSubCreateParser.cpp
new file mode 100644
index 0000000..47f35c9
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/PubSubCreateParser.cpp
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma clang diagnostic ignored "-Wunused-private-field"
+
+#include <Swiften/Parser/PayloadParsers/PubSubCreateParser.h>
+
+#include <boost/optional.hpp>
+
+
+#include <Swiften/Parser/PayloadParserFactoryCollection.h>
+#include <Swiften/Parser/PayloadParserFactory.h>
+
+
+using namespace Swift;
+
+PubSubCreateParser::PubSubCreateParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) {
+}
+
+PubSubCreateParser::~PubSubCreateParser() {
+}
+
+void PubSubCreateParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) {
+ if (level == 0) {
+ if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) {
+ getPayloadInternal()->setNode(*attributeValue);
+ }
+ }
+
+
+
+ if (level >= 1 && currentPayloadParser) {
+ currentPayloadParser->handleStartElement(element, ns, attributes);
+ }
+ ++level;
+}
+
+void PubSubCreateParser::handleEndElement(const std::string& element, const std::string& ns) {
+ --level;
+ if (currentPayloadParser) {
+ if (level >= 1) {
+ currentPayloadParser->handleEndElement(element, ns);
+ }
+
+ if (level == 1) {
+
+ currentPayloadParser.reset();
+ }
+ }
+}
+
+void PubSubCreateParser::handleCharacterData(const std::string& data) {
+ if (level > 1 && currentPayloadParser) {
+ currentPayloadParser->handleCharacterData(data);
+ }
+}
diff --git a/Swiften/Parser/PayloadParsers/PubSubCreateParser.h b/Swiften/Parser/PayloadParsers/PubSubCreateParser.h
new file mode 100644
index 0000000..865b8ec
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/PubSubCreateParser.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <boost/shared_ptr.hpp>
+
+#include <Swiften/Base/Override.h>
+#include <Swiften/Base/API.h>
+#include <Swiften/Elements/PubSubCreate.h>
+#include <Swiften/Parser/GenericPayloadParser.h>
+
+namespace Swift {
+ class PayloadParserFactoryCollection;
+ class PayloadParser;
+
+ class SWIFTEN_API PubSubCreateParser : public GenericPayloadParser<PubSubCreate> {
+ public:
+ PubSubCreateParser(PayloadParserFactoryCollection* parsers);
+ virtual ~PubSubCreateParser();
+
+ virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE;
+ virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE;
+ virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE;
+
+ private:
+ PayloadParserFactoryCollection* parsers;
+ int level;
+ boost::shared_ptr<PayloadParser> currentPayloadParser;
+ };
+}
diff --git a/Swiften/Parser/PayloadParsers/PubSubDefaultParser.cpp b/Swiften/Parser/PayloadParsers/PubSubDefaultParser.cpp
new file mode 100644
index 0000000..7a370cd
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/PubSubDefaultParser.cpp
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma clang diagnostic ignored "-Wunused-private-field"
+
+#include <Swiften/Parser/PayloadParsers/PubSubDefaultParser.h>
+
+#include <boost/optional.hpp>
+
+
+#include <Swiften/Parser/PayloadParserFactoryCollection.h>
+#include <Swiften/Parser/PayloadParserFactory.h>
+#include <Swiften/Parser/EnumParser.h>
+
+using namespace Swift;
+
+PubSubDefaultParser::PubSubDefaultParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) {
+}
+
+PubSubDefaultParser::~PubSubDefaultParser() {
+}
+
+void PubSubDefaultParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) {
+ if (level == 0) {
+ if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) {
+ getPayloadInternal()->setNode(*attributeValue);
+ }
+ if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("type")) {
+ if (boost::optional<PubSubDefault::Type> value = EnumParser<PubSubDefault::Type>()(PubSubDefault::None, "none")(PubSubDefault::Collection, "collection")(PubSubDefault::Leaf, "leaf").parse(*attributeValue)) {
+ getPayloadInternal()->setType(*value);
+ }
+ }
+ }
+
+
+
+ if (level >= 1 && currentPayloadParser) {
+ currentPayloadParser->handleStartElement(element, ns, attributes);
+ }
+ ++level;
+}
+
+void PubSubDefaultParser::handleEndElement(const std::string& element, const std::string& ns) {
+ --level;
+ if (currentPayloadParser) {
+ if (level >= 1) {
+ currentPayloadParser->handleEndElement(element, ns);
+ }
+
+ if (level == 1) {
+
+ currentPayloadParser.reset();
+ }
+ }
+}
+
+void PubSubDefaultParser::handleCharacterData(const std::string& data) {
+ if (level > 1 && currentPayloadParser) {
+ currentPayloadParser->handleCharacterData(data);
+ }
+}
diff --git a/Swiften/Parser/PayloadParsers/PubSubDefaultParser.h b/Swiften/Parser/PayloadParsers/PubSubDefaultParser.h
new file mode 100644
index 0000000..7bd8d66
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/PubSubDefaultParser.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <boost/shared_ptr.hpp>
+
+#include <Swiften/Base/Override.h>
+#include <Swiften/Base/API.h>
+#include <Swiften/Elements/PubSubDefault.h>
+#include <Swiften/Parser/GenericPayloadParser.h>
+
+namespace Swift {
+ class PayloadParserFactoryCollection;
+ class PayloadParser;
+
+ class SWIFTEN_API PubSubDefaultParser : public GenericPayloadParser<PubSubDefault> {
+ public:
+ PubSubDefaultParser(PayloadParserFactoryCollection* parsers);
+ virtual ~PubSubDefaultParser();
+
+ virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE;
+ virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE;
+ virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE;
+
+ private:
+ PayloadParserFactoryCollection* parsers;
+ int level;
+ boost::shared_ptr<PayloadParser> currentPayloadParser;
+ };
+}
diff --git a/Swiften/Parser/PayloadParsers/PubSubErrorParser.cpp b/Swiften/Parser/PayloadParsers/PubSubErrorParser.cpp
new file mode 100644
index 0000000..9752cd2
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/PubSubErrorParser.cpp
@@ -0,0 +1,104 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#include <Swiften/Parser/PayloadParsers/PubSubErrorParser.h>
+
+using namespace Swift;
+
+PubSubErrorParser::PubSubErrorParser() : level(0) {
+ typeParser
+ (PubSubError::ClosedNode, "closed-node")
+ (PubSubError::ConfigurationRequired, "configuration-required")
+ (PubSubError::InvalidJID, "invalid-jid")
+ (PubSubError::InvalidOptions, "invalid-options")
+ (PubSubError::InvalidPayload, "invalid-payload")
+ (PubSubError::InvalidSubscriptionID, "invalid-subid")
+ (PubSubError::ItemForbidden, "item-forbidden")
+ (PubSubError::ItemRequired, "item-required")
+ (PubSubError::JIDRequired, "jid-required")
+ (PubSubError::MaximumItemsExceeded, "max-items-exceeded")
+ (PubSubError::MaximumNodesExceeded, "max-nodes-exceeded")
+ (PubSubError::NodeIDRequired, "nodeid-required")
+ (PubSubError::NotInRosterGroup, "not-in-roster-group")
+ (PubSubError::NotSubscribed, "not-subscribed")
+ (PubSubError::PayloadTooBig, "payload-too-big")
+ (PubSubError::PayloadRequired, "payload-required")
+ (PubSubError::PendingSubscription, "pending-subscription")
+ (PubSubError::PresenceSubscriptionRequired, "presence-subscription-required")
+ (PubSubError::SubscriptionIDRequired, "subid-required")
+ (PubSubError::TooManySubscriptions, "too-many-subscriptions")
+ (PubSubError::Unsupported, "unsupported")
+ (PubSubError::UnsupportedAccessModel, "unsupported-access-model");
+ unsupportedTypeParser
+ (PubSubError::AccessAuthorize, "access-authorize")
+ (PubSubError::AccessOpen, "access-open")
+ (PubSubError::AccessPresence, "access-presence")
+ (PubSubError::AccessRoster, "access-roster")
+ (PubSubError::AccessWhitelist, "access-whitelist")
+ (PubSubError::AutoCreate, "auto-create")
+ (PubSubError::AutoSubscribe, "auto-subscribe")
+ (PubSubError::Collections, "collections")
+ (PubSubError::ConfigNode, "config-node")
+ (PubSubError::CreateAndConfigure, "create-and-configure")
+ (PubSubError::CreateNodes, "create-nodes")
+ (PubSubError::DeleteItems, "delete-items")
+ (PubSubError::DeleteNodes, "delete-nodes")
+ (PubSubError::FilteredNotifications, "filtered-notifications")
+ (PubSubError::GetPending, "get-pending")
+ (PubSubError::InstantNodes, "instant-nodes")
+ (PubSubError::ItemIDs, "item-ids")
+ (PubSubError::LastPublished, "last-published")
+ (PubSubError::LeasedSubscription, "leased-subscription")
+ (PubSubError::ManageSubscriptions, "manage-subscriptions")
+ (PubSubError::MemberAffiliation, "member-affiliation")
+ (PubSubError::MetaData, "meta-data")
+ (PubSubError::ModifyAffiliations, "modify-affiliations")
+ (PubSubError::MultiCollection, "multi-collection")
+ (PubSubError::MultiSubscribe, "multi-subscribe")
+ (PubSubError::OutcastAffiliation, "outcast-affiliation")
+ (PubSubError::PersistentItems, "persistent-items")
+ (PubSubError::PresenceNotifications, "presence-notifications")
+ (PubSubError::PresenceSubscribe, "presence-subscribe")
+ (PubSubError::Publish, "publish")
+ (PubSubError::PublishOptions, "publish-options")
+ (PubSubError::PublishOnlyAffiliation, "publish-only-affiliation")
+ (PubSubError::PublisherAffiliation, "publisher-affiliation")
+ (PubSubError::PurgeNodes, "purge-nodes")
+ (PubSubError::RetractItems, "retract-items")
+ (PubSubError::RetrieveAffiliations, "retrieve-affiliations")
+ (PubSubError::RetrieveDefault, "retrieve-default")
+ (PubSubError::RetrieveItems, "retrieve-items")
+ (PubSubError::RetrieveSubscriptions, "retrieve-subscriptions")
+ (PubSubError::Subscribe, "subscribe")
+ (PubSubError::SubscriptionOptions, "subscription-options")
+ (PubSubError::SubscriptionNotifications, "subscription-notifications");
+}
+
+PubSubErrorParser::~PubSubErrorParser() {
+}
+
+void PubSubErrorParser::handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) {
+ if (level == 1) {
+ if (boost::optional<PubSubError::Type> type = typeParser.parse(element)) {
+ getPayloadInternal()->setType(*type);
+ if (type == PubSubError::Unsupported) {
+ if (boost::optional<std::string> feature = attributes.getAttributeValue("feature")) {
+ if (boost::optional<PubSubError::UnsupportedFeatureType> unsupportedType = unsupportedTypeParser.parse(*feature)) {
+ getPayloadInternal()->setUnsupportedFeatureType(*unsupportedType);
+ }
+ }
+ }
+ }
+ }
+ ++level;
+}
+
+void PubSubErrorParser::handleEndElement(const std::string&, const std::string&) {
+ --level;
+}
+
+void PubSubErrorParser::handleCharacterData(const std::string&) {
+}
diff --git a/Swiften/Parser/PayloadParsers/PubSubErrorParser.h b/Swiften/Parser/PayloadParsers/PubSubErrorParser.h
new file mode 100644
index 0000000..eb7dcfe
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/PubSubErrorParser.h
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <boost/shared_ptr.hpp>
+
+#include <Swiften/Base/Override.h>
+#include <Swiften/Base/API.h>
+#include <Swiften/Elements/PubSubError.h>
+#include <Swiften/Parser/GenericPayloadParser.h>
+#include <Swiften/Parser/EnumParser.h>
+
+namespace Swift {
+ class PayloadParserFactoryCollection;
+ class PayloadParser;
+
+ class SWIFTEN_API PubSubErrorParser : public GenericPayloadParser<PubSubError> {
+ public:
+ PubSubErrorParser();
+ virtual ~PubSubErrorParser();
+
+ virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE;
+ virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE;
+ virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE;
+
+ private:
+ int level;
+ EnumParser<PubSubError::Type> typeParser;
+ EnumParser<PubSubError::UnsupportedFeatureType> unsupportedTypeParser;
+ };
+}
diff --git a/Swiften/Parser/PayloadParsers/PubSubErrorParserFactory.cpp b/Swiften/Parser/PayloadParsers/PubSubErrorParserFactory.cpp
new file mode 100644
index 0000000..10dfd63
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/PubSubErrorParserFactory.cpp
@@ -0,0 +1,12 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#include <Swiften/Parser/PayloadParsers/PubSubErrorParserFactory.h>
+
+using namespace Swift;
+
+PubSubErrorParserFactory::~PubSubErrorParserFactory() {
+}
diff --git a/Swiften/Parser/PayloadParsers/PubSubErrorParserFactory.h b/Swiften/Parser/PayloadParsers/PubSubErrorParserFactory.h
new file mode 100644
index 0000000..e2386da
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/PubSubErrorParserFactory.h
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Parser/PayloadParserFactory.h>
+#include <Swiften/Parser/PayloadParsers/PubSubErrorParser.h>
+
+namespace Swift {
+ class PubSubErrorParserFactory : public PayloadParserFactory {
+ public:
+ PubSubErrorParserFactory() {
+ }
+ ~PubSubErrorParserFactory();
+
+ virtual bool canParse(const std::string&, const std::string& ns, const AttributeMap&) const {
+ return ns == "http://jabber.org/protocol/pubsub#errors";
+ }
+
+ virtual PayloadParser* createPayloadParser() {
+ return new PubSubErrorParser();
+ }
+ };
+}
+
+
diff --git a/Swiften/Parser/PayloadParsers/PubSubEventAssociateParser.cpp b/Swiften/Parser/PayloadParsers/PubSubEventAssociateParser.cpp
new file mode 100644
index 0000000..f187be8
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/PubSubEventAssociateParser.cpp
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma clang diagnostic ignored "-Wunused-private-field"
+
+#include <Swiften/Parser/PayloadParsers/PubSubEventAssociateParser.h>
+
+#include <boost/optional.hpp>
+
+
+#include <Swiften/Parser/PayloadParserFactoryCollection.h>
+#include <Swiften/Parser/PayloadParserFactory.h>
+
+
+using namespace Swift;
+
+PubSubEventAssociateParser::PubSubEventAssociateParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) {
+}
+
+PubSubEventAssociateParser::~PubSubEventAssociateParser() {
+}
+
+void PubSubEventAssociateParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) {
+ if (level == 0) {
+ if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) {
+ getPayloadInternal()->setNode(*attributeValue);
+ }
+ }
+
+
+
+ if (level >= 1 && currentPayloadParser) {
+ currentPayloadParser->handleStartElement(element, ns, attributes);
+ }
+ ++level;
+}
+
+void PubSubEventAssociateParser::handleEndElement(const std::string& element, const std::string& ns) {
+ --level;
+ if (currentPayloadParser) {
+ if (level >= 1) {
+ currentPayloadParser->handleEndElement(element, ns);
+ }
+
+ if (level == 1) {
+
+ currentPayloadParser.reset();
+ }
+ }
+}
+
+void PubSubEventAssociateParser::handleCharacterData(const std::string& data) {
+ if (level > 1 && currentPayloadParser) {
+ currentPayloadParser->handleCharacterData(data);
+ }
+}
diff --git a/Swiften/Parser/PayloadParsers/PubSubEventAssociateParser.h b/Swiften/Parser/PayloadParsers/PubSubEventAssociateParser.h
new file mode 100644
index 0000000..000edf2
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/PubSubEventAssociateParser.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <boost/shared_ptr.hpp>
+
+#include <Swiften/Base/Override.h>
+#include <Swiften/Base/API.h>
+#include <Swiften/Elements/PubSubEventAssociate.h>
+#include <Swiften/Parser/GenericPayloadParser.h>
+
+namespace Swift {
+ class PayloadParserFactoryCollection;
+ class PayloadParser;
+
+ class SWIFTEN_API PubSubEventAssociateParser : public GenericPayloadParser<PubSubEventAssociate> {
+ public:
+ PubSubEventAssociateParser(PayloadParserFactoryCollection* parsers);
+ virtual ~PubSubEventAssociateParser();
+
+ virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE;
+ virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE;
+ virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE;
+
+ private:
+ PayloadParserFactoryCollection* parsers;
+ int level;
+ boost::shared_ptr<PayloadParser> currentPayloadParser;
+ };
+}
diff --git a/Swiften/Parser/PayloadParsers/PubSubEventCollectionParser.cpp b/Swiften/Parser/PayloadParsers/PubSubEventCollectionParser.cpp
new file mode 100644
index 0000000..08b9c65
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/PubSubEventCollectionParser.cpp
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma clang diagnostic ignored "-Wunused-private-field"
+
+#include <Swiften/Parser/PayloadParsers/PubSubEventCollectionParser.h>
+
+#include <boost/optional.hpp>
+
+
+#include <Swiften/Parser/PayloadParserFactoryCollection.h>
+#include <Swiften/Parser/PayloadParserFactory.h>
+#include <Swiften/Parser/PayloadParsers/PubSubEventAssociateParser.h>
+#include <Swiften/Parser/PayloadParsers/PubSubEventDisassociateParser.h>
+
+using namespace Swift;
+
+PubSubEventCollectionParser::PubSubEventCollectionParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) {
+}
+
+PubSubEventCollectionParser::~PubSubEventCollectionParser() {
+}
+
+void PubSubEventCollectionParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) {
+ if (level == 0) {
+ if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) {
+ getPayloadInternal()->setNode(*attributeValue);
+ }
+ }
+
+ if (level == 1) {
+ if (element == "disassociate" && ns == "http://jabber.org/protocol/pubsub#event") {
+ currentPayloadParser = boost::make_shared<PubSubEventDisassociateParser>(parsers);
+ }
+ if (element == "associate" && ns == "http://jabber.org/protocol/pubsub#event") {
+ currentPayloadParser = boost::make_shared<PubSubEventAssociateParser>(parsers);
+ }
+ }
+
+ if (level >= 1 && currentPayloadParser) {
+ currentPayloadParser->handleStartElement(element, ns, attributes);
+ }
+ ++level;
+}
+
+void PubSubEventCollectionParser::handleEndElement(const std::string& element, const std::string& ns) {
+ --level;
+ if (currentPayloadParser) {
+ if (level >= 1) {
+ currentPayloadParser->handleEndElement(element, ns);
+ }
+
+ if (level == 1) {
+ if (element == "disassociate" && ns == "http://jabber.org/protocol/pubsub#event") {
+ getPayloadInternal()->setDisassociate(boost::dynamic_pointer_cast<PubSubEventDisassociate>(currentPayloadParser->getPayload()));
+ }
+ if (element == "associate" && ns == "http://jabber.org/protocol/pubsub#event") {
+ getPayloadInternal()->setAssociate(boost::dynamic_pointer_cast<PubSubEventAssociate>(currentPayloadParser->getPayload()));
+ }
+ currentPayloadParser.reset();
+ }
+ }
+}
+
+void PubSubEventCollectionParser::handleCharacterData(const std::string& data) {
+ if (level > 1 && currentPayloadParser) {
+ currentPayloadParser->handleCharacterData(data);
+ }
+}
diff --git a/Swiften/Parser/PayloadParsers/PubSubEventCollectionParser.h b/Swiften/Parser/PayloadParsers/PubSubEventCollectionParser.h
new file mode 100644
index 0000000..aad97d2
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/PubSubEventCollectionParser.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <boost/shared_ptr.hpp>
+
+#include <Swiften/Base/Override.h>
+#include <Swiften/Base/API.h>
+#include <Swiften/Elements/PubSubEventCollection.h>
+#include <Swiften/Parser/GenericPayloadParser.h>
+
+namespace Swift {
+ class PayloadParserFactoryCollection;
+ class PayloadParser;
+
+ class SWIFTEN_API PubSubEventCollectionParser : public GenericPayloadParser<PubSubEventCollection> {
+ public:
+ PubSubEventCollectionParser(PayloadParserFactoryCollection* parsers);
+ virtual ~PubSubEventCollectionParser();
+
+ virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE;
+ virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE;
+ virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE;
+
+ private:
+ PayloadParserFactoryCollection* parsers;
+ int level;
+ boost::shared_ptr<PayloadParser> currentPayloadParser;
+ };
+}
diff --git a/Swiften/Parser/PayloadParsers/PubSubEventConfigurationParser.cpp b/Swiften/Parser/PayloadParsers/PubSubEventConfigurationParser.cpp
new file mode 100644
index 0000000..f905299
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/PubSubEventConfigurationParser.cpp
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma clang diagnostic ignored "-Wunused-private-field"
+
+#include <Swiften/Parser/PayloadParsers/PubSubEventConfigurationParser.h>
+
+#include <boost/optional.hpp>
+
+
+#include <Swiften/Parser/PayloadParserFactoryCollection.h>
+#include <Swiften/Parser/PayloadParserFactory.h>
+#include <Swiften/Parser/PayloadParsers/FormParser.h>
+
+using namespace Swift;
+
+PubSubEventConfigurationParser::PubSubEventConfigurationParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) {
+}
+
+PubSubEventConfigurationParser::~PubSubEventConfigurationParser() {
+}
+
+void PubSubEventConfigurationParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) {
+ if (level == 0) {
+ if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) {
+ getPayloadInternal()->setNode(*attributeValue);
+ }
+ }
+
+ if (level == 1) {
+ if (element == "x" && ns == "jabber:x:data") {
+ currentPayloadParser = boost::make_shared<FormParser>();
+ }
+ }
+
+ if (level >= 1 && currentPayloadParser) {
+ currentPayloadParser->handleStartElement(element, ns, attributes);
+ }
+ ++level;
+}
+
+void PubSubEventConfigurationParser::handleEndElement(const std::string& element, const std::string& ns) {
+ --level;
+ if (currentPayloadParser) {
+ if (level >= 1) {
+ currentPayloadParser->handleEndElement(element, ns);
+ }
+
+ if (level == 1) {
+ if (element == "x" && ns == "jabber:x:data") {
+ getPayloadInternal()->setData(boost::dynamic_pointer_cast<Form>(currentPayloadParser->getPayload()));
+ }
+ currentPayloadParser.reset();
+ }
+ }
+}
+
+void PubSubEventConfigurationParser::handleCharacterData(const std::string& data) {
+ if (level > 1 && currentPayloadParser) {
+ currentPayloadParser->handleCharacterData(data);
+ }
+}
diff --git a/Swiften/Parser/PayloadParsers/PubSubEventConfigurationParser.h b/Swiften/Parser/PayloadParsers/PubSubEventConfigurationParser.h
new file mode 100644
index 0000000..7189460
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/PubSubEventConfigurationParser.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <boost/shared_ptr.hpp>
+
+#include <Swiften/Base/Override.h>
+#include <Swiften/Base/API.h>
+#include <Swiften/Elements/PubSubEventConfiguration.h>
+#include <Swiften/Parser/GenericPayloadParser.h>
+
+namespace Swift {
+ class PayloadParserFactoryCollection;
+ class PayloadParser;
+
+ class SWIFTEN_API PubSubEventConfigurationParser : public GenericPayloadParser<PubSubEventConfiguration> {
+ public:
+ PubSubEventConfigurationParser(PayloadParserFactoryCollection* parsers);
+ virtual ~PubSubEventConfigurationParser();
+
+ virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE;
+ virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE;
+ virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE;
+
+ private:
+ PayloadParserFactoryCollection* parsers;
+ int level;
+ boost::shared_ptr<PayloadParser> currentPayloadParser;
+ };
+}
diff --git a/Swiften/Parser/PayloadParsers/PubSubEventDeleteParser.cpp b/Swiften/Parser/PayloadParsers/PubSubEventDeleteParser.cpp
new file mode 100644
index 0000000..03c7423
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/PubSubEventDeleteParser.cpp
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma clang diagnostic ignored "-Wunused-private-field"
+
+#include <Swiften/Parser/PayloadParsers/PubSubEventDeleteParser.h>
+
+#include <boost/optional.hpp>
+
+
+#include <Swiften/Parser/PayloadParserFactoryCollection.h>
+#include <Swiften/Parser/PayloadParserFactory.h>
+#include <Swiften/Parser/PayloadParsers/PubSubEventRedirectParser.h>
+
+using namespace Swift;
+
+PubSubEventDeleteParser::PubSubEventDeleteParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) {
+}
+
+PubSubEventDeleteParser::~PubSubEventDeleteParser() {
+}
+
+void PubSubEventDeleteParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) {
+ if (level == 0) {
+ if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) {
+ getPayloadInternal()->setNode(*attributeValue);
+ }
+ }
+
+ if (level == 1) {
+ if (element == "redirect" && ns == "http://jabber.org/protocol/pubsub#event") {
+ currentPayloadParser = boost::make_shared<PubSubEventRedirectParser>(parsers);
+ }
+ }
+
+ if (level >= 1 && currentPayloadParser) {
+ currentPayloadParser->handleStartElement(element, ns, attributes);
+ }
+ ++level;
+}
+
+void PubSubEventDeleteParser::handleEndElement(const std::string& element, const std::string& ns) {
+ --level;
+ if (currentPayloadParser) {
+ if (level >= 1) {
+ currentPayloadParser->handleEndElement(element, ns);
+ }
+
+ if (level == 1) {
+ if (element == "redirect" && ns == "http://jabber.org/protocol/pubsub#event") {
+ getPayloadInternal()->setRedirects(boost::dynamic_pointer_cast<PubSubEventRedirect>(currentPayloadParser->getPayload()));
+ }
+ currentPayloadParser.reset();
+ }
+ }
+}
+
+void PubSubEventDeleteParser::handleCharacterData(const std::string& data) {
+ if (level > 1 && currentPayloadParser) {
+ currentPayloadParser->handleCharacterData(data);
+ }
+}
diff --git a/Swiften/Parser/PayloadParsers/PubSubEventDeleteParser.h b/Swiften/Parser/PayloadParsers/PubSubEventDeleteParser.h
new file mode 100644
index 0000000..36f8e0b
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/PubSubEventDeleteParser.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <boost/shared_ptr.hpp>
+
+#include <Swiften/Base/Override.h>
+#include <Swiften/Base/API.h>
+#include <Swiften/Elements/PubSubEventDelete.h>
+#include <Swiften/Parser/GenericPayloadParser.h>
+
+namespace Swift {
+ class PayloadParserFactoryCollection;
+ class PayloadParser;
+
+ class SWIFTEN_API PubSubEventDeleteParser : public GenericPayloadParser<PubSubEventDelete> {
+ public:
+ PubSubEventDeleteParser(PayloadParserFactoryCollection* parsers);
+ virtual ~PubSubEventDeleteParser();
+
+ virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE;
+ virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE;
+ virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE;
+
+ private:
+ PayloadParserFactoryCollection* parsers;
+ int level;
+ boost::shared_ptr<PayloadParser> currentPayloadParser;
+ };
+}
diff --git a/Swiften/Parser/PayloadParsers/PubSubEventDisassociateParser.cpp b/Swiften/Parser/PayloadParsers/PubSubEventDisassociateParser.cpp
new file mode 100644
index 0000000..287ac35
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/PubSubEventDisassociateParser.cpp
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma clang diagnostic ignored "-Wunused-private-field"
+
+#include <Swiften/Parser/PayloadParsers/PubSubEventDisassociateParser.h>
+
+#include <boost/optional.hpp>
+
+
+#include <Swiften/Parser/PayloadParserFactoryCollection.h>
+#include <Swiften/Parser/PayloadParserFactory.h>
+
+
+using namespace Swift;
+
+PubSubEventDisassociateParser::PubSubEventDisassociateParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) {
+}
+
+PubSubEventDisassociateParser::~PubSubEventDisassociateParser() {
+}
+
+void PubSubEventDisassociateParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) {
+ if (level == 0) {
+ if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) {
+ getPayloadInternal()->setNode(*attributeValue);
+ }
+ }
+
+
+
+ if (level >= 1 && currentPayloadParser) {
+ currentPayloadParser->handleStartElement(element, ns, attributes);
+ }
+ ++level;
+}
+
+void PubSubEventDisassociateParser::handleEndElement(const std::string& element, const std::string& ns) {
+ --level;
+ if (currentPayloadParser) {
+ if (level >= 1) {
+ currentPayloadParser->handleEndElement(element, ns);
+ }
+
+ if (level == 1) {
+
+ currentPayloadParser.reset();
+ }
+ }
+}
+
+void PubSubEventDisassociateParser::handleCharacterData(const std::string& data) {
+ if (level > 1 && currentPayloadParser) {
+ currentPayloadParser->handleCharacterData(data);
+ }
+}
diff --git a/Swiften/Parser/PayloadParsers/PubSubEventDisassociateParser.h b/Swiften/Parser/PayloadParsers/PubSubEventDisassociateParser.h
new file mode 100644
index 0000000..9015100
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/PubSubEventDisassociateParser.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <boost/shared_ptr.hpp>
+
+#include <Swiften/Base/Override.h>
+#include <Swiften/Base/API.h>
+#include <Swiften/Elements/PubSubEventDisassociate.h>
+#include <Swiften/Parser/GenericPayloadParser.h>
+
+namespace Swift {
+ class PayloadParserFactoryCollection;
+ class PayloadParser;
+
+ class SWIFTEN_API PubSubEventDisassociateParser : public GenericPayloadParser<PubSubEventDisassociate> {
+ public:
+ PubSubEventDisassociateParser(PayloadParserFactoryCollection* parsers);
+ virtual ~PubSubEventDisassociateParser();
+
+ virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE;
+ virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE;
+ virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE;
+
+ private:
+ PayloadParserFactoryCollection* parsers;
+ int level;
+ boost::shared_ptr<PayloadParser> currentPayloadParser;
+ };
+}
diff --git a/Swiften/Parser/PayloadParsers/PubSubEventItemParser.cpp b/Swiften/Parser/PayloadParsers/PubSubEventItemParser.cpp
new file mode 100644
index 0000000..8903545
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/PubSubEventItemParser.cpp
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma clang diagnostic ignored "-Wunused-private-field"
+
+#include <Swiften/Parser/PayloadParsers/PubSubEventItemParser.h>
+
+#include <boost/optional.hpp>
+
+
+#include <Swiften/Parser/PayloadParserFactoryCollection.h>
+#include <Swiften/Parser/PayloadParserFactory.h>
+
+
+using namespace Swift;
+
+PubSubEventItemParser::PubSubEventItemParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) {
+}
+
+PubSubEventItemParser::~PubSubEventItemParser() {
+}
+
+void PubSubEventItemParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) {
+ if (level == 0) {
+ if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) {
+ getPayloadInternal()->setNode(*attributeValue);
+ }
+ if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("publisher")) {
+ getPayloadInternal()->setPublisher(*attributeValue);
+ }
+ if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("id")) {
+ getPayloadInternal()->setID(*attributeValue);
+ }
+ }
+
+ if (level == 1) {
+ if (PayloadParserFactory* factory = parsers->getPayloadParserFactory(element, ns, attributes)) {
+ currentPayloadParser.reset(factory->createPayloadParser());
+ }
+ }
+
+ if (level >= 1 && currentPayloadParser) {
+ currentPayloadParser->handleStartElement(element, ns, attributes);
+ }
+ ++level;
+}
+
+void PubSubEventItemParser::handleEndElement(const std::string& element, const std::string& ns) {
+ --level;
+ if (currentPayloadParser) {
+ if (level >= 1) {
+ currentPayloadParser->handleEndElement(element, ns);
+ }
+
+ if (level == 1) {
+ getPayloadInternal()->addData(currentPayloadParser->getPayload());
+ currentPayloadParser.reset();
+ }
+ }
+}
+
+void PubSubEventItemParser::handleCharacterData(const std::string& data) {
+ if (level > 1 && currentPayloadParser) {
+ currentPayloadParser->handleCharacterData(data);
+ }
+}
diff --git a/Swiften/Parser/PayloadParsers/PubSubEventItemParser.h b/Swiften/Parser/PayloadParsers/PubSubEventItemParser.h
new file mode 100644
index 0000000..6c16043
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/PubSubEventItemParser.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <boost/shared_ptr.hpp>
+
+#include <Swiften/Base/Override.h>
+#include <Swiften/Base/API.h>
+#include <Swiften/Elements/PubSubEventItem.h>
+#include <Swiften/Parser/GenericPayloadParser.h>
+
+namespace Swift {
+ class PayloadParserFactoryCollection;
+ class PayloadParser;
+
+ class SWIFTEN_API PubSubEventItemParser : public GenericPayloadParser<PubSubEventItem> {
+ public:
+ PubSubEventItemParser(PayloadParserFactoryCollection* parsers);
+ virtual ~PubSubEventItemParser();
+
+ virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE;
+ virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE;
+ virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE;
+
+ private:
+ PayloadParserFactoryCollection* parsers;
+ int level;
+ boost::shared_ptr<PayloadParser> currentPayloadParser;
+ };
+}
diff --git a/Swiften/Parser/PayloadParsers/PubSubEventItemsParser.cpp b/Swiften/Parser/PayloadParsers/PubSubEventItemsParser.cpp
new file mode 100644
index 0000000..fa155e9
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/PubSubEventItemsParser.cpp
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma clang diagnostic ignored "-Wunused-private-field"
+
+#include <Swiften/Parser/PayloadParsers/PubSubEventItemsParser.h>
+
+#include <boost/optional.hpp>
+
+
+#include <Swiften/Parser/PayloadParserFactoryCollection.h>
+#include <Swiften/Parser/PayloadParserFactory.h>
+#include <Swiften/Parser/PayloadParsers/PubSubEventRetractParser.h>
+#include <Swiften/Parser/PayloadParsers/PubSubEventItemParser.h>
+
+using namespace Swift;
+
+PubSubEventItemsParser::PubSubEventItemsParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) {
+}
+
+PubSubEventItemsParser::~PubSubEventItemsParser() {
+}
+
+void PubSubEventItemsParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) {
+ if (level == 0) {
+ if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) {
+ getPayloadInternal()->setNode(*attributeValue);
+ }
+ }
+
+ if (level == 1) {
+ if (element == "item" && ns == "http://jabber.org/protocol/pubsub#event") {
+ currentPayloadParser = boost::make_shared<PubSubEventItemParser>(parsers);
+ }
+ if (element == "retract" && ns == "http://jabber.org/protocol/pubsub#event") {
+ currentPayloadParser = boost::make_shared<PubSubEventRetractParser>(parsers);
+ }
+ }
+
+ if (level >= 1 && currentPayloadParser) {
+ currentPayloadParser->handleStartElement(element, ns, attributes);
+ }
+ ++level;
+}
+
+void PubSubEventItemsParser::handleEndElement(const std::string& element, const std::string& ns) {
+ --level;
+ if (currentPayloadParser) {
+ if (level >= 1) {
+ currentPayloadParser->handleEndElement(element, ns);
+ }
+
+ if (level == 1) {
+ if (element == "item" && ns == "http://jabber.org/protocol/pubsub#event") {
+ getPayloadInternal()->addItem(boost::dynamic_pointer_cast<PubSubEventItem>(currentPayloadParser->getPayload()));
+ }
+ if (element == "retract" && ns == "http://jabber.org/protocol/pubsub#event") {
+ getPayloadInternal()->addRetract(boost::dynamic_pointer_cast<PubSubEventRetract>(currentPayloadParser->getPayload()));
+ }
+ currentPayloadParser.reset();
+ }
+ }
+}
+
+void PubSubEventItemsParser::handleCharacterData(const std::string& data) {
+ if (level > 1 && currentPayloadParser) {
+ currentPayloadParser->handleCharacterData(data);
+ }
+}
diff --git a/Swiften/Parser/PayloadParsers/PubSubEventItemsParser.h b/Swiften/Parser/PayloadParsers/PubSubEventItemsParser.h
new file mode 100644
index 0000000..60ecb25
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/PubSubEventItemsParser.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <boost/shared_ptr.hpp>
+
+#include <Swiften/Base/Override.h>
+#include <Swiften/Base/API.h>
+#include <Swiften/Elements/PubSubEventItems.h>
+#include <Swiften/Parser/GenericPayloadParser.h>
+
+namespace Swift {
+ class PayloadParserFactoryCollection;
+ class PayloadParser;
+
+ class SWIFTEN_API PubSubEventItemsParser : public GenericPayloadParser<PubSubEventItems> {
+ public:
+ PubSubEventItemsParser(PayloadParserFactoryCollection* parsers);
+ virtual ~PubSubEventItemsParser();
+
+ virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE;
+ virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE;
+ virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE;
+
+ private:
+ PayloadParserFactoryCollection* parsers;
+ int level;
+ boost::shared_ptr<PayloadParser> currentPayloadParser;
+ };
+}
diff --git a/Swiften/Parser/PayloadParsers/PubSubEventParser.cpp b/Swiften/Parser/PayloadParsers/PubSubEventParser.cpp
new file mode 100644
index 0000000..c4406a9
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/PubSubEventParser.cpp
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma clang diagnostic ignored "-Wunused-private-field"
+
+#include <Swiften/Parser/PayloadParsers/PubSubEventParser.h>
+
+#include <boost/optional.hpp>
+
+
+#include <Swiften/Parser/PayloadParserFactoryCollection.h>
+#include <Swiften/Parser/PayloadParserFactory.h>
+#include <Swiften/Parser/PayloadParsers/PubSubEventItemsParser.h>
+#include <Swiften/Parser/PayloadParsers/PubSubEventDeleteParser.h>
+#include <Swiften/Parser/PayloadParsers/PubSubEventSubscriptionParser.h>
+#include <Swiften/Parser/PayloadParsers/PubSubEventPurgeParser.h>
+#include <Swiften/Parser/PayloadParsers/PubSubEventCollectionParser.h>
+#include <Swiften/Parser/PayloadParsers/PubSubEventConfigurationParser.h>
+
+using namespace Swift;
+
+PubSubEventParser::PubSubEventParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) {
+}
+
+PubSubEventParser::~PubSubEventParser() {
+}
+
+void PubSubEventParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) {
+
+
+ if (level == 1) {
+ if (element == "items" && ns == "http://jabber.org/protocol/pubsub#event") {
+ currentPayloadParser = boost::make_shared<PubSubEventItemsParser>(parsers);
+ }
+ if (element == "collection" && ns == "http://jabber.org/protocol/pubsub#event") {
+ currentPayloadParser = boost::make_shared<PubSubEventCollectionParser>(parsers);
+ }
+ if (element == "purge" && ns == "http://jabber.org/protocol/pubsub#event") {
+ currentPayloadParser = boost::make_shared<PubSubEventPurgeParser>(parsers);
+ }
+ if (element == "configuration" && ns == "http://jabber.org/protocol/pubsub#event") {
+ currentPayloadParser = boost::make_shared<PubSubEventConfigurationParser>(parsers);
+ }
+ if (element == "delete" && ns == "http://jabber.org/protocol/pubsub#event") {
+ currentPayloadParser = boost::make_shared<PubSubEventDeleteParser>(parsers);
+ }
+ if (element == "subscription" && ns == "http://jabber.org/protocol/pubsub#event") {
+ currentPayloadParser = boost::make_shared<PubSubEventSubscriptionParser>(parsers);
+ }
+ }
+
+ if (level >= 1 && currentPayloadParser) {
+ currentPayloadParser->handleStartElement(element, ns, attributes);
+ }
+ ++level;
+}
+
+void PubSubEventParser::handleEndElement(const std::string& element, const std::string& ns) {
+ --level;
+ if (currentPayloadParser) {
+ if (level >= 1) {
+ currentPayloadParser->handleEndElement(element, ns);
+ }
+
+ if (level == 1) {
+ if (currentPayloadParser) {
+ getPayloadInternal()->setPayload(boost::dynamic_pointer_cast<PubSubEventPayload>(currentPayloadParser->getPayload()));
+ }
+ currentPayloadParser.reset();
+ }
+ }
+}
+
+void PubSubEventParser::handleCharacterData(const std::string& data) {
+ if (level > 1 && currentPayloadParser) {
+ currentPayloadParser->handleCharacterData(data);
+ }
+}
diff --git a/Swiften/Parser/PayloadParsers/PubSubEventParser.h b/Swiften/Parser/PayloadParsers/PubSubEventParser.h
new file mode 100644
index 0000000..1042e75
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/PubSubEventParser.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <boost/shared_ptr.hpp>
+
+#include <Swiften/Base/Override.h>
+#include <Swiften/Base/API.h>
+#include <Swiften/Elements/PubSubEvent.h>
+#include <Swiften/Parser/GenericPayloadParser.h>
+
+namespace Swift {
+ class PayloadParserFactoryCollection;
+ class PayloadParser;
+
+ class SWIFTEN_API PubSubEventParser : public GenericPayloadParser<PubSubEvent> {
+ public:
+ PubSubEventParser(PayloadParserFactoryCollection* parsers);
+ virtual ~PubSubEventParser();
+
+ virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE;
+ virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE;
+ virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE;
+
+ private:
+ PayloadParserFactoryCollection* parsers;
+ int level;
+ boost::shared_ptr<PayloadParser> currentPayloadParser;
+ };
+}
diff --git a/Swiften/Parser/PayloadParsers/PubSubEventPurgeParser.cpp b/Swiften/Parser/PayloadParsers/PubSubEventPurgeParser.cpp
new file mode 100644
index 0000000..14d1e96
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/PubSubEventPurgeParser.cpp
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma clang diagnostic ignored "-Wunused-private-field"
+
+#include <Swiften/Parser/PayloadParsers/PubSubEventPurgeParser.h>
+
+#include <boost/optional.hpp>
+
+
+#include <Swiften/Parser/PayloadParserFactoryCollection.h>
+#include <Swiften/Parser/PayloadParserFactory.h>
+
+
+using namespace Swift;
+
+PubSubEventPurgeParser::PubSubEventPurgeParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) {
+}
+
+PubSubEventPurgeParser::~PubSubEventPurgeParser() {
+}
+
+void PubSubEventPurgeParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) {
+ if (level == 0) {
+ if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) {
+ getPayloadInternal()->setNode(*attributeValue);
+ }
+ }
+
+
+
+ if (level >= 1 && currentPayloadParser) {
+ currentPayloadParser->handleStartElement(element, ns, attributes);
+ }
+ ++level;
+}
+
+void PubSubEventPurgeParser::handleEndElement(const std::string& element, const std::string& ns) {
+ --level;
+ if (currentPayloadParser) {
+ if (level >= 1) {
+ currentPayloadParser->handleEndElement(element, ns);
+ }
+
+ if (level == 1) {
+
+ currentPayloadParser.reset();
+ }
+ }
+}
+
+void PubSubEventPurgeParser::handleCharacterData(const std::string& data) {
+ if (level > 1 && currentPayloadParser) {
+ currentPayloadParser->handleCharacterData(data);
+ }
+}
diff --git a/Swiften/Parser/PayloadParsers/PubSubEventPurgeParser.h b/Swiften/Parser/PayloadParsers/PubSubEventPurgeParser.h
new file mode 100644
index 0000000..740bff3
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/PubSubEventPurgeParser.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <boost/shared_ptr.hpp>
+
+#include <Swiften/Base/Override.h>
+#include <Swiften/Base/API.h>
+#include <Swiften/Elements/PubSubEventPurge.h>
+#include <Swiften/Parser/GenericPayloadParser.h>
+
+namespace Swift {
+ class PayloadParserFactoryCollection;
+ class PayloadParser;
+
+ class SWIFTEN_API PubSubEventPurgeParser : public GenericPayloadParser<PubSubEventPurge> {
+ public:
+ PubSubEventPurgeParser(PayloadParserFactoryCollection* parsers);
+ virtual ~PubSubEventPurgeParser();
+
+ virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE;
+ virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE;
+ virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE;
+
+ private:
+ PayloadParserFactoryCollection* parsers;
+ int level;
+ boost::shared_ptr<PayloadParser> currentPayloadParser;
+ };
+}
diff --git a/Swiften/Parser/PayloadParsers/PubSubEventRedirectParser.cpp b/Swiften/Parser/PayloadParsers/PubSubEventRedirectParser.cpp
new file mode 100644
index 0000000..f053117
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/PubSubEventRedirectParser.cpp
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma clang diagnostic ignored "-Wunused-private-field"
+
+#include <Swiften/Parser/PayloadParsers/PubSubEventRedirectParser.h>
+
+#include <boost/optional.hpp>
+
+
+#include <Swiften/Parser/PayloadParserFactoryCollection.h>
+#include <Swiften/Parser/PayloadParserFactory.h>
+
+
+using namespace Swift;
+
+PubSubEventRedirectParser::PubSubEventRedirectParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) {
+}
+
+PubSubEventRedirectParser::~PubSubEventRedirectParser() {
+}
+
+void PubSubEventRedirectParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) {
+ if (level == 0) {
+ if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("uri")) {
+ getPayloadInternal()->setURI(*attributeValue);
+ }
+ }
+
+
+
+ if (level >= 1 && currentPayloadParser) {
+ currentPayloadParser->handleStartElement(element, ns, attributes);
+ }
+ ++level;
+}
+
+void PubSubEventRedirectParser::handleEndElement(const std::string& element, const std::string& ns) {
+ --level;
+ if (currentPayloadParser) {
+ if (level >= 1) {
+ currentPayloadParser->handleEndElement(element, ns);
+ }
+
+ if (level == 1) {
+
+ currentPayloadParser.reset();
+ }
+ }
+}
+
+void PubSubEventRedirectParser::handleCharacterData(const std::string& data) {
+ if (level > 1 && currentPayloadParser) {
+ currentPayloadParser->handleCharacterData(data);
+ }
+}
diff --git a/Swiften/Parser/PayloadParsers/PubSubEventRedirectParser.h b/Swiften/Parser/PayloadParsers/PubSubEventRedirectParser.h
new file mode 100644
index 0000000..33880ed
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/PubSubEventRedirectParser.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <boost/shared_ptr.hpp>
+
+#include <Swiften/Base/Override.h>
+#include <Swiften/Base/API.h>
+#include <Swiften/Elements/PubSubEventRedirect.h>
+#include <Swiften/Parser/GenericPayloadParser.h>
+
+namespace Swift {
+ class PayloadParserFactoryCollection;
+ class PayloadParser;
+
+ class SWIFTEN_API PubSubEventRedirectParser : public GenericPayloadParser<PubSubEventRedirect> {
+ public:
+ PubSubEventRedirectParser(PayloadParserFactoryCollection* parsers);
+ virtual ~PubSubEventRedirectParser();
+
+ virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE;
+ virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE;
+ virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE;
+
+ private:
+ PayloadParserFactoryCollection* parsers;
+ int level;
+ boost::shared_ptr<PayloadParser> currentPayloadParser;
+ };
+}
diff --git a/Swiften/Parser/PayloadParsers/PubSubEventRetractParser.cpp b/Swiften/Parser/PayloadParsers/PubSubEventRetractParser.cpp
new file mode 100644
index 0000000..da3dea3
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/PubSubEventRetractParser.cpp
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma clang diagnostic ignored "-Wunused-private-field"
+
+#include <Swiften/Parser/PayloadParsers/PubSubEventRetractParser.h>
+
+#include <boost/optional.hpp>
+
+
+#include <Swiften/Parser/PayloadParserFactoryCollection.h>
+#include <Swiften/Parser/PayloadParserFactory.h>
+
+
+using namespace Swift;
+
+PubSubEventRetractParser::PubSubEventRetractParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) {
+}
+
+PubSubEventRetractParser::~PubSubEventRetractParser() {
+}
+
+void PubSubEventRetractParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) {
+ if (level == 0) {
+ if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("id")) {
+ getPayloadInternal()->setID(*attributeValue);
+ }
+ }
+
+
+
+ if (level >= 1 && currentPayloadParser) {
+ currentPayloadParser->handleStartElement(element, ns, attributes);
+ }
+ ++level;
+}
+
+void PubSubEventRetractParser::handleEndElement(const std::string& element, const std::string& ns) {
+ --level;
+ if (currentPayloadParser) {
+ if (level >= 1) {
+ currentPayloadParser->handleEndElement(element, ns);
+ }
+
+ if (level == 1) {
+
+ currentPayloadParser.reset();
+ }
+ }
+}
+
+void PubSubEventRetractParser::handleCharacterData(const std::string& data) {
+ if (level > 1 && currentPayloadParser) {
+ currentPayloadParser->handleCharacterData(data);
+ }
+}
diff --git a/Swiften/Parser/PayloadParsers/PubSubEventRetractParser.h b/Swiften/Parser/PayloadParsers/PubSubEventRetractParser.h
new file mode 100644
index 0000000..115bb7a
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/PubSubEventRetractParser.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <boost/shared_ptr.hpp>
+
+#include <Swiften/Base/Override.h>
+#include <Swiften/Base/API.h>
+#include <Swiften/Elements/PubSubEventRetract.h>
+#include <Swiften/Parser/GenericPayloadParser.h>
+
+namespace Swift {
+ class PayloadParserFactoryCollection;
+ class PayloadParser;
+
+ class SWIFTEN_API PubSubEventRetractParser : public GenericPayloadParser<PubSubEventRetract> {
+ public:
+ PubSubEventRetractParser(PayloadParserFactoryCollection* parsers);
+ virtual ~PubSubEventRetractParser();
+
+ virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE;
+ virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE;
+ virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE;
+
+ private:
+ PayloadParserFactoryCollection* parsers;
+ int level;
+ boost::shared_ptr<PayloadParser> currentPayloadParser;
+ };
+}
diff --git a/Swiften/Parser/PayloadParsers/PubSubEventSubscriptionParser.cpp b/Swiften/Parser/PayloadParsers/PubSubEventSubscriptionParser.cpp
new file mode 100644
index 0000000..3367202
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/PubSubEventSubscriptionParser.cpp
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma clang diagnostic ignored "-Wunused-private-field"
+
+#include <Swiften/Parser/PayloadParsers/PubSubEventSubscriptionParser.h>
+
+#include <boost/optional.hpp>
+
+
+#include <Swiften/Parser/PayloadParserFactoryCollection.h>
+#include <Swiften/Parser/PayloadParserFactory.h>
+#include <Swiften/Base/DateTime.h>
+#include <Swiften/Parser/EnumParser.h>
+
+using namespace Swift;
+
+PubSubEventSubscriptionParser::PubSubEventSubscriptionParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) {
+}
+
+PubSubEventSubscriptionParser::~PubSubEventSubscriptionParser() {
+}
+
+void PubSubEventSubscriptionParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) {
+ if (level == 0) {
+ if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) {
+ getPayloadInternal()->setNode(*attributeValue);
+ }
+ if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("jid")) {
+ if (boost::optional<JID> jid = JID::parse(*attributeValue)) {
+ getPayloadInternal()->setJID(*jid);
+ }
+ }
+ if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("subscription")) {
+ if (boost::optional<PubSubEventSubscription::SubscriptionType> value = EnumParser<PubSubEventSubscription::SubscriptionType>()(PubSubEventSubscription::None, "none")(PubSubEventSubscription::Pending, "pending")(PubSubEventSubscription::Subscribed, "subscribed")(PubSubEventSubscription::Unconfigured, "unconfigured").parse(*attributeValue)) {
+ getPayloadInternal()->setSubscription(*value);
+ }
+ }
+ if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("subid")) {
+ getPayloadInternal()->setSubscriptionID(*attributeValue);
+ }
+ if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("expiry")) {
+ getPayloadInternal()->setExpiry(stringToDateTime(*attributeValue));
+ }
+ }
+
+
+
+ if (level >= 1 && currentPayloadParser) {
+ currentPayloadParser->handleStartElement(element, ns, attributes);
+ }
+ ++level;
+}
+
+void PubSubEventSubscriptionParser::handleEndElement(const std::string& element, const std::string& ns) {
+ --level;
+ if (currentPayloadParser) {
+ if (level >= 1) {
+ currentPayloadParser->handleEndElement(element, ns);
+ }
+
+ if (level == 1) {
+
+ currentPayloadParser.reset();
+ }
+ }
+}
+
+void PubSubEventSubscriptionParser::handleCharacterData(const std::string& data) {
+ if (level > 1 && currentPayloadParser) {
+ currentPayloadParser->handleCharacterData(data);
+ }
+}
diff --git a/Swiften/Parser/PayloadParsers/PubSubEventSubscriptionParser.h b/Swiften/Parser/PayloadParsers/PubSubEventSubscriptionParser.h
new file mode 100644
index 0000000..1469920
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/PubSubEventSubscriptionParser.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <boost/shared_ptr.hpp>
+
+#include <Swiften/Base/Override.h>
+#include <Swiften/Base/API.h>
+#include <Swiften/Elements/PubSubEventSubscription.h>
+#include <Swiften/Parser/GenericPayloadParser.h>
+
+namespace Swift {
+ class PayloadParserFactoryCollection;
+ class PayloadParser;
+
+ class SWIFTEN_API PubSubEventSubscriptionParser : public GenericPayloadParser<PubSubEventSubscription> {
+ public:
+ PubSubEventSubscriptionParser(PayloadParserFactoryCollection* parsers);
+ virtual ~PubSubEventSubscriptionParser();
+
+ virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE;
+ virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE;
+ virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE;
+
+ private:
+ PayloadParserFactoryCollection* parsers;
+ int level;
+ boost::shared_ptr<PayloadParser> currentPayloadParser;
+ };
+}
diff --git a/Swiften/Parser/PayloadParsers/PubSubItemParser.cpp b/Swiften/Parser/PayloadParsers/PubSubItemParser.cpp
new file mode 100644
index 0000000..2e7d01a
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/PubSubItemParser.cpp
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma clang diagnostic ignored "-Wunused-private-field"
+
+#include <Swiften/Parser/PayloadParsers/PubSubItemParser.h>
+
+#include <boost/optional.hpp>
+
+
+#include <Swiften/Parser/PayloadParserFactoryCollection.h>
+#include <Swiften/Parser/PayloadParserFactory.h>
+
+
+using namespace Swift;
+
+PubSubItemParser::PubSubItemParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) {
+}
+
+PubSubItemParser::~PubSubItemParser() {
+}
+
+void PubSubItemParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) {
+ if (level == 0) {
+ if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("id")) {
+ getPayloadInternal()->setID(*attributeValue);
+ }
+ }
+
+ if (level == 1) {
+ if (PayloadParserFactory* factory = parsers->getPayloadParserFactory(element, ns, attributes)) {
+ currentPayloadParser.reset(factory->createPayloadParser());
+ }
+ }
+
+ if (level >= 1 && currentPayloadParser) {
+ currentPayloadParser->handleStartElement(element, ns, attributes);
+ }
+ ++level;
+}
+
+void PubSubItemParser::handleEndElement(const std::string& element, const std::string& ns) {
+ --level;
+ if (currentPayloadParser) {
+ if (level >= 1) {
+ currentPayloadParser->handleEndElement(element, ns);
+ }
+
+ if (level == 1) {
+ getPayloadInternal()->addData(currentPayloadParser->getPayload());
+ currentPayloadParser.reset();
+ }
+ }
+}
+
+void PubSubItemParser::handleCharacterData(const std::string& data) {
+ if (level > 1 && currentPayloadParser) {
+ currentPayloadParser->handleCharacterData(data);
+ }
+}
diff --git a/Swiften/Parser/PayloadParsers/PubSubItemParser.h b/Swiften/Parser/PayloadParsers/PubSubItemParser.h
new file mode 100644
index 0000000..4f02211
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/PubSubItemParser.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <boost/shared_ptr.hpp>
+
+#include <Swiften/Base/Override.h>
+#include <Swiften/Base/API.h>
+#include <Swiften/Elements/PubSubItem.h>
+#include <Swiften/Parser/GenericPayloadParser.h>
+
+namespace Swift {
+ class PayloadParserFactoryCollection;
+ class PayloadParser;
+
+ class SWIFTEN_API PubSubItemParser : public GenericPayloadParser<PubSubItem> {
+ public:
+ PubSubItemParser(PayloadParserFactoryCollection* parsers);
+ virtual ~PubSubItemParser();
+
+ virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE;
+ virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE;
+ virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE;
+
+ private:
+ PayloadParserFactoryCollection* parsers;
+ int level;
+ boost::shared_ptr<PayloadParser> currentPayloadParser;
+ };
+}
diff --git a/Swiften/Parser/PayloadParsers/PubSubItemsParser.cpp b/Swiften/Parser/PayloadParsers/PubSubItemsParser.cpp
new file mode 100644
index 0000000..615f05d
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/PubSubItemsParser.cpp
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma clang diagnostic ignored "-Wunused-private-field"
+
+#include <Swiften/Parser/PayloadParsers/PubSubItemsParser.h>
+
+#include <boost/optional.hpp>
+#include <boost/lexical_cast.hpp>
+
+#include <Swiften/Parser/PayloadParserFactoryCollection.h>
+#include <Swiften/Parser/PayloadParserFactory.h>
+#include <Swiften/Parser/PayloadParsers/PubSubItemParser.h>
+
+using namespace Swift;
+
+PubSubItemsParser::PubSubItemsParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) {
+}
+
+PubSubItemsParser::~PubSubItemsParser() {
+}
+
+void PubSubItemsParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) {
+ if (level == 0) {
+ if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) {
+ getPayloadInternal()->setNode(*attributeValue);
+ }
+ if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("max_items")) {
+ try {
+ getPayloadInternal()->setMaximumItems(boost::lexical_cast<unsigned int>(*attributeValue));
+ }
+ catch (boost::bad_lexical_cast&) {
+ }
+ }
+ if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("subid")) {
+ getPayloadInternal()->setSubscriptionID(*attributeValue);
+ }
+ }
+
+ if (level == 1) {
+ if (element == "item" && ns == "http://jabber.org/protocol/pubsub") {
+ currentPayloadParser = boost::make_shared<PubSubItemParser>(parsers);
+ }
+ }
+
+ if (level >= 1 && currentPayloadParser) {
+ currentPayloadParser->handleStartElement(element, ns, attributes);
+ }
+ ++level;
+}
+
+void PubSubItemsParser::handleEndElement(const std::string& element, const std::string& ns) {
+ --level;
+ if (currentPayloadParser) {
+ if (level >= 1) {
+ currentPayloadParser->handleEndElement(element, ns);
+ }
+
+ if (level == 1) {
+ if (element == "item" && ns == "http://jabber.org/protocol/pubsub") {
+ getPayloadInternal()->addItem(boost::dynamic_pointer_cast<PubSubItem>(currentPayloadParser->getPayload()));
+ }
+ currentPayloadParser.reset();
+ }
+ }
+}
+
+void PubSubItemsParser::handleCharacterData(const std::string& data) {
+ if (level > 1 && currentPayloadParser) {
+ currentPayloadParser->handleCharacterData(data);
+ }
+}
diff --git a/Swiften/Parser/PayloadParsers/PubSubItemsParser.h b/Swiften/Parser/PayloadParsers/PubSubItemsParser.h
new file mode 100644
index 0000000..895863f
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/PubSubItemsParser.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <boost/shared_ptr.hpp>
+
+#include <Swiften/Base/Override.h>
+#include <Swiften/Base/API.h>
+#include <Swiften/Elements/PubSubItems.h>
+#include <Swiften/Parser/GenericPayloadParser.h>
+
+namespace Swift {
+ class PayloadParserFactoryCollection;
+ class PayloadParser;
+
+ class SWIFTEN_API PubSubItemsParser : public GenericPayloadParser<PubSubItems> {
+ public:
+ PubSubItemsParser(PayloadParserFactoryCollection* parsers);
+ virtual ~PubSubItemsParser();
+
+ virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE;
+ virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE;
+ virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE;
+
+ private:
+ PayloadParserFactoryCollection* parsers;
+ int level;
+ boost::shared_ptr<PayloadParser> currentPayloadParser;
+ };
+}
diff --git a/Swiften/Parser/PayloadParsers/PubSubOptionsParser.cpp b/Swiften/Parser/PayloadParsers/PubSubOptionsParser.cpp
new file mode 100644
index 0000000..3bf4998
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/PubSubOptionsParser.cpp
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma clang diagnostic ignored "-Wunused-private-field"
+
+#include <Swiften/Parser/PayloadParsers/PubSubOptionsParser.h>
+
+#include <boost/optional.hpp>
+
+
+#include <Swiften/Parser/PayloadParserFactoryCollection.h>
+#include <Swiften/Parser/PayloadParserFactory.h>
+#include <Swiften/Parser/PayloadParsers/FormParser.h>
+
+using namespace Swift;
+
+PubSubOptionsParser::PubSubOptionsParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) {
+}
+
+PubSubOptionsParser::~PubSubOptionsParser() {
+}
+
+void PubSubOptionsParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) {
+ if (level == 0) {
+ if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) {
+ getPayloadInternal()->setNode(*attributeValue);
+ }
+ if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("jid")) {
+ if (boost::optional<JID> jid = JID::parse(*attributeValue)) {
+ getPayloadInternal()->setJID(*jid);
+ }
+ }
+ if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("subid")) {
+ getPayloadInternal()->setSubscriptionID(*attributeValue);
+ }
+ }
+
+ if (level == 1) {
+ if (element == "x" && ns == "jabber:x:data") {
+ currentPayloadParser = boost::make_shared<FormParser>();
+ }
+ }
+
+ if (level >= 1 && currentPayloadParser) {
+ currentPayloadParser->handleStartElement(element, ns, attributes);
+ }
+ ++level;
+}
+
+void PubSubOptionsParser::handleEndElement(const std::string& element, const std::string& ns) {
+ --level;
+ if (currentPayloadParser) {
+ if (level >= 1) {
+ currentPayloadParser->handleEndElement(element, ns);
+ }
+
+ if (level == 1) {
+ if (element == "x" && ns == "jabber:x:data") {
+ getPayloadInternal()->setData(boost::dynamic_pointer_cast<Form>(currentPayloadParser->getPayload()));
+ }
+ currentPayloadParser.reset();
+ }
+ }
+}
+
+void PubSubOptionsParser::handleCharacterData(const std::string& data) {
+ if (level > 1 && currentPayloadParser) {
+ currentPayloadParser->handleCharacterData(data);
+ }
+}
diff --git a/Swiften/Parser/PayloadParsers/PubSubOptionsParser.h b/Swiften/Parser/PayloadParsers/PubSubOptionsParser.h
new file mode 100644
index 0000000..3c8754b
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/PubSubOptionsParser.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <boost/shared_ptr.hpp>
+
+#include <Swiften/Base/Override.h>
+#include <Swiften/Base/API.h>
+#include <Swiften/Elements/PubSubOptions.h>
+#include <Swiften/Parser/GenericPayloadParser.h>
+
+namespace Swift {
+ class PayloadParserFactoryCollection;
+ class PayloadParser;
+
+ class SWIFTEN_API PubSubOptionsParser : public GenericPayloadParser<PubSubOptions> {
+ public:
+ PubSubOptionsParser(PayloadParserFactoryCollection* parsers);
+ virtual ~PubSubOptionsParser();
+
+ virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE;
+ virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE;
+ virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE;
+
+ private:
+ PayloadParserFactoryCollection* parsers;
+ int level;
+ boost::shared_ptr<PayloadParser> currentPayloadParser;
+ };
+}
diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationParser.cpp b/Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationParser.cpp
new file mode 100644
index 0000000..a648862
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationParser.cpp
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma clang diagnostic ignored "-Wunused-private-field"
+
+#include <Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationParser.h>
+
+#include <boost/optional.hpp>
+
+
+#include <Swiften/Parser/PayloadParserFactoryCollection.h>
+#include <Swiften/Parser/PayloadParserFactory.h>
+#include <Swiften/Parser/EnumParser.h>
+
+using namespace Swift;
+
+PubSubOwnerAffiliationParser::PubSubOwnerAffiliationParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) {
+}
+
+PubSubOwnerAffiliationParser::~PubSubOwnerAffiliationParser() {
+}
+
+void PubSubOwnerAffiliationParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) {
+ if (level == 0) {
+ if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("jid")) {
+ if (boost::optional<JID> jid = JID::parse(*attributeValue)) {
+ getPayloadInternal()->setJID(*jid);
+ }
+ }
+ if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("affiliation")) {
+ if (boost::optional<PubSubOwnerAffiliation::Type> value = EnumParser<PubSubOwnerAffiliation::Type>()(PubSubOwnerAffiliation::None, "none")(PubSubOwnerAffiliation::Member, "member")(PubSubOwnerAffiliation::Outcast, "outcast")(PubSubOwnerAffiliation::Owner, "owner")(PubSubOwnerAffiliation::Publisher, "publisher")(PubSubOwnerAffiliation::PublishOnly, "publish-only").parse(*attributeValue)) {
+ getPayloadInternal()->setType(*value);
+ }
+ }
+ }
+
+
+
+ if (level >= 1 && currentPayloadParser) {
+ currentPayloadParser->handleStartElement(element, ns, attributes);
+ }
+ ++level;
+}
+
+void PubSubOwnerAffiliationParser::handleEndElement(const std::string& element, const std::string& ns) {
+ --level;
+ if (currentPayloadParser) {
+ if (level >= 1) {
+ currentPayloadParser->handleEndElement(element, ns);
+ }
+
+ if (level == 1) {
+
+ currentPayloadParser.reset();
+ }
+ }
+}
+
+void PubSubOwnerAffiliationParser::handleCharacterData(const std::string& data) {
+ if (level > 1 && currentPayloadParser) {
+ currentPayloadParser->handleCharacterData(data);
+ }
+}
diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationParser.h b/Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationParser.h
new file mode 100644
index 0000000..ae54b5f
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationParser.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <boost/shared_ptr.hpp>
+
+#include <Swiften/Base/Override.h>
+#include <Swiften/Base/API.h>
+#include <Swiften/Elements/PubSubOwnerAffiliation.h>
+#include <Swiften/Parser/GenericPayloadParser.h>
+
+namespace Swift {
+ class PayloadParserFactoryCollection;
+ class PayloadParser;
+
+ class SWIFTEN_API PubSubOwnerAffiliationParser : public GenericPayloadParser<PubSubOwnerAffiliation> {
+ public:
+ PubSubOwnerAffiliationParser(PayloadParserFactoryCollection* parsers);
+ virtual ~PubSubOwnerAffiliationParser();
+
+ virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE;
+ virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE;
+ virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE;
+
+ private:
+ PayloadParserFactoryCollection* parsers;
+ int level;
+ boost::shared_ptr<PayloadParser> currentPayloadParser;
+ };
+}
diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationsParser.cpp b/Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationsParser.cpp
new file mode 100644
index 0000000..b824279
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationsParser.cpp
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma clang diagnostic ignored "-Wunused-private-field"
+
+#include <Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationsParser.h>
+
+#include <boost/optional.hpp>
+
+
+#include <Swiften/Parser/PayloadParserFactoryCollection.h>
+#include <Swiften/Parser/PayloadParserFactory.h>
+#include <Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationParser.h>
+
+using namespace Swift;
+
+PubSubOwnerAffiliationsParser::PubSubOwnerAffiliationsParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) {
+}
+
+PubSubOwnerAffiliationsParser::~PubSubOwnerAffiliationsParser() {
+}
+
+void PubSubOwnerAffiliationsParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) {
+ if (level == 0) {
+ if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) {
+ getPayloadInternal()->setNode(*attributeValue);
+ }
+ }
+
+ if (level == 1) {
+ if (element == "affiliation" && ns == "http://jabber.org/protocol/pubsub#owner") {
+ currentPayloadParser = boost::make_shared<PubSubOwnerAffiliationParser>(parsers);
+ }
+ }
+
+ if (level >= 1 && currentPayloadParser) {
+ currentPayloadParser->handleStartElement(element, ns, attributes);
+ }
+ ++level;
+}
+
+void PubSubOwnerAffiliationsParser::handleEndElement(const std::string& element, const std::string& ns) {
+ --level;
+ if (currentPayloadParser) {
+ if (level >= 1) {
+ currentPayloadParser->handleEndElement(element, ns);
+ }
+
+ if (level == 1) {
+ if (element == "affiliation" && ns == "http://jabber.org/protocol/pubsub#owner") {
+ getPayloadInternal()->addAffiliation(boost::dynamic_pointer_cast<PubSubOwnerAffiliation>(currentPayloadParser->getPayload()));
+ }
+ currentPayloadParser.reset();
+ }
+ }
+}
+
+void PubSubOwnerAffiliationsParser::handleCharacterData(const std::string& data) {
+ if (level > 1 && currentPayloadParser) {
+ currentPayloadParser->handleCharacterData(data);
+ }
+}
diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationsParser.h b/Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationsParser.h
new file mode 100644
index 0000000..755d58c
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationsParser.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <boost/shared_ptr.hpp>
+
+#include <Swiften/Base/Override.h>
+#include <Swiften/Base/API.h>
+#include <Swiften/Elements/PubSubOwnerAffiliations.h>
+#include <Swiften/Parser/GenericPayloadParser.h>
+
+namespace Swift {
+ class PayloadParserFactoryCollection;
+ class PayloadParser;
+
+ class SWIFTEN_API PubSubOwnerAffiliationsParser : public GenericPayloadParser<PubSubOwnerAffiliations> {
+ public:
+ PubSubOwnerAffiliationsParser(PayloadParserFactoryCollection* parsers);
+ virtual ~PubSubOwnerAffiliationsParser();
+
+ virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE;
+ virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE;
+ virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE;
+
+ private:
+ PayloadParserFactoryCollection* parsers;
+ int level;
+ boost::shared_ptr<PayloadParser> currentPayloadParser;
+ };
+}
diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerConfigureParser.cpp b/Swiften/Parser/PayloadParsers/PubSubOwnerConfigureParser.cpp
new file mode 100644
index 0000000..43d262f
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/PubSubOwnerConfigureParser.cpp
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma clang diagnostic ignored "-Wunused-private-field"
+
+#include <Swiften/Parser/PayloadParsers/PubSubOwnerConfigureParser.h>
+
+#include <boost/optional.hpp>
+
+
+#include <Swiften/Parser/PayloadParserFactoryCollection.h>
+#include <Swiften/Parser/PayloadParserFactory.h>
+#include <Swiften/Parser/PayloadParsers/FormParser.h>
+
+using namespace Swift;
+
+PubSubOwnerConfigureParser::PubSubOwnerConfigureParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) {
+}
+
+PubSubOwnerConfigureParser::~PubSubOwnerConfigureParser() {
+}
+
+void PubSubOwnerConfigureParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) {
+ if (level == 0) {
+ if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) {
+ getPayloadInternal()->setNode(*attributeValue);
+ }
+ }
+
+ if (level == 1) {
+ if (element == "x" && ns == "jabber:x:data") {
+ currentPayloadParser = boost::make_shared<FormParser>();
+ }
+ }
+
+ if (level >= 1 && currentPayloadParser) {
+ currentPayloadParser->handleStartElement(element, ns, attributes);
+ }
+ ++level;
+}
+
+void PubSubOwnerConfigureParser::handleEndElement(const std::string& element, const std::string& ns) {
+ --level;
+ if (currentPayloadParser) {
+ if (level >= 1) {
+ currentPayloadParser->handleEndElement(element, ns);
+ }
+
+ if (level == 1) {
+ if (element == "x" && ns == "jabber:x:data") {
+ getPayloadInternal()->setData(boost::dynamic_pointer_cast<Form>(currentPayloadParser->getPayload()));
+ }
+ currentPayloadParser.reset();
+ }
+ }
+}
+
+void PubSubOwnerConfigureParser::handleCharacterData(const std::string& data) {
+ if (level > 1 && currentPayloadParser) {
+ currentPayloadParser->handleCharacterData(data);
+ }
+}
diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerConfigureParser.h b/Swiften/Parser/PayloadParsers/PubSubOwnerConfigureParser.h
new file mode 100644
index 0000000..f9a8553
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/PubSubOwnerConfigureParser.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <boost/shared_ptr.hpp>
+
+#include <Swiften/Base/Override.h>
+#include <Swiften/Base/API.h>
+#include <Swiften/Elements/PubSubOwnerConfigure.h>
+#include <Swiften/Parser/GenericPayloadParser.h>
+
+namespace Swift {
+ class PayloadParserFactoryCollection;
+ class PayloadParser;
+
+ class SWIFTEN_API PubSubOwnerConfigureParser : public GenericPayloadParser<PubSubOwnerConfigure> {
+ public:
+ PubSubOwnerConfigureParser(PayloadParserFactoryCollection* parsers);
+ virtual ~PubSubOwnerConfigureParser();
+
+ virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE;
+ virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE;
+ virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE;
+
+ private:
+ PayloadParserFactoryCollection* parsers;
+ int level;
+ boost::shared_ptr<PayloadParser> currentPayloadParser;
+ };
+}
diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerDefaultParser.cpp b/Swiften/Parser/PayloadParsers/PubSubOwnerDefaultParser.cpp
new file mode 100644
index 0000000..4c284bf
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/PubSubOwnerDefaultParser.cpp
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma clang diagnostic ignored "-Wunused-private-field"
+
+#include <Swiften/Parser/PayloadParsers/PubSubOwnerDefaultParser.h>
+
+#include <boost/optional.hpp>
+
+
+#include <Swiften/Parser/PayloadParserFactoryCollection.h>
+#include <Swiften/Parser/PayloadParserFactory.h>
+#include <Swiften/Parser/PayloadParsers/FormParser.h>
+
+using namespace Swift;
+
+PubSubOwnerDefaultParser::PubSubOwnerDefaultParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) {
+}
+
+PubSubOwnerDefaultParser::~PubSubOwnerDefaultParser() {
+}
+
+void PubSubOwnerDefaultParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) {
+
+
+ if (level == 1) {
+ if (element == "x" && ns == "jabber:x:data") {
+ currentPayloadParser = boost::make_shared<FormParser>();
+ }
+ }
+
+ if (level >= 1 && currentPayloadParser) {
+ currentPayloadParser->handleStartElement(element, ns, attributes);
+ }
+ ++level;
+}
+
+void PubSubOwnerDefaultParser::handleEndElement(const std::string& element, const std::string& ns) {
+ --level;
+ if (currentPayloadParser) {
+ if (level >= 1) {
+ currentPayloadParser->handleEndElement(element, ns);
+ }
+
+ if (level == 1) {
+ if (element == "x" && ns == "jabber:x:data") {
+ getPayloadInternal()->setData(boost::dynamic_pointer_cast<Form>(currentPayloadParser->getPayload()));
+ }
+ currentPayloadParser.reset();
+ }
+ }
+}
+
+void PubSubOwnerDefaultParser::handleCharacterData(const std::string& data) {
+ if (level > 1 && currentPayloadParser) {
+ currentPayloadParser->handleCharacterData(data);
+ }
+}
diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerDefaultParser.h b/Swiften/Parser/PayloadParsers/PubSubOwnerDefaultParser.h
new file mode 100644
index 0000000..5207bc5
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/PubSubOwnerDefaultParser.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <boost/shared_ptr.hpp>
+
+#include <Swiften/Base/Override.h>
+#include <Swiften/Base/API.h>
+#include <Swiften/Elements/PubSubOwnerDefault.h>
+#include <Swiften/Parser/GenericPayloadParser.h>
+
+namespace Swift {
+ class PayloadParserFactoryCollection;
+ class PayloadParser;
+
+ class SWIFTEN_API PubSubOwnerDefaultParser : public GenericPayloadParser<PubSubOwnerDefault> {
+ public:
+ PubSubOwnerDefaultParser(PayloadParserFactoryCollection* parsers);
+ virtual ~PubSubOwnerDefaultParser();
+
+ virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE;
+ virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE;
+ virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE;
+
+ private:
+ PayloadParserFactoryCollection* parsers;
+ int level;
+ boost::shared_ptr<PayloadParser> currentPayloadParser;
+ };
+}
diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerDeleteParser.cpp b/Swiften/Parser/PayloadParsers/PubSubOwnerDeleteParser.cpp
new file mode 100644
index 0000000..a2b7a9d
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/PubSubOwnerDeleteParser.cpp
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma clang diagnostic ignored "-Wunused-private-field"
+
+#include <Swiften/Parser/PayloadParsers/PubSubOwnerDeleteParser.h>
+
+#include <boost/optional.hpp>
+
+
+#include <Swiften/Parser/PayloadParserFactoryCollection.h>
+#include <Swiften/Parser/PayloadParserFactory.h>
+#include <Swiften/Parser/PayloadParsers/PubSubOwnerRedirectParser.h>
+
+using namespace Swift;
+
+PubSubOwnerDeleteParser::PubSubOwnerDeleteParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) {
+}
+
+PubSubOwnerDeleteParser::~PubSubOwnerDeleteParser() {
+}
+
+void PubSubOwnerDeleteParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) {
+ if (level == 0) {
+ if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) {
+ getPayloadInternal()->setNode(*attributeValue);
+ }
+ }
+
+ if (level == 1) {
+ if (element == "redirect" && ns == "http://jabber.org/protocol/pubsub#owner") {
+ currentPayloadParser = boost::make_shared<PubSubOwnerRedirectParser>(parsers);
+ }
+ }
+
+ if (level >= 1 && currentPayloadParser) {
+ currentPayloadParser->handleStartElement(element, ns, attributes);
+ }
+ ++level;
+}
+
+void PubSubOwnerDeleteParser::handleEndElement(const std::string& element, const std::string& ns) {
+ --level;
+ if (currentPayloadParser) {
+ if (level >= 1) {
+ currentPayloadParser->handleEndElement(element, ns);
+ }
+
+ if (level == 1) {
+ if (element == "redirect" && ns == "http://jabber.org/protocol/pubsub#owner") {
+ getPayloadInternal()->setRedirect(boost::dynamic_pointer_cast<PubSubOwnerRedirect>(currentPayloadParser->getPayload()));
+ }
+ currentPayloadParser.reset();
+ }
+ }
+}
+
+void PubSubOwnerDeleteParser::handleCharacterData(const std::string& data) {
+ if (level > 1 && currentPayloadParser) {
+ currentPayloadParser->handleCharacterData(data);
+ }
+}
diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerDeleteParser.h b/Swiften/Parser/PayloadParsers/PubSubOwnerDeleteParser.h
new file mode 100644
index 0000000..c171ab8
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/PubSubOwnerDeleteParser.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <boost/shared_ptr.hpp>
+
+#include <Swiften/Base/Override.h>
+#include <Swiften/Base/API.h>
+#include <Swiften/Elements/PubSubOwnerDelete.h>
+#include <Swiften/Parser/GenericPayloadParser.h>
+
+namespace Swift {
+ class PayloadParserFactoryCollection;
+ class PayloadParser;
+
+ class SWIFTEN_API PubSubOwnerDeleteParser : public GenericPayloadParser<PubSubOwnerDelete> {
+ public:
+ PubSubOwnerDeleteParser(PayloadParserFactoryCollection* parsers);
+ virtual ~PubSubOwnerDeleteParser();
+
+ virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE;
+ virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE;
+ virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE;
+
+ private:
+ PayloadParserFactoryCollection* parsers;
+ int level;
+ boost::shared_ptr<PayloadParser> currentPayloadParser;
+ };
+}
diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerPubSubParser.cpp b/Swiften/Parser/PayloadParsers/PubSubOwnerPubSubParser.cpp
new file mode 100644
index 0000000..5262997
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/PubSubOwnerPubSubParser.cpp
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma clang diagnostic ignored "-Wunused-private-field"
+
+#include <Swiften/Parser/PayloadParsers/PubSubOwnerPubSubParser.h>
+
+#include <boost/optional.hpp>
+
+
+#include <Swiften/Parser/PayloadParserFactoryCollection.h>
+#include <Swiften/Parser/PayloadParserFactory.h>
+#include <Swiften/Parser/PayloadParsers/PubSubOwnerDefaultParser.h>
+#include <Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionsParser.h>
+#include <Swiften/Parser/PayloadParsers/PubSubOwnerDeleteParser.h>
+#include <Swiften/Parser/PayloadParsers/PubSubOwnerPurgeParser.h>
+#include <Swiften/Parser/PayloadParsers/PubSubOwnerConfigureParser.h>
+#include <Swiften/Parser/PayloadParsers/PubSubOwnerAffiliationsParser.h>
+
+using namespace Swift;
+
+PubSubOwnerPubSubParser::PubSubOwnerPubSubParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) {
+}
+
+PubSubOwnerPubSubParser::~PubSubOwnerPubSubParser() {
+}
+
+void PubSubOwnerPubSubParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) {
+
+
+ if (level == 1) {
+ if (element == "configure" && ns == "http://jabber.org/protocol/pubsub#owner") {
+ currentPayloadParser = boost::make_shared<PubSubOwnerConfigureParser>(parsers);
+ }
+ if (element == "subscriptions" && ns == "http://jabber.org/protocol/pubsub#owner") {
+ currentPayloadParser = boost::make_shared<PubSubOwnerSubscriptionsParser>(parsers);
+ }
+ if (element == "default" && ns == "http://jabber.org/protocol/pubsub#owner") {
+ currentPayloadParser = boost::make_shared<PubSubOwnerDefaultParser>(parsers);
+ }
+ if (element == "purge" && ns == "http://jabber.org/protocol/pubsub#owner") {
+ currentPayloadParser = boost::make_shared<PubSubOwnerPurgeParser>(parsers);
+ }
+ if (element == "affiliations" && ns == "http://jabber.org/protocol/pubsub#owner") {
+ currentPayloadParser = boost::make_shared<PubSubOwnerAffiliationsParser>(parsers);
+ }
+ if (element == "delete" && ns == "http://jabber.org/protocol/pubsub#owner") {
+ currentPayloadParser = boost::make_shared<PubSubOwnerDeleteParser>(parsers);
+ }
+ }
+
+ if (level >= 1 && currentPayloadParser) {
+ currentPayloadParser->handleStartElement(element, ns, attributes);
+ }
+ ++level;
+}
+
+void PubSubOwnerPubSubParser::handleEndElement(const std::string& element, const std::string& ns) {
+ --level;
+ if (currentPayloadParser) {
+ if (level >= 1) {
+ currentPayloadParser->handleEndElement(element, ns);
+ }
+
+ if (level == 1) {
+ if (currentPayloadParser) {
+ getPayloadInternal()->setPayload(boost::dynamic_pointer_cast<PubSubOwnerPayload>(currentPayloadParser->getPayload()));
+ }
+ currentPayloadParser.reset();
+ }
+ }
+}
+
+void PubSubOwnerPubSubParser::handleCharacterData(const std::string& data) {
+ if (level > 1 && currentPayloadParser) {
+ currentPayloadParser->handleCharacterData(data);
+ }
+}
diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerPubSubParser.h b/Swiften/Parser/PayloadParsers/PubSubOwnerPubSubParser.h
new file mode 100644
index 0000000..25fee8a
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/PubSubOwnerPubSubParser.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <boost/shared_ptr.hpp>
+
+#include <Swiften/Base/Override.h>
+#include <Swiften/Base/API.h>
+#include <Swiften/Elements/PubSubOwnerPubSub.h>
+#include <Swiften/Parser/GenericPayloadParser.h>
+
+namespace Swift {
+ class PayloadParserFactoryCollection;
+ class PayloadParser;
+
+ class SWIFTEN_API PubSubOwnerPubSubParser : public GenericPayloadParser<PubSubOwnerPubSub> {
+ public:
+ PubSubOwnerPubSubParser(PayloadParserFactoryCollection* parsers);
+ virtual ~PubSubOwnerPubSubParser();
+
+ virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE;
+ virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE;
+ virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE;
+
+ private:
+ PayloadParserFactoryCollection* parsers;
+ int level;
+ boost::shared_ptr<PayloadParser> currentPayloadParser;
+ };
+}
diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerPurgeParser.cpp b/Swiften/Parser/PayloadParsers/PubSubOwnerPurgeParser.cpp
new file mode 100644
index 0000000..ebea0a7
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/PubSubOwnerPurgeParser.cpp
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma clang diagnostic ignored "-Wunused-private-field"
+
+#include <Swiften/Parser/PayloadParsers/PubSubOwnerPurgeParser.h>
+
+#include <boost/optional.hpp>
+
+
+#include <Swiften/Parser/PayloadParserFactoryCollection.h>
+#include <Swiften/Parser/PayloadParserFactory.h>
+
+
+using namespace Swift;
+
+PubSubOwnerPurgeParser::PubSubOwnerPurgeParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) {
+}
+
+PubSubOwnerPurgeParser::~PubSubOwnerPurgeParser() {
+}
+
+void PubSubOwnerPurgeParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) {
+ if (level == 0) {
+ if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) {
+ getPayloadInternal()->setNode(*attributeValue);
+ }
+ }
+
+
+
+ if (level >= 1 && currentPayloadParser) {
+ currentPayloadParser->handleStartElement(element, ns, attributes);
+ }
+ ++level;
+}
+
+void PubSubOwnerPurgeParser::handleEndElement(const std::string& element, const std::string& ns) {
+ --level;
+ if (currentPayloadParser) {
+ if (level >= 1) {
+ currentPayloadParser->handleEndElement(element, ns);
+ }
+
+ if (level == 1) {
+
+ currentPayloadParser.reset();
+ }
+ }
+}
+
+void PubSubOwnerPurgeParser::handleCharacterData(const std::string& data) {
+ if (level > 1 && currentPayloadParser) {
+ currentPayloadParser->handleCharacterData(data);
+ }
+}
diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerPurgeParser.h b/Swiften/Parser/PayloadParsers/PubSubOwnerPurgeParser.h
new file mode 100644
index 0000000..0b85d3d
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/PubSubOwnerPurgeParser.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <boost/shared_ptr.hpp>
+
+#include <Swiften/Base/Override.h>
+#include <Swiften/Base/API.h>
+#include <Swiften/Elements/PubSubOwnerPurge.h>
+#include <Swiften/Parser/GenericPayloadParser.h>
+
+namespace Swift {
+ class PayloadParserFactoryCollection;
+ class PayloadParser;
+
+ class SWIFTEN_API PubSubOwnerPurgeParser : public GenericPayloadParser<PubSubOwnerPurge> {
+ public:
+ PubSubOwnerPurgeParser(PayloadParserFactoryCollection* parsers);
+ virtual ~PubSubOwnerPurgeParser();
+
+ virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE;
+ virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE;
+ virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE;
+
+ private:
+ PayloadParserFactoryCollection* parsers;
+ int level;
+ boost::shared_ptr<PayloadParser> currentPayloadParser;
+ };
+}
diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerRedirectParser.cpp b/Swiften/Parser/PayloadParsers/PubSubOwnerRedirectParser.cpp
new file mode 100644
index 0000000..bc54e86
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/PubSubOwnerRedirectParser.cpp
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma clang diagnostic ignored "-Wunused-private-field"
+
+#include <Swiften/Parser/PayloadParsers/PubSubOwnerRedirectParser.h>
+
+#include <boost/optional.hpp>
+
+
+#include <Swiften/Parser/PayloadParserFactoryCollection.h>
+#include <Swiften/Parser/PayloadParserFactory.h>
+
+
+using namespace Swift;
+
+PubSubOwnerRedirectParser::PubSubOwnerRedirectParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) {
+}
+
+PubSubOwnerRedirectParser::~PubSubOwnerRedirectParser() {
+}
+
+void PubSubOwnerRedirectParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) {
+ if (level == 0) {
+ if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("uri")) {
+ getPayloadInternal()->setURI(*attributeValue);
+ }
+ }
+
+
+
+ if (level >= 1 && currentPayloadParser) {
+ currentPayloadParser->handleStartElement(element, ns, attributes);
+ }
+ ++level;
+}
+
+void PubSubOwnerRedirectParser::handleEndElement(const std::string& element, const std::string& ns) {
+ --level;
+ if (currentPayloadParser) {
+ if (level >= 1) {
+ currentPayloadParser->handleEndElement(element, ns);
+ }
+
+ if (level == 1) {
+
+ currentPayloadParser.reset();
+ }
+ }
+}
+
+void PubSubOwnerRedirectParser::handleCharacterData(const std::string& data) {
+ if (level > 1 && currentPayloadParser) {
+ currentPayloadParser->handleCharacterData(data);
+ }
+}
diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerRedirectParser.h b/Swiften/Parser/PayloadParsers/PubSubOwnerRedirectParser.h
new file mode 100644
index 0000000..9a97d74
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/PubSubOwnerRedirectParser.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <boost/shared_ptr.hpp>
+
+#include <Swiften/Base/Override.h>
+#include <Swiften/Base/API.h>
+#include <Swiften/Elements/PubSubOwnerRedirect.h>
+#include <Swiften/Parser/GenericPayloadParser.h>
+
+namespace Swift {
+ class PayloadParserFactoryCollection;
+ class PayloadParser;
+
+ class SWIFTEN_API PubSubOwnerRedirectParser : public GenericPayloadParser<PubSubOwnerRedirect> {
+ public:
+ PubSubOwnerRedirectParser(PayloadParserFactoryCollection* parsers);
+ virtual ~PubSubOwnerRedirectParser();
+
+ virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE;
+ virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE;
+ virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE;
+
+ private:
+ PayloadParserFactoryCollection* parsers;
+ int level;
+ boost::shared_ptr<PayloadParser> currentPayloadParser;
+ };
+}
diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionParser.cpp b/Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionParser.cpp
new file mode 100644
index 0000000..7c91526
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionParser.cpp
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma clang diagnostic ignored "-Wunused-private-field"
+
+#include <Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionParser.h>
+
+#include <boost/optional.hpp>
+
+
+#include <Swiften/Parser/PayloadParserFactoryCollection.h>
+#include <Swiften/Parser/PayloadParserFactory.h>
+#include <Swiften/Parser/EnumParser.h>
+
+using namespace Swift;
+
+PubSubOwnerSubscriptionParser::PubSubOwnerSubscriptionParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) {
+}
+
+PubSubOwnerSubscriptionParser::~PubSubOwnerSubscriptionParser() {
+}
+
+void PubSubOwnerSubscriptionParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) {
+ if (level == 0) {
+ if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("jid")) {
+ if (boost::optional<JID> jid = JID::parse(*attributeValue)) {
+ getPayloadInternal()->setJID(*jid);
+ }
+ }
+ if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("subscription")) {
+ if (boost::optional<PubSubOwnerSubscription::SubscriptionType> value = EnumParser<PubSubOwnerSubscription::SubscriptionType>()(PubSubOwnerSubscription::None, "none")(PubSubOwnerSubscription::Pending, "pending")(PubSubOwnerSubscription::Subscribed, "subscribed")(PubSubOwnerSubscription::Unconfigured, "unconfigured").parse(*attributeValue)) {
+ getPayloadInternal()->setSubscription(*value);
+ }
+ }
+ }
+
+
+
+ if (level >= 1 && currentPayloadParser) {
+ currentPayloadParser->handleStartElement(element, ns, attributes);
+ }
+ ++level;
+}
+
+void PubSubOwnerSubscriptionParser::handleEndElement(const std::string& element, const std::string& ns) {
+ --level;
+ if (currentPayloadParser) {
+ if (level >= 1) {
+ currentPayloadParser->handleEndElement(element, ns);
+ }
+
+ if (level == 1) {
+
+ currentPayloadParser.reset();
+ }
+ }
+}
+
+void PubSubOwnerSubscriptionParser::handleCharacterData(const std::string& data) {
+ if (level > 1 && currentPayloadParser) {
+ currentPayloadParser->handleCharacterData(data);
+ }
+}
diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionParser.h b/Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionParser.h
new file mode 100644
index 0000000..8ef8d5b
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionParser.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <boost/shared_ptr.hpp>
+
+#include <Swiften/Base/Override.h>
+#include <Swiften/Base/API.h>
+#include <Swiften/Elements/PubSubOwnerSubscription.h>
+#include <Swiften/Parser/GenericPayloadParser.h>
+
+namespace Swift {
+ class PayloadParserFactoryCollection;
+ class PayloadParser;
+
+ class SWIFTEN_API PubSubOwnerSubscriptionParser : public GenericPayloadParser<PubSubOwnerSubscription> {
+ public:
+ PubSubOwnerSubscriptionParser(PayloadParserFactoryCollection* parsers);
+ virtual ~PubSubOwnerSubscriptionParser();
+
+ virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE;
+ virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE;
+ virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE;
+
+ private:
+ PayloadParserFactoryCollection* parsers;
+ int level;
+ boost::shared_ptr<PayloadParser> currentPayloadParser;
+ };
+}
diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionsParser.cpp b/Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionsParser.cpp
new file mode 100644
index 0000000..ebe90d8
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionsParser.cpp
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma clang diagnostic ignored "-Wunused-private-field"
+
+#include <Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionsParser.h>
+
+#include <boost/optional.hpp>
+
+
+#include <Swiften/Parser/PayloadParserFactoryCollection.h>
+#include <Swiften/Parser/PayloadParserFactory.h>
+#include <Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionParser.h>
+
+using namespace Swift;
+
+PubSubOwnerSubscriptionsParser::PubSubOwnerSubscriptionsParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) {
+}
+
+PubSubOwnerSubscriptionsParser::~PubSubOwnerSubscriptionsParser() {
+}
+
+void PubSubOwnerSubscriptionsParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) {
+ if (level == 0) {
+ if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) {
+ getPayloadInternal()->setNode(*attributeValue);
+ }
+ }
+
+ if (level == 1) {
+ if (element == "subscription" && ns == "http://jabber.org/protocol/pubsub#owner") {
+ currentPayloadParser = boost::make_shared<PubSubOwnerSubscriptionParser>(parsers);
+ }
+ }
+
+ if (level >= 1 && currentPayloadParser) {
+ currentPayloadParser->handleStartElement(element, ns, attributes);
+ }
+ ++level;
+}
+
+void PubSubOwnerSubscriptionsParser::handleEndElement(const std::string& element, const std::string& ns) {
+ --level;
+ if (currentPayloadParser) {
+ if (level >= 1) {
+ currentPayloadParser->handleEndElement(element, ns);
+ }
+
+ if (level == 1) {
+ if (element == "subscription" && ns == "http://jabber.org/protocol/pubsub#owner") {
+ getPayloadInternal()->addSubscription(boost::dynamic_pointer_cast<PubSubOwnerSubscription>(currentPayloadParser->getPayload()));
+ }
+ currentPayloadParser.reset();
+ }
+ }
+}
+
+void PubSubOwnerSubscriptionsParser::handleCharacterData(const std::string& data) {
+ if (level > 1 && currentPayloadParser) {
+ currentPayloadParser->handleCharacterData(data);
+ }
+}
diff --git a/Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionsParser.h b/Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionsParser.h
new file mode 100644
index 0000000..a5459a9
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/PubSubOwnerSubscriptionsParser.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <boost/shared_ptr.hpp>
+
+#include <Swiften/Base/Override.h>
+#include <Swiften/Base/API.h>
+#include <Swiften/Elements/PubSubOwnerSubscriptions.h>
+#include <Swiften/Parser/GenericPayloadParser.h>
+
+namespace Swift {
+ class PayloadParserFactoryCollection;
+ class PayloadParser;
+
+ class SWIFTEN_API PubSubOwnerSubscriptionsParser : public GenericPayloadParser<PubSubOwnerSubscriptions> {
+ public:
+ PubSubOwnerSubscriptionsParser(PayloadParserFactoryCollection* parsers);
+ virtual ~PubSubOwnerSubscriptionsParser();
+
+ virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE;
+ virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE;
+ virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE;
+
+ private:
+ PayloadParserFactoryCollection* parsers;
+ int level;
+ boost::shared_ptr<PayloadParser> currentPayloadParser;
+ };
+}
diff --git a/Swiften/Parser/PayloadParsers/PubSubParser.cpp b/Swiften/Parser/PayloadParsers/PubSubParser.cpp
new file mode 100644
index 0000000..5b1462b
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/PubSubParser.cpp
@@ -0,0 +1,125 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma clang diagnostic ignored "-Wunused-private-field"
+
+#include <Swiften/Parser/PayloadParsers/PubSubParser.h>
+
+#include <boost/optional.hpp>
+
+
+#include <Swiften/Parser/PayloadParserFactoryCollection.h>
+#include <Swiften/Parser/PayloadParserFactory.h>
+#include <Swiften/Parser/PayloadParsers/PubSubSubscriptionParser.h>
+#include <Swiften/Parser/PayloadParsers/PubSubConfigureParser.h>
+#include <Swiften/Parser/PayloadParsers/PubSubDefaultParser.h>
+#include <Swiften/Parser/PayloadParsers/PubSubCreateParser.h>
+#include <Swiften/Parser/PayloadParsers/PubSubAffiliationsParser.h>
+#include <Swiften/Parser/PayloadParsers/PubSubOptionsParser.h>
+#include <Swiften/Parser/PayloadParsers/PubSubPublishParser.h>
+#include <Swiften/Parser/PayloadParsers/PubSubOptionsParser.h>
+#include <Swiften/Parser/PayloadParsers/PubSubSubscribeParser.h>
+#include <Swiften/Parser/PayloadParsers/PubSubUnsubscribeParser.h>
+#include <Swiften/Parser/PayloadParsers/PubSubItemsParser.h>
+#include <Swiften/Parser/PayloadParsers/PubSubRetractParser.h>
+#include <Swiften/Parser/PayloadParsers/PubSubSubscriptionsParser.h>
+
+using namespace Swift;
+
+PubSubParser::PubSubParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) {
+}
+
+PubSubParser::~PubSubParser() {
+}
+
+void PubSubParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) {
+ if (level == 1) {
+ if (element == "items" && ns == "http://jabber.org/protocol/pubsub") {
+ currentPayloadParser = boost::make_shared<PubSubItemsParser>(parsers);
+ }
+ if (element == "create" && ns == "http://jabber.org/protocol/pubsub") {
+ currentPayloadParser = boost::make_shared<PubSubCreateParser>(parsers);
+ }
+ if (element == "publish" && ns == "http://jabber.org/protocol/pubsub") {
+ currentPayloadParser = boost::make_shared<PubSubPublishParser>(parsers);
+ }
+ if (element == "affiliations" && ns == "http://jabber.org/protocol/pubsub") {
+ currentPayloadParser = boost::make_shared<PubSubAffiliationsParser>(parsers);
+ }
+ if (element == "retract" && ns == "http://jabber.org/protocol/pubsub") {
+ currentPayloadParser = boost::make_shared<PubSubRetractParser>(parsers);
+ }
+ if (element == "options" && ns == "http://jabber.org/protocol/pubsub") {
+ currentPayloadParser = boost::make_shared<PubSubOptionsParser>(parsers);
+ }
+ if (element == "configure" && ns == "http://jabber.org/protocol/pubsub") {
+ currentPayloadParser = boost::make_shared<PubSubConfigureParser>(parsers);
+ }
+ if (element == "default" && ns == "http://jabber.org/protocol/pubsub") {
+ currentPayloadParser = boost::make_shared<PubSubDefaultParser>(parsers);
+ }
+ if (element == "subscriptions" && ns == "http://jabber.org/protocol/pubsub") {
+ currentPayloadParser = boost::make_shared<PubSubSubscriptionsParser>(parsers);
+ }
+ if (element == "subscribe" && ns == "http://jabber.org/protocol/pubsub") {
+ currentPayloadParser = boost::make_shared<PubSubSubscribeParser>(parsers);
+ }
+ if (element == "unsubscribe" && ns == "http://jabber.org/protocol/pubsub") {
+ currentPayloadParser = boost::make_shared<PubSubUnsubscribeParser>(parsers);
+ }
+ if (element == "subscription" && ns == "http://jabber.org/protocol/pubsub") {
+ currentPayloadParser = boost::make_shared<PubSubSubscriptionParser>(parsers);
+ }
+ }
+
+ if (level >= 1 && currentPayloadParser) {
+ currentPayloadParser->handleStartElement(element, ns, attributes);
+ }
+ ++level;
+}
+
+void PubSubParser::handleEndElement(const std::string& element, const std::string& ns) {
+ --level;
+ if (currentPayloadParser) {
+ if (level >= 1) {
+ currentPayloadParser->handleEndElement(element, ns);
+ }
+
+ if (level == 1) {
+ if (currentPayloadParser) {
+ if (element == "options" && ns == "http://jabber.org/protocol/pubsub") {
+ optionsPayload = boost::dynamic_pointer_cast<PubSubOptions>(currentPayloadParser->getPayload());
+ }
+ else if (element == "configure" && ns == "http://jabber.org/protocol/pubsub") {
+ configurePayload = boost::dynamic_pointer_cast<PubSubConfigure>(currentPayloadParser->getPayload());
+ }
+ else {
+ getPayloadInternal()->setPayload(boost::dynamic_pointer_cast<PubSubPayload>(currentPayloadParser->getPayload()));
+ }
+ }
+ currentPayloadParser.reset();
+ }
+
+ if (level == 0) {
+ if (boost::shared_ptr<PubSubCreate> create = boost::dynamic_pointer_cast<PubSubCreate>(getPayloadInternal()->getPayload())) {
+ if (configurePayload) {
+ create->setConfigure(configurePayload);
+ }
+ }
+ if (boost::shared_ptr<PubSubSubscribe> subscribe = boost::dynamic_pointer_cast<PubSubSubscribe>(getPayloadInternal()->getPayload())) {
+ if (optionsPayload) {
+ subscribe->setOptions(optionsPayload);
+ }
+ }
+ }
+ }
+}
+
+void PubSubParser::handleCharacterData(const std::string& data) {
+ if (level > 1 && currentPayloadParser) {
+ currentPayloadParser->handleCharacterData(data);
+ }
+}
diff --git a/Swiften/Parser/PayloadParsers/PubSubParser.h b/Swiften/Parser/PayloadParsers/PubSubParser.h
new file mode 100644
index 0000000..0618361
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/PubSubParser.h
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <boost/shared_ptr.hpp>
+
+#include <Swiften/Base/Override.h>
+#include <Swiften/Base/API.h>
+#include <Swiften/Elements/PubSub.h>
+#include <Swiften/Parser/GenericPayloadParser.h>
+
+namespace Swift {
+ class PayloadParserFactoryCollection;
+ class PayloadParser;
+ class PubSubOptions;
+ class PubSubConfigure;
+
+ class SWIFTEN_API PubSubParser : public GenericPayloadParser<PubSub> {
+ public:
+ PubSubParser(PayloadParserFactoryCollection* parsers);
+ virtual ~PubSubParser();
+
+ virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE;
+ virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE;
+ virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE;
+
+ private:
+ PayloadParserFactoryCollection* parsers;
+ int level;
+ boost::shared_ptr<PayloadParser> currentPayloadParser;
+ boost::shared_ptr<PubSubConfigure> configurePayload;
+ boost::shared_ptr<PubSubOptions> optionsPayload;
+ };
+}
diff --git a/Swiften/Parser/PayloadParsers/PubSubPublishParser.cpp b/Swiften/Parser/PayloadParsers/PubSubPublishParser.cpp
new file mode 100644
index 0000000..ca358c3
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/PubSubPublishParser.cpp
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma clang diagnostic ignored "-Wunused-private-field"
+
+#include <Swiften/Parser/PayloadParsers/PubSubPublishParser.h>
+
+#include <boost/optional.hpp>
+
+
+#include <Swiften/Parser/PayloadParserFactoryCollection.h>
+#include <Swiften/Parser/PayloadParserFactory.h>
+#include <Swiften/Parser/PayloadParsers/PubSubItemParser.h>
+
+using namespace Swift;
+
+PubSubPublishParser::PubSubPublishParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) {
+}
+
+PubSubPublishParser::~PubSubPublishParser() {
+}
+
+void PubSubPublishParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) {
+ if (level == 0) {
+ if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) {
+ getPayloadInternal()->setNode(*attributeValue);
+ }
+ }
+
+ if (level == 1) {
+ if (element == "item" && ns == "http://jabber.org/protocol/pubsub") {
+ currentPayloadParser = boost::make_shared<PubSubItemParser>(parsers);
+ }
+ }
+
+ if (level >= 1 && currentPayloadParser) {
+ currentPayloadParser->handleStartElement(element, ns, attributes);
+ }
+ ++level;
+}
+
+void PubSubPublishParser::handleEndElement(const std::string& element, const std::string& ns) {
+ --level;
+ if (currentPayloadParser) {
+ if (level >= 1) {
+ currentPayloadParser->handleEndElement(element, ns);
+ }
+
+ if (level == 1) {
+ if (element == "item" && ns == "http://jabber.org/protocol/pubsub") {
+ getPayloadInternal()->addItem(boost::dynamic_pointer_cast<PubSubItem>(currentPayloadParser->getPayload()));
+ }
+ currentPayloadParser.reset();
+ }
+ }
+}
+
+void PubSubPublishParser::handleCharacterData(const std::string& data) {
+ if (level > 1 && currentPayloadParser) {
+ currentPayloadParser->handleCharacterData(data);
+ }
+}
diff --git a/Swiften/Parser/PayloadParsers/PubSubPublishParser.h b/Swiften/Parser/PayloadParsers/PubSubPublishParser.h
new file mode 100644
index 0000000..3d64e9d
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/PubSubPublishParser.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <boost/shared_ptr.hpp>
+
+#include <Swiften/Base/Override.h>
+#include <Swiften/Base/API.h>
+#include <Swiften/Elements/PubSubPublish.h>
+#include <Swiften/Parser/GenericPayloadParser.h>
+
+namespace Swift {
+ class PayloadParserFactoryCollection;
+ class PayloadParser;
+
+ class SWIFTEN_API PubSubPublishParser : public GenericPayloadParser<PubSubPublish> {
+ public:
+ PubSubPublishParser(PayloadParserFactoryCollection* parsers);
+ virtual ~PubSubPublishParser();
+
+ virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE;
+ virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE;
+ virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE;
+
+ private:
+ PayloadParserFactoryCollection* parsers;
+ int level;
+ boost::shared_ptr<PayloadParser> currentPayloadParser;
+ };
+}
diff --git a/Swiften/Parser/PayloadParsers/PubSubRetractParser.cpp b/Swiften/Parser/PayloadParsers/PubSubRetractParser.cpp
new file mode 100644
index 0000000..f4a42d0
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/PubSubRetractParser.cpp
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma clang diagnostic ignored "-Wunused-private-field"
+
+#include <Swiften/Parser/PayloadParsers/PubSubRetractParser.h>
+
+#include <boost/optional.hpp>
+
+
+#include <Swiften/Parser/PayloadParserFactoryCollection.h>
+#include <Swiften/Parser/PayloadParserFactory.h>
+#include <Swiften/Parser/PayloadParsers/PubSubItemParser.h>
+
+using namespace Swift;
+
+PubSubRetractParser::PubSubRetractParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) {
+}
+
+PubSubRetractParser::~PubSubRetractParser() {
+}
+
+void PubSubRetractParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) {
+ if (level == 0) {
+ if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) {
+ getPayloadInternal()->setNode(*attributeValue);
+ }
+ if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("notify")) {
+ getPayloadInternal()->setNotify(*attributeValue == "true" ? true : false);
+ }
+ }
+
+ if (level == 1) {
+ if (element == "item" && ns == "http://jabber.org/protocol/pubsub") {
+ currentPayloadParser = boost::make_shared<PubSubItemParser>(parsers);
+ }
+ }
+
+ if (level >= 1 && currentPayloadParser) {
+ currentPayloadParser->handleStartElement(element, ns, attributes);
+ }
+ ++level;
+}
+
+void PubSubRetractParser::handleEndElement(const std::string& element, const std::string& ns) {
+ --level;
+ if (currentPayloadParser) {
+ if (level >= 1) {
+ currentPayloadParser->handleEndElement(element, ns);
+ }
+
+ if (level == 1) {
+ if (element == "item" && ns == "http://jabber.org/protocol/pubsub") {
+ getPayloadInternal()->addItem(boost::dynamic_pointer_cast<PubSubItem>(currentPayloadParser->getPayload()));
+ }
+ currentPayloadParser.reset();
+ }
+ }
+}
+
+void PubSubRetractParser::handleCharacterData(const std::string& data) {
+ if (level > 1 && currentPayloadParser) {
+ currentPayloadParser->handleCharacterData(data);
+ }
+}
diff --git a/Swiften/Parser/PayloadParsers/PubSubRetractParser.h b/Swiften/Parser/PayloadParsers/PubSubRetractParser.h
new file mode 100644
index 0000000..2b5e633
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/PubSubRetractParser.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <boost/shared_ptr.hpp>
+
+#include <Swiften/Base/Override.h>
+#include <Swiften/Base/API.h>
+#include <Swiften/Elements/PubSubRetract.h>
+#include <Swiften/Parser/GenericPayloadParser.h>
+
+namespace Swift {
+ class PayloadParserFactoryCollection;
+ class PayloadParser;
+
+ class SWIFTEN_API PubSubRetractParser : public GenericPayloadParser<PubSubRetract> {
+ public:
+ PubSubRetractParser(PayloadParserFactoryCollection* parsers);
+ virtual ~PubSubRetractParser();
+
+ virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE;
+ virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE;
+ virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE;
+
+ private:
+ PayloadParserFactoryCollection* parsers;
+ int level;
+ boost::shared_ptr<PayloadParser> currentPayloadParser;
+ };
+}
diff --git a/Swiften/Parser/PayloadParsers/PubSubSubscribeOptionsParser.cpp b/Swiften/Parser/PayloadParsers/PubSubSubscribeOptionsParser.cpp
new file mode 100644
index 0000000..caed681
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/PubSubSubscribeOptionsParser.cpp
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma clang diagnostic ignored "-Wunused-private-field"
+
+#include <Swiften/Parser/PayloadParsers/PubSubSubscribeOptionsParser.h>
+
+#include <boost/optional.hpp>
+
+
+#include <Swiften/Parser/PayloadParserFactoryCollection.h>
+#include <Swiften/Parser/PayloadParserFactory.h>
+
+
+using namespace Swift;
+
+PubSubSubscribeOptionsParser::PubSubSubscribeOptionsParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) {
+}
+
+PubSubSubscribeOptionsParser::~PubSubSubscribeOptionsParser() {
+}
+
+void PubSubSubscribeOptionsParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) {
+
+
+
+
+ if (level >= 1 && currentPayloadParser) {
+ currentPayloadParser->handleStartElement(element, ns, attributes);
+ }
+ ++level;
+}
+
+void PubSubSubscribeOptionsParser::handleEndElement(const std::string& element, const std::string& ns) {
+ --level;
+ if (currentPayloadParser) {
+ if (level >= 1) {
+ currentPayloadParser->handleEndElement(element, ns);
+ }
+
+ if (level == 1) {
+ if (element == "required") {
+ getPayloadInternal()->setRequired(true);
+ }
+ currentPayloadParser.reset();
+ }
+ }
+}
+
+void PubSubSubscribeOptionsParser::handleCharacterData(const std::string& data) {
+ if (level > 1 && currentPayloadParser) {
+ currentPayloadParser->handleCharacterData(data);
+ }
+}
diff --git a/Swiften/Parser/PayloadParsers/PubSubSubscribeOptionsParser.h b/Swiften/Parser/PayloadParsers/PubSubSubscribeOptionsParser.h
new file mode 100644
index 0000000..c9ac1ca
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/PubSubSubscribeOptionsParser.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <boost/shared_ptr.hpp>
+
+#include <Swiften/Base/Override.h>
+#include <Swiften/Base/API.h>
+#include <Swiften/Elements/PubSubSubscribeOptions.h>
+#include <Swiften/Parser/GenericPayloadParser.h>
+
+namespace Swift {
+ class PayloadParserFactoryCollection;
+ class PayloadParser;
+
+ class SWIFTEN_API PubSubSubscribeOptionsParser : public GenericPayloadParser<PubSubSubscribeOptions> {
+ public:
+ PubSubSubscribeOptionsParser(PayloadParserFactoryCollection* parsers);
+ virtual ~PubSubSubscribeOptionsParser();
+
+ virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE;
+ virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE;
+ virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE;
+
+ private:
+ PayloadParserFactoryCollection* parsers;
+ int level;
+ boost::shared_ptr<PayloadParser> currentPayloadParser;
+ };
+}
diff --git a/Swiften/Parser/PayloadParsers/PubSubSubscribeParser.cpp b/Swiften/Parser/PayloadParsers/PubSubSubscribeParser.cpp
new file mode 100644
index 0000000..093c2c4
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/PubSubSubscribeParser.cpp
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma clang diagnostic ignored "-Wunused-private-field"
+
+#include <Swiften/Parser/PayloadParsers/PubSubSubscribeParser.h>
+
+#include <boost/optional.hpp>
+
+
+#include <Swiften/Parser/PayloadParserFactoryCollection.h>
+#include <Swiften/Parser/PayloadParserFactory.h>
+
+
+using namespace Swift;
+
+PubSubSubscribeParser::PubSubSubscribeParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) {
+}
+
+PubSubSubscribeParser::~PubSubSubscribeParser() {
+}
+
+void PubSubSubscribeParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) {
+ if (level == 0) {
+ if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) {
+ getPayloadInternal()->setNode(*attributeValue);
+ }
+ if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("jid")) {
+ if (boost::optional<JID> jid = JID::parse(*attributeValue)) {
+ getPayloadInternal()->setJID(*jid);
+ }
+ }
+ }
+
+
+
+ if (level >= 1 && currentPayloadParser) {
+ currentPayloadParser->handleStartElement(element, ns, attributes);
+ }
+ ++level;
+}
+
+void PubSubSubscribeParser::handleEndElement(const std::string& element, const std::string& ns) {
+ --level;
+ if (currentPayloadParser) {
+ if (level >= 1) {
+ currentPayloadParser->handleEndElement(element, ns);
+ }
+
+ if (level == 1) {
+
+ currentPayloadParser.reset();
+ }
+ }
+}
+
+void PubSubSubscribeParser::handleCharacterData(const std::string& data) {
+ if (level > 1 && currentPayloadParser) {
+ currentPayloadParser->handleCharacterData(data);
+ }
+}
diff --git a/Swiften/Parser/PayloadParsers/PubSubSubscribeParser.h b/Swiften/Parser/PayloadParsers/PubSubSubscribeParser.h
new file mode 100644
index 0000000..f0ad09d
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/PubSubSubscribeParser.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <boost/shared_ptr.hpp>
+
+#include <Swiften/Base/Override.h>
+#include <Swiften/Base/API.h>
+#include <Swiften/Elements/PubSubSubscribe.h>
+#include <Swiften/Parser/GenericPayloadParser.h>
+
+namespace Swift {
+ class PayloadParserFactoryCollection;
+ class PayloadParser;
+
+ class SWIFTEN_API PubSubSubscribeParser : public GenericPayloadParser<PubSubSubscribe> {
+ public:
+ PubSubSubscribeParser(PayloadParserFactoryCollection* parsers);
+ virtual ~PubSubSubscribeParser();
+
+ virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE;
+ virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE;
+ virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE;
+
+ private:
+ PayloadParserFactoryCollection* parsers;
+ int level;
+ boost::shared_ptr<PayloadParser> currentPayloadParser;
+ };
+}
diff --git a/Swiften/Parser/PayloadParsers/PubSubSubscriptionParser.cpp b/Swiften/Parser/PayloadParsers/PubSubSubscriptionParser.cpp
new file mode 100644
index 0000000..be06ec8
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/PubSubSubscriptionParser.cpp
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma clang diagnostic ignored "-Wunused-private-field"
+
+#include <Swiften/Parser/PayloadParsers/PubSubSubscriptionParser.h>
+
+#include <boost/optional.hpp>
+
+
+#include <Swiften/Parser/PayloadParserFactoryCollection.h>
+#include <Swiften/Parser/PayloadParserFactory.h>
+#include <Swiften/Parser/EnumParser.h>
+#include <Swiften/Parser/PayloadParsers/PubSubSubscribeOptionsParser.h>
+
+using namespace Swift;
+
+PubSubSubscriptionParser::PubSubSubscriptionParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) {
+}
+
+PubSubSubscriptionParser::~PubSubSubscriptionParser() {
+}
+
+void PubSubSubscriptionParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) {
+ if (level == 0) {
+ if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) {
+ getPayloadInternal()->setNode(*attributeValue);
+ }
+ if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("subid")) {
+ getPayloadInternal()->setSubscriptionID(*attributeValue);
+ }
+ if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("jid")) {
+ if (boost::optional<JID> jid = JID::parse(*attributeValue)) {
+ getPayloadInternal()->setJID(*jid);
+ }
+ }
+ if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("subscription")) {
+ if (boost::optional<PubSubSubscription::SubscriptionType> value = EnumParser<PubSubSubscription::SubscriptionType>()(PubSubSubscription::None, "none")(PubSubSubscription::Pending, "pending")(PubSubSubscription::Subscribed, "subscribed")(PubSubSubscription::Unconfigured, "unconfigured").parse(*attributeValue)) {
+ getPayloadInternal()->setSubscription(*value);
+ }
+ }
+ }
+
+ if (level == 1) {
+ if (element == "subscribe-options" && ns == "http://jabber.org/protocol/pubsub") {
+ currentPayloadParser = boost::make_shared<PubSubSubscribeOptionsParser>(parsers);
+ }
+ }
+
+ if (level >= 1 && currentPayloadParser) {
+ currentPayloadParser->handleStartElement(element, ns, attributes);
+ }
+ ++level;
+}
+
+void PubSubSubscriptionParser::handleEndElement(const std::string& element, const std::string& ns) {
+ --level;
+ if (currentPayloadParser) {
+ if (level >= 1) {
+ currentPayloadParser->handleEndElement(element, ns);
+ }
+
+ if (level == 1) {
+ if (element == "subscribe-options" && ns == "http://jabber.org/protocol/pubsub") {
+ getPayloadInternal()->setOptions(boost::dynamic_pointer_cast<PubSubSubscribeOptions>(currentPayloadParser->getPayload()));
+ }
+ currentPayloadParser.reset();
+ }
+ }
+}
+
+void PubSubSubscriptionParser::handleCharacterData(const std::string& data) {
+ if (level > 1 && currentPayloadParser) {
+ currentPayloadParser->handleCharacterData(data);
+ }
+}
diff --git a/Swiften/Parser/PayloadParsers/PubSubSubscriptionParser.h b/Swiften/Parser/PayloadParsers/PubSubSubscriptionParser.h
new file mode 100644
index 0000000..49290c2
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/PubSubSubscriptionParser.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <boost/shared_ptr.hpp>
+
+#include <Swiften/Base/Override.h>
+#include <Swiften/Base/API.h>
+#include <Swiften/Elements/PubSubSubscription.h>
+#include <Swiften/Parser/GenericPayloadParser.h>
+
+namespace Swift {
+ class PayloadParserFactoryCollection;
+ class PayloadParser;
+
+ class SWIFTEN_API PubSubSubscriptionParser : public GenericPayloadParser<PubSubSubscription> {
+ public:
+ PubSubSubscriptionParser(PayloadParserFactoryCollection* parsers);
+ virtual ~PubSubSubscriptionParser();
+
+ virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE;
+ virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE;
+ virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE;
+
+ private:
+ PayloadParserFactoryCollection* parsers;
+ int level;
+ boost::shared_ptr<PayloadParser> currentPayloadParser;
+ };
+}
diff --git a/Swiften/Parser/PayloadParsers/PubSubSubscriptionsParser.cpp b/Swiften/Parser/PayloadParsers/PubSubSubscriptionsParser.cpp
new file mode 100644
index 0000000..3ac3ca0
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/PubSubSubscriptionsParser.cpp
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma clang diagnostic ignored "-Wunused-private-field"
+
+#include <Swiften/Parser/PayloadParsers/PubSubSubscriptionsParser.h>
+
+#include <boost/optional.hpp>
+
+
+#include <Swiften/Parser/PayloadParserFactoryCollection.h>
+#include <Swiften/Parser/PayloadParserFactory.h>
+#include <Swiften/Parser/PayloadParsers/PubSubSubscriptionParser.h>
+
+using namespace Swift;
+
+PubSubSubscriptionsParser::PubSubSubscriptionsParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) {
+}
+
+PubSubSubscriptionsParser::~PubSubSubscriptionsParser() {
+}
+
+void PubSubSubscriptionsParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) {
+ if (level == 0) {
+ if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) {
+ getPayloadInternal()->setNode(*attributeValue);
+ }
+ }
+
+ if (level == 1) {
+ if (element == "subscription" && ns == "http://jabber.org/protocol/pubsub") {
+ currentPayloadParser = boost::make_shared<PubSubSubscriptionParser>(parsers);
+ }
+ }
+
+ if (level >= 1 && currentPayloadParser) {
+ currentPayloadParser->handleStartElement(element, ns, attributes);
+ }
+ ++level;
+}
+
+void PubSubSubscriptionsParser::handleEndElement(const std::string& element, const std::string& ns) {
+ --level;
+ if (currentPayloadParser) {
+ if (level >= 1) {
+ currentPayloadParser->handleEndElement(element, ns);
+ }
+
+ if (level == 1) {
+ if (element == "subscription" && ns == "http://jabber.org/protocol/pubsub") {
+ getPayloadInternal()->addSubscription(boost::dynamic_pointer_cast<PubSubSubscription>(currentPayloadParser->getPayload()));
+ }
+ currentPayloadParser.reset();
+ }
+ }
+}
+
+void PubSubSubscriptionsParser::handleCharacterData(const std::string& data) {
+ if (level > 1 && currentPayloadParser) {
+ currentPayloadParser->handleCharacterData(data);
+ }
+}
diff --git a/Swiften/Parser/PayloadParsers/PubSubSubscriptionsParser.h b/Swiften/Parser/PayloadParsers/PubSubSubscriptionsParser.h
new file mode 100644
index 0000000..b08db93
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/PubSubSubscriptionsParser.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <boost/shared_ptr.hpp>
+
+#include <Swiften/Base/Override.h>
+#include <Swiften/Base/API.h>
+#include <Swiften/Elements/PubSubSubscriptions.h>
+#include <Swiften/Parser/GenericPayloadParser.h>
+
+namespace Swift {
+ class PayloadParserFactoryCollection;
+ class PayloadParser;
+
+ class SWIFTEN_API PubSubSubscriptionsParser : public GenericPayloadParser<PubSubSubscriptions> {
+ public:
+ PubSubSubscriptionsParser(PayloadParserFactoryCollection* parsers);
+ virtual ~PubSubSubscriptionsParser();
+
+ virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE;
+ virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE;
+ virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE;
+
+ private:
+ PayloadParserFactoryCollection* parsers;
+ int level;
+ boost::shared_ptr<PayloadParser> currentPayloadParser;
+ };
+}
diff --git a/Swiften/Parser/PayloadParsers/PubSubUnsubscribeParser.cpp b/Swiften/Parser/PayloadParsers/PubSubUnsubscribeParser.cpp
new file mode 100644
index 0000000..53b4fae
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/PubSubUnsubscribeParser.cpp
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma clang diagnostic ignored "-Wunused-private-field"
+
+#include <Swiften/Parser/PayloadParsers/PubSubUnsubscribeParser.h>
+
+#include <boost/optional.hpp>
+
+
+#include <Swiften/Parser/PayloadParserFactoryCollection.h>
+#include <Swiften/Parser/PayloadParserFactory.h>
+
+
+using namespace Swift;
+
+PubSubUnsubscribeParser::PubSubUnsubscribeParser(PayloadParserFactoryCollection* parsers) : parsers(parsers), level(0) {
+}
+
+PubSubUnsubscribeParser::~PubSubUnsubscribeParser() {
+}
+
+void PubSubUnsubscribeParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) {
+ if (level == 0) {
+ if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("node")) {
+ getPayloadInternal()->setNode(*attributeValue);
+ }
+ if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("jid")) {
+ if (boost::optional<JID> jid = JID::parse(*attributeValue)) {
+ getPayloadInternal()->setJID(*jid);
+ }
+ }
+ if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("subid")) {
+ getPayloadInternal()->setSubscriptionID(*attributeValue);
+ }
+ }
+
+
+
+ if (level >= 1 && currentPayloadParser) {
+ currentPayloadParser->handleStartElement(element, ns, attributes);
+ }
+ ++level;
+}
+
+void PubSubUnsubscribeParser::handleEndElement(const std::string& element, const std::string& ns) {
+ --level;
+ if (currentPayloadParser) {
+ if (level >= 1) {
+ currentPayloadParser->handleEndElement(element, ns);
+ }
+
+ if (level == 1) {
+
+ currentPayloadParser.reset();
+ }
+ }
+}
+
+void PubSubUnsubscribeParser::handleCharacterData(const std::string& data) {
+ if (level > 1 && currentPayloadParser) {
+ currentPayloadParser->handleCharacterData(data);
+ }
+}
diff --git a/Swiften/Parser/PayloadParsers/PubSubUnsubscribeParser.h b/Swiften/Parser/PayloadParsers/PubSubUnsubscribeParser.h
new file mode 100644
index 0000000..a9e5ed0
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/PubSubUnsubscribeParser.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <boost/shared_ptr.hpp>
+
+#include <Swiften/Base/Override.h>
+#include <Swiften/Base/API.h>
+#include <Swiften/Elements/PubSubUnsubscribe.h>
+#include <Swiften/Parser/GenericPayloadParser.h>
+
+namespace Swift {
+ class PayloadParserFactoryCollection;
+ class PayloadParser;
+
+ class SWIFTEN_API PubSubUnsubscribeParser : public GenericPayloadParser<PubSubUnsubscribe> {
+ public:
+ PubSubUnsubscribeParser(PayloadParserFactoryCollection* parsers);
+ virtual ~PubSubUnsubscribeParser();
+
+ virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE;
+ virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE;
+ virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE;
+
+ private:
+ PayloadParserFactoryCollection* parsers;
+ int level;
+ boost::shared_ptr<PayloadParser> currentPayloadParser;
+ };
+}
diff --git a/Swiften/Parser/PayloadParsers/SearchPayloadParser.h b/Swiften/Parser/PayloadParsers/SearchPayloadParser.h
index 006e0d9..d456eb8 100644
--- a/Swiften/Parser/PayloadParsers/SearchPayloadParser.h
+++ b/Swiften/Parser/PayloadParsers/SearchPayloadParser.h
@@ -28,7 +28,7 @@ namespace Swift {
enum Level {
TopLevel = 0,
PayloadLevel = 1,
- ItemLevel = 2,
+ ItemLevel = 2
};
int level;
FormParserFactory* formParserFactory;
diff --git a/Swiften/Parser/PayloadParsers/StreamInitiationFileInfoParser.cpp b/Swiften/Parser/PayloadParsers/StreamInitiationFileInfoParser.cpp
index 0a13844..cc69348 100644
--- a/Swiften/Parser/PayloadParsers/StreamInitiationFileInfoParser.cpp
+++ b/Swiften/Parser/PayloadParsers/StreamInitiationFileInfoParser.cpp
@@ -35,7 +35,7 @@ void StreamInitiationFileInfoParser::handleStartElement(const std::string& eleme
} else {
parseDescription = false;
if (element == "range") {
- int offset = 0;
+ boost::uintmax_t offset = 0;
try {
offset = boost::lexical_cast<boost::uintmax_t>(attributes.getAttributeValue("offset").get_value_or("0"));
} catch (boost::bad_lexical_cast &) {
diff --git a/Swiften/Parser/PayloadParsers/StreamInitiationParser.cpp b/Swiften/Parser/PayloadParsers/StreamInitiationParser.cpp
index fd3d019..ff0a061 100644
--- a/Swiften/Parser/PayloadParsers/StreamInitiationParser.cpp
+++ b/Swiften/Parser/PayloadParsers/StreamInitiationParser.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010 Remko Tronçon
+ * Copyright (c) 2010-2013 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
@@ -40,7 +40,7 @@ void StreamInitiationParser::handleStartElement(const std::string& element, cons
currentFile = StreamInitiationFileInfo();
currentFile.setName(attributes.getAttribute("name"));
try {
- currentFile.setSize(boost::lexical_cast<int>(attributes.getAttribute("size")));
+ currentFile.setSize(boost::lexical_cast<unsigned long long>(attributes.getAttribute("size")));
}
catch (boost::bad_lexical_cast&) {
}
@@ -96,8 +96,8 @@ void StreamInitiationParser::handleEndElement(const std::string& element, const
}
}
else if (form->getType() == Form::SubmitType) {
- if (field->getRawValues().size() > 0) {
- getPayloadInternal()->setRequestedMethod(field->getRawValues()[0]);
+ if (!field->getValues().empty()) {
+ getPayloadInternal()->setRequestedMethod(field->getValues()[0]);
}
}
}
diff --git a/Swiften/Parser/PayloadParsers/StreamInitiationParser.h b/Swiften/Parser/PayloadParsers/StreamInitiationParser.h
index c2ffd07..f7350cd 100644
--- a/Swiften/Parser/PayloadParsers/StreamInitiationParser.h
+++ b/Swiften/Parser/PayloadParsers/StreamInitiationParser.h
@@ -29,7 +29,7 @@ namespace Swift {
TopLevel = 0,
PayloadLevel = 1,
FileOrFeatureLevel = 2,
- FormOrDescriptionLevel = 3,
+ FormOrDescriptionLevel = 3
};
int level;
FormParserFactory* formParserFactory;
diff --git a/Swiften/Parser/PayloadParsers/UnitTest/BlockParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/BlockParserTest.cpp
new file mode 100644
index 0000000..ddd3a88
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/UnitTest/BlockParserTest.cpp
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2013 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+
+#include <Swiften/Parser/PayloadParsers/BlockParser.h>
+#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h>
+
+#include <Swiften/Elements/BlockPayload.h>
+#include <Swiften/Elements/UnblockPayload.h>
+#include <Swiften/Elements/BlockListPayload.h>
+
+using namespace Swift;
+
+class BlockParserTest : public CppUnit::TestFixture
+{
+ CPPUNIT_TEST_SUITE(BlockParserTest);
+ CPPUNIT_TEST(testExample4);
+ CPPUNIT_TEST(testExample6);
+ CPPUNIT_TEST(testExample10);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ BlockParserTest() {}
+
+ void testExample4() {
+ PayloadsParserTester parser;
+
+ CPPUNIT_ASSERT(parser.parse("<blocklist xmlns='urn:xmpp:blocking'>"
+ "<item jid='romeo@montague.net'/>"
+ "<item jid='iago@shakespeare.lit'/>"
+ "</blocklist>"));
+
+ BlockListPayload* payload = dynamic_cast<BlockListPayload*>(parser.getPayload().get());
+ CPPUNIT_ASSERT(payload);
+ CPPUNIT_ASSERT(2 == payload->getItems().size());
+ CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.net"), payload->getItems()[0]);
+ CPPUNIT_ASSERT_EQUAL(JID("iago@shakespeare.lit"), payload->getItems()[1]);
+ }
+
+ void testExample6() {
+ PayloadsParserTester parser;
+
+ CPPUNIT_ASSERT(parser.parse("<block xmlns='urn:xmpp:blocking'>"
+ "<item jid='romeo@montague.net'/>"
+ "</block>"));
+
+ BlockPayload* payload = dynamic_cast<BlockPayload*>(parser.getPayload().get());
+ CPPUNIT_ASSERT(payload);
+ CPPUNIT_ASSERT(1 == payload->getItems().size());
+ CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.net"), payload->getItems()[0]);
+ }
+
+ void testExample10() {
+ PayloadsParserTester parser;
+
+ CPPUNIT_ASSERT(parser.parse("<unblock xmlns='urn:xmpp:blocking'>"
+ "<item jid='romeo@montague.net'/>"
+ "</unblock>"));
+
+ UnblockPayload* payload = dynamic_cast<UnblockPayload*>(parser.getPayload().get());
+ CPPUNIT_ASSERT(payload);
+ CPPUNIT_ASSERT(1 == payload->getItems().size());
+ CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.net"), payload->getItems()[0]);
+ }
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(BlockParserTest);
diff --git a/Swiften/Parser/PayloadParsers/UnitTest/FormParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/FormParserTest.cpp
index c36fbeb..bc8f1bc 100644
--- a/Swiften/Parser/PayloadParsers/UnitTest/FormParserTest.cpp
+++ b/Swiften/Parser/PayloadParsers/UnitTest/FormParserTest.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010 Remko Tronçon
+ * Copyright (c) 2010-2013 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
@@ -54,13 +54,13 @@ class FormParserTest : public CppUnit::TestFixture {
"</field>"
"<field label=\"Password for special access\" type=\"text-private\" var=\"password\"/>"
"<field label=\"What features will the bot support?\" type=\"list-multi\" var=\"features\">"
- "<value>news</value>"
- "<value>search</value>"
"<option label=\"Contests\"><value>contests</value></option>"
"<option label=\"News\"><value>news</value></option>"
"<option label=\"Polls\"><value>polls</value></option>"
"<option label=\"Reminders\"><value>reminders</value></option>"
"<option label=\"Search\"><value>search</value></option>"
+ "<value>news</value>"
+ "<value>search</value>"
"</field>"
"<field label=\"Maximum number of subscribers\" type=\"list-single\" var=\"maxsubs\">"
"<value>20</value>"
@@ -84,37 +84,35 @@ class FormParserTest : public CppUnit::TestFixture {
Form* payload = dynamic_cast<Form*>(parser.getPayload().get());
CPPUNIT_ASSERT_EQUAL(10, static_cast<int>(payload->getFields().size()));
- CPPUNIT_ASSERT_EQUAL(std::string("jabber:bot"), boost::dynamic_pointer_cast<HiddenFormField>(payload->getFields()[0])->getValue());
+ CPPUNIT_ASSERT_EQUAL(std::string("jabber:bot"), payload->getFields()[0]->getValues()[0]);
CPPUNIT_ASSERT_EQUAL(std::string("FORM_TYPE"), payload->getFields()[0]->getName());
CPPUNIT_ASSERT(!payload->getFields()[0]->getRequired());
- CPPUNIT_ASSERT_EQUAL(std::string("Section 1: Bot Info"), boost::dynamic_pointer_cast<FixedFormField>(payload->getFields()[1])->getValue());
+ CPPUNIT_ASSERT_EQUAL(std::string("Section 1: Bot Info"), payload->getFields()[1]->getValues()[0]);
CPPUNIT_ASSERT_EQUAL(std::string("The name of your bot"), payload->getFields()[2]->getLabel());
- CPPUNIT_ASSERT_EQUAL(std::string("This is a bot.\nA quite good one actually"), boost::dynamic_pointer_cast<TextMultiFormField>(payload->getFields()[3])->getValue());
+ CPPUNIT_ASSERT_EQUAL(std::string("This is a bot.\nA quite good one actually"), payload->getFields()[3]->getTextMultiValue());
- CPPUNIT_ASSERT_EQUAL(true, boost::dynamic_pointer_cast<BooleanFormField>(payload->getFields()[4])->getValue());
+ CPPUNIT_ASSERT_EQUAL(true, payload->getFields()[4]->getBoolValue());
CPPUNIT_ASSERT(payload->getFields()[4]->getRequired());
- CPPUNIT_ASSERT_EQUAL(std::string("1"), boost::dynamic_pointer_cast<BooleanFormField>(payload->getFields()[4])->getRawValues()[0]);
-
- CPPUNIT_ASSERT_EQUAL(std::string("news"), boost::dynamic_pointer_cast<ListMultiFormField>(payload->getFields()[6])->getValue()[0]);
- CPPUNIT_ASSERT_EQUAL(std::string("news"), payload->getFields()[6]->getRawValues()[0]);
- CPPUNIT_ASSERT_EQUAL(std::string("search"), boost::dynamic_pointer_cast<ListMultiFormField>(payload->getFields()[6])->getValue()[1]);
- CPPUNIT_ASSERT_EQUAL(std::string("search"), payload->getFields()[6]->getRawValues()[1]);
+ CPPUNIT_ASSERT_EQUAL(std::string("1"), payload->getFields()[4]->getValues()[0]);
+ CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(payload->getFields()[6]->getValues().size()));
+ CPPUNIT_ASSERT_EQUAL(std::string("news"), payload->getFields()[6]->getValues()[0]);
+ CPPUNIT_ASSERT_EQUAL(std::string("search"), payload->getFields()[6]->getValues()[1]);
CPPUNIT_ASSERT_EQUAL(5, static_cast<int>(payload->getFields()[6]->getOptions().size()));
CPPUNIT_ASSERT_EQUAL(std::string("Contests"), payload->getFields()[6]->getOptions()[0].label);
CPPUNIT_ASSERT_EQUAL(std::string("contests"), payload->getFields()[6]->getOptions()[0].value);
CPPUNIT_ASSERT_EQUAL(std::string("News"), payload->getFields()[6]->getOptions()[1].label);
CPPUNIT_ASSERT_EQUAL(std::string("news"), payload->getFields()[6]->getOptions()[1].value);
- CPPUNIT_ASSERT_EQUAL(std::string("20"), boost::dynamic_pointer_cast<ListSingleFormField>(payload->getFields()[7])->getValue());
+ CPPUNIT_ASSERT_EQUAL(std::string("20"), payload->getFields()[7]->getValues()[0]);
- CPPUNIT_ASSERT_EQUAL(JID("foo@bar.com"), boost::dynamic_pointer_cast<JIDMultiFormField>(payload->getFields()[8])->getValue()[0]);
- CPPUNIT_ASSERT_EQUAL(JID("baz@fum.org"), boost::dynamic_pointer_cast<JIDMultiFormField>(payload->getFields()[8])->getValue()[1]);
+ CPPUNIT_ASSERT_EQUAL(JID("foo@bar.com"), payload->getFields()[8]->getJIDMultiValue(0));
+ CPPUNIT_ASSERT_EQUAL(JID("baz@fum.org"), payload->getFields()[8]->getJIDMultiValue(1));
CPPUNIT_ASSERT_EQUAL(std::string("Tell all your friends about your new bot!"), payload->getFields()[8]->getDescription());
- CPPUNIT_ASSERT_EQUAL(std::string("foo"), boost::dynamic_pointer_cast<TextSingleFormField>(payload->getFields()[9])->getValue());
+ CPPUNIT_ASSERT_EQUAL(std::string("foo"), payload->getFields()[9]->getValues()[0]);
}
void testParse_FormItems() {
@@ -157,29 +155,28 @@ class FormParserTest : public CppUnit::TestFixture {
Form::FormItem item = items[0];
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(4), item.size());
- CPPUNIT_ASSERT_EQUAL(std::string("Benvolio"), item[0]->getRawValues()[0]);
+ CPPUNIT_ASSERT_EQUAL(std::string("Benvolio"), item[0]->getValues()[0]);
CPPUNIT_ASSERT_EQUAL(std::string("first"), item[0]->getName());
- CPPUNIT_ASSERT_EQUAL(std::string("Montague"), item[1]->getRawValues()[0]);
+ CPPUNIT_ASSERT_EQUAL(std::string("Montague"), item[1]->getValues()[0]);
CPPUNIT_ASSERT_EQUAL(std::string("last"), item[1]->getName());
- JIDSingleFormField::ref jidField = boost::dynamic_pointer_cast<JIDSingleFormField>(item[2]);
- CPPUNIT_ASSERT(jidField);
- CPPUNIT_ASSERT_EQUAL(JID("benvolio@montague.net"), jidField->getValue());
+ boost::shared_ptr<FormField> jidField = item[2];
+ CPPUNIT_ASSERT_EQUAL(JID("benvolio@montague.net"), jidField->getJIDSingleValue());
CPPUNIT_ASSERT_EQUAL(std::string("jid"), item[2]->getName());
- CPPUNIT_ASSERT_EQUAL(std::string("male"), item[3]->getRawValues()[0]);
+ CPPUNIT_ASSERT_EQUAL(std::string("male"), item[3]->getValues()[0]);
CPPUNIT_ASSERT_EQUAL(std::string("x-gender"), item[3]->getName());
item = items[1];
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(4), item.size());
- CPPUNIT_ASSERT_EQUAL(std::string("Romeo"), item[0]->getRawValues()[0]);
+ CPPUNIT_ASSERT_EQUAL(std::string("Romeo"), item[0]->getValues()[0]);
CPPUNIT_ASSERT_EQUAL(std::string("first"), item[0]->getName());
- CPPUNIT_ASSERT_EQUAL(std::string("Montague"), item[1]->getRawValues()[0]);
+ CPPUNIT_ASSERT_EQUAL(std::string("Montague"), item[1]->getValues()[0]);
CPPUNIT_ASSERT_EQUAL(std::string("last"), item[1]->getName());
- jidField = boost::dynamic_pointer_cast<JIDSingleFormField>(item[2]);
+ jidField = item[2];
CPPUNIT_ASSERT(jidField);
- CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.net"), jidField->getValue());
+ CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.net"), jidField->getJIDSingleValue());
CPPUNIT_ASSERT_EQUAL(std::string("jid"), item[2]->getName());
- CPPUNIT_ASSERT_EQUAL(std::string("male"), item[3]->getRawValues()[0]);
+ CPPUNIT_ASSERT_EQUAL(std::string("male"), item[3]->getValues()[0]);
CPPUNIT_ASSERT_EQUAL(std::string("x-gender"), item[3]->getName());
}
};
diff --git a/Swiften/Parser/PayloadParsers/UnitTest/IdleParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/IdleParserTest.cpp
new file mode 100644
index 0000000..74da474
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/UnitTest/IdleParserTest.cpp
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2013 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+
+#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h>
+#include <Swiften/Elements/Presence.h>
+#include <Swiften/Elements/Idle.h>
+#include <Swiften/Base/DateTime.h>
+
+using namespace Swift;
+
+class IdleParserTest : public CppUnit::TestFixture {
+ CPPUNIT_TEST_SUITE(IdleParserTest);
+ CPPUNIT_TEST(testParse_XepWhatever_Example1);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ void testParse_XepWhatever_Example1() {
+ PayloadsParserTester parser;
+ CPPUNIT_ASSERT(parser.parse(
+ "<presence from='juliet@capulet.com/balcony'>\n"
+ "<show>away</show>\n"
+ "<idle xmlns='urn:xmpp:idle:1' since='1969-07-21T02:56:15Z'/>\n"
+ "</presence>\n"
+ ));
+
+ Presence::ref presence = parser.getPayload<Presence>();
+ CPPUNIT_ASSERT(presence);
+ Idle::ref idle = presence->getPayload<Idle>();
+ CPPUNIT_ASSERT(idle);
+ CPPUNIT_ASSERT(stringToDateTime("1969-07-21T02:56:15Z") == idle->getSince());
+ }
+};
diff --git a/Swiften/Parser/PayloadParsers/UnitTest/JingleParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/JingleParserTest.cpp
index 8719a5d..8c8601a 100644
--- a/Swiften/Parser/PayloadParsers/UnitTest/JingleParserTest.cpp
+++ b/Swiften/Parser/PayloadParsers/UnitTest/JingleParserTest.cpp
@@ -121,7 +121,7 @@ class JingleParserTest : public CppUnit::TestFixture {
JingleIBBTransportPayload::ref transportPaylod = payload->getTransport<JingleIBBTransportPayload>();
CPPUNIT_ASSERT(transportPaylod);
- CPPUNIT_ASSERT_EQUAL(4096, transportPaylod->getBlockSize());
+ CPPUNIT_ASSERT_EQUAL(4096U, *transportPaylod->getBlockSize());
CPPUNIT_ASSERT_EQUAL(std::string("ch3d9s71"), transportPaylod->getSessionID());
}
@@ -158,7 +158,7 @@ class JingleParserTest : public CppUnit::TestFixture {
JingleIBBTransportPayload::ref transportPaylod = payload->getTransport<JingleIBBTransportPayload>();
CPPUNIT_ASSERT(transportPaylod);
- CPPUNIT_ASSERT_EQUAL(2048, transportPaylod->getBlockSize());
+ CPPUNIT_ASSERT_EQUAL(2048U, *transportPaylod->getBlockSize());
CPPUNIT_ASSERT_EQUAL(std::string("ch3d9s71"), transportPaylod->getSessionID());
}
@@ -191,7 +191,7 @@ class JingleParserTest : public CppUnit::TestFixture {
JingleIBBTransportPayload::ref transportPaylod = payload->getTransport<JingleIBBTransportPayload>();
CPPUNIT_ASSERT(transportPaylod);
- CPPUNIT_ASSERT_EQUAL(2048, transportPaylod->getBlockSize());
+ CPPUNIT_ASSERT_EQUAL(2048U, *transportPaylod->getBlockSize());
CPPUNIT_ASSERT_EQUAL(std::string("bt8a71h6"), transportPaylod->getSessionID());
}
@@ -468,7 +468,7 @@ class JingleParserTest : public CppUnit::TestFixture {
StreamInitiationFileInfo file = content->getDescription<JingleFileTransferDescription>()->getRequests()[0];
CPPUNIT_ASSERT_EQUAL(std::string("552da749930852c69ae5d2141d3766b1"), file.getHash());
- CPPUNIT_ASSERT_EQUAL(static_cast<boost::uintmax_t>(270336), file.getRangeOffset());
+ CPPUNIT_ASSERT_EQUAL(static_cast<unsigned long long>(270336), file.getRangeOffset());
CPPUNIT_ASSERT_EQUAL(true, file.getSupportsRangeRequests());
}
diff --git a/Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h b/Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h
index 213cd06..b328670 100644
--- a/Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h
+++ b/Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h
@@ -1,13 +1,11 @@
/*
- * Copyright (c) 2010 Remko Tronçon
+ * Copyright (c) 2010-2013 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
#pragma once
-#include <cppunit/extensions/HelperMacros.h>
-
#include <Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h>
#include <Swiften/Parser/XMLParser.h>
#include <Swiften/Parser/XMLParserClient.h>
@@ -32,9 +30,9 @@ namespace Swift {
virtual void handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) {
if (level == 0) {
- CPPUNIT_ASSERT(!payloadParser.get());
+ assert(!payloadParser.get());
PayloadParserFactory* payloadParserFactory = factories.getPayloadParserFactory(element, ns, attributes);
- CPPUNIT_ASSERT(payloadParserFactory);
+ assert(payloadParserFactory);
payloadParser.reset(payloadParserFactory->createPayloadParser());
}
payloadParser->handleStartElement(element, ns, attributes);
diff --git a/Swiften/Parser/PayloadParsers/UnitTest/SearchPayloadParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/SearchPayloadParserTest.cpp
index ef48ced..59ea3ff 100644
--- a/Swiften/Parser/PayloadParsers/UnitTest/SearchPayloadParserTest.cpp
+++ b/Swiften/Parser/PayloadParsers/UnitTest/SearchPayloadParserTest.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010 Remko Tronçon
+ * Copyright (c) 2010-2013 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
@@ -155,25 +155,25 @@ class SearchPayloadParserTest : public CppUnit::TestFixture {
Form::FormItem item = items[0];
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(4), item.size());
- CPPUNIT_ASSERT_EQUAL(std::string("Benvolio"), item[0]->getRawValues()[0]);
+ CPPUNIT_ASSERT_EQUAL(std::string("Benvolio"), item[0]->getValues()[0]);
CPPUNIT_ASSERT_EQUAL(std::string("first"), item[0]->getName());
- CPPUNIT_ASSERT_EQUAL(std::string("Montague"), item[1]->getRawValues()[0]);
+ CPPUNIT_ASSERT_EQUAL(std::string("Montague"), item[1]->getValues()[0]);
CPPUNIT_ASSERT_EQUAL(std::string("last"), item[1]->getName());
- CPPUNIT_ASSERT_EQUAL(std::string("benvolio@montague.net"), item[2]->getRawValues()[0]);
+ CPPUNIT_ASSERT_EQUAL(std::string("benvolio@montague.net"), item[2]->getValues()[0]);
CPPUNIT_ASSERT_EQUAL(std::string("jid"), item[2]->getName());
- CPPUNIT_ASSERT_EQUAL(std::string("male"), item[3]->getRawValues()[0]);
+ CPPUNIT_ASSERT_EQUAL(std::string("male"), item[3]->getValues()[0]);
CPPUNIT_ASSERT_EQUAL(std::string("x-gender"), item[3]->getName());
item = items[1];
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(4), item.size());
- CPPUNIT_ASSERT_EQUAL(std::string("Romeo"), item[0]->getRawValues()[0]);
+ CPPUNIT_ASSERT_EQUAL(std::string("Romeo"), item[0]->getValues()[0]);
CPPUNIT_ASSERT_EQUAL(std::string("first"), item[0]->getName());
- CPPUNIT_ASSERT_EQUAL(std::string("Montague"), item[1]->getRawValues()[0]);
+ CPPUNIT_ASSERT_EQUAL(std::string("Montague"), item[1]->getValues()[0]);
CPPUNIT_ASSERT_EQUAL(std::string("last"), item[1]->getName());
- CPPUNIT_ASSERT_EQUAL(std::string("romeo@montague.net"), item[2]->getRawValues()[0]);
+ CPPUNIT_ASSERT_EQUAL(std::string("romeo@montague.net"), item[2]->getValues()[0]);
CPPUNIT_ASSERT_EQUAL(std::string("jid"), item[2]->getName());
- CPPUNIT_ASSERT_EQUAL(std::string("male"), item[3]->getRawValues()[0]);
+ CPPUNIT_ASSERT_EQUAL(std::string("male"), item[3]->getValues()[0]);
CPPUNIT_ASSERT_EQUAL(std::string("x-gender"), item[3]->getName());
}
};
diff --git a/Swiften/Parser/PayloadParsers/UnitTest/VCardParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/VCardParserTest.cpp
index f1e6635..6436e90 100644
--- a/Swiften/Parser/PayloadParsers/UnitTest/VCardParserTest.cpp
+++ b/Swiften/Parser/PayloadParsers/UnitTest/VCardParserTest.cpp
@@ -7,6 +7,8 @@
#include <Swiften/Base/ByteArray.h>
#include <QA/Checker/IO.h>
+#include <boost/date_time/posix_time/posix_time.hpp>
+
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
@@ -19,6 +21,7 @@ class VCardParserTest : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(VCardParserTest);
CPPUNIT_TEST(testParse);
CPPUNIT_TEST(testParse_Photo);
+ CPPUNIT_TEST(testParse_NewlinedPhoto);
CPPUNIT_TEST(testParse_Nickname);
CPPUNIT_TEST_SUITE_END();
@@ -48,8 +51,36 @@ class VCardParserTest : public CppUnit::TestFixture {
"<WORK/>"
"<X400/>"
"</EMAIL>"
+ "<TEL>"
+ "<NUMBER>555-6273</NUMBER>"
+ "<HOME/>"
+ "<VOICE/>"
+ "</TEL>"
+ "<ADR>"
+ "<LOCALITY>Any Town</LOCALITY>"
+ "<STREET>Fake Street 123</STREET>"
+ "<PCODE>12345</PCODE>"
+ "<CTRY>USA</CTRY>"
+ "<HOME/>"
+ "</ADR>"
+ "<LABEL>"
+ "<LINE>Fake Street 123</LINE>"
+ "<LINE>12345 Any Town</LINE>"
+ "<LINE>USA</LINE>"
+ "<HOME/>"
+ "</LABEL>"
"<NICKNAME>DreamGirl</NICKNAME>"
- "<BDAY>1234</BDAY>"
+ "<BDAY>1865-05-04</BDAY>"
+ "<JID>alice@teaparty.lit</JID>"
+ "<JID>alice@wonderland.lit</JID>"
+ "<DESC>I once fell down a rabbit hole.</DESC>"
+ "<ORG>"
+ "<ORGNAME>Alice In Wonderland Inc.</ORGNAME>"
+ "</ORG>"
+ "<TITLE>Some Title</TITLE>"
+ "<ROLE>Main Character</ROLE>"
+ "<URL>http://wonderland.lit/~alice</URL>"
+ "<URL>http://teaparty.lit/~alice2</URL>"
"<MAILER>mutt</MAILER>"
"</vCard>"));
@@ -62,7 +93,7 @@ class VCardParserTest : public CppUnit::TestFixture {
CPPUNIT_ASSERT_EQUAL(std::string("Mrs"), payload->getPrefix());
CPPUNIT_ASSERT_EQUAL(std::string("PhD"), payload->getSuffix());
CPPUNIT_ASSERT_EQUAL(std::string("DreamGirl"), payload->getNickname());
- CPPUNIT_ASSERT_EQUAL(std::string("<BDAY xmlns=\"vcard-temp\">1234</BDAY><MAILER xmlns=\"vcard-temp\">mutt</MAILER>"), payload->getUnknownContent());
+ CPPUNIT_ASSERT_EQUAL(boost::posix_time::ptime(boost::gregorian::date(1865, 5, 4)), payload->getBirthday());
CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(payload->getEMailAddresses().size()));
CPPUNIT_ASSERT_EQUAL(std::string("alice@wonderland.lit"), payload->getEMailAddresses()[0].address);
CPPUNIT_ASSERT(payload->getEMailAddresses()[0].isHome);
@@ -76,6 +107,45 @@ class VCardParserTest : public CppUnit::TestFixture {
CPPUNIT_ASSERT(!payload->getEMailAddresses()[1].isPreferred);
CPPUNIT_ASSERT(payload->getEMailAddresses()[1].isWork);
CPPUNIT_ASSERT(payload->getEMailAddresses()[1].isX400);
+
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(payload->getTelephones().size()));
+ CPPUNIT_ASSERT_EQUAL(std::string("555-6273"), payload->getTelephones()[0].number);
+ CPPUNIT_ASSERT(payload->getTelephones()[0].isHome);
+ CPPUNIT_ASSERT(payload->getTelephones()[0].isVoice);
+ CPPUNIT_ASSERT(!payload->getTelephones()[0].isPreferred);
+
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(payload->getAddresses().size()));
+ CPPUNIT_ASSERT_EQUAL(std::string("Any Town"), payload->getAddresses()[0].locality);
+ CPPUNIT_ASSERT_EQUAL(std::string("Fake Street 123"), payload->getAddresses()[0].street);
+ CPPUNIT_ASSERT_EQUAL(std::string("12345"), payload->getAddresses()[0].postalCode);
+ CPPUNIT_ASSERT_EQUAL(std::string("USA"), payload->getAddresses()[0].country);
+ CPPUNIT_ASSERT(payload->getAddresses()[0].isHome);
+
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(payload->getAddressLabels().size()));
+ CPPUNIT_ASSERT_EQUAL(std::string("Fake Street 123"), payload->getAddressLabels()[0].lines[0]);
+ CPPUNIT_ASSERT_EQUAL(std::string("12345 Any Town"), payload->getAddressLabels()[0].lines[1]);
+ CPPUNIT_ASSERT_EQUAL(std::string("USA"), payload->getAddressLabels()[0].lines[2]);
+ CPPUNIT_ASSERT(payload->getAddressLabels()[0].isHome);
+
+ CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(payload->getJIDs().size()));
+ CPPUNIT_ASSERT_EQUAL(JID("alice@teaparty.lit"), payload->getJIDs()[0]);
+ CPPUNIT_ASSERT_EQUAL(JID("alice@wonderland.lit"), payload->getJIDs()[1]);
+
+ CPPUNIT_ASSERT_EQUAL(std::string("I once fell down a rabbit hole."), payload->getDescription());
+
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(payload->getOrganizations().size()));
+ CPPUNIT_ASSERT_EQUAL(std::string("Alice In Wonderland Inc."), payload->getOrganizations()[0].name);
+ CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(payload->getOrganizations()[0].units.size()));
+
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(payload->getTitles().size()));
+ CPPUNIT_ASSERT_EQUAL(std::string("Some Title"), payload->getTitles()[0]);
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(payload->getRoles().size()));
+ CPPUNIT_ASSERT_EQUAL(std::string("Main Character"), payload->getRoles()[0]);
+ CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(payload->getURLs().size()));
+ CPPUNIT_ASSERT_EQUAL(std::string("http://wonderland.lit/~alice"), payload->getURLs()[0]);
+ CPPUNIT_ASSERT_EQUAL(std::string("http://teaparty.lit/~alice2"), payload->getURLs()[1]);
+
+ CPPUNIT_ASSERT_EQUAL(std::string("<MAILER xmlns=\"vcard-temp\">mutt</MAILER>"), payload->getUnknownContent());
}
void testParse_Photo() {
@@ -97,6 +167,30 @@ class VCardParserTest : public CppUnit::TestFixture {
CPPUNIT_ASSERT_EQUAL(createByteArray("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890"), payload->getPhoto());
}
+ void testParse_NewlinedPhoto() {
+ PayloadsParserTester parser;
+
+ CPPUNIT_ASSERT(parser.parse(
+ "<vCard xmlns='vcard-temp'>"
+ "<PHOTO>"
+ "<TYPE>image/jpeg</TYPE>"
+ "<BINVAL>"
+ "dTsETKSAskgu2/BqVO+ogcu3DJy4QATGJqpsa6znWwNGiLnVElVVB6PtS+mTiHUXsrOlKvRjtvzV\n"
+ "VDknNaRF58Elmu5EC6VoCllBEEB/lFf0emYn2gkp0X1khNi75dl+rOj95Ar6XuwLh+ZoSStqwOWj\n"
+ "pIpxmZmVw7E69qr0FY0oI3zcaxXwzHw7Lx9Qf4sH7ufQvIN88ga+hwp8MiXevh3Ac8pN00kgINlq\n"
+ "9AY/bYJL418Y/6wWsJbgmrJ/N78wSMpC7VVszLBZVv8uFnupubyi8Ophd/1wIWWzPPwAbBhepWVb\n"
+ "1oPiFEBT5MNKCMTPEi0npXtedVz0HQbbPNIVwmo="
+ "</BINVAL>"
+ "</PHOTO>"
+ "</vCard>"));
+
+ VCard* payload = dynamic_cast<VCard*>(parser.getPayload().get());
+ CPPUNIT_ASSERT_EQUAL(std::string("image/jpeg"), payload->getPhotoType());
+ CPPUNIT_ASSERT_EQUAL(createByteArray("\x75\x3B\x04\x4C\xA4\x80\xB2\x48\x2E\xDB\xF0\x6A\x54\xEF\xA8\x81\xCB\xB7\x0C\x9C\xB8\x40\x04\xC6\x26\xAA\x6C\x6B\xAC\xE7\x5B\x03\x46\x88\xB9\xD5\x12\x55\x55\x07\xA3\xED\x4B\xE9\x93\x88\x75\x17\xB2\xB3\xA5\x2A\xF4\x63\xB6\xFC\xD5\x54\x39\x27\x35\xA4\x45\xE7\xC1\x25\x9A\xEE\x44\x0B\xA5\x68\x0A\x59\x41\x10\x40\x7F\x94\x57\xF4\x7A\x66\x27\xDA\x09\x29\xD1\x7D\x64\x84\xD8\xBB\xE5\xD9\x7E\xAC\xE8\xFD\xE4\x0A\xFA\x5E\xEC\x0B\x87\xE6\x68\x49\x2B\x6A\xC0\xE5\xA3\xA4\x8A\x71\x99\x99\x95\xC3\xB1\x3A\xF6\xAA\xF4\x15\x8D\x28\x23\x7C\xDC\x6B\x15\xF0\xCC\x7C\x3B\x2F\x1F\x50\x7F\x8B\x07\xEE\xE7\xD0\xBC\x83\x7C\xF2\x06\xBE\x87\x0A\x7C\x32\x25\xDE\xBE\x1D\xC0\x73\xCA\x4D\xD3\x49\x20\x20\xD9\x6A\xF4\x06\x3F\x6D\x82\x4B\xE3\x5F\x18\xFF\xAC\x16\xB0\x96\xE0\x9A\xB2\x7F\x37\xBF\x30\x48\xCA\x42\xED\x55\x6C\xCC\xB0\x59\x56\xFF\x2E\x16\x7B\xA9\xB9\xBC\xA2\xF0\xEA\x61\x77\xFD\x70\x21\x65\xB3\x3C\xFC\x00\x6C\x18\x5E\xA5\x65\x5B\xD6\x83\xE2\x14\x40\x53\xE4\xC3\x4A\x08\xC4\xCF\x12\x2D\x27\xA5\x7B\x5E\x75\x5C\xF4\x1D\x06\xDB\x3C\xD2\x15\xC2\x6A", 257), payload->getPhoto());
+ }
+
+
+
void testParse_Nickname() {
PayloadsParserTester parser;
diff --git a/Swiften/Parser/PayloadParsers/UserLocationParser.cpp b/Swiften/Parser/PayloadParsers/UserLocationParser.cpp
new file mode 100644
index 0000000..d3aac69
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/UserLocationParser.cpp
@@ -0,0 +1,106 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#include <Swiften/Parser/PayloadParsers/UserLocationParser.h>
+
+#include <boost/lexical_cast.hpp>
+
+#include <Swiften/Base/DateTime.h>
+
+using namespace Swift;
+
+UserLocationParser::UserLocationParser() : level(0) {
+}
+
+UserLocationParser::~UserLocationParser() {
+}
+
+void UserLocationParser::handleStartElement(const std::string&, const std::string&, const AttributeMap&) {
+ if (level == 1) {
+ currentText = "";
+ }
+ ++level;
+}
+
+void UserLocationParser::handleEndElement(const std::string& element, const std::string&) {
+ --level;
+ if (level == 1) {
+ try {
+ if (element == "accuracy") {
+ getPayloadInternal()->setAccuracy(boost::lexical_cast<float>(currentText));
+ }
+ else if (element == "alt") {
+ getPayloadInternal()->setAltitude(boost::lexical_cast<float>(currentText));
+ }
+ else if (element == "area") {
+ getPayloadInternal()->setArea(currentText);
+ }
+ else if (element == "bearing") {
+ getPayloadInternal()->setBearing(boost::lexical_cast<float>(currentText));
+ }
+ else if (element == "building") {
+ getPayloadInternal()->setBuilding(currentText);
+ }
+ else if (element == "country") {
+ getPayloadInternal()->setCountry(currentText);
+ }
+ else if (element == "countrycode") {
+ getPayloadInternal()->setCountryCode(currentText);
+ }
+ else if (element == "datum") {
+ getPayloadInternal()->setDatum(currentText);
+ }
+ else if (element == "description") {
+ getPayloadInternal()->setDescription(currentText);
+ }
+ else if (element == "error") {
+ getPayloadInternal()->setError(boost::lexical_cast<float>(currentText));
+ }
+ else if (element == "floor") {
+ getPayloadInternal()->setFloor(currentText);
+ }
+ else if (element == "lat") {
+ getPayloadInternal()->setLatitude(boost::lexical_cast<float>(currentText));
+ }
+ else if (element == "locality") {
+ getPayloadInternal()->setLocality(currentText);
+ }
+ else if (element == "lon") {
+ getPayloadInternal()->setLongitude(boost::lexical_cast<float>(currentText));
+ }
+ else if (element == "postalcode") {
+ getPayloadInternal()->setPostalCode(currentText);
+ }
+ else if (element == "region") {
+ getPayloadInternal()->setRegion(currentText);
+ }
+ else if (element == "room") {
+ getPayloadInternal()->setRoom(currentText);
+ }
+ else if (element == "speed") {
+ getPayloadInternal()->setSpeed(boost::lexical_cast<float>(currentText));
+ }
+ else if (element == "street") {
+ getPayloadInternal()->setStreet(currentText);
+ }
+ else if (element == "text") {
+ getPayloadInternal()->setText(currentText);
+ }
+ else if (element == "timestamp") {
+ getPayloadInternal()->setTimestamp(stringToDateTime(currentText));
+ }
+ else if (element == "uri") {
+ getPayloadInternal()->setURI(currentText);
+ }
+ }
+ catch (const boost::bad_lexical_cast&) {
+ }
+ }
+}
+
+void UserLocationParser::handleCharacterData(const std::string& data) {
+ currentText += data;
+}
diff --git a/Swiften/Parser/PayloadParsers/UserLocationParser.h b/Swiften/Parser/PayloadParsers/UserLocationParser.h
new file mode 100644
index 0000000..eb6e668
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/UserLocationParser.h
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <boost/shared_ptr.hpp>
+#include <string>
+
+#include <Swiften/Base/Override.h>
+#include <Swiften/Base/API.h>
+#include <Swiften/Parser/GenericPayloadParser.h>
+#include <Swiften/Elements/UserLocation.h>
+
+namespace Swift {
+ class SWIFTEN_API UserLocationParser : public GenericPayloadParser<UserLocation> {
+ public:
+ UserLocationParser();
+ virtual ~UserLocationParser();
+
+ virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) SWIFTEN_OVERRIDE;
+ virtual void handleEndElement(const std::string& element, const std::string&) SWIFTEN_OVERRIDE;
+ virtual void handleCharacterData(const std::string& data) SWIFTEN_OVERRIDE;
+
+ private:
+ int level;
+ std::string currentText;
+ };
+}
diff --git a/Swiften/Parser/PayloadParsers/VCardParser.cpp b/Swiften/Parser/PayloadParsers/VCardParser.cpp
index 553d26a..0028411 100644
--- a/Swiften/Parser/PayloadParsers/VCardParser.cpp
+++ b/Swiften/Parser/PayloadParsers/VCardParser.cpp
@@ -6,6 +6,7 @@
#include <Swiften/Parser/PayloadParsers/VCardParser.h>
#include <Swiften/Base/foreach.h>
+#include <Swiften/Base/DateTime.h>
#include <Swiften/StringCodecs/Base64.h>
#include <Swiften/Parser/SerializingParser.h>
@@ -20,6 +21,18 @@ void VCardParser::handleStartElement(const std::string& element, const std::stri
if (elementHierarchy == "/vCard/EMAIL") {
currentEMailAddress_ = VCard::EMailAddress();
}
+ if (elementHierarchy == "/vCard/TEL") {
+ currentTelephone_ = VCard::Telephone();
+ }
+ if (elementHierarchy == "/vCard/ADR") {
+ currentAddress_ = VCard::Address();
+ }
+ if (elementHierarchy == "/vCard/LABEL") {
+ currentAddressLabel_ = VCard::AddressLabel();
+ }
+ if (elementHierarchy == "/vCard/ORG") {
+ currentOrganization_ = VCard::Organization();
+ }
if (elementStack_.size() == 2) {
assert(!unknownContentParser_);
unknownContentParser_ = new SerializingParser();
@@ -68,6 +81,8 @@ void VCardParser::handleEndElement(const std::string& element, const std::string
getPayloadInternal()->setPhotoType(currentText_);
}
else if (elementHierarchy == "/vCard/PHOTO/BINVAL") {
+ currentText_.erase(std::remove(currentText_.begin(), currentText_.end(), '\n'), currentText_.end());
+ currentText_.erase(std::remove(currentText_.begin(), currentText_.end(), '\r'), currentText_.end());
getPayloadInternal()->setPhoto(Base64::decode(currentText_));
}
else if (elementHierarchy == "/vCard/PHOTO") {
@@ -90,9 +105,160 @@ void VCardParser::handleEndElement(const std::string& element, const std::string
else if (elementHierarchy == "/vCard/EMAIL/PREF") {
currentEMailAddress_.isPreferred = true;
}
- else if (elementHierarchy == "/vCard/EMAIL") {
+ else if (elementHierarchy == "/vCard/EMAIL" && !currentEMailAddress_.address.empty()) {
getPayloadInternal()->addEMailAddress(currentEMailAddress_);
}
+ else if (elementHierarchy == "/vCard/BDAY" && !currentText_.empty()) {
+ getPayloadInternal()->setBirthday(stringToDateTime(currentText_));
+ }
+ else if (elementHierarchy == "/vCard/TEL/NUMBER") {
+ currentTelephone_.number = currentText_;
+ }
+ else if (elementHierarchy == "/vCard/TEL/HOME") {
+ currentTelephone_.isHome = true;
+ }
+ else if (elementHierarchy == "/vCard/TEL/WORK") {
+ currentTelephone_.isWork = true;
+ }
+ else if (elementHierarchy == "/vCard/TEL/VOICE") {
+ currentTelephone_.isVoice = true;
+ }
+ else if (elementHierarchy == "/vCard/TEL/FAX") {
+ currentTelephone_.isFax = true;
+ }
+ else if (elementHierarchy == "/vCard/TEL/PAGER") {
+ currentTelephone_.isPager = true;
+ }
+ else if (elementHierarchy == "/vCard/TEL/MSG") {
+ currentTelephone_.isMSG = true;
+ }
+ else if (elementHierarchy == "/vCard/TEL/CELL") {
+ currentTelephone_.isCell = true;
+ }
+ else if (elementHierarchy == "/vCard/TEL/VIDEO") {
+ currentTelephone_.isVideo = true;
+ }
+ else if (elementHierarchy == "/vCard/TEL/BBS") {
+ currentTelephone_.isBBS = true;
+ }
+ else if (elementHierarchy == "/vCard/TEL/MODEM") {
+ currentTelephone_.isModem = true;
+ }
+ else if (elementHierarchy == "/vCard/TEL/ISDN") {
+ currentTelephone_.isISDN = true;
+ }
+ else if (elementHierarchy == "/vCard/TEL/PCS") {
+ currentTelephone_.isPCS = true;
+ }
+ else if (elementHierarchy == "/vCard/TEL/PREF") {
+ currentTelephone_.isPreferred = true;
+ }
+ else if (elementHierarchy == "/vCard/TEL" && !currentTelephone_.number.empty()) {
+ getPayloadInternal()->addTelephone(currentTelephone_);
+ }
+ else if (elementHierarchy == "/vCard/ADR/HOME") {
+ currentAddress_.isHome = true;
+ }
+ else if (elementHierarchy == "/vCard/ADR/WORK") {
+ currentAddress_.isWork = true;
+ }
+ else if (elementHierarchy == "/vCard/ADR/POSTAL") {
+ currentAddress_.isPostal = true;
+ }
+ else if (elementHierarchy == "/vCard/ADR/PARCEL") {
+ currentAddress_.isParcel = true;
+ }
+ else if (elementHierarchy == "/vCard/ADR/DOM") {
+ currentAddress_.deliveryType = VCard::DomesticDelivery;
+ }
+ else if (elementHierarchy == "/vCard/ADR/INTL") {
+ currentAddress_.deliveryType = VCard::InternationalDelivery;
+ }
+ else if (elementHierarchy == "/vCard/ADR/PREF") {
+ currentAddress_.isPreferred = true;
+ }
+ else if (elementHierarchy == "/vCard/ADR/POBOX") {
+ currentAddress_.poBox = currentText_;
+ }
+ else if (elementHierarchy == "/vCard/ADR/EXTADD") {
+ currentAddress_.addressExtension = currentText_;
+ }
+ else if (elementHierarchy == "/vCard/ADR/STREET") {
+ currentAddress_.street = currentText_;
+ }
+ else if (elementHierarchy == "/vCard/ADR/LOCALITY") {
+ currentAddress_.locality = currentText_;
+ }
+ else if (elementHierarchy == "/vCard/ADR/REGION") {
+ currentAddress_.region = currentText_;
+ }
+ else if (elementHierarchy == "/vCard/ADR/PCODE") {
+ currentAddress_.postalCode = currentText_;
+ }
+ else if (elementHierarchy == "/vCard/ADR/CTRY") {
+ currentAddress_.country = currentText_;
+ }
+ else if (elementHierarchy == "/vCard/ADR") {
+ if (!currentAddress_.poBox.empty() || !currentAddress_.addressExtension.empty() ||
+ !currentAddress_.street.empty() || !currentAddress_.locality.empty() ||
+ !currentAddress_.region.empty() || !currentAddress_.region.empty() ||
+ !currentAddress_.postalCode.empty() || !currentAddress_.country.empty()) {
+ getPayloadInternal()->addAddress(currentAddress_);
+ }
+ }
+ else if (elementHierarchy == "/vCard/LABEL/HOME") {
+ currentAddressLabel_.isHome = true;
+ }
+ else if (elementHierarchy == "/vCard/LABEL/WORK") {
+ currentAddressLabel_.isWork = true;
+ }
+ else if (elementHierarchy == "/vCard/LABEL/POSTAL") {
+ currentAddressLabel_.isPostal = true;
+ }
+ else if (elementHierarchy == "/vCard/LABEL/PARCEL") {
+ currentAddressLabel_.isParcel = true;
+ }
+ else if (elementHierarchy == "/vCard/LABEL/DOM") {
+ currentAddressLabel_.deliveryType = VCard::DomesticDelivery;
+ }
+ else if (elementHierarchy == "/vCard/LABEL/INTL") {
+ currentAddressLabel_.deliveryType = VCard::InternationalDelivery;
+ }
+ else if (elementHierarchy == "/vCard/LABEL/PREF") {
+ currentAddressLabel_.isPreferred = true;
+ }
+ else if (elementHierarchy == "/vCard/LABEL/LINE") {
+ currentAddressLabel_.lines.push_back(currentText_);
+ }
+ else if (elementHierarchy == "/vCard/LABEL") {
+ getPayloadInternal()->addAddressLabel(currentAddressLabel_);
+ }
+ else if (elementHierarchy == "/vCard/JID" && !currentText_.empty()) {
+ getPayloadInternal()->addJID(JID(currentText_));
+ }
+ else if (elementHierarchy == "/vCard/DESC") {
+ getPayloadInternal()->setDescription(currentText_);
+ }
+ else if (elementHierarchy == "/vCard/ORG/ORGNAME") {
+ currentOrganization_.name = currentText_;
+ }
+ else if (elementHierarchy == "/vCard/ORG/ORGUNIT" && !currentText_.empty()) {
+ currentOrganization_.units.push_back(currentText_);
+ }
+ else if (elementHierarchy == "/vCard/ORG") {
+ if (!currentOrganization_.name.empty() || !currentOrganization_.units.empty()) {
+ getPayloadInternal()->addOrganization(currentOrganization_);
+ }
+ }
+ else if (elementHierarchy == "/vCard/TITLE" && !currentText_.empty()) {
+ getPayloadInternal()->addTitle(currentText_);
+ }
+ else if (elementHierarchy == "/vCard/ROLE" && !currentText_.empty()) {
+ getPayloadInternal()->addRole(currentText_);
+ }
+ else if (elementHierarchy == "/vCard/URL" && !currentText_.empty()) {
+ getPayloadInternal()->addURL(currentText_);
+ }
else if (elementStack_.size() == 2 && unknownContentParser_) {
getPayloadInternal()->addUnknownContent(unknownContentParser_->getResult());
}
diff --git a/Swiften/Parser/PayloadParsers/VCardParser.h b/Swiften/Parser/PayloadParsers/VCardParser.h
index b1c47a3..f10d639 100644
--- a/Swiften/Parser/PayloadParsers/VCardParser.h
+++ b/Swiften/Parser/PayloadParsers/VCardParser.h
@@ -28,6 +28,10 @@ namespace Swift {
private:
std::vector<std::string> elementStack_;
VCard::EMailAddress currentEMailAddress_;
+ VCard::Telephone currentTelephone_;
+ VCard::Address currentAddress_;
+ VCard::AddressLabel currentAddressLabel_;
+ VCard::Organization currentOrganization_;
SerializingParser* unknownContentParser_;
std::string currentText_;
};
diff --git a/Swiften/Parser/PayloadParsers/WhiteboardParser.cpp b/Swiften/Parser/PayloadParsers/WhiteboardParser.cpp
index 09d8de9..a480813 100644
--- a/Swiften/Parser/PayloadParsers/WhiteboardParser.cpp
+++ b/Swiften/Parser/PayloadParsers/WhiteboardParser.cpp
@@ -83,8 +83,8 @@ namespace Swift {
std::string pathData = attributes.getAttributeValue("d").get_value_or("");
std::vector<std::pair<int, int> > points;
if (pathData[0] == 'M') {
- unsigned int pos = 1;
- unsigned int npos;
+ size_t pos = 1;
+ size_t npos;
int x, y;
if (pathData[pos] == ' ') {
pos++;
@@ -163,8 +163,8 @@ namespace Swift {
std::string pointsData = attributes.getAttributeValue("points").get_value_or("");
std::vector<std::pair<int, int> > points;
- unsigned int pos = 0;
- unsigned int npos;
+ size_t pos = 0;
+ size_t npos;
int x, y;
try {
while (pos < pointsData.size()) {