Changeset - 64f1921f8d5c
[Not reviewed]
include/Swiften/Elements/XHTMLIMPayload.cpp
Show inline comments
 
new file 100644
 
/*
 
 * Copyright (c) 2011 Jan Kaluza
 
 * Licensed under the Simplified BSD license.
 
 * See Documentation/Licenses/BSD-simplified.txt for more information.
 
 */
 

	
 
#include <Swiften/Elements/XHTMLIMPayload.h>
 

	
 
namespace Swift {
 

	
 
XHTMLIMPayload::XHTMLIMPayload(const std::string &body) : body_(body) {
 
}
 

	
 
}
include/Swiften/Elements/XHTMLIMPayload.h
Show inline comments
 
new file 100644
 
/*
 
 * Copyright (c) 2011 Jan Kaluza
 
 * Licensed under the Simplified BSD license.
 
 * See Documentation/Licenses/BSD-simplified.txt for more information.
 
 */
 

	
 
#pragma once
 

	
 
#include <vector>
 

	
 
#include <string>
 
#include <Swiften/Elements/Payload.h>
 

	
 
namespace Swift {
 
	class XHTMLIMPayload : public Payload {
 
		public:
 
			XHTMLIMPayload(const std::string &body = "");
 

	
 
			const std::string& getBody() const { return body_; }
 

	
 
			void setBody(const std::string& body) { 
 
				body_ = body;
 
			}
 

	
 
		private:
 
			std::string body_;
 
	};
 
}
include/Swiften/Parser/PayloadParsers/XHTMLIMParser.cpp
Show inline comments
 
new file 100644
 
/*
 
 * Copyright (c) 2011 Jan Kaluza
 
 * Licensed under the Simplified BSD license.
 
 * See Documentation/Licenses/BSD-simplified.txt for more information.
 
 */
 

	
 
#include <Swiften/Parser/PayloadParsers/XHTMLIMParser.h>
 
#include <Swiften/Parser/SerializingParser.h>
 

	
 
namespace Swift {
 

	
 
XHTMLIMParser::XHTMLIMParser() : level_(TopLevel), bodyParser_(0) {
 
}
 

	
 
void XHTMLIMParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) {
 
	++level_;
 
	if (level_ == BodyLevel) {
 
		if (element == "body") {
 
			assert(!bodyParser_);
 
			bodyParser_ = new SerializingParser();
 
		}
 
	}
 
	else if (level_ >= InsideBodyLevel && bodyParser_) {
 
		bodyParser_->handleStartElement(element, ns, attributes);
 
	}
 
}
 

	
 
void XHTMLIMParser::handleEndElement(const std::string& element, const std::string& ns) {
 
	if (level_ == BodyLevel) {
 
		if (bodyParser_) {
 
			if (element == "body") {
 
				getPayloadInternal()->setBody(bodyParser_->getResult());
 
			}
 
			delete bodyParser_;
 
			bodyParser_ = 0;
 
		}
 
	}
 
	else if (bodyParser_ && level_ >= InsideBodyLevel) {
 
		bodyParser_->handleEndElement(element, ns);
 
	}
 
	--level_;
 
}
 

	
 
void XHTMLIMParser::handleCharacterData(const std::string& data) {
 
	if (bodyParser_) {
 
		bodyParser_->handleCharacterData(data);
 
	}
 
	else {
 
		currentText_ += data;
 
	}
 
}
 

	
 
boost::shared_ptr<XHTMLIMPayload> XHTMLIMParser::getLabelPayload() const {
 
	return getPayloadInternal();
 
}
 

	
 
}
include/Swiften/Parser/PayloadParsers/XHTMLIMParser.h
Show inline comments
 
new file 100644
 
/*
 
 * Copyright (c) 2011 Jan Kaluza
 
 * Licensed under the Simplified BSD license.
 
 * See Documentation/Licenses/BSD-simplified.txt for more information.
 
 */
 

	
 
#pragma once
 

	
 
#include <Swiften/Elements/XHTMLIMPayload.h>
 
#include <Swiften/Parser/GenericPayloadParser.h>
 

	
 
namespace Swift {
 
	class SerializingParser;
 

	
 
	class XHTMLIMParser : public GenericPayloadParser<XHTMLIMPayload> {
 
		public:
 
			XHTMLIMParser();
 

	
 
			virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes);
 
			virtual void handleEndElement(const std::string& element, const std::string&);
 
			virtual void handleCharacterData(const std::string& data);
 
