summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Parser/PayloadParsers/FormParser.cpp')
-rw-r--r--Swiften/Parser/PayloadParsers/FormParser.cpp61
1 files changed, 49 insertions, 12 deletions
diff --git a/Swiften/Parser/PayloadParsers/FormParser.cpp b/Swiften/Parser/PayloadParsers/FormParser.cpp
index 3905302..2df0a85 100644
--- a/Swiften/Parser/PayloadParsers/FormParser.cpp
+++ b/Swiften/Parser/PayloadParsers/FormParser.cpp
@@ -6,9 +6,11 @@
#include <Swiften/Parser/PayloadParsers/FormParser.h>
+#include <Swiften/Base/foreach.h>
+
namespace Swift {
-FormParser::FormParser() : level_(TopLevel) {
+FormParser::FormParser() : level_(TopLevel), parsingItem_(false), parsingReported_(false) {
}
void FormParser::handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) {
@@ -35,32 +37,43 @@ void FormParser::handleStartElement(const std::string& element, const std::strin
currentText_.clear();
}
else if (element == "field") {
- std::string type = attributes.getAttribute("type");
- if (type == "boolean") {
+ 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") {
+ else if (type == "fixed" || boost::dynamic_pointer_cast<FixedFormField>(correspondingReportedField)) {
currentFieldParseHelper_ = FixedFormFieldParseHelper::create();
}
- else if (type == "hidden") {
+ else if (type == "hidden" || boost::dynamic_pointer_cast<HiddenFormField>(correspondingReportedField)) {
currentFieldParseHelper_ = HiddenFormFieldParseHelper::create();
}
- else if (type == "jid-multi") {
+ else if (type == "jid-multi" || boost::dynamic_pointer_cast<JIDMultiFormField>(correspondingReportedField)) {
currentFieldParseHelper_ = JIDMultiFormFieldParseHelper::create();
}
- else if (type == "jid-single") {
+ else if (type == "jid-single" || boost::dynamic_pointer_cast<JIDSingleFormField>(correspondingReportedField)) {
currentFieldParseHelper_ = JIDSingleFormFieldParseHelper::create();
}
- else if (type == "list-multi") {
+ else if (type == "list-multi" || boost::dynamic_pointer_cast<ListMultiFormField>(correspondingReportedField)) {
currentFieldParseHelper_ = ListMultiFormFieldParseHelper::create();
}
- else if (type == "list-single") {
+ else if (type == "list-single" || boost::dynamic_pointer_cast<ListSingleFormField>(correspondingReportedField)) {
currentFieldParseHelper_ = ListSingleFormFieldParseHelper::create();
}
- else if (type == "text-multi") {
+ else if (type == "text-multi" || boost::dynamic_pointer_cast<TextMultiFormField>(correspondingReportedField)) {
currentFieldParseHelper_ = TextMultiFormFieldParseHelper::create();
}
- else if (type == "text-private") {
+ else if (type == "text-private" || boost::dynamic_pointer_cast<TextPrivateFormField>(correspondingReportedField)) {
currentFieldParseHelper_ = TextPrivateFormFieldParseHelper::create();
}
else /*if (type == "text-single") || undefined */ {
@@ -71,6 +84,14 @@ void FormParser::handleStartElement(const std::string& element, const std::strin
currentFieldParseHelper_->getField()->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();
@@ -104,7 +125,13 @@ void FormParser::handleEndElement(const std::string& element, const std::string&
}
else if (element == "field") {
if (currentFieldParseHelper_) {
- getPayloadInternal()->addField(currentFieldParseHelper_->getField());
+ if (parsingReported_) {
+ getPayloadInternal()->addReportedField(currentFieldParseHelper_->getField());
+ } else if (parsingItem_) {
+ currentFields_.push_back(currentFieldParseHelper_->getField());
+ } else {
+ getPayloadInternal()->addField(currentFieldParseHelper_->getField());
+ }
currentFieldParseHelper_.reset();
}
}
@@ -123,6 +150,16 @@ void FormParser::handleEndElement(const std::string& element, const std::string&
currentFieldParseHelper_->addValue(currentText_);
}
}
+ if (element == "reported") {
+ parsingReported_ = false;
+ level_++;
+ }
+ else if (element == "item") {
+ parsingItem_ = false;
+ level_++;
+ getPayloadInternal()->addItem(currentFields_);
+ currentFields_.clear();
+ }
}
void FormParser::handleCharacterData(const std::string& text) {