Changeset - d6c003bad3b6
[Not reviewed]
include/Swiften/Elements/AttentionPayload.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/AttentionPayload.h>
 

	
 
namespace Swift {
 

	
 
AttentionPayload::AttentionPayload() {
 
}
 

	
 
}
include/Swiften/Elements/AttentionPayload.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 <boost/shared_ptr.hpp>
 

	
 
#include <Swiften/Elements/Payload.h>
 

	
 
namespace Swift {
 
	class AttentionPayload : public Payload {
 
		public:
 
			typedef boost::shared_ptr<AttentionPayload> ref;
 

	
 
		public:
 
			AttentionPayload();
 
	};
 
}
include/Swiften/Parser/PayloadParsers/AttentionParser.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/AttentionParser.h>
 

	
 
namespace Swift {
 

	
 
AttentionParser::AttentionParser() /*: level_(0)*/ {
 
}
 

	
 
void AttentionParser::handleStartElement(const std::string& /*element*/, const std::string& /*ns*/, const AttributeMap& /*attributes*/) {
 
}
 

	
 
void AttentionParser::handleEndElement(const std::string&, const std::string&) {
 
}
 

	
 
void AttentionParser::handleCharacterData(const std::string&) {
 

	
 
}
 

	
 
}
include/Swiften/Parser/PayloadParsers/AttentionParser.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/AttentionPayload.h>
 
#include <Swiften/Parser/GenericPayloadParser.h>
 

	
 
namespace Swift {
 
	class AttentionParser : public GenericPayloadParser<AttentionPayload> {
 
		public:
 
			AttentionParser();
 

	
 
			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);
 

	
 
// 		private:
 
// 			int level_;
 
	};
 
}
include/Swiften/Serializer/PayloadSerializers/AttentionSerializer.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/AttentionSerializer.h>
 

	
 
#include <boost/shared_ptr.hpp>
 

	
 
#include <Swiften/Serializer/XML/XMLTextNode.h>
 
#include <Swiften/Serializer/XML/XMLRawTextNode.h>
 
#include <Swiften/Serializer/XML/XMLElement.h>
 

	
 
namespace Swift {
 

	
 
AttentionSerializer::AttentionSerializer() : GenericPayloadSerializer<AttentionPayload>() {
 
}
 

	
 
std::string AttentionSerializer::serializePayload(boost::shared_ptr<AttentionPayload> attention)  const {
 
	XMLElement attentionElement("attention", "urn:xmpp:attention:0");
 

	
 
	return attentionElement.serialize();
 
}
 

	
 
}
include/Swiften/Serializer/PayloadSerializers/AttentionSerializer.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/AttentionPayload.h>
 

	
 
namespace Swift {
 
	class AttentionSerializer : public GenericPayloadSerializer<AttentionPayload> {
 
		public:
 
			AttentionSerializer();
 

	
 
			virtual std::string serializePayload(boost::shared_ptr<AttentionPayload>)  const;
 
	};
 
}
src/transport.cpp
Show inline comments
 
@@ -7,48 +7,50 @@
 
 * it under the terms of the GNU General Public License as published by
 
 * the Free Software Foundation; either version 2 of the License, or
 
 * (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 "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);
 
@@ -80,48 +82,51 @@ Component::Component(Swift::EventLoop *loop, Config *config, Factory *factory) {
 
	m_jid = Swift::JID(CONFIG_STRING(m_config, "service.jid"));
 

	
 
	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->addPayloadSerializer(new Swift::AttentionSerializer());
 

	
 
		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)