summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2011-01-29 17:48:13 (GMT)
committerRemko Tronçon <git@el-tramo.be>2011-01-29 18:45:34 (GMT)
commit869c52b244c2d03313e9eda83fac05bf0fc3a619 (patch)
tree63f0518e15d0c23ece6eb55733c2ef44f710bf01 /Swiften/Jingle
parent11a7f5c48ea9c90e9adaaa06a96e0a9116234bff (diff)
downloadswift-contrib-869c52b244c2d03313e9eda83fac05bf0fc3a619.zip
swift-contrib-869c52b244c2d03313e9eda83fac05bf0fc3a619.tar.bz2
Added some experimental Jingle classes.
Diffstat (limited to 'Swiften/Jingle')
-rw-r--r--Swiften/Jingle/IncomingJingleSession.cpp15
-rw-r--r--Swiften/Jingle/IncomingJingleSession.h20
-rw-r--r--Swiften/Jingle/IncomingJingleSessionHandler.cpp14
-rw-r--r--Swiften/Jingle/IncomingJingleSessionHandler.h18
-rw-r--r--Swiften/Jingle/JingleResponder.cpp45
-rw-r--r--Swiften/Jingle/JingleResponder.h26
-rw-r--r--Swiften/Jingle/JingleSession.cpp30
-rw-r--r--Swiften/Jingle/JingleSession.h53
-rw-r--r--Swiften/Jingle/JingleSessionManager.cpp45
-rw-r--r--Swiften/Jingle/JingleSessionManager.h49
-rw-r--r--Swiften/Jingle/SConscript11
11 files changed, 326 insertions, 0 deletions
diff --git a/Swiften/Jingle/IncomingJingleSession.cpp b/Swiften/Jingle/IncomingJingleSession.cpp
new file mode 100644
index 0000000..29155b8
--- /dev/null
+++ b/Swiften/Jingle/IncomingJingleSession.cpp
@@ -0,0 +1,15 @@
+/*
+ * Copyright (c) 2010 Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#include <Swiften/Jingle/IncomingJingleSession.h>
+
+namespace Swift {
+
+IncomingJingleSession::IncomingJingleSession(const String& id, const std::vector<JingleContent::ref>& contents) : JingleSession(id, contents) {
+
+}
+
+}
diff --git a/Swiften/Jingle/IncomingJingleSession.h b/Swiften/Jingle/IncomingJingleSession.h
new file mode 100644
index 0000000..222100f
--- /dev/null
+++ b/Swiften/Jingle/IncomingJingleSession.h
@@ -0,0 +1,20 @@
+/*
+ * Copyright (c) 2011 Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#pragma once
+
+#include <boost/shared_ptr.hpp>
+
+#include <Swiften/Jingle/JingleSession.h>
+
+namespace Swift {
+ class IncomingJingleSession : public JingleSession {
+ public:
+ IncomingJingleSession(const String& id, const std::vector<JingleContent::ref>& contents);
+
+ typedef boost::shared_ptr<IncomingJingleSession> ref;
+ };
+}
diff --git a/Swiften/Jingle/IncomingJingleSessionHandler.cpp b/Swiften/Jingle/IncomingJingleSessionHandler.cpp
new file mode 100644
index 0000000..d38118c
--- /dev/null
+++ b/Swiften/Jingle/IncomingJingleSessionHandler.cpp
@@ -0,0 +1,14 @@
+/*
+ * Copyright (c) 2010 Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#include <Swiften/Jingle/IncomingJingleSessionHandler.h>
+
+namespace Swift {
+
+IncomingJingleSessionHandler::~IncomingJingleSessionHandler() {
+}
+
+}
diff --git a/Swiften/Jingle/IncomingJingleSessionHandler.h b/Swiften/Jingle/IncomingJingleSessionHandler.h
new file mode 100644
index 0000000..5bf9237
--- /dev/null
+++ b/Swiften/Jingle/IncomingJingleSessionHandler.h
@@ -0,0 +1,18 @@
+/*
+ * Copyright (c) 2011 Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Jingle/IncomingJingleSession.h>
+
+namespace Swift {
+ class IncomingJingleSessionHandler {
+ public:
+ virtual ~IncomingJingleSessionHandler();
+
+ virtual bool handleIncomingJingleSession(IncomingJingleSession::ref) = 0;
+ };
+}
diff --git a/Swiften/Jingle/JingleResponder.cpp b/Swiften/Jingle/JingleResponder.cpp
new file mode 100644
index 0000000..3dfc327
--- /dev/null
+++ b/Swiften/Jingle/JingleResponder.cpp
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2011 Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#include <Swiften/Jingle/JingleResponder.h>
+
+#include <boost/smart_ptr/make_shared.hpp>
+
+#include <Swiften/Jingle/JingleSessionManager.h>
+#include <Swiften/Jingle/IncomingJingleSession.h>
+
+namespace Swift {
+
+JingleResponder::JingleResponder(JingleSessionManager* sessionManager, IQRouter* router) : SetResponder<JinglePayload>(router), sessionManager(sessionManager) {
+}
+
+bool JingleResponder::handleSetRequest(const JID& from, const JID&, const String& id, boost::shared_ptr<JinglePayload> payload) {
+ if (payload->getAction() == JinglePayload::SessionInitiate) {
+ if (sessionManager->getSession(from, payload->getSessionID())) {
+ // TODO: Add tie-break error
+ sendError(from, id, ErrorPayload::Conflict, ErrorPayload::Cancel);
+ }
+ else {
+ sendResponse(from, id, boost::shared_ptr<JinglePayload>());
+ IncomingJingleSession::ref session = boost::make_shared<IncomingJingleSession>(id, payload->getContents());
+ sessionManager->handleIncomingSession(from, session);
+ }
+ }
+ else {
+ JingleSession::ref session = sessionManager->getSession(from, payload->getSessionID());
+ if (session) {
+ session->handleIncomingAction(payload);
+ sendResponse(from, id, boost::shared_ptr<JinglePayload>());
+ }
+ else {
+ // TODO: Add jingle-specific error
+ sendError(from, id, ErrorPayload::ItemNotFound, ErrorPayload::Cancel);
+ }
+ }
+ return true;
+}
+
+}
diff --git a/Swiften/Jingle/JingleResponder.h b/Swiften/Jingle/JingleResponder.h
new file mode 100644
index 0000000..47dc90a
--- /dev/null
+++ b/Swiften/Jingle/JingleResponder.h
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2011 Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Queries/SetResponder.h>
+#include <Swiften/Elements/JinglePayload.h>
+
+namespace Swift {
+ class IQRouter;
+ class JingleSessionManager;
+
+ class JingleResponder : public SetResponder<JinglePayload> {
+ public:
+ JingleResponder(JingleSessionManager* sessionManager, IQRouter* router);
+
+ private:
+ virtual bool handleSetRequest(const JID& from, const JID& to, const String& id, boost::shared_ptr<JinglePayload> payload);
+
+ private:
+ JingleSessionManager* sessionManager;
+ };
+}
diff --git a/Swiften/Jingle/JingleSession.cpp b/Swiften/Jingle/JingleSession.cpp
new file mode 100644
index 0000000..3dbb12a
--- /dev/null
+++ b/Swiften/Jingle/JingleSession.cpp
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2010 Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#include <Swiften/Jingle/JingleSession.h>
+
+#include <boost/smart_ptr/make_shared.hpp>
+
+namespace Swift {
+
+JingleSession::JingleSession(const String& id, const std::vector<JingleContent::ref>& contents) : id(id), contents(contents) {
+
+}
+
+JingleSession::~JingleSession() {
+}
+
+void JingleSession::handleIncomingAction(JinglePayload::ref) {
+}
+
+void JingleSession::terminate(JinglePayload::Reason::Type reason) {
+ JinglePayload::ref payload = boost::make_shared<JinglePayload>(JinglePayload::SessionTerminate, id);
+ payload->setReason(JinglePayload::Reason(reason));
+ //onAction(payload)
+}
+
+
+}
diff --git a/Swiften/Jingle/JingleSession.h b/Swiften/Jingle/JingleSession.h
new file mode 100644
index 0000000..7ed86c2
--- /dev/null
+++ b/Swiften/Jingle/JingleSession.h
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2011 Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#pragma once
+
+#include <boost/shared_ptr.hpp>
+
+#include <Swiften/Base/boost_bsignals.h>
+#include <Swiften/Base/String.h>
+#include <Swiften/Elements/JinglePayload.h>
+#include <Swiften/Elements/JingleContent.h>
+#include <Swiften/Base/foreach.h>
+
+namespace Swift {
+ class JingleSession {
+ friend class JingleResponder;
+ public:
+ typedef boost::shared_ptr<JingleSession> ref;
+
+ JingleSession(const String& id, const std::vector<JingleContent::ref>& contents);
+ virtual ~JingleSession();
+
+ String getID() const {
+ return id;
+ }
+
+ template<typename T>
+ JingleContent::ref getContentWithDescription() const {
+ foreach (JingleContent::ref content, contents) {
+ if (content->getDescription<T>()) {
+ return content;
+ }
+ }
+ return JingleContent::ref();
+ }
+
+ const std::vector<JingleContent::ref> getContents() const {
+ return contents;
+ }
+
+ void terminate(JinglePayload::Reason::Type reason);
+
+ private:
+ void handleIncomingAction(JinglePayload::ref);
+
+ private:
+ String id;
+ std::vector<JingleContent::ref> contents;
+ };
+}
diff --git a/Swiften/Jingle/JingleSessionManager.cpp b/Swiften/Jingle/JingleSessionManager.cpp
new file mode 100644
index 0000000..d8630cc
--- /dev/null
+++ b/Swiften/Jingle/JingleSessionManager.cpp
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2011 Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#include <Swiften/Jingle/JingleSessionManager.h>
+#include <Swiften/Jingle/JingleResponder.h>
+#include <Swiften/Jingle/IncomingJingleSessionHandler.h>
+
+namespace Swift {
+
+JingleSessionManager::JingleSessionManager(IQRouter* router) : router(router) {
+ responder = new JingleResponder(this, router);
+}
+
+JingleSessionManager::~JingleSessionManager() {
+ delete responder;
+}
+
+JingleSession::ref JingleSessionManager::getSession(const JID& jid, const String& id) const {
+ SessionMap::const_iterator i = incomingSessions.find(JIDSession(jid, id));
+ return i != incomingSessions.end() ? i->second : JingleSession::ref();
+}
+
+void JingleSessionManager::addIncomingSessionHandler(IncomingJingleSessionHandler* handler) {
+ incomingSessionHandlers.push_back(handler);
+}
+
+void JingleSessionManager::removeIncomingSessionHandler(IncomingJingleSessionHandler* handler) {
+ incomingSessionHandlers.erase(std::remove(incomingSessionHandlers.begin(), incomingSessionHandlers.end(), handler), incomingSessionHandlers.end());
+}
+
+void JingleSessionManager::handleIncomingSession(const JID& from, IncomingJingleSession::ref session) {
+ incomingSessions.insert(std::make_pair(JIDSession(from, session->getID()), session));
+ foreach (IncomingJingleSessionHandler* handler, incomingSessionHandlers) {
+ if (handler->handleIncomingJingleSession(session)) {
+ return;
+ }
+ }
+ // TODO: Finish session
+}
+
+
+}
diff --git a/Swiften/Jingle/JingleSessionManager.h b/Swiften/Jingle/JingleSessionManager.h
new file mode 100644
index 0000000..ea4199d
--- /dev/null
+++ b/Swiften/Jingle/JingleSessionManager.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2011 Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#pragma once
+
+#include <boost/shared_ptr.hpp>
+#include <map>
+
+#include <Swiften/Base/boost_bsignals.h>
+#include <Swiften/Jingle/IncomingJingleSession.h>
+
+namespace Swift {
+ class IQRouter;
+ class JingleResponder;
+ class IncomingJingleSessionHandler;
+
+ class JingleSessionManager {
+ friend class JingleResponder;
+ public:
+ JingleSessionManager(IQRouter* router);
+ ~JingleSessionManager();
+
+ JingleSession::ref getSession(const JID& jid, const String& id) const;
+
+ void addIncomingSessionHandler(IncomingJingleSessionHandler* handler);
+ void removeIncomingSessionHandler(IncomingJingleSessionHandler* handler);
+
+ protected:
+ void handleIncomingSession(const JID& from, IncomingJingleSession::ref);
+
+ private:
+ IQRouter* router;
+ JingleResponder* responder;
+ std::vector<IncomingJingleSessionHandler*> incomingSessionHandlers;
+ struct JIDSession {
+ JIDSession(const JID& jid, const String& session) : jid(jid), session(session) {}
+ bool operator<(const JIDSession& o) const {
+ return jid == o.jid ? session < o.session : jid < o.jid;
+ }
+ JID jid;
+ String session;
+ };
+ typedef std::map<JIDSession, JingleSession::ref> SessionMap;
+ SessionMap incomingSessions;
+ };
+}
diff --git a/Swiften/Jingle/SConscript b/Swiften/Jingle/SConscript
new file mode 100644
index 0000000..c1aadea
--- /dev/null
+++ b/Swiften/Jingle/SConscript
@@ -0,0 +1,11 @@
+Import("swiften_env")
+
+sources = [
+ "IncomingJingleSession.cpp",
+ "IncomingJingleSessionHandler.cpp",
+ "JingleSessionManager.cpp",
+ "JingleResponder.cpp",
+ "JingleSession.cpp",
+ ]
+
+swiften_env.Append(SWIFTEN_OBJECTS = swiften_env.StaticObject(sources))