			boost::shared_ptr<XHTMLIMPayload> getLabelPayload() const;
 
		private:
 
			enum Level { 
 
				TopLevel = 0, 
 
				PayloadLevel = 1,
 
				BodyLevel = 2,
 
				InsideBodyLevel = 3
 
			};
 
			int level_;
 
			SerializingParser* bodyParser_;
 
			std::string currentText_;
 
	};
 
}
include/Swiften/Serializer/PayloadSerializers/XHTMLIMSerializer.cpp
Show inline comments
 
new file 100644
 
/*
 
 * Copyright (c) 2011 Jan Kaluza
 
 * Licensed under the Simplified BSD license.
 
 * See Documentation/Licenses/BSD-simplified.txt for more information.
 
 */
 

	
 
#include <Swiften/Serializer/PayloadSerializers/XHTMLIMSerializer.h>
 
#include <Swiften/Base/foreach.h>
 
#include <Swiften/Serializer/XML/XMLRawTextNode.h>
 
#include <Swiften/Serializer/XML/XMLTextNode.h>
 
#include <Swiften/Serializer/XML/XMLElement.h>
 

	
 
namespace Swift {
 

	
 
XHTMLIMSerializer::XHTMLIMSerializer() : GenericPayloadSerializer<XHTMLIMPayload>() {
 
}
 

	
 
std::string XHTMLIMSerializer::serializePayload(boost::shared_ptr<XHTMLIMPayload> payload)  const {
 
	XMLElement html("html", "http://jabber.org/protocol/xhtml-im");
 

	
 
	boost::shared_ptr<XMLElement> body(new XMLElement("body", "http://www.w3.org/1999/xhtml"));
 
	body->addNode(boost::shared_ptr<XMLRawTextNode>(new XMLRawTextNode(payload->getBody())));
 
	html.addNode(body);
 

	
 
	return html.serialize();
 
}
 

	
 
}
include/Swiften/Serializer/PayloadSerializers/XHTMLIMSerializer.h
Show inline comments
 
new file 100644
 
/*
 
 * Copyright (c) 2011 Jan Kaluza
 
 * Licensed under the Simplified BSD license.
 
 * See Documentation/Licenses/BSD-simplified.txt for more information.
 
 */
 

	
 
#pragma once
 

	
 
#include <Swiften/Serializer/GenericPayloadSerializer.h>
 
#include <Swiften/Elements/XHTMLIMPayload.h>
 

	
 
namespace Swift {
 
	class XHTMLIMSerializer : public GenericPayloadSerializer<XHTMLIMPayload> {
 
		public:
 
			XHTMLIMSerializer();
 

	
 
			virtual std::string serializePayload(boost::shared_ptr<XHTMLIMPayload> xhtml)  const;
 
	};
 
}
src/transport.cpp
Show inline comments
 
@@ -9,48 +9,50 @@
 
 * (at your option) any later version.
 
 *
 
 * This program is distributed in the hope that it will be useful,
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
 * GNU General Public License for more details.
 
 *
 
 * You should have received a copy of the GNU General Public License
 
 * along with this program; if not, write to the Free Software
 
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
 
 */
 

	
 
#include "transport/transport.h"
 
#include <boost/bind.hpp>
 
#include "transport/storagebackend.h"
 
#include "transport/factory.h"
 
#include "discoinforesponder.h"
 
#include "discoitemsresponder.h"
 
#include "storageparser.h"
 
#include "Swiften/TLS/OpenSSL/OpenSSLServerContext.h"
 
#include "Swiften/TLS/PKCS12Certificate.h"
 
#include "Swiften/TLS/OpenSSL/OpenSSLServerContextFactory.h"
 
#include "Swiften/Parser/PayloadParsers/AttentionParser.h"
 
#include "Swiften/Serializer/PayloadSerializers/AttentionSerializer.h"
 
#include "Swiften/Parser/PayloadParsers/XHTMLIMParser.h"
 
#include "Swiften/Serializer/PayloadSerializers/XHTMLIMSerializer.h"
 
#include "log4cxx/logger.h"
 
#include "log4cxx/consoleappender.h"
 
#include "log4cxx/patternlayout.h"
 
#include "log4cxx/propertyconfigurator.h"
 

	
 
using namespace Swift;
 
using namespace boost;
 
using namespace log4cxx;
 

	
 
namespace Transport {
 
	
 
static LoggerPtr logger = Logger::getLogger("Component");
 
static LoggerPtr logger_xml = Logger::getLogger("Component.XML");
 

	
 
class MyUserRegistry : public Swift::UserRegistry {
 
