summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMili Verma <mili.verma@isode.com>2015-06-23 09:08:56 (GMT)
committerKevin Smith <kevin.smith@isode.com>2015-06-29 14:51:46 (GMT)
commitea41bd07a0e014c12cce144b421abac9f21d1269 (patch)
treef6c5b44863d8cb7949bfe5ce29da90f07878efe9
parent595fdfa75d4757d5654bf3189c23c85a66ec6836 (diff)
downloadswift-ea41bd07a0e014c12cce144b421abac9f21d1269.zip
swift-ea41bd07a0e014c12cce144b421abac9f21d1269.tar.bz2
Parse hostname for xep-0233
Test-information: Verified with M-Link. Unit tests pass. Change-Id: Ic675c8d7cd70e01be61c51c0280e1d7208b364ba
-rw-r--r--Swiften/Elements/StreamFeatures.h12
-rw-r--r--Swiften/Parser/StreamFeaturesParser.cpp13
-rw-r--r--Swiften/Parser/StreamFeaturesParser.h3
-rw-r--r--Swiften/Parser/UnitTest/StreamFeaturesParserTest.cpp40
4 files changed, 63 insertions, 5 deletions
diff --git a/Swiften/Elements/StreamFeatures.h b/Swiften/Elements/StreamFeatures.h
index 26dc1ba..10563a9 100644
--- a/Swiften/Elements/StreamFeatures.h
+++ b/Swiften/Elements/StreamFeatures.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2010-2014 Isode Limited. 2 * Copyright (c) 2010-2015 Isode Limited.
3 * All rights reserved. 3 * All rights reserved.
4 * See the COPYING file for more information. 4 * See the COPYING file for more information.
5 */ 5 */
@@ -8,6 +8,7 @@
8 8
9#include <vector> 9#include <vector>
10#include <string> 10#include <string>
11#include <boost/optional.hpp>
11#include <boost/shared_ptr.hpp> 12#include <boost/shared_ptr.hpp>
12 13
13#include <Swiften/Base/API.h> 14#include <Swiften/Base/API.h>
@@ -68,6 +69,14 @@ namespace Swift {
68 return !authenticationMechanisms_.empty(); 69 return !authenticationMechanisms_.empty();
69 } 70 }
70 71
72 const boost::optional<std::string> getAuthenticationHostname() const {
73 return authenticationHostname_;
74 }
75
76 void setAuthenticationHostname(const boost::optional<std::string> authenticationHostname) {
77 authenticationHostname_ = authenticationHostname;
78 }
79
71 bool hasStreamManagement() const { 80 bool hasStreamManagement() const {
72 return hasStreamManagement_; 81 return hasStreamManagement_;
73 } 82 }
@@ -92,5 +101,6 @@ namespace Swift {
92 bool hasSession_; 101 bool hasSession_;
93 bool hasStreamManagement_; 102 bool hasStreamManagement_;
94 bool hasRosterVersioning_; 103 bool hasRosterVersioning_;
104 boost::optional<std::string> authenticationHostname_;
95 }; 105 };
96} 106}
diff --git a/Swiften/Parser/StreamFeaturesParser.cpp b/Swiften/Parser/StreamFeaturesParser.cpp
index f0b8c9a..913c50d 100644
--- a/Swiften/Parser/StreamFeaturesParser.cpp
+++ b/Swiften/Parser/StreamFeaturesParser.cpp
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2010 Isode Limited. 2 * Copyright (c) 2010-2015 Isode Limited.
3 * All rights reserved. 3 * All rights reserved.
4 * See the COPYING file for more information. 4 * See the COPYING file for more information.
5 */ 5 */
@@ -8,7 +8,7 @@
8 8
9namespace Swift { 9namespace Swift {
10 10
11StreamFeaturesParser::StreamFeaturesParser() : GenericElementParser<StreamFeatures>(), currentDepth_(0), inMechanisms_(false), inMechanism_(false), inCompression_(false), inCompressionMethod_(false) { 11StreamFeaturesParser::StreamFeaturesParser() : GenericElementParser<StreamFeatures>(), currentDepth_(0), inMechanisms_(false), inMechanism_(false), inAuthenticationHostname_(false), inCompression_(false), inCompressionMethod_(false) {
12} 12}
13 13
14void StreamFeaturesParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap&) { 14void StreamFeaturesParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap&) {
@@ -44,6 +44,11 @@ void StreamFeaturesParser::handleStartElement(const std::string& element, const
44 inMechanism_ = true; 44 inMechanism_ = true;
45 currentText_ = ""; 45 currentText_ = "";
46 } 46 }
47 else if (inMechanisms_ && element == "hostname" && ns == "urn:xmpp:domain-based-name:1") {
48 inAuthenticationHostname_ = true;
49 currentText_ = "";
50 }
51
47 } 52 }
48 ++currentDepth_; 53 ++currentDepth_;
49} 54}
@@ -63,6 +68,10 @@ void StreamFeaturesParser::handleEndElement(const std::string&, const std::strin
63 getElementGeneric()->addAuthenticationMechanism(currentText_); 68 getElementGeneric()->addAuthenticationMechanism(currentText_);
64 inMechanism_ = false; 69 inMechanism_ = false;
65 } 70 }
71 else if (inAuthenticationHostname_) {
72 getElementGeneric()->setAuthenticationHostname(currentText_);
73 inAuthenticationHostname_ = false;
74 }
66 } 75 }
67} 76}
68 77
diff --git a/Swiften/Parser/StreamFeaturesParser.h b/Swiften/Parser/StreamFeaturesParser.h
index 20eabdc..9ae5fd8 100644
--- a/Swiften/Parser/StreamFeaturesParser.h
+++ b/Swiften/Parser/StreamFeaturesParser.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2010 Isode Limited. 2 * Copyright (c) 2010-2015 Isode Limited.
3 * All rights reserved. 3 * All rights reserved.
4 * See the COPYING file for more information. 4 * See the COPYING file for more information.
5 */ 5 */
@@ -26,6 +26,7 @@ namespace Swift {
26 std::string currentText_; 26 std::string currentText_;
27 bool inMechanisms_; 27 bool inMechanisms_;
28 bool inMechanism_; 28 bool inMechanism_;
29 bool inAuthenticationHostname_;
29 bool inCompression_; 30 bool inCompression_;
30 bool inCompressionMethod_; 31 bool inCompressionMethod_;
31 }; 32 };
diff --git a/Swiften/Parser/UnitTest/StreamFeaturesParserTest.cpp b/Swiften/Parser/UnitTest/StreamFeaturesParserTest.cpp
index 8dd3a22..f6c9336 100644
--- a/Swiften/Parser/UnitTest/StreamFeaturesParserTest.cpp
+++ b/Swiften/Parser/UnitTest/StreamFeaturesParserTest.cpp
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2010 Isode Limited. 2 * Copyright (c) 2010-2015 Isode Limited.
3 * All rights reserved. 3 * All rights reserved.
4 * See the COPYING file for more information. 4 * See the COPYING file for more information.
5 */ 5 */
@@ -16,6 +16,8 @@ class StreamFeaturesParserTest : public CppUnit::TestFixture {
16 CPPUNIT_TEST_SUITE(StreamFeaturesParserTest); 16 CPPUNIT_TEST_SUITE(StreamFeaturesParserTest);
17 CPPUNIT_TEST(testParse); 17 CPPUNIT_TEST(testParse);
18 CPPUNIT_TEST(testParse_Empty); 18 CPPUNIT_TEST(testParse_Empty);
19 CPPUNIT_TEST(testParse_AuthenticationHostname);
20 CPPUNIT_TEST(testParse_AuthenticationHostnameEmpty);
19 CPPUNIT_TEST_SUITE_END(); 21 CPPUNIT_TEST_SUITE_END();
20 22
21 public: 23 public:
@@ -49,6 +51,7 @@ class StreamFeaturesParserTest : public CppUnit::TestFixture {
49 CPPUNIT_ASSERT(element->hasAuthenticationMechanisms()); 51 CPPUNIT_ASSERT(element->hasAuthenticationMechanisms());
50 CPPUNIT_ASSERT(element->hasAuthenticationMechanism("DIGEST-MD5")); 52 CPPUNIT_ASSERT(element->hasAuthenticationMechanism("DIGEST-MD5"));
51 CPPUNIT_ASSERT(element->hasAuthenticationMechanism("PLAIN")); 53 CPPUNIT_ASSERT(element->hasAuthenticationMechanism("PLAIN"));
54 CPPUNIT_ASSERT(!element->getAuthenticationHostname());
52 CPPUNIT_ASSERT(element->hasStreamManagement()); 55 CPPUNIT_ASSERT(element->hasStreamManagement());
53 CPPUNIT_ASSERT(element->hasRosterVersioning()); 56 CPPUNIT_ASSERT(element->hasRosterVersioning());
54 } 57 }
@@ -65,6 +68,41 @@ class StreamFeaturesParserTest : public CppUnit::TestFixture {
65 CPPUNIT_ASSERT(!element->hasResourceBind()); 68 CPPUNIT_ASSERT(!element->hasResourceBind());
66 CPPUNIT_ASSERT(!element->hasAuthenticationMechanisms()); 69 CPPUNIT_ASSERT(!element->hasAuthenticationMechanisms());
67 } 70 }
71
72 void testParse_AuthenticationHostname() {
73 StreamFeaturesParser testling;
74 ElementParserTester parser(&testling);
75 std::string hostname("auth42.us.example.com");
76
77 CPPUNIT_ASSERT(parser.parse(
78 "<stream:features xmlns:stream='http://etherx.jabber.org/streams'>"
79 "<mechanisms xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">"
80 "<mechanism>GSSAPI</mechanism>"
81 "<hostname xmlns=\"urn:xmpp:domain-based-name:1\">auth42.us.example.com</hostname>"
82 "</mechanisms>"
83 "</stream:features>"));
84
85 StreamFeatures::ref element = boost::dynamic_pointer_cast<StreamFeatures>(testling.getElement());
86 CPPUNIT_ASSERT(element->hasAuthenticationMechanism("GSSAPI"));
87 CPPUNIT_ASSERT_EQUAL(*element->getAuthenticationHostname(), hostname);
88 }
89
90 void testParse_AuthenticationHostnameEmpty() {
91 StreamFeaturesParser testling;
92 ElementParserTester parser(&testling);
93
94 CPPUNIT_ASSERT(parser.parse(
95 "<stream:features xmlns:stream='http://etherx.jabber.org/streams'>"
96 "<mechanisms xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">"
97 "<mechanism>GSSAPI</mechanism>"
98 "<hostname xmlns=\"urn:xmpp:domain-based-name:1\"></hostname>"
99 "</mechanisms>"
100 "</stream:features>"));
101
102 StreamFeatures::ref element = boost::dynamic_pointer_cast<StreamFeatures>(testling.getElement());
103 CPPUNIT_ASSERT(element->hasAuthenticationMechanism("GSSAPI"));
104 CPPUNIT_ASSERT(element->getAuthenticationHostname()->empty());
105 }
68}; 106};
69 107
70CPPUNIT_TEST_SUITE_REGISTRATION(StreamFeaturesParserTest); 108CPPUNIT_TEST_SUITE_REGISTRATION(StreamFeaturesParserTest);