diff options
-rw-r--r-- | Swiften/Disco/CapsInfoGenerator.cpp | 24 | ||||
-rw-r--r-- | Swiften/Disco/UnitTest/CapsInfoGeneratorTest.cpp | 51 | ||||
-rw-r--r-- | Swiften/Elements/DiscoInfo.h | 17 | ||||
-rw-r--r-- | Swiften/Elements/Form.cpp | 22 | ||||
-rw-r--r-- | Swiften/Elements/Form.h | 2 | ||||
-rw-r--r-- | Swiften/Elements/FormField.h | 13 | ||||
-rw-r--r-- | Swiften/Elements/UnitTest/FormTest.cpp | 36 | ||||
-rw-r--r-- | Swiften/Parser/GenericPayloadParser.h | 2 | ||||
-rw-r--r-- | Swiften/Parser/PayloadParsers/DiscoInfoParser.cpp | 27 | ||||
-rw-r--r-- | Swiften/Parser/PayloadParsers/DiscoInfoParser.h | 1 | ||||
-rw-r--r-- | Swiften/Parser/PayloadParsers/FormParser.cpp | 3 | ||||
-rw-r--r-- | Swiften/Parser/PayloadParsers/FormParser.h | 5 | ||||
-rw-r--r-- | Swiften/Parser/PayloadParsers/UnitTest/DiscoInfoParserTest.cpp | 22 | ||||
-rw-r--r-- | Swiften/Parser/PayloadParsers/UnitTest/FormParserTest.cpp | 12 | ||||
-rw-r--r-- | Swiften/SConscript | 2 | ||||
-rw-r--r-- | Swiften/Serializer/PayloadSerializers/DiscoInfoSerializer.cpp | 5 | ||||
-rw-r--r-- | Swiften/Serializer/PayloadSerializers/UnitTest/DiscoInfoSerializerTest.cpp | 22 |
17 files changed, 251 insertions, 15 deletions
diff --git a/Swiften/Disco/CapsInfoGenerator.cpp b/Swiften/Disco/CapsInfoGenerator.cpp index 67ed979..94f2a7a 100644 --- a/Swiften/Disco/CapsInfoGenerator.cpp +++ b/Swiften/Disco/CapsInfoGenerator.cpp @@ -10,9 +10,16 @@ #include "Swiften/Base/foreach.h" #include "Swiften/Elements/DiscoInfo.h" +#include "Swiften/Elements/FormField.h" #include "Swiften/StringCodecs/SHA1.h" #include "Swiften/StringCodecs/Base64.h" +namespace { + bool compareFields(Swift::FormField::ref f1, Swift::FormField::ref f2) { + return f1->getName() < f2->getName(); + } +} + namespace Swift { CapsInfoGenerator::CapsInfoGenerator(const String& node) : node_(node) { @@ -33,6 +40,23 @@ CapsInfo CapsInfoGenerator::generateCapsInfo(const DiscoInfo& discoInfo) const { serializedCaps += feature + "<"; } + foreach(Form::ref extension, discoInfo.getExtensions()) { + serializedCaps += extension->getFormType() + "<"; + std::vector<FormField::ref> fields(extension->getFields()); + std::sort(fields.begin(), fields.end(), &compareFields); + foreach(FormField::ref field, fields) { + if (field->getName() == "FORM_TYPE") { + continue; + } + serializedCaps += field->getName() + "<"; + std::vector<String> values(field->getRawValues()); + std::sort(values.begin(), values.end()); + foreach(const String& value, values) { + serializedCaps += value + "<"; + } + } + } + String version(Base64::encode(SHA1::getHash(serializedCaps))); return CapsInfo(node_, version, "sha-1"); } diff --git a/Swiften/Disco/UnitTest/CapsInfoGeneratorTest.cpp b/Swiften/Disco/UnitTest/CapsInfoGeneratorTest.cpp index a8fe5b7..aec3a92 100644 --- a/Swiften/Disco/UnitTest/CapsInfoGeneratorTest.cpp +++ b/Swiften/Disco/UnitTest/CapsInfoGeneratorTest.cpp @@ -12,15 +12,13 @@ using namespace Swift; -class CapsInfoGeneratorTest : public CppUnit::TestFixture -{ +class CapsInfoGeneratorTest : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(CapsInfoGeneratorTest); CPPUNIT_TEST(testGenerate_XEP0115SimpleExample); + CPPUNIT_TEST(testGenerate_XEP0115ComplexExample); CPPUNIT_TEST_SUITE_END(); public: - CapsInfoGeneratorTest() {} - void testGenerate_XEP0115SimpleExample() { DiscoInfo discoInfo; discoInfo.addIdentity(DiscoInfo::Identity("Exodus 0.9.1", "client", "pc")); @@ -36,6 +34,51 @@ class CapsInfoGeneratorTest : public CppUnit::TestFixture CPPUNIT_ASSERT_EQUAL(String("sha-1"), result.getHash()); CPPUNIT_ASSERT_EQUAL(String("QgayPKawpkPSDYmwT/WM94uAlu0="), result.getVersion()); } + + void testGenerate_XEP0115ComplexExample() { + DiscoInfo discoInfo; + discoInfo.addIdentity(DiscoInfo::Identity("Psi 0.11", "client", "pc", "en")); + discoInfo.addIdentity(DiscoInfo::Identity("\xce\xa8 0.11", "client", "pc", "el")); + discoInfo.addFeature("http://jabber.org/protocol/disco#items"); + discoInfo.addFeature("http://jabber.org/protocol/caps"); + discoInfo.addFeature("http://jabber.org/protocol/disco#info"); + discoInfo.addFeature("http://jabber.org/protocol/muc"); + + Form::ref extension(new Form(Form::ResultType)); + FormField::ref field = HiddenFormField::create("urn:xmpp:dataforms:softwareinfo"); + field->setName("FORM_TYPE"); + extension->addField(field); + std::vector<String> ipVersions; + ipVersions.push_back("ipv6"); + ipVersions.push_back("ipv4"); + field = ListMultiFormField::create(ipVersions); + field->addRawValue("ipv6"); + field->addRawValue("ipv4"); + field->setName("ip_version"); + extension->addField(field); + field = TextSingleFormField::create("Psi"); + field->addRawValue("Psi"); + field->setName("software"); + extension->addField(field); + field = TextSingleFormField::create("0.11"); + field->addRawValue("0.11"); + field->setName("software_version"); + extension->addField(field); + field = TextSingleFormField::create("Mac"); + field->setName("os"); + field->addRawValue("Mac"); + extension->addField(field); + field = TextSingleFormField::create("10.5.1"); + field->setName("os_version"); + field->addRawValue("10.5.1"); + extension->addField(field); + discoInfo.addExtension(extension); + + CapsInfoGenerator testling("http://psi-im.org"); + CapsInfo result = testling.generateCapsInfo(discoInfo); + + CPPUNIT_ASSERT_EQUAL(String("q07IKJEyjvHSyhy//CH0CxmKi8w="), result.getVersion()); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(CapsInfoGeneratorTest); diff --git a/Swiften/Elements/DiscoInfo.h b/Swiften/Elements/DiscoInfo.h index cee9200..2cc914a 100644 --- a/Swiften/Elements/DiscoInfo.h +++ b/Swiften/Elements/DiscoInfo.h @@ -4,8 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#ifndef SWIFTEN_DiscoInfo_H -#define SWIFTEN_DiscoInfo_H +#pragma once #include <vector> #include <algorithm> @@ -13,6 +12,7 @@ #include "Swiften/Elements/Payload.h" #include "Swiften/Base/String.h" #include "Swiften/Base/Shared.h" +#include "Swiften/Elements/Form.h" namespace Swift { class DiscoInfo : public Payload, public Shared<DiscoInfo> { @@ -60,7 +60,7 @@ namespace Swift { node_ = node; } - const std::vector<Identity> getIdentities() const { + const std::vector<Identity>& getIdentities() const { return identities_; } @@ -80,11 +80,18 @@ namespace Swift { return std::find(features_.begin(), features_.end(), feature) != features_.end(); } + void addExtension(Form::ref form) { + extensions_.push_back(form); + } + + const std::vector<Form::ref> getExtensions() const { + return extensions_; + } + private: String node_; std::vector<Identity> identities_; std::vector<String> features_; + std::vector<Form::ref> extensions_; }; } - -#endif diff --git a/Swiften/Elements/Form.cpp b/Swiften/Elements/Form.cpp new file mode 100644 index 0000000..9420fb9 --- /dev/null +++ b/Swiften/Elements/Form.cpp @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include "Swiften/Elements/Form.h" +#include "Swiften/Base/foreach.h" + +namespace Swift { + +String Form::getFormType() const { + foreach(FormField::ref field, fields_) { + boost::shared_ptr<HiddenFormField> f = boost::dynamic_pointer_cast<HiddenFormField>(field); + if (f && f->getName() == "FORM_TYPE") { + return f->getValue(); + } + } + return ""; +} + +} diff --git a/Swiften/Elements/Form.h b/Swiften/Elements/Form.h index 34068ee..f5826a5 100644 --- a/Swiften/Elements/Form.h +++ b/Swiften/Elements/Form.h @@ -38,6 +38,8 @@ namespace Swift { Type getType() { return type_; } void setType(Type type) { type_ = type; } + String getFormType() const; + private: std::vector<boost::shared_ptr<FormField> > fields_; String title_; diff --git a/Swiften/Elements/FormField.h b/Swiften/Elements/FormField.h index 732203a..a0240e1 100644 --- a/Swiften/Elements/FormField.h +++ b/Swiften/Elements/FormField.h @@ -4,6 +4,9 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ +// FIXME: We currently keep 2 values: the raw values, and the actual value. +// We should only store the raw values, and deduce the actual values from this + #pragma once #include <vector> @@ -45,6 +48,14 @@ namespace Swift { return options; } + const std::vector<String> getRawValues() const { + return rawValues; + } + + void addRawValue(const String& value) { + rawValues.push_back(value); + } + protected: FormField() : required(false) {} @@ -54,6 +65,7 @@ namespace Swift { String description; bool required; std::vector<Option> options; + std::vector<String> rawValues; }; template<typename T> class GenericFormField : public FormField { @@ -99,4 +111,5 @@ namespace Swift { SWIFTEN_DECLARE_FORM_FIELD(JIDSingle, JID); SWIFTEN_DECLARE_FORM_FIELD(JIDMulti, std::vector<JID>); SWIFTEN_DECLARE_FORM_FIELD(ListMulti, std::vector<String>); + SWIFTEN_DECLARE_FORM_FIELD(Untyped, std::vector<String>); } diff --git a/Swiften/Elements/UnitTest/FormTest.cpp b/Swiften/Elements/UnitTest/FormTest.cpp new file mode 100644 index 0000000..3852d98 --- /dev/null +++ b/Swiften/Elements/UnitTest/FormTest.cpp @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/extensions/TestFactoryRegistry.h> +#include <boost/shared_ptr.hpp> + +#include "Swiften/Elements/Form.h" + +using namespace Swift; + +class FormTest : public CppUnit::TestFixture { + CPPUNIT_TEST_SUITE(FormTest); + CPPUNIT_TEST(testGetFormType); + CPPUNIT_TEST_SUITE_END(); + + public: + void testGetFormType() { + Form form; + + form.addField(FixedFormField::create("Foo")); + + FormField::ref field = HiddenFormField::create("jabber:bot"); + field->setName("FORM_TYPE"); + form.addField(field); + + form.addField(FixedFormField::create("Bar")); + + CPPUNIT_ASSERT_EQUAL(String("jabber:bot"), form.getFormType()); + } +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(FormTest); diff --git a/Swiften/Parser/GenericPayloadParser.h b/Swiften/Parser/GenericPayloadParser.h index 9e6fddb..0c0f8c3 100644 --- a/Swiften/Parser/GenericPayloadParser.h +++ b/Swiften/Parser/GenericPayloadParser.h @@ -13,6 +13,7 @@ namespace Swift { class String; + class FormParser; template<typename PAYLOAD_TYPE> class GenericPayloadParser : public PayloadParser { @@ -25,7 +26,6 @@ namespace Swift { return payload_; } - protected: virtual boost::shared_ptr<PAYLOAD_TYPE> getPayloadInternal() const { return payload_; } diff --git a/Swiften/Parser/PayloadParsers/DiscoInfoParser.cpp b/Swiften/Parser/PayloadParsers/DiscoInfoParser.cpp index 81f2ce8..c47c703 100644 --- a/Swiften/Parser/PayloadParsers/DiscoInfoParser.cpp +++ b/Swiften/Parser/PayloadParsers/DiscoInfoParser.cpp @@ -5,13 +5,14 @@ */ #include "Swiften/Parser/PayloadParsers/DiscoInfoParser.h" +#include "Swiften/Parser/PayloadParsers/FormParser.h" namespace Swift { -DiscoInfoParser::DiscoInfoParser() : level_(TopLevel) { +DiscoInfoParser::DiscoInfoParser() : level_(TopLevel), formParser_(NULL) { } -void DiscoInfoParser::handleStartElement(const String& element, const String&, const AttributeMap& attributes) { +void DiscoInfoParser::handleStartElement(const String& element, const String& ns, const AttributeMap& attributes) { if (level_ == PayloadLevel) { if (element == "identity") { getPayloadInternal()->addIdentity(DiscoInfo::Identity(attributes.getAttribute("name"), attributes.getAttribute("category"), attributes.getAttribute("type"), attributes.getAttribute("lang"))); @@ -19,15 +20,33 @@ void DiscoInfoParser::handleStartElement(const String& element, const String&, c else if (element == "feature") { getPayloadInternal()->addFeature(attributes.getAttribute("var")); } + else if (element == "x" && ns == "jabber:x:data") { + assert(!formParser_); + formParser_ = new FormParser(); + } + } + if (formParser_) { + formParser_->handleStartElement(element, ns, attributes); } ++level_; } -void DiscoInfoParser::handleEndElement(const String&, const String&) { +void DiscoInfoParser::handleEndElement(const String& element, const String& ns) { --level_; + if (formParser_) { + formParser_->handleEndElement(element, ns); + } + if (level_ == PayloadLevel && formParser_) { + getPayloadInternal()->addExtension(formParser_->getPayloadInternal()); + delete formParser_; + formParser_ = NULL; + } } -void DiscoInfoParser::handleCharacterData(const String&) { +void DiscoInfoParser::handleCharacterData(const String& data) { + if (formParser_) { + formParser_->handleCharacterData(data); + } } } diff --git a/Swiften/Parser/PayloadParsers/DiscoInfoParser.h b/Swiften/Parser/PayloadParsers/DiscoInfoParser.h index 925d349..d9bfb54 100644 --- a/Swiften/Parser/PayloadParsers/DiscoInfoParser.h +++ b/Swiften/Parser/PayloadParsers/DiscoInfoParser.h @@ -24,5 +24,6 @@ namespace Swift { PayloadLevel = 1 }; int level_; + FormParser* formParser_; }; } diff --git a/Swiften/Parser/PayloadParsers/FormParser.cpp b/Swiften/Parser/PayloadParsers/FormParser.cpp index f08e7a3..dc15ece 100644 --- a/Swiften/Parser/PayloadParsers/FormParser.cpp +++ b/Swiften/Parser/PayloadParsers/FormParser.cpp @@ -66,6 +66,9 @@ void FormParser::handleStartElement(const String& element, const String&, const else if (type == "text-single") { currentFieldParseHelper_ = TextSingleFormFieldParseHelper::create(); } + else { + currentFieldParseHelper_ = UntypedFormFieldParseHelper::create(); + } if (currentFieldParseHelper_) { currentFieldParseHelper_->getField()->setName(attributes.getAttribute("var")); currentFieldParseHelper_->getField()->setLabel(attributes.getAttribute("label")); diff --git a/Swiften/Parser/PayloadParsers/FormParser.h b/Swiften/Parser/PayloadParsers/FormParser.h index 76a54b9..c41e27f 100644 --- a/Swiften/Parser/PayloadParsers/FormParser.h +++ b/Swiften/Parser/PayloadParsers/FormParser.h @@ -32,6 +32,7 @@ namespace Swift { class BoolFieldParseHelper : public FieldParseHelper { virtual void addValue(const String& s) { boost::dynamic_pointer_cast< GenericFormField<bool> >(getField())->setValue(s == "1" || s == "true"); + getField()->addRawValue(s); } }; class StringFieldParseHelper : public FieldParseHelper { @@ -43,6 +44,7 @@ namespace Swift { else { field->setValue(field->getValue() + "\n" + s); } + getField()->addRawValue(s); } }; class JIDFieldParseHelper : public FieldParseHelper { @@ -57,6 +59,7 @@ namespace Swift { std::vector<String> l = field->getValue(); l.push_back(s); field->setValue(l); + getField()->addRawValue(s); } }; class JIDListFieldParseHelper : public FieldParseHelper { @@ -66,6 +69,7 @@ namespace Swift { std::vector<JID> l = field->getValue(); l.push_back(JID(s)); field->setValue(l); + getField()->addRawValue(s); } }; @@ -92,6 +96,7 @@ namespace Swift { SWIFTEN_DECLARE_FORM_FIELD_PARSE_HELPER(JIDSingle, JID); SWIFTEN_DECLARE_FORM_FIELD_PARSE_HELPER(JIDMulti, JIDList); SWIFTEN_DECLARE_FORM_FIELD_PARSE_HELPER(ListMulti, StringList); + SWIFTEN_DECLARE_FORM_FIELD_PARSE_HELPER(Untyped, StringList); enum Level { TopLevel = 0, diff --git a/Swiften/Parser/PayloadParsers/UnitTest/DiscoInfoParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/DiscoInfoParserTest.cpp index 2e7e7af..79b28db 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/DiscoInfoParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/DiscoInfoParserTest.cpp @@ -16,6 +16,7 @@ class DiscoInfoParserTest : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(DiscoInfoParserTest); CPPUNIT_TEST(testParse); + CPPUNIT_TEST(testParse_Form); CPPUNIT_TEST_SUITE_END(); public: @@ -48,6 +49,27 @@ class DiscoInfoParserTest : public CppUnit::TestFixture CPPUNIT_ASSERT_EQUAL(String("bar-feature"), payload->getFeatures()[1]); CPPUNIT_ASSERT_EQUAL(String("baz-feature"), payload->getFeatures()[2]); } + + void testParse_Form() { + PayloadsParserTester parser; + + CPPUNIT_ASSERT(parser.parse( + "<query xmlns=\"http://jabber.org/protocol/disco#info\">" + "<feature var=\"foo-feature\"/>" + "<x type=\"submit\" xmlns=\"jabber:x:data\">" + "<title>Bot Configuration</title>" + "<instructions>Hello!</instructions>" + "</x>" + "<feature var=\"bar-feature\"/>" + "</query>")); + + DiscoInfo* payload = dynamic_cast<DiscoInfo*>(parser.getPayload().get()); + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(payload->getExtensions().size())); + CPPUNIT_ASSERT_EQUAL(String("Bot Configuration"), payload->getExtensions()[0]->getTitle()); + CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(payload->getFeatures().size())); + CPPUNIT_ASSERT_EQUAL(String("foo-feature"), payload->getFeatures()[0]); + CPPUNIT_ASSERT_EQUAL(String("bar-feature"), payload->getFeatures()[1]); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(DiscoInfoParserTest); diff --git a/Swiften/Parser/PayloadParsers/UnitTest/FormParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/FormParserTest.cpp index 0d6e85e..aede75d 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/FormParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/FormParserTest.cpp @@ -75,11 +75,15 @@ class FormParserTest : public CppUnit::TestFixture { "<value>foo@bar.com</value>" "<value>baz@fum.org</value>" "</field>" + "<field var=\"untyped\">" + "<value>foo</value>" + "<value>baz</value>" + "</field>" "</x>")); Form* payload = dynamic_cast<Form*>(parser.getPayload().get()); - CPPUNIT_ASSERT_EQUAL(9, static_cast<int>(payload->getFields().size())); + CPPUNIT_ASSERT_EQUAL(10, static_cast<int>(payload->getFields().size())); CPPUNIT_ASSERT_EQUAL(String("jabber:bot"), boost::dynamic_pointer_cast<HiddenFormField>(payload->getFields()[0])->getValue()); CPPUNIT_ASSERT_EQUAL(String("FORM_TYPE"), payload->getFields()[0]->getName()); CPPUNIT_ASSERT(!payload->getFields()[0]->getRequired()); @@ -92,9 +96,12 @@ class FormParserTest : public CppUnit::TestFixture { CPPUNIT_ASSERT_EQUAL(true, boost::dynamic_pointer_cast<BooleanFormField>(payload->getFields()[4])->getValue()); CPPUNIT_ASSERT(payload->getFields()[4]->getRequired()); + CPPUNIT_ASSERT_EQUAL(String("1"), boost::dynamic_pointer_cast<BooleanFormField>(payload->getFields()[4])->getRawValues()[0]); CPPUNIT_ASSERT_EQUAL(String("news"), boost::dynamic_pointer_cast<ListMultiFormField>(payload->getFields()[6])->getValue()[0]); + CPPUNIT_ASSERT_EQUAL(String("news"), payload->getFields()[6]->getRawValues()[0]); CPPUNIT_ASSERT_EQUAL(String("search"), boost::dynamic_pointer_cast<ListMultiFormField>(payload->getFields()[6])->getValue()[1]); + CPPUNIT_ASSERT_EQUAL(String("search"), payload->getFields()[6]->getRawValues()[1]); CPPUNIT_ASSERT_EQUAL(5, static_cast<int>(payload->getFields()[6]->getOptions().size())); CPPUNIT_ASSERT_EQUAL(String("Contests"), payload->getFields()[6]->getOptions()[0].label); CPPUNIT_ASSERT_EQUAL(String("contests"), payload->getFields()[6]->getOptions()[0].value); @@ -106,6 +113,9 @@ class FormParserTest : public CppUnit::TestFixture { 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(String("Tell all your friends about your new bot!"), payload->getFields()[8]->getDescription()); + + CPPUNIT_ASSERT_EQUAL(String("foo"), boost::dynamic_pointer_cast<UntypedFormField>(payload->getFields()[9])->getValue()[0]); + CPPUNIT_ASSERT_EQUAL(String("baz"), boost::dynamic_pointer_cast<UntypedFormField>(payload->getFields()[9])->getValue()[1]); } }; diff --git a/Swiften/SConscript b/Swiften/SConscript index 87afed9..c5ad9a6 100644 --- a/Swiften/SConscript +++ b/Swiften/SConscript @@ -33,6 +33,7 @@ if env["SCONS_STAGE"] == "build" : "Compress/ZLibDecompressor.cpp", "Compress/ZLibCompressor.cpp", "Elements/DiscoInfo.cpp", + "Elements/Form.cpp", "Elements/Element.cpp", "Elements/IQ.cpp", "Elements/Payload.cpp", @@ -156,6 +157,7 @@ if env["SCONS_STAGE"] == "build" : File("Disco/UnitTest/EntityCapsManagerTest.cpp"), File("Elements/UnitTest/IQTest.cpp"), File("Elements/UnitTest/StanzaTest.cpp"), + File("Elements/UnitTest/FormTest.cpp"), File("Elements/UnitTest/StanzasTest.cpp"), File("EventLoop/UnitTest/EventLoopTest.cpp"), File("EventLoop/UnitTest/SimpleEventLoopTest.cpp"), diff --git a/Swiften/Serializer/PayloadSerializers/DiscoInfoSerializer.cpp b/Swiften/Serializer/PayloadSerializers/DiscoInfoSerializer.cpp index dcc51b9..f5923dc 100644 --- a/Swiften/Serializer/PayloadSerializers/DiscoInfoSerializer.cpp +++ b/Swiften/Serializer/PayloadSerializers/DiscoInfoSerializer.cpp @@ -10,6 +10,8 @@ #include "Swiften/Base/foreach.h" #include "Swiften/Serializer/XML/XMLElement.h" +#include "Swiften/Serializer/XML/XMLRawTextNode.h" +#include "Swiften/Serializer/PayloadSerializers/FormSerializer.h" namespace Swift { @@ -36,6 +38,9 @@ String DiscoInfoSerializer::serializePayload(boost::shared_ptr<DiscoInfo> discoI featureElement->setAttribute("var", feature); queryElement.addNode(featureElement); } + foreach(const Form::ref extension, discoInfo->getExtensions()) { + queryElement.addNode(boost::shared_ptr<XMLRawTextNode>(new XMLRawTextNode(FormSerializer().serialize(extension)))); + } return queryElement.serialize(); } diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/DiscoInfoSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/DiscoInfoSerializerTest.cpp index 6a81298..c67fcdb 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/DiscoInfoSerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/DiscoInfoSerializerTest.cpp @@ -15,6 +15,7 @@ class DiscoInfoSerializerTest : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(DiscoInfoSerializerTest); CPPUNIT_TEST(testSerialize); + CPPUNIT_TEST(testSerialize_Form); CPPUNIT_TEST_SUITE_END(); public: @@ -39,6 +40,27 @@ class DiscoInfoSerializerTest : public CppUnit::TestFixture CPPUNIT_ASSERT_EQUAL(expectedResult, testling.serialize(discoInfo)); } + + void testSerialize_Form() { + DiscoInfoSerializer testling; + boost::shared_ptr<DiscoInfo> discoInfo(new DiscoInfo()); + discoInfo->addFeature("http://jabber.org/protocol/caps"); + discoInfo->addFeature("http://jabber.org/protocol/disco#info"); + boost::shared_ptr<Form> form(new Form(Form::FormType)); + form->setTitle("Bot Configuration"); + discoInfo->addExtension(form); + + String expectedResult = + "<query xmlns=\"http://jabber.org/protocol/disco#info\">" + "<feature var=\"http://jabber.org/protocol/caps\"/>" + "<feature var=\"http://jabber.org/protocol/disco#info\"/>" + "<x type=\"form\" xmlns=\"jabber:x:data\">" + "<title>Bot Configuration</title>" + "</x>" + "</query>"; + + CPPUNIT_ASSERT_EQUAL(expectedResult, testling.serialize(discoInfo)); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(DiscoInfoSerializerTest); |