	public:
 
		MyUserRegistry(Component *c) {component = c;}
 
		~MyUserRegistry() {}
 
		bool isValidUserPassword(const JID& user, const Swift::SafeByteArray& password) const {
 
			users[user.toBare().toString()] = Swift::safeByteArrayToString(password);
 
			Swift::Presence::ref response = Swift::Presence::create();
 
			response->setTo(component->getJID());
 
			response->setFrom(user);
 
			response->setType(Swift::Presence::Available);
 
@@ -83,50 +85,52 @@ Component::Component(Swift::EventLoop *loop, Config *config, Factory *factory) {
 

	
 
	m_factories = new BoostNetworkFactories(loop);
 

	
 
	m_reconnectTimer = m_factories->getTimerFactory()->createTimer(1000);
 
	m_reconnectTimer->onTick.connect(bind(&Component::start, this)); 
 

	
 
	if (CONFIG_BOOL(m_config, "service.server_mode")) {
 
		LOG4CXX_INFO(logger, "Creating component in server mode on port " << CONFIG_INT(m_config, "service.port"));
 
		m_userRegistry = new MyUserRegistry(this);
 
		m_server = new Swift::Server(loop, m_factories, m_userRegistry, m_jid, CONFIG_INT(m_config, "service.port"));
 
		if (!CONFIG_STRING(m_config, "service.cert").empty()) {
 
			LOG4CXX_INFO(logger, "Using PKCS#12 certificate " << CONFIG_STRING(m_config, "service.cert"));
 
			TLSServerContextFactory *f = new OpenSSLServerContextFactory();
 
			m_server->addTLSEncryption(f, PKCS12Certificate(CONFIG_STRING(m_config, "service.cert"), createSafeByteArray(CONFIG_STRING(m_config, "service.cert_password"))));
 
		}
 
		else {
 
			LOG4CXX_WARN(logger, "No PKCS#12 certificate used. TLS is disabled.");
 
		}
 
// 		m_server->start();
 
		m_stanzaChannel = m_server->getStanzaChannel();
 
		m_iqRouter = m_server->getIQRouter();
 

	
 
		m_server->addPayloadParserFactory(new GenericPayloadParserFactory<StorageParser>("private", "jabber:iq:private"));
 
		m_server->addPayloadParserFactory(new GenericPayloadParserFactory<Swift::AttentionParser>("attention", "urn:xmpp:attention:0"));
 
		m_server->addPayloadParserFactory(new GenericPayloadParserFactory<Swift::XHTMLIMParser>("html", "http://jabber.org/protocol/xhtml-im"));
 

	
 
		m_server->addPayloadSerializer(new Swift::AttentionSerializer());
 
		m_server->addPayloadSerializer(new Swift::XHTMLIMSerializer());
 

	
 
		m_server->onDataRead.connect(bind(&Component::handleDataRead, this, _1));
 
		m_server->onDataWritten.connect(bind(&Component::handleDataWritten, this, _1));
 
	}
 
	else {
 
		m_component = new Swift::Component(loop, m_factories, m_jid, CONFIG_STRING(m_config, "service.password"));
 
		m_component->setSoftwareVersion("", "");
 
		m_component->onConnected.connect(bind(&Component::handleConnected, this));
 
		m_component->onError.connect(bind(&Component::handleConnectionError, this, _1));
 
		m_component->onDataRead.connect(bind(&Component::handleDataRead, this, _1));
 
		m_component->onDataWritten.connect(bind(&Component::handleDataWritten, this, _1));
 
		m_stanzaChannel = m_component->getStanzaChannel();
 
		m_iqRouter = m_component->getIQRouter();
 
	}
 

	
 
	m_capsMemoryStorage = new CapsMemoryStorage();
 
	m_capsManager = new CapsManager(m_capsMemoryStorage, m_stanzaChannel, m_iqRouter);
 
	m_entityCapsManager = new EntityCapsManager(m_capsManager, m_stanzaChannel);
 
 	m_entityCapsManager->onCapsChanged.connect(boost::bind(&Component::handleCapsChanged, this, _1));
 
	
 
	m_presenceOracle = new PresenceOracle(m_stanzaChannel);
 
	m_presenceOracle->onPresenceChange.connect(bind(&Component::handlePresence, this, _1));
 

	
 
	m_discoInfoResponder = new DiscoInfoResponder(m_iqRouter);
0 comments (0 inline, 0 general)