summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2011-10-07 18:09:30 (GMT)
committerRemko Tronçon <git@el-tramo.be>2011-10-07 18:09:30 (GMT)
commit6b98253a4127c975bd59b6a49ddb203337a8c32b (patch)
tree546a24e1687f50e403215152d65e21971568f166
parentb2f58c4f3eb93e3a32062670df5eb6682aed273a (diff)
downloadswift-contrib-6b98253a4127c975bd59b6a49ddb203337a8c32b.zip
swift-contrib-6b98253a4127c975bd59b6a49ddb203337a8c32b.tar.bz2
Hoist XML parser factory creation out of Swiften.
-rw-r--r--Limber/Server/ServerFromClientSession.cpp3
-rw-r--r--Limber/Server/ServerFromClientSession.h2
-rw-r--r--Limber/main.cpp4
-rw-r--r--Slimber/Server.cpp6
-rw-r--r--Slimber/Server.h2
-rw-r--r--Swiften/Client/CoreClient.cpp2
-rw-r--r--Swiften/Component/CoreComponent.cpp2
-rw-r--r--Swiften/Examples/ParserTester/ParserTester.cpp4
-rw-r--r--Swiften/LinkLocal/IncomingLinkLocalSession.cpp5
-rw-r--r--Swiften/LinkLocal/IncomingLinkLocalSession.h5
-rw-r--r--Swiften/LinkLocal/OutgoingLinkLocalSession.cpp5
-rw-r--r--Swiften/LinkLocal/OutgoingLinkLocalSession.h5
-rw-r--r--Swiften/Network/BoostNetworkFactories.cpp3
-rw-r--r--Swiften/Network/BoostNetworkFactories.h5
-rw-r--r--Swiften/Network/NetworkFactories.h2
-rw-r--r--Swiften/Parser/UnitTest/XMPPParserTest.cpp22
-rw-r--r--Swiften/Parser/XMPPParser.cpp7
-rw-r--r--Swiften/Parser/XMPPParser.h5
-rw-r--r--Swiften/Session/BasicSessionStream.cpp5
-rw-r--r--Swiften/Session/BasicSessionStream.h4
-rw-r--r--Swiften/Session/Session.cpp6
-rw-r--r--Swiften/Session/Session.h5
-rw-r--r--Swiften/StreamStack/UnitTest/StreamStackTest.cpp4
-rw-r--r--Swiften/StreamStack/UnitTest/XMPPLayerTest.cpp7
-rw-r--r--Swiften/StreamStack/XMPPLayer.cpp6
-rw-r--r--Swiften/StreamStack/XMPPLayer.h3
26 files changed, 87 insertions, 42 deletions
diff --git a/Limber/Server/ServerFromClientSession.cpp b/Limber/Server/ServerFromClientSession.cpp
index 3a37c65..fd361b7 100644
--- a/Limber/Server/ServerFromClientSession.cpp
+++ b/Limber/Server/ServerFromClientSession.cpp
@@ -28,8 +28,9 @@ ServerFromClientSession::ServerFromClientSession(
boost::shared_ptr<Connection> connection,
PayloadParserFactoryCollection* payloadParserFactories,
PayloadSerializerCollection* payloadSerializers,
+ XMLParserFactory* xmlParserFactory,
UserRegistry* userRegistry) :
- Session(connection, payloadParserFactories, payloadSerializers),
+ Session(connection, payloadParserFactories, payloadSerializers, xmlParserFactory),
id_(id),
userRegistry_(userRegistry),
authenticated_(false),
diff --git a/Limber/Server/ServerFromClientSession.h b/Limber/Server/ServerFromClientSession.h
index 1a0e109..34ea40e 100644
--- a/Limber/Server/ServerFromClientSession.h
+++ b/Limber/Server/ServerFromClientSession.h
@@ -27,6 +27,7 @@ namespace Swift {
class XMPPLayer;
class ConnectionLayer;
class Connection;
+ class XMLParserFactory;
class ServerFromClientSession : public Session {
public:
@@ -35,6 +36,7 @@ namespace Swift {
boost::shared_ptr<Connection> connection,
PayloadParserFactoryCollection* payloadParserFactories,
PayloadSerializerCollection* payloadSerializers,
+ XMLParserFactory* xmlParserFactory,
UserRegistry* userRegistry);
boost::signal<void ()> onSessionStarted;
diff --git a/Limber/main.cpp b/Limber/main.cpp
index e6bc45d..350b357 100644
--- a/Limber/main.cpp
+++ b/Limber/main.cpp
@@ -23,6 +23,7 @@
#include "Limber/Server/SimpleUserRegistry.h"
#include "Limber/Server/ServerFromClientSession.h"
#include "Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h"
+#include "Swiften/Parser/PlatformXMLParserFactory.h"
#include "Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h"
using namespace Swift;
@@ -37,7 +38,7 @@ class Server {
private:
void handleNewConnection(boost::shared_ptr<Connection> c) {
- boost::shared_ptr<ServerFromClientSession> session(new ServerFromClientSession(idGenerator_.generateID(), c, &payloadParserFactories_, &payloadSerializers_, userRegistry_));
+ boost::shared_ptr<ServerFromClientSession> session(new ServerFromClientSession(idGenerator_.generateID(), c, &payloadParserFactories_, &payloadSerializers_, &xmlParserFactory, userRegistry_));
serverFromClientSessions_.push_back(session);
session->onElementReceived.connect(boost::bind(&Server::handleElementReceived, this, _1, session));
session->onSessionFinished.connect(boost::bind(&Server::handleSessionFinished, this, session));
@@ -81,6 +82,7 @@ class Server {
private:
IDGenerator idGenerator_;
+ PlatformXMLParserFactory xmlParserFactory;
UserRegistry* userRegistry_;
BoostIOServiceThread boostIOServiceThread_;
boost::shared_ptr<BoostConnectionServer> serverFromClientConnectionServer_;
diff --git a/Slimber/Server.cpp b/Slimber/Server.cpp
index 84b33fa..769217f 100644
--- a/Slimber/Server.cpp
+++ b/Slimber/Server.cpp
@@ -147,7 +147,7 @@ void Server::handleNewClientConnection(boost::shared_ptr<Connection> connection)
}
serverFromClientSession = boost::shared_ptr<ServerFromClientSession>(
new ServerFromClientSession(idGenerator.generateID(), connection,
- &payloadParserFactories, &payloadSerializers, &userRegistry));
+ &payloadParserFactories, &payloadSerializers, &xmlParserFactory, &userRegistry));
serverFromClientSession->setAllowSASLEXTERNAL();
serverFromClientSession->onSessionStarted.connect(
boost::bind(&Server::handleSessionStarted, this));
@@ -281,7 +281,7 @@ void Server::handleNewLinkLocalConnection(boost::shared_ptr<Connection> connecti
boost::shared_ptr<IncomingLinkLocalSession> session(
new IncomingLinkLocalSession(
selfJID, connection,
- &payloadParserFactories, &payloadSerializers));
+ &payloadParserFactories, &payloadSerializers, &xmlParserFactory));
registerLinkLocalSession(session);
}
@@ -312,7 +312,7 @@ void Server::handleConnectFinished(boost::shared_ptr<LinkLocalConnector> connect
boost::shared_ptr<OutgoingLinkLocalSession> outgoingSession(
new OutgoingLinkLocalSession(
selfJID, connector->getService().getJID(), connector->getConnection(),
- &payloadParserFactories, &payloadSerializers));
+ &payloadParserFactories, &payloadSerializers, &xmlParserFactory));
foreach(const boost::shared_ptr<Element> element, connector->getQueuedElements()) {
outgoingSession->queueElement(element);
}
diff --git a/Slimber/Server.h b/Slimber/Server.h
index 58b1e7c..96401d9 100644
--- a/Slimber/Server.h
+++ b/Slimber/Server.h
@@ -14,6 +14,7 @@
#include "Swiften/Network/BoostConnectionServer.h"
#include "Limber/Server/UserRegistry.h"
#include "Swiften/Base/IDGenerator.h"
+#include "Swiften/Parser/PlatformXMLParserFactory.h"
#include "Limber/Server/ServerFromClientSession.h"
#include "Swiften/JID/JID.h"
#include "Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h"
@@ -98,6 +99,7 @@ namespace Swift {
FullPayloadSerializerCollection payloadSerializers;
BoostIOServiceThread boostIOServiceThread;
DummyUserRegistry userRegistry;
+ PlatformXMLParserFactory xmlParserFactory;
bool linkLocalServiceRegistered;
bool rosterRequested;
int clientConnectionPort;
diff --git a/Swiften/Client/CoreClient.cpp b/Swiften/Client/CoreClient.cpp
index f6a3f20..dbc6de2 100644
--- a/Swiften/Client/CoreClient.cpp
+++ b/Swiften/Client/CoreClient.cpp
@@ -101,7 +101,7 @@ void CoreClient::handleConnectorFinished(boost::shared_ptr<Connection> connectio
connection_ = connection;
assert(!sessionStream_);
- sessionStream_ = boost::make_shared<BasicSessionStream>(ClientStreamType, connection_, getPayloadParserFactories(), getPayloadSerializers(), tlsFactories->getTLSContextFactory(), networkFactories->getTimerFactory());
+ sessionStream_ = boost::make_shared<BasicSessionStream>(ClientStreamType, connection_, getPayloadParserFactories(), getPayloadSerializers(), tlsFactories->getTLSContextFactory(), networkFactories->getTimerFactory(), networkFactories->getXMLParserFactory());
if (!certificate_.empty()) {
sessionStream_->setTLSCertificate(PKCS12Certificate(certificate_, password_));
}
diff --git a/Swiften/Component/CoreComponent.cpp b/Swiften/Component/CoreComponent.cpp
index 7ee1ff5..e630ddf 100644
--- a/Swiften/Component/CoreComponent.cpp
+++ b/Swiften/Component/CoreComponent.cpp
@@ -63,7 +63,7 @@ void CoreComponent::handleConnectorFinished(boost::shared_ptr<Connection> connec
connection_ = connection;
assert(!sessionStream_);
- sessionStream_ = boost::shared_ptr<BasicSessionStream>(new BasicSessionStream(ComponentStreamType, connection_, getPayloadParserFactories(), getPayloadSerializers(), NULL, networkFactories->getTimerFactory()));
+ sessionStream_ = boost::shared_ptr<BasicSessionStream>(new BasicSessionStream(ComponentStreamType, connection_, getPayloadParserFactories(), getPayloadSerializers(), NULL, networkFactories->getTimerFactory(), networkFactories->getXMLParserFactory()));
sessionStream_->onDataRead.connect(boost::bind(&CoreComponent::handleDataRead, this, _1));
sessionStream_->onDataWritten.connect(boost::bind(&CoreComponent::handleDataWritten, this, _1));
diff --git a/Swiften/Examples/ParserTester/ParserTester.cpp b/Swiften/Examples/ParserTester/ParserTester.cpp
index 211d44f..009eef4 100644
--- a/Swiften/Examples/ParserTester/ParserTester.cpp
+++ b/Swiften/Examples/ParserTester/ParserTester.cpp
@@ -11,6 +11,7 @@
#include <Swiften/Parser/UnitTest/ParserTester.h>
#include <Swiften/Parser/XMPPParser.h>
#include <Swiften/Parser/XMPPParserClient.h>
+#include <Swiften/Parser/PlatformXMLParserFactory.h>
#include <Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h>
using namespace Swift;
@@ -35,7 +36,8 @@ int main(int argc, char* argv[]) {
}
FullPayloadParserFactoryCollection factories;
MyXMPPParserClient parserClient;
- XMPPParser parser(&parserClient, &factories);
+ PlatformXMLParserFactory xmlParserFactory;
+ XMPPParser parser(&parserClient, &factories, &xmlParserFactory);
ParserTester<XMLParserClient> tester(&parser);
std::string line;
diff --git a/Swiften/LinkLocal/IncomingLinkLocalSession.cpp b/Swiften/LinkLocal/IncomingLinkLocalSession.cpp
index c4dea64..b89de81 100644
--- a/Swiften/LinkLocal/IncomingLinkLocalSession.cpp
+++ b/Swiften/LinkLocal/IncomingLinkLocalSession.cpp
@@ -22,8 +22,9 @@ IncomingLinkLocalSession::IncomingLinkLocalSession(
const JID& localJID,
boost::shared_ptr<Connection> connection,
PayloadParserFactoryCollection* payloadParserFactories,
- PayloadSerializerCollection* payloadSerializers) :
- Session(connection, payloadParserFactories, payloadSerializers),
+ PayloadSerializerCollection* payloadSerializers,
+ XMLParserFactory* xmlParserFactory) :
+ Session(connection, payloadParserFactories, payloadSerializers, xmlParserFactory),
initialized(false) {
setLocalJID(localJID);
}
diff --git a/Swiften/LinkLocal/IncomingLinkLocalSession.h b/Swiften/LinkLocal/IncomingLinkLocalSession.h
index 68e21a5..f00c166 100644
--- a/Swiften/LinkLocal/IncomingLinkLocalSession.h
+++ b/Swiften/LinkLocal/IncomingLinkLocalSession.h
@@ -15,7 +15,7 @@
namespace Swift {
class ProtocolHeader;
-
+ class XMLParserFactory;
class Element;
class PayloadParserFactoryCollection;
class PayloadSerializerCollection;
@@ -26,7 +26,8 @@ namespace Swift {
const JID& localJID,
boost::shared_ptr<Connection> connection,
PayloadParserFactoryCollection* payloadParserFactories,
- PayloadSerializerCollection* payloadSerializers);
+ PayloadSerializerCollection* payloadSerializers,
+ XMLParserFactory* xmlParserFactory);
boost::signal<void ()> onSessionStarted;
diff --git a/Swiften/LinkLocal/OutgoingLinkLocalSession.cpp b/Swiften/LinkLocal/OutgoingLinkLocalSession.cpp
index 9d712f8..7a59715 100644
--- a/Swiften/LinkLocal/OutgoingLinkLocalSession.cpp
+++ b/Swiften/LinkLocal/OutgoingLinkLocalSession.cpp
@@ -21,8 +21,9 @@ OutgoingLinkLocalSession::OutgoingLinkLocalSession(
const JID& remoteJID,
boost::shared_ptr<Connection> connection,
PayloadParserFactoryCollection* payloadParserFactories,
- PayloadSerializerCollection* payloadSerializers) :
- Session(connection, payloadParserFactories, payloadSerializers) {
+ PayloadSerializerCollection* payloadSerializers,
+ XMLParserFactory* xmlParserFactory) :
+ Session(connection, payloadParserFactories, payloadSerializers, xmlParserFactory) {
setLocalJID(localJID);
setRemoteJID(remoteJID);
}
diff --git a/Swiften/LinkLocal/OutgoingLinkLocalSession.h b/Swiften/LinkLocal/OutgoingLinkLocalSession.h
index 430c446..b97f2bf 100644
--- a/Swiften/LinkLocal/OutgoingLinkLocalSession.h
+++ b/Swiften/LinkLocal/OutgoingLinkLocalSession.h
@@ -16,7 +16,7 @@
namespace Swift {
class ConnectionFactory;
-
+ class XMLParserFactory;
class Element;
class PayloadParserFactoryCollection;
class PayloadSerializerCollection;
@@ -28,7 +28,8 @@ namespace Swift {
const JID& remoteJID,
boost::shared_ptr<Connection> connection,
PayloadParserFactoryCollection* payloadParserFactories,
- PayloadSerializerCollection* payloadSerializers);
+ PayloadSerializerCollection* payloadSerializers,
+ XMLParserFactory* xmlParserFactory);
void queueElement(boost::shared_ptr<Element> element);
diff --git a/Swiften/Network/BoostNetworkFactories.cpp b/Swiften/Network/BoostNetworkFactories.cpp
index 315290c..56be2b7 100644
--- a/Swiften/Network/BoostNetworkFactories.cpp
+++ b/Swiften/Network/BoostNetworkFactories.cpp
@@ -10,6 +10,7 @@
#include <Swiften/Network/PlatformDomainNameResolver.h>
#include <Swiften/Network/BoostConnectionServerFactory.h>
#include <Swiften/Network/PlatformNATTraversalWorker.h>
+#include <Swiften/Parser/PlatformXMLParserFactory.h>
#include <Swiften/Network/NullNATTraverser.h>
namespace Swift {
@@ -24,9 +25,11 @@ BoostNetworkFactories::BoostNetworkFactories(EventLoop* eventLoop) {
#else
natTraverser = new NullNATTraverser(eventLoop);
#endif
+ xmlParserFactory = new PlatformXMLParserFactory();
}
BoostNetworkFactories::~BoostNetworkFactories() {
+ delete xmlParserFactory;
delete natTraverser;
delete connectionServerFactory;
delete domainNameResolver;
diff --git a/Swiften/Network/BoostNetworkFactories.h b/Swiften/Network/BoostNetworkFactories.h
index bc7a963..c9ecb59 100644
--- a/Swiften/Network/BoostNetworkFactories.h
+++ b/Swiften/Network/BoostNetworkFactories.h
@@ -42,6 +42,10 @@ namespace Swift {
return natTraverser;
}
+ virtual XMLParserFactory* getXMLParserFactory() const {
+ return xmlParserFactory;
+ }
+
private:
BoostIOServiceThread ioServiceThread;
TimerFactory* timerFactory;
@@ -49,5 +53,6 @@ namespace Swift {
DomainNameResolver* domainNameResolver;
ConnectionServerFactory* connectionServerFactory;
NATTraverser* natTraverser;
+ XMLParserFactory* xmlParserFactory;
};
}
diff --git a/Swiften/Network/NetworkFactories.h b/Swiften/Network/NetworkFactories.h
index 05ddfe3..42c9f6a 100644
--- a/Swiften/Network/NetworkFactories.h
+++ b/Swiften/Network/NetworkFactories.h
@@ -12,6 +12,7 @@ namespace Swift {
class DomainNameResolver;
class ConnectionServerFactory;
class NATTraverser;
+ class XMLParserFactory;
/**
* An interface collecting network factories.
@@ -25,5 +26,6 @@ namespace Swift {
virtual DomainNameResolver* getDomainNameResolver() const = 0;
virtual ConnectionServerFactory* getConnectionServerFactory() const = 0;
virtual NATTraverser* getNATTraverser() const = 0;
+ virtual XMLParserFactory* getXMLParserFactory() const = 0;
};
}
diff --git a/Swiften/Parser/UnitTest/XMPPParserTest.cpp b/Swiften/Parser/UnitTest/XMPPParserTest.cpp
index dbee18a..f8d60f2 100644
--- a/Swiften/Parser/UnitTest/XMPPParserTest.cpp
+++ b/Swiften/Parser/UnitTest/XMPPParserTest.cpp
@@ -14,6 +14,7 @@
#include <Swiften/Parser/ElementParser.h>
#include <Swiften/Parser/XMPPParserClient.h>
#include <Swiften/Parser/PayloadParserFactoryCollection.h>
+#include <Swiften/Parser/PlatformXMLParserFactory.h>
#include <Swiften/Elements/Presence.h>
#include <Swiften/Elements/IQ.h>
#include <Swiften/Elements/Message.h>
@@ -38,7 +39,7 @@ class XMPPParserTest : public CppUnit::TestFixture {
public:
void testParse_SimpleSession() {
- XMPPParser testling(&client_, &factories_);
+ XMPPParser testling(&client_, &factories_, &xmlParserFactory_);
CPPUNIT_ASSERT(testling.parse("<?xml version='1.0'?>"));
CPPUNIT_ASSERT(testling.parse("<stream:stream to='example.com' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' >"));
@@ -57,7 +58,7 @@ class XMPPParserTest : public CppUnit::TestFixture {
}
void testParse_SimpleClientFromServerSession() {
- XMPPParser testling(&client_, &factories_);
+ XMPPParser testling(&client_, &factories_, &xmlParserFactory_);
CPPUNIT_ASSERT(testling.parse("<?xml version='1.0'?>"));
CPPUNIT_ASSERT(testling.parse("<stream:stream from='example.com' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' id='aeab'>"));
@@ -70,7 +71,7 @@ class XMPPParserTest : public CppUnit::TestFixture {
void testParse_Presence() {
- XMPPParser testling(&client_, &factories_);
+ XMPPParser testling(&client_, &factories_, &xmlParserFactory_);
CPPUNIT_ASSERT(testling.parse("<stream:stream xmlns:stream='http://etherx.jabber.org/streams'>"));
CPPUNIT_ASSERT(testling.parse("<presence/>"));
@@ -81,7 +82,7 @@ class XMPPParserTest : public CppUnit::TestFixture {
}
void testParse_IQ() {
- XMPPParser testling(&client_, &factories_);
+ XMPPParser testling(&client_, &factories_, &xmlParserFactory_);
CPPUNIT_ASSERT(testling.parse("<stream:stream xmlns:stream='http://etherx.jabber.org/streams'>"));
CPPUNIT_ASSERT(testling.parse("<iq/>"));
@@ -92,7 +93,7 @@ class XMPPParserTest : public CppUnit::TestFixture {
}
void testParse_Message() {
- XMPPParser testling(&client_, &factories_);
+ XMPPParser testling(&client_, &factories_, &xmlParserFactory_);
CPPUNIT_ASSERT(testling.parse("<stream:stream xmlns:stream='http://etherx.jabber.org/streams'>"));
CPPUNIT_ASSERT(testling.parse("<message/>"));
@@ -103,7 +104,7 @@ class XMPPParserTest : public CppUnit::TestFixture {
}
void testParse_StreamFeatures() {
- XMPPParser testling(&client_, &factories_);
+ XMPPParser testling(&client_, &factories_, &xmlParserFactory_);
CPPUNIT_ASSERT(testling.parse("<stream:stream xmlns:stream='http://etherx.jabber.org/streams'>"));
CPPUNIT_ASSERT(testling.parse("<stream:features/>"));
@@ -114,7 +115,7 @@ class XMPPParserTest : public CppUnit::TestFixture {
}
void testParse_UnknownElement() {
- XMPPParser testling(&client_, &factories_);
+ XMPPParser testling(&client_, &factories_, &xmlParserFactory_);
CPPUNIT_ASSERT(testling.parse("<stream:stream xmlns:stream='http://etherx.jabber.org/streams'>"));
CPPUNIT_ASSERT(testling.parse("<presence/>"));
@@ -132,7 +133,7 @@ class XMPPParserTest : public CppUnit::TestFixture {
}
void testParse_StrayCharacterData() {
- XMPPParser testling(&client_, &factories_);
+ XMPPParser testling(&client_, &factories_, &xmlParserFactory_);
CPPUNIT_ASSERT(testling.parse("<stream:stream xmlns:stream='http://etherx.jabber.org/streams'>"));
CPPUNIT_ASSERT(testling.parse("<presence/>"));
@@ -145,13 +146,13 @@ class XMPPParserTest : public CppUnit::TestFixture {
}
void testParse_InvalidStreamStart() {
- XMPPParser testling(&client_, &factories_);
+ XMPPParser testling(&client_, &factories_, &xmlParserFactory_);
CPPUNIT_ASSERT(!testling.parse("<tream>"));
}
void testParse_ElementEndAfterInvalidStreamStart() {
- XMPPParser testling(&client_, &factories_);
+ XMPPParser testling(&client_, &factories_, &xmlParserFactory_);
CPPUNIT_ASSERT(!testling.parse("<tream/>"));
}
@@ -189,6 +190,7 @@ class XMPPParserTest : public CppUnit::TestFixture {
std::vector<Event> events;
} client_;
PayloadParserFactoryCollection factories_;
+ PlatformXMLParserFactory xmlParserFactory_;
};
CPPUNIT_TEST_SUITE_REGISTRATION(XMPPParserTest);
diff --git a/Swiften/Parser/XMPPParser.cpp b/Swiften/Parser/XMPPParser.cpp
index 6779b86..069a5bd 100644
--- a/Swiften/Parser/XMPPParser.cpp
+++ b/Swiften/Parser/XMPPParser.cpp
@@ -12,7 +12,6 @@
#include <Swiften/Elements/ProtocolHeader.h>
#include <string>
#include <Swiften/Parser/XMLParser.h>
-#include <Swiften/Parser/PlatformXMLParserFactory.h>
#include <Swiften/Parser/XMPPParserClient.h>
#include <Swiften/Parser/XMPPParser.h>
#include <Swiften/Parser/ElementParser.h>
@@ -41,6 +40,7 @@
#include <Swiften/Parser/UnknownElementParser.h>
#include <Swiften/Parser/TLSProceedParser.h>
#include <Swiften/Parser/ComponentHandshakeParser.h>
+#include <Swiften/Parser/XMLParserFactory.h>
// TODO: Whenever an error occurs in the handlers, stop the parser by returing
// a bool value, and stopping the XML parser
@@ -49,14 +49,15 @@ namespace Swift {
XMPPParser::XMPPParser(
XMPPParserClient* client,
- PayloadParserFactoryCollection* payloadParserFactories) :
+ PayloadParserFactoryCollection* payloadParserFactories,
+ XMLParserFactory* xmlParserFactory) :
xmlParser_(0),
client_(client),
payloadParserFactories_(payloadParserFactories),
level_(0),
currentElementParser_(0),
parseErrorOccurred_(false) {
- xmlParser_ = PlatformXMLParserFactory().createXMLParser(this);
+ xmlParser_ = xmlParserFactory->createXMLParser(this);
}
XMPPParser::~XMPPParser() {
diff --git a/Swiften/Parser/XMPPParser.h b/Swiften/Parser/XMPPParser.h
index b5d6d24..6cce2bd 100644
--- a/Swiften/Parser/XMPPParser.h
+++ b/Swiften/Parser/XMPPParser.h
@@ -15,7 +15,7 @@
namespace Swift {
class XMLParser;
class XMPPParserClient;
-
+ class XMLParserFactory;
class ElementParser;
class PayloadParserFactoryCollection;
@@ -23,7 +23,8 @@ namespace Swift {
public:
XMPPParser(
XMPPParserClient* parserClient,
- PayloadParserFactoryCollection* payloadParserFactories);
+ PayloadParserFactoryCollection* payloadParserFactories,
+ XMLParserFactory* xmlParserFactory);
~XMPPParser();
bool parse(const std::string&);
diff --git a/Swiften/Session/BasicSessionStream.cpp b/Swiften/Session/BasicSessionStream.cpp
index d08be4f..07a04b8 100644
--- a/Swiften/Session/BasicSessionStream.cpp
+++ b/Swiften/Session/BasicSessionStream.cpp
@@ -25,7 +25,8 @@ BasicSessionStream::BasicSessionStream(
PayloadParserFactoryCollection* payloadParserFactories,
PayloadSerializerCollection* payloadSerializers,
TLSContextFactory* tlsContextFactory,
- TimerFactory* timerFactory) :
+ TimerFactory* timerFactory,
+ XMLParserFactory* xmlParserFactory) :
available(false),
connection(connection),
payloadParserFactories(payloadParserFactories),
@@ -36,7 +37,7 @@ BasicSessionStream::BasicSessionStream(
compressionLayer(NULL),
tlsLayer(NULL),
whitespacePingLayer(NULL) {
- xmppLayer = new XMPPLayer(payloadParserFactories, payloadSerializers, streamType);
+ xmppLayer = new XMPPLayer(payloadParserFactories, payloadSerializers, xmlParserFactory, streamType);
xmppLayer->onStreamStart.connect(boost::bind(&BasicSessionStream::handleStreamStartReceived, this, _1));
xmppLayer->onElement.connect(boost::bind(&BasicSessionStream::handleElementReceived, this, _1));
xmppLayer->onError.connect(boost::bind(&BasicSessionStream::handleXMPPError, this));
diff --git a/Swiften/Session/BasicSessionStream.h b/Swiften/Session/BasicSessionStream.h
index 2a1ed8a..2ed5ac6 100644
--- a/Swiften/Session/BasicSessionStream.h
+++ b/Swiften/Session/BasicSessionStream.h
@@ -24,6 +24,7 @@ namespace Swift {
class XMPPLayer;
class ConnectionLayer;
class CompressionLayer;
+ class XMLParserFactory;
class BasicSessionStream : public SessionStream {
public:
@@ -33,7 +34,8 @@ namespace Swift {
PayloadParserFactoryCollection* payloadParserFactories,
PayloadSerializerCollection* payloadSerializers,
TLSContextFactory* tlsContextFactory,
- TimerFactory* whitespacePingLayerFactory
+ TimerFactory* whitespacePingLayerFactory,
+ XMLParserFactory* xmlParserFactory
);
~BasicSessionStream();
diff --git a/Swiften/Session/Session.cpp b/Swiften/Session/Session.cpp
index e8b8308..661cb8d 100644
--- a/Swiften/Session/Session.cpp
+++ b/Swiften/Session/Session.cpp
@@ -16,10 +16,12 @@ namespace Swift {
Session::Session(
boost::shared_ptr<Connection> connection,
PayloadParserFactoryCollection* payloadParserFactories,
- PayloadSerializerCollection* payloadSerializers) :
+ PayloadSerializerCollection* payloadSerializers,
+ XMLParserFactory* xmlParserFactory) :
connection(connection),
payloadParserFactories(payloadParserFactories),
payloadSerializers(payloadSerializers),
+ xmlParserFactory(xmlParserFactory),
xmppLayer(NULL),
connectionLayer(NULL),
streamStack(0),
@@ -64,7 +66,7 @@ void Session::finishSession(const SessionError& error) {
}
void Session::initializeStreamStack() {
- xmppLayer = new XMPPLayer(payloadParserFactories, payloadSerializers, ClientStreamType);
+ xmppLayer = new XMPPLayer(payloadParserFactories, payloadSerializers, xmlParserFactory, ClientStreamType);
xmppLayer->onStreamStart.connect(
boost::bind(&Session::handleStreamStart, shared_from_this(), _1));
xmppLayer->onElement.connect(boost::bind(&Session::handleElement, shared_from_this(), _1));
diff --git a/Swiften/Session/Session.h b/Swiften/Session/Session.h
index 9e954c7..c937430 100644
--- a/Swiften/Session/Session.h
+++ b/Swiften/Session/Session.h
@@ -25,6 +25,7 @@ namespace Swift {
class PayloadParserFactoryCollection;
class PayloadSerializerCollection;
class XMPPLayer;
+ class XMLParserFactory;
class Session : public boost::enable_shared_from_this<Session> {
public:
@@ -45,7 +46,8 @@ namespace Swift {
Session(
boost::shared_ptr<Connection> connection,
PayloadParserFactoryCollection* payloadParserFactories,
- PayloadSerializerCollection* payloadSerializers);
+ PayloadSerializerCollection* payloadSerializers,
+ XMLParserFactory* xmlParserFactory);
virtual ~Session();
void startSession();
@@ -103,6 +105,7 @@ namespace Swift {
boost::shared_ptr<Connection> connection;
PayloadParserFactoryCollection* payloadParserFactories;
PayloadSerializerCollection* payloadSerializers;
+ XMLParserFactory* xmlParserFactory;
XMPPLayer* xmppLayer;
ConnectionLayer* connectionLayer;
StreamStack* streamStack;
diff --git a/Swiften/StreamStack/UnitTest/StreamStackTest.cpp b/Swiften/StreamStack/UnitTest/StreamStackTest.cpp
index d3c0a7c..213948a 100644
--- a/Swiften/StreamStack/UnitTest/StreamStackTest.cpp
+++ b/Swiften/StreamStack/UnitTest/StreamStackTest.cpp
@@ -19,6 +19,7 @@
#include <Swiften/StreamStack/LowLayer.h>
#include <Swiften/StreamStack/XMPPLayer.h>
#include <Swiften/StreamStack/StreamLayer.h>
+#include <Swiften/Parser/PlatformXMLParserFactory.h>
#include <Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h>
#include <Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h>
@@ -38,7 +39,7 @@ class StreamStackTest : public CppUnit::TestFixture {
public:
void setUp() {
physicalStream_ = new TestLowLayer();
- xmppStream_ = new XMPPLayer(&parserFactories_, &serializers_, ClientStreamType);
+ xmppStream_ = new XMPPLayer(&parserFactories_, &serializers_, &xmlParserFactory_, ClientStreamType);
elementsReceived_ = 0;
dataWriteReceived_ = 0;
}
@@ -172,6 +173,7 @@ class StreamStackTest : public CppUnit::TestFixture {
FullPayloadParserFactoryCollection parserFactories_;
FullPayloadSerializerCollection serializers_;
TestLowLayer* physicalStream_;
+ PlatformXMLParserFactory xmlParserFactory_;
XMPPLayer* xmppStream_;
int elementsReceived_;
int dataWriteReceived_;
diff --git a/Swiften/StreamStack/UnitTest/XMPPLayerTest.cpp b/Swiften/StreamStack/UnitTest/XMPPLayerTest.cpp
index bb0ce61..8123c00 100644
--- a/Swiften/StreamStack/UnitTest/XMPPLayerTest.cpp
+++ b/Swiften/StreamStack/UnitTest/XMPPLayerTest.cpp
@@ -14,6 +14,7 @@
#include <Swiften/Base/ByteArray.h>
#include <Swiften/StreamStack/XMPPLayer.h>
#include <Swiften/StreamStack/LowLayer.h>
+#include <Swiften/Parser/PlatformXMLParserFactory.h>
#include <Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h>
#include <Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h>
@@ -32,7 +33,7 @@ class XMPPLayerTest : public CppUnit::TestFixture {
public:
void setUp() {
lowLayer_ = new DummyLowLayer();
- testling_ = new XMPPLayerExposed(&parserFactories_, &serializers_, ClientStreamType);
+ testling_ = new XMPPLayerExposed(&parserFactories_, &serializers_, &xmlParserFactory_, ClientStreamType);
testling_->setChildLayer(lowLayer_);
elementsReceived_ = 0;
errorReceived_ = 0;
@@ -112,7 +113,8 @@ class XMPPLayerTest : public CppUnit::TestFixture {
XMPPLayerExposed(
PayloadParserFactoryCollection* payloadParserFactories,
PayloadSerializerCollection* payloadSerializers,
- StreamType streamType) : XMPPLayer(payloadParserFactories, payloadSerializers, streamType) {}
+ XMLParserFactory* xmlParserFactory,
+ StreamType streamType) : XMPPLayer(payloadParserFactories, payloadSerializers, xmlParserFactory, streamType) {}
using XMPPLayer::handleDataRead;
using HighLayer::setChildLayer;
@@ -131,6 +133,7 @@ class XMPPLayerTest : public CppUnit::TestFixture {
FullPayloadSerializerCollection serializers_;
DummyLowLayer* lowLayer_;
XMPPLayerExposed* testling_;
+ PlatformXMLParserFactory xmlParserFactory_;
int elementsReceived_;
int errorReceived_;
};
diff --git a/Swiften/StreamStack/XMPPLayer.cpp b/Swiften/StreamStack/XMPPLayer.cpp
index 1dcd84f..94afcf9 100644
--- a/Swiften/StreamStack/XMPPLayer.cpp
+++ b/Swiften/StreamStack/XMPPLayer.cpp
@@ -14,12 +14,14 @@ namespace Swift {
XMPPLayer::XMPPLayer(
PayloadParserFactoryCollection* payloadParserFactories,
PayloadSerializerCollection* payloadSerializers,
+ XMLParserFactory* xmlParserFactory,
StreamType streamType) :
payloadParserFactories_(payloadParserFactories),
payloadSerializers_(payloadSerializers),
+ xmlParserFactory_(xmlParserFactory),
resetParserAfterParse_(false),
inParser_(false) {
- xmppParser_ = new XMPPParser(this, payloadParserFactories_);
+ xmppParser_ = new XMPPParser(this, payloadParserFactories_, xmlParserFactory);
xmppSerializer_ = new XMPPSerializer(payloadSerializers_, streamType);
}
@@ -68,7 +70,7 @@ void XMPPLayer::handleDataRead(const SafeByteArray& data) {
void XMPPLayer::doResetParser() {
delete xmppParser_;
- xmppParser_ = new XMPPParser(this, payloadParserFactories_);
+ xmppParser_ = new XMPPParser(this, payloadParserFactories_, xmlParserFactory_);
resetParserAfterParse_ = false;
}
diff --git a/Swiften/StreamStack/XMPPLayer.h b/Swiften/StreamStack/XMPPLayer.h
index 54bdd42..9be00b2 100644
--- a/Swiften/StreamStack/XMPPLayer.h
+++ b/Swiften/StreamStack/XMPPLayer.h
@@ -22,12 +22,14 @@ namespace Swift {
class PayloadParserFactoryCollection;
class XMPPSerializer;
class PayloadSerializerCollection;
+ class XMLParserFactory;
class XMPPLayer : public XMPPParserClient, public HighLayer, boost::noncopyable {
public:
XMPPLayer(
PayloadParserFactoryCollection* payloadParserFactories,
PayloadSerializerCollection* payloadSerializers,
+ XMLParserFactory* xmlParserFactory,
StreamType streamType);
~XMPPLayer();
@@ -60,6 +62,7 @@ namespace Swift {
PayloadParserFactoryCollection* payloadParserFactories_;
XMPPParser* xmppParser_;
PayloadSerializerCollection* payloadSerializers_;
+ XMLParserFactory* xmlParserFactory_;
XMPPSerializer* xmppSerializer_;
bool resetParserAfterParse_;
bool inParser_;