summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Network/BOSHConnection.cpp')
-rw-r--r--Swiften/Network/BOSHConnection.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/Swiften/Network/BOSHConnection.cpp b/Swiften/Network/BOSHConnection.cpp
index 23772eb..83f12f7 100644
--- a/Swiften/Network/BOSHConnection.cpp
+++ b/Swiften/Network/BOSHConnection.cpp
@@ -1,43 +1,43 @@
/*
* Copyright (c) 2011 Thilo Cestonaro
* Licensed under the simplified BSD license.
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
/*
- * Copyright (c) 2011 Kevin Smith
+ * Copyright (c) 2011-2014 Kevin Smith
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
#include <Swiften/Network/BOSHConnection.h>
#include <boost/bind.hpp>
#include <boost/thread.hpp>
#include <boost/lexical_cast.hpp>
#include <string>
#include <Swiften/Base/Log.h>
#include <Swiften/Base/String.h>
#include <Swiften/Base/Concat.h>
#include <Swiften/Base/ByteArray.h>
#include <Swiften/Network/HostAddressPort.h>
#include <Swiften/Parser/BOSHBodyExtractor.h>
namespace Swift {
BOSHConnection::BOSHConnection(const URL& boshURL, Connector::ref connector, XMLParserFactory* parserFactory)
: boshURL_(boshURL),
connector_(connector),
parserFactory_(parserFactory),
sid_(),
waitingForStartResponse_(false),
pending_(false),
connectionReady_(false)
{
}
BOSHConnection::~BOSHConnection() {
cancelConnector();
if (connection_) {
connection_->onDataRead.disconnect(boost::bind(&BOSHConnection::handleDataRead, shared_from_this(), _1));
@@ -103,71 +103,71 @@ std::pair<SafeByteArray, size_t> BOSHConnection::createHTTPRequest(const SafeByt
safeContent.insert(safeContent.end(), contentTail.begin(), contentTail.end());
size = safeContent.size();
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_);
assert(!sid_.empty());
SafeByteArray safeHeader = createHTTPRequest(data, streamRestart, terminate, rid_, sid_, boshURL_).first;
onBOSHDataWritten(safeHeader);
connection_->write(safeHeader);
pending_ = true;
SWIFT_LOG(debug) << "write data: " << safeByteArrayToString(safeHeader) << std::endl;
}
void BOSHConnection::handleConnectFinished(Connection::ref connection) {
cancelConnector();
- connectionReady_ = connection;
+ connectionReady_ = !!connection;
if (connectionReady_) {
connection_ = connection;
connection_->onDataRead.connect(boost::bind(&BOSHConnection::handleDataRead, shared_from_this(), _1));
connection_->onDisconnected.connect(boost::bind(&BOSHConnection::handleDisconnected, shared_from_this(), _1));
}
onConnectFinished(!connectionReady_);
}
void BOSHConnection::startStream(const std::string& to, unsigned long long rid) {
assert(connectionReady_);
// Session Creation Request
std::stringstream content;
std::stringstream header;
content << "<body content='text/xml; charset=utf-8'"
<< " hold='1'"
<< " to='" << to << "'"
<< " rid='" << rid << "'"
<< " ver='1.6'"
<< " wait='60'" /* FIXME: we probably want this configurable*/
// << " ack='0'" FIXME: support acks
<< " xml:lang='en'"
<< " xmlns:xmpp='urn:xmpp:bosh'"
<< " xmpp:version='1.0'"
<< " xmlns='http://jabber.org/protocol/httpbind' />";
std::string contentString = content.str();
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"