summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2010-09-14 16:17:30 (GMT)
committerRemko Tronçon <git@el-tramo.be>2010-09-14 19:48:53 (GMT)
commitef5a4dc3a5b0224628a225ef0dccc679287478be (patch)
tree126d8f752f18d3d5891cd32cacf2a21734ab0b92 /Swiften/Disco
parent9ecba612d790c1f613dc959888f62e5d3575faae (diff)
downloadswift-ef5a4dc3a5b0224628a225ef0dccc679287478be.zip
swift-ef5a4dc3a5b0224628a225ef0dccc679287478be.tar.bz2
Add extended disco support to caps verifier.
Diffstat (limited to 'Swiften/Disco')
-rw-r--r--Swiften/Disco/CapsInfoGenerator.cpp24
-rw-r--r--Swiften/Disco/UnitTest/CapsInfoGeneratorTest.cpp51
2 files changed, 71 insertions, 4 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);