diff options
Diffstat (limited to 'Swiften/Network/BOSHConnection.cpp')
-rw-r--r-- | Swiften/Network/BOSHConnection.cpp | 36 |
1 files changed, 24 insertions, 12 deletions
diff --git a/Swiften/Network/BOSHConnection.cpp b/Swiften/Network/BOSHConnection.cpp index 73f8ed6..28e27d5 100644 --- a/Swiften/Network/BOSHConnection.cpp +++ b/Swiften/Network/BOSHConnection.cpp @@ -6,5 +6,5 @@ /* - * 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. @@ -33,4 +33,5 @@ BOSHConnection::BOSHConnection(const URL& boshURL, Connector::ref connector, XML sid_(), waitingForStartResponse_(false), + rid_(~0ULL), pending_(false), connectionReady_(false) @@ -61,9 +62,12 @@ void BOSHConnection::cancelConnector() { void BOSHConnection::disconnect() { - cancelConnector(); if (connection_) { connection_->disconnect(); sid_ = ""; } + else { + /* handleDisconnected takes care of the connector_ as well */ + handleDisconnected(boost::optional<Connection::Error>()); + } } @@ -102,7 +106,11 @@ std::pair<SafeByteArray, size_t> BOSHConnection::createHTTPRequest(const SafeByt size = safeContent.size(); - header << "POST /" << boshURL.getPath() << " HTTP/1.1\r\n" - << "Host: " << boshURL.getHost() << ":" << boshURL.getPort() << "\r\n" - /*<< "Accept-Encoding: deflate\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"; @@ -129,5 +137,5 @@ void BOSHConnection::write(const SafeByteArray& data, bool streamRestart, bool t void BOSHConnection::handleConnectFinished(Connection::ref connection) { cancelConnector(); - connectionReady_ = connection; + connectionReady_ = !!connection; if (connectionReady_) { connection_ = connection; @@ -150,5 +158,5 @@ void BOSHConnection::startStream(const std::string& to, unsigned long long rid) << " ver='1.6'" << " wait='60'" /* FIXME: we probably want this configurable*/ - /*<< " ack='0'" FIXME: support acks */ + // << " ack='0'" FIXME: support acks << " xml:lang='en'" << " xmlns:xmpp='urn:xmpp:bosh'" @@ -158,7 +166,11 @@ void BOSHConnection::startStream(const std::string& to, unsigned long long rid) std::string contentString = content.str(); - header << "POST /" << boshURL_.getPath() << " HTTP/1.1\r\n" - << "Host: " << boshURL_.getHost() << ":" << boshURL_.getPort() << "\r\n" - /*<< "Accept-Encoding: deflate\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: " << contentString.size() << "\r\n\r\n" @@ -198,5 +210,5 @@ void BOSHConnection::handleDataRead(boost::shared_ptr<SafeByteArray> data) { sid_ = parser.getBody()->attributes.getAttribute("sid"); std::string requestsString = parser.getBody()->attributes.getAttribute("requests"); - int requests = 2; + size_t requests = 2; if (!requestsString.empty()) { try { @@ -274,5 +286,5 @@ void BOSHConnection::setSID(const std::string& sid) { void BOSHConnection::handleDisconnected(const boost::optional<Connection::Error>& error) { cancelConnector(); - onDisconnected(error); + onDisconnected(error ? true : false); sid_ = ""; connectionReady_ = false; |