diff options
author | Tobias Markmann <tm@ayena.de> | 2012-01-06 22:18:25 (GMT) |
---|---|---|
committer | Kevin Smith <git@kismith.co.uk> | 2012-01-23 14:51:26 (GMT) |
commit | 83afa3d4bf18e4feb8a33d084ed181508084fc64 (patch) | |
tree | b81a0c6eaaedbad3f3e607ea52a69acf98f95eff /Swiften/Serializer/PayloadSerializers/FormSerializer.cpp | |
parent | 093d499945d779cfed92b45e413644834004b0d9 (diff) | |
download | swift-contrib-83afa3d4bf18e4feb8a33d084ed181508084fc64.zip swift-contrib-83afa3d4bf18e4feb8a33d084ed181508084fc64.tar.bz2 |
XEP-0004 form support for user search.
License: This patch is BSD-licensed, see http://www.opensource.org/licenses/bsd-license.php
Diffstat (limited to 'Swiften/Serializer/PayloadSerializers/FormSerializer.cpp')
-rw-r--r-- | Swiften/Serializer/PayloadSerializers/FormSerializer.cpp | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/Swiften/Serializer/PayloadSerializers/FormSerializer.cpp b/Swiften/Serializer/PayloadSerializers/FormSerializer.cpp index 7a6bb79..15c4f32 100644 --- a/Swiften/Serializer/PayloadSerializers/FormSerializer.cpp +++ b/Swiften/Serializer/PayloadSerializers/FormSerializer.cpp @@ -52,12 +52,27 @@ std::string FormSerializer::serializePayload(boost::shared_ptr<Form> form) cons multiLineify(form->getInstructions(), "instructions", formElement); } foreach(boost::shared_ptr<FormField> field, form->getFields()) { - formElement->addNode(fieldToXML(field)); + formElement->addNode(fieldToXML(field, true)); } + if (!form->getReportedFields().empty()) { + boost::shared_ptr<XMLElement> reportedElement(new XMLElement("reported")); + foreach(FormField::ref field, form->getReportedFields()) { + reportedElement->addNode(fieldToXML(field, true)); + } + formElement->addNode(reportedElement); + } + foreach(Form::FormItem item, form->getItems()) { + boost::shared_ptr<XMLElement> itemElement(new XMLElement("item")); + foreach(FormField::ref field, item) { + itemElement->addNode(fieldToXML(field, false)); + } + formElement->addNode(itemElement); + } + return formElement->serialize(); } -boost::shared_ptr<XMLElement> FormSerializer::fieldToXML(boost::shared_ptr<FormField> field) const { +boost::shared_ptr<XMLElement> FormSerializer::fieldToXML(boost::shared_ptr<FormField> field, bool withTypeAttribute) const { boost::shared_ptr<XMLElement> fieldElement(new XMLElement("field")); if (!field->getName().empty()) { fieldElement->setAttribute("var", field->getName()); @@ -115,7 +130,7 @@ boost::shared_ptr<XMLElement> FormSerializer::fieldToXML(boost::shared_ptr<FormF fieldType = "jid-single"; boost::shared_ptr<XMLElement> valueElement(new XMLElement("value")); valueElement->addNode(XMLTextNode::create(boost::dynamic_pointer_cast<JIDSingleFormField>(field)->getValue().toString())); - fieldElement->addNode(valueElement); + if ( boost::dynamic_pointer_cast<JIDSingleFormField>(field)->getValue().isValid()) fieldElement->addNode(valueElement); } else if (boost::dynamic_pointer_cast<ListMultiFormField>(field)) { fieldType = "list-multi"; @@ -133,7 +148,7 @@ boost::shared_ptr<XMLElement> FormSerializer::fieldToXML(boost::shared_ptr<FormF else { assert(false); } - if (!fieldType.empty()) { + if (!fieldType.empty() && withTypeAttribute) { fieldElement->setAttribute("type", fieldType); } |