summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Smith <git@kismith.co.uk>2011-11-12 16:56:21 (GMT)
committerKevin Smith <git@kismith.co.uk>2011-12-13 08:17:58 (GMT)
commit81c09a0f6a3e87b078340d7f35d0dea4c03f3a6d (patch)
tree4371c5808ee26b2b5ed79ace9ccb439ff2988945 /Swiften/Network/BOSHConnection.h
parentfd17fe0d239f97cedebe4ceffa234155bd299b68 (diff)
downloadswift-contrib-81c09a0f6a3e87b078340d7f35d0dea4c03f3a6d.zip
swift-contrib-81c09a0f6a3e87b078340d7f35d0dea4c03f3a6d.tar.bz2
BOSH Support for Swiften
This adds support for BOSH to Swiften. It does not expose it to Swift. Release-Notes: Swiften now allows connects over BOSH, if used appropriately.
Diffstat (limited to 'Swiften/Network/BOSHConnection.h')
-rw-r--r--Swiften/Network/BOSHConnection.h67
1 files changed, 59 insertions, 8 deletions
diff --git a/Swiften/Network/BOSHConnection.h b/Swiften/Network/BOSHConnection.h
index 0da92ba..283ea10 100644
--- a/Swiften/Network/BOSHConnection.h
+++ b/Swiften/Network/BOSHConnection.h
@@ -4,6 +4,13 @@
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
+/*
+ * Copyright (c) 2011 Kevin Smith
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+
#pragma once
#include <boost/enable_shared_from_this.hpp>
@@ -11,6 +18,9 @@
#include <Swiften/Network/Connection.h>
#include <Swiften/Network/HostAddressPort.h>
#include <Swiften/Base/String.h>
+#include <Swiften/Base/URL.h>
+#include <Swiften/Base/Error.h>
+#include <Swiften/Session/SessionStream.h>
namespace boost {
class thread;
@@ -21,32 +31,73 @@ namespace boost {
namespace Swift {
class ConnectionFactory;
+ class XMLParserFactory;
+ class TLSContextFactory;
+
+ class BOSHError : public SessionStream::Error {
+ public:
+ enum Type {BadRequest, HostGone, HostUnknown, ImproperAddressing,
+ InternalServerError, ItemNotFound, OtherRequest, PolicyViolation,
+ RemoteConnectionFailed, RemoteStreamError, SeeOtherURI, SystemShutdown, UndefinedCondition,
+ NoError};
+ BOSHError(Type type) : SessionStream::Error(SessionStream::Error::ConnectionReadError), type(type) {}
+ Type getType() {return type;}
+ typedef boost::shared_ptr<BOSHError> ref;
+ private:
+ Type type;
+
+ };
+
class BOSHConnection : public Connection, public boost::enable_shared_from_this<BOSHConnection> {
public:
typedef boost::shared_ptr<BOSHConnection> ref;
- static ref create(ConnectionFactory* connectionFactory) {
- return ref(new BOSHConnection(connectionFactory));
+ static ref create(const URL& boshURL, ConnectionFactory* connectionFactory, XMLParserFactory* parserFactory, TLSContextFactory* tlsFactory) {
+ return ref(new BOSHConnection(boshURL, connectionFactory, parserFactory, tlsFactory));
}
virtual ~BOSHConnection();
virtual void listen();
virtual void connect(const HostAddressPort& address);
virtual void disconnect();
virtual void write(const SafeByteArray& data);
+
virtual HostAddressPort getLocalAddress() const;
+ const std::string& getSID();
+ void setRID(unsigned long rid);
+ void setSID(const std::string& sid);
+ void startStream(const std::string& to, unsigned long rid);
+ void terminateStream();
+ bool isReadyToSend();
+ void restartStream();
+ static std::pair<SafeByteArray, size_t> createHTTPRequest(const SafeByteArray& data, bool streamRestart, bool terminate, long rid, const std::string& sid, const URL& boshURL);
+
+ boost::signal<void (BOSHError::ref)> onSessionTerminated;
+ boost::signal<void (const std::string& /*sid*/, size_t /*requests*/)> onSessionStarted;
+ boost::signal<void (const SafeByteArray&)> onXMPPDataRead;
+ boost::signal<void (const SafeByteArray&)> onBOSHDataRead;
+ boost::signal<void (const SafeByteArray&)> onBOSHDataWritten;
+ boost::signal<void (const std::string&)> onHTTPError;
private:
- BOSHConnection(ConnectionFactory* connectionFactory);
+ BOSHConnection(const URL& boshURL, ConnectionFactory* connectionFactory, XMLParserFactory* parserFactory, TLSContextFactory* tlsFactory);
+
void handleConnectionConnectFinished(bool error);
- void handleDataRead(const SafeByteArray& data);
+ void handleDataRead(boost::shared_ptr<SafeByteArray> data);
void handleDisconnected(const boost::optional<Error>& error);
+ void write(const SafeByteArray& data, bool streamRestart, bool terminate); /* FIXME: refactor */
+ BOSHError::Type parseTerminationCondition(const std::string& text);
- bool reopenAfterAction;
+ URL boshURL_;
ConnectionFactory* connectionFactory_;
- HostAddressPort server_;
- boost::shared_ptr<Connection> newConnection_;
- boost::shared_ptr<Connection> currentConnection_;
+ XMLParserFactory* parserFactory_;
+ boost::shared_ptr<Connection> connection_;
std::string sid_;
+ bool waitingForStartResponse_;
+ unsigned long rid_;
+ SafeByteArray buffer_;
+ bool pending_;
+ TLSContextFactory* tlsFactory_;
+ bool connectionReady_;
};
}