summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften')
-rw-r--r--Swiften/Base/URL.cpp2
-rw-r--r--Swiften/Base/UnitTest/URLTest.cpp20
-rw-r--r--Swiften/Network/BOSHConnection.cpp8
-rw-r--r--Swiften/Network/UnitTest/BOSHConnectionPoolTest.cpp4
-rw-r--r--Swiften/Network/UnitTest/BOSHConnectionTest.cpp2
5 files changed, 25 insertions, 11 deletions
diff --git a/Swiften/Base/URL.cpp b/Swiften/Base/URL.cpp
index 320e2ad..866cd45 100644
--- a/Swiften/Base/URL.cpp
+++ b/Swiften/Base/URL.cpp
@@ -36,25 +36,25 @@ URL URL::fromString(const std::string& urlString) {
// Authority
if (urlString.size() > colonIndex + 2 && urlString[colonIndex+1] == '/' && urlString[colonIndex+2] == '/') {
size_t authorityIndex = colonIndex + 3;
size_t slashIndex = urlString.find('/', authorityIndex);
std::string authority;
std::string path;
if (slashIndex == std::string::npos) {
authority = urlString.substr(authorityIndex);
path = "";
}
else {
authority = urlString.substr(authorityIndex, slashIndex - authorityIndex);
- path = unescape(urlString.substr(slashIndex + 1));
+ path = unescape(urlString.substr(slashIndex));
}
size_t atIndex = authority.find('@');
std::string userInfo;
std::string hostAndPort;
if (atIndex != std::string::npos) {
userInfo = authority.substr(0, atIndex);
hostAndPort = authority.substr(atIndex + 1);
}
else {
userInfo = "";
hostAndPort = authority;
diff --git a/Swiften/Base/UnitTest/URLTest.cpp b/Swiften/Base/UnitTest/URLTest.cpp
index 09912ed..e82321f 100644
--- a/Swiften/Base/UnitTest/URLTest.cpp
+++ b/Swiften/Base/UnitTest/URLTest.cpp
@@ -9,96 +9,106 @@
#include <Swiften/Base/URL.h>
#include <boost/lexical_cast.hpp>
using namespace Swift;
class URLTest : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(URLTest);
CPPUNIT_TEST(testFromString);
CPPUNIT_TEST(testFromString_WithoutPath);
CPPUNIT_TEST(testFromString_WithRootPath);
CPPUNIT_TEST(testFromString_WithPort);
+ CPPUNIT_TEST(testFromString_WithPortOnePartPath);
CPPUNIT_TEST(testFromString_WithPortWithoutPath);
CPPUNIT_TEST(testFromString_WithUserInfo);
CPPUNIT_TEST(testFromString_NonASCIIHost);
CPPUNIT_TEST(testFromString_NonASCIIPath);
CPPUNIT_TEST(testToString);
CPPUNIT_TEST(testToString_WithPort);
CPPUNIT_TEST_SUITE_END();
public:
void testFromString() {
URL url = URL::fromString("http://foo.bar/baz/bam");
CPPUNIT_ASSERT_EQUAL(std::string("http"), url.getScheme());
CPPUNIT_ASSERT_EQUAL(std::string("foo.bar"), url.getHost());
CPPUNIT_ASSERT(!url.getPort());
- CPPUNIT_ASSERT_EQUAL(std::string("baz/bam"), url.getPath());
+ CPPUNIT_ASSERT_EQUAL(std::string("/baz/bam"), url.getPath());
}
void testFromString_WithoutPath() {
URL url = URL::fromString("http://foo.bar");
CPPUNIT_ASSERT_EQUAL(std::string("http"), url.getScheme());
CPPUNIT_ASSERT_EQUAL(std::string("foo.bar"), url.getHost());
CPPUNIT_ASSERT(!url.getPort());
CPPUNIT_ASSERT_EQUAL(std::string(""), url.getPath());
}
void testFromString_WithRootPath() {
URL url = URL::fromString("http://foo.bar/");
CPPUNIT_ASSERT_EQUAL(std::string("http"), url.getScheme());
CPPUNIT_ASSERT_EQUAL(std::string("foo.bar"), url.getHost());
CPPUNIT_ASSERT(!url.getPort());
- CPPUNIT_ASSERT_EQUAL(std::string(""), url.getPath());
+ CPPUNIT_ASSERT_EQUAL(std::string("/"), url.getPath());
}
void testFromString_WithPort() {
URL url = URL::fromString("http://foo.bar:1234/baz/bam");
CPPUNIT_ASSERT_EQUAL(std::string("http"), url.getScheme());
CPPUNIT_ASSERT_EQUAL(std::string("foo.bar"), url.getHost());
CPPUNIT_ASSERT_EQUAL(1234, *url.getPort());
- CPPUNIT_ASSERT_EQUAL(std::string("baz/bam"), url.getPath());
+ CPPUNIT_ASSERT_EQUAL(std::string("/baz/bam"), url.getPath());
+ }
+
+ void testFromString_WithPortOnePartPath() {
+ URL url = URL::fromString("http://foo.bar:11440/http-bind/");
+
+ CPPUNIT_ASSERT_EQUAL(std::string("http"), url.getScheme());
+ CPPUNIT_ASSERT_EQUAL(std::string("foo.bar"), url.getHost());
+ CPPUNIT_ASSERT_EQUAL(11440, *url.getPort());
+ CPPUNIT_ASSERT_EQUAL(std::string("/http-bind/"), url.getPath());
}
void testFromString_WithPortWithoutPath() {
URL url = URL::fromString("http://foo.bar:1234");
CPPUNIT_ASSERT_EQUAL(std::string("http"), url.getScheme());
CPPUNIT_ASSERT_EQUAL(std::string("foo.bar"), url.getHost());
CPPUNIT_ASSERT_EQUAL(1234, *url.getPort());
CPPUNIT_ASSERT_EQUAL(std::string(""), url.getPath());
}
void testFromString_WithUserInfo() {
URL url = URL::fromString("http://user:pass@foo.bar/baz/bam");
CPPUNIT_ASSERT_EQUAL(std::string("http"), url.getScheme());
CPPUNIT_ASSERT_EQUAL(std::string("foo.bar"), url.getHost());
- CPPUNIT_ASSERT_EQUAL(std::string("baz/bam"), url.getPath());
+ CPPUNIT_ASSERT_EQUAL(std::string("/baz/bam"), url.getPath());
}
void testFromString_NonASCIIHost() {
URL url = URL::fromString("http://www.tron%C3%A7on.be/baz/bam");
CPPUNIT_ASSERT_EQUAL(std::string("www.tron\xc3\xa7on.be"), url.getHost());
}
void testFromString_NonASCIIPath() {
URL url = URL::fromString("http://foo.bar/baz/tron%C3%A7on/bam");
- CPPUNIT_ASSERT_EQUAL(std::string("baz/tron\xc3\xa7on/bam"), url.getPath());
+ CPPUNIT_ASSERT_EQUAL(std::string("/baz/tron\xc3\xa7on/bam"), url.getPath());
}
void testToString() {
CPPUNIT_ASSERT_EQUAL(std::string("http://foo.bar/baz/bam"), URL("http", "foo.bar", "/baz/bam").toString());
}
void testToString_WithPort() {
CPPUNIT_ASSERT_EQUAL(std::string("http://foo.bar:1234/baz/bam"), URL("http", "foo.bar", 1234, "/baz/bam").toString());
}
};
CPPUNIT_TEST_SUITE_REGISTRATION(URLTest);
diff --git a/Swiften/Network/BOSHConnection.cpp b/Swiften/Network/BOSHConnection.cpp
index 73f8ed6..4741549 100644
--- a/Swiften/Network/BOSHConnection.cpp
+++ b/Swiften/Network/BOSHConnection.cpp
@@ -92,26 +92,30 @@ std::pair<SafeByteArray, size_t> BOSHConnection::createHTTPRequest(const SafeByt
}
if (terminate) {
content << " type='terminate'";
}
content << " xmlns='http://jabber.org/protocol/httpbind'>";
SafeByteArray safeContent = createSafeByteArray(content.str());
safeContent.insert(safeContent.end(), data.begin(), data.end());
safeContent.insert(safeContent.end(), contentTail.begin(), contentTail.end());
size = safeContent.size();
- header << "POST /" << boshURL.getPath() << " HTTP/1.1\r\n"
- << "Host: " << boshURL.getHost() << ":" << boshURL.getPort() << "\r\n"
+ header << "POST " << boshURL.getPath() << " HTTP/1.1\r\n"
+ << "Host: " << boshURL.getHost();
+ if (boshURL.getPort()) {
+ header << ":" << *boshURL.getPort();
+ }
+ header << "\r\n"
/*<< "Accept-Encoding: deflate\r\n"*/
<< "Content-Type: text/xml; charset=utf-8\r\n"
<< "Content-Length: " << size << "\r\n\r\n";
SafeByteArray safeHeader = createSafeByteArray(header.str());
safeHeader.insert(safeHeader.end(), safeContent.begin(), safeContent.end());
return std::pair<SafeByteArray, size_t>(safeHeader, size);
}
void BOSHConnection::write(const SafeByteArray& data, bool streamRestart, bool terminate) {
assert(connectionReady_);
diff --git a/Swiften/Network/UnitTest/BOSHConnectionPoolTest.cpp b/Swiften/Network/UnitTest/BOSHConnectionPoolTest.cpp
index 82762c5..7a2f0e6 100644
--- a/Swiften/Network/UnitTest/BOSHConnectionPoolTest.cpp
+++ b/Swiften/Network/UnitTest/BOSHConnectionPoolTest.cpp
@@ -38,25 +38,25 @@ class BOSHConnectionPoolTest : public CppUnit::TestFixture {
CPPUNIT_TEST(testConnectionCount_OneWrite);
CPPUNIT_TEST(testConnectionCount_TwoWrites);
CPPUNIT_TEST(testConnectionCount_ThreeWrites);
CPPUNIT_TEST(testConnectionCount_ThreeWrites_ManualConnect);
CPPUNIT_TEST(testConnectionCount_ThreeWritesTwoReads);
CPPUNIT_TEST(testSession);
CPPUNIT_TEST(testWrite_Empty);
CPPUNIT_TEST_SUITE_END();
public:
void setUp() {
to = "wonderland.lit";
- path = "http-bind";
+ path = "/http-bind";
port = "5280";
sid = "MyShinySID";
initial = "<body wait='60' "
"inactivity='30' "
"polling='5' "
"requests='2' "
"hold='1' "
"maxpause='120' "
"sid='" + sid + "' "
"ver='1.6' "
"from='wonderland.lit' "
"xmlns='http://jabber.org/protocol/httpbind'/>";
@@ -227,25 +227,25 @@ class BOSHConnectionPoolTest : public CppUnit::TestFixture {
rid++;
testling->write(createSafeByteArray("<bluh/>"));
CPPUNIT_ASSERT(c0->pending);
CPPUNIT_ASSERT(c1->pending);
CPPUNIT_ASSERT_EQUAL(st(6), boshDataWritten.size()); /* Don't send data, no room */
eventLoop->processEvents();
CPPUNIT_ASSERT_EQUAL(st(2), connectionFactory->connections.size());
}
void testSession() {
to = "prosody.doomsong.co.uk";
resolver->addAddress("prosody.doomsong.co.uk", HostAddress("127.0.0.1"));
- path = "http-bind/";
+ path = "/http-bind/";
boshURL = URL("http", to, 5280, path);
PoolRef testling = createTestling();
CPPUNIT_ASSERT_EQUAL(st(1), connectionFactory->connections.size());
eventLoop->processEvents();
CPPUNIT_ASSERT_EQUAL(st(1), boshDataWritten.size()); /* header*/
CPPUNIT_ASSERT_EQUAL(st(1), connectionFactory->connections.size());
std::string response = "<body authid='743da605-4c2e-4de1-afac-ac040dd4a940' xmpp:version='1.0' xmlns:stream='http://etherx.jabber.org/streams' xmlns:xmpp='urn:xmpp:xbosh' inactivity='60' wait='60' polling='5' secure='true' hold='1' from='prosody.doomsong.co.uk' ver='1.6' sid='743da605-4c2e-4de1-afac-ac040dd4a940' requests='2' xmlns='http://jabber.org/protocol/httpbind'><stream:features><auth xmlns='http://jabber.org/features/iq-auth'/><mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl'><mechanism>SCRAM-SHA-1</mechanism><mechanism>DIGEST-MD5</mechanism></mechanisms></stream:features></body>";
readResponse(response, connectionFactory->connections[0]);
eventLoop->processEvents();
CPPUNIT_ASSERT_EQUAL(st(1), boshDataWritten.size());
diff --git a/Swiften/Network/UnitTest/BOSHConnectionTest.cpp b/Swiften/Network/UnitTest/BOSHConnectionTest.cpp
index 31aed1b..7ef0249 100644
--- a/Swiften/Network/UnitTest/BOSHConnectionTest.cpp
+++ b/Swiften/Network/UnitTest/BOSHConnectionTest.cpp
@@ -184,25 +184,25 @@ class BOSHConnectionTest : public CppUnit::TestFixture {
std::pair<SafeByteArray, size_t> http = BOSHConnection::createHTTPRequest(createSafeByteArray(data), false, false, 42, sid, URL());
CPPUNIT_ASSERT_EQUAL(fullBody.size(), http.second);
std::string response = safeByteArrayToString(http.first);
size_t bodyPosition = response.find("\r\n\r\n");
CPPUNIT_ASSERT_EQUAL(fullBody, response.substr(bodyPosition+4));
}
private:
BOSHConnection::ref createTestling() {
resolver->addAddress("wonderland.lit", HostAddress("127.0.0.1"));
Connector::ref connector = Connector::create("wonderland.lit", 5280, false, resolver, connectionFactory, timerFactory);
- BOSHConnection::ref c = BOSHConnection::create(URL("http", "wonderland.lit", 5280, "http-bind"), connector, &parserFactory);
+ BOSHConnection::ref c = BOSHConnection::create(URL("http", "wonderland.lit", 5280, "/http-bind"), connector, &parserFactory);
c->onConnectFinished.connect(boost::bind(&BOSHConnectionTest::handleConnectFinished, this, _1));
c->onDisconnected.connect(boost::bind(&BOSHConnectionTest::handleDisconnected, this, _1));
c->onXMPPDataRead.connect(boost::bind(&BOSHConnectionTest::handleDataRead, this, _1));
c->onSessionStarted.connect(boost::bind(&BOSHConnectionTest::handleSID, this, _1));
c->setRID(42);
return c;
}
void handleConnectFinished(bool error) {
connectFinished = true;
connectFinishedWithError = error;
}