aboutsummaryrefslogtreecommitdiff
path: root/src/server
diff options
context:
space:
mode:
authorJeremy Lainé <jeremy.laine@m4x.org>2010-08-28 13:28:37 +0000
committerJeremy Lainé <jeremy.laine@m4x.org>2010-08-28 13:28:37 +0000
commit2de9fa8c747bb481fd48c35c6b2a116e84d6929c (patch)
tree717e6e0554547d9560bde1b28e9ec155b2c3edca /src/server
parent97adcfb517528e257fd256761d31dc7524293724 (diff)
downloadqxmpp-2de9fa8c747bb481fd48c35c6b2a116e84d6929c.tar.gz
rework QXmppServerExtension initialisation
Diffstat (limited to 'src/server')
-rw-r--r--src/server/mod_disco.cpp23
-rw-r--r--src/server/mod_disco.h3
-rw-r--r--src/server/mod_ping.cpp8
-rw-r--r--src/server/mod_ping.h4
-rw-r--r--src/server/mod_proxy65.cpp50
-rw-r--r--src/server/mod_proxy65.h2
6 files changed, 38 insertions, 52 deletions
diff --git a/src/server/mod_disco.cpp b/src/server/mod_disco.cpp
index fe257cf6..961f1f91 100644
--- a/src/server/mod_disco.cpp
+++ b/src/server/mod_disco.cpp
@@ -21,6 +21,7 @@
*
*/
+#include <QCoreApplication>
#include <QDomElement>
#include "QXmppConstants.h"
@@ -48,7 +49,7 @@ void QXmppServerDiscovery::setDiscoveryItems(const QStringList &items)
bool QXmppServerDiscovery::handleStanza(QXmppStream *incoming, const QDomElement &element)
{
- if (element.attribute("to") != m_server->domain())
+ if (element.attribute("to") != server()->domain())
return false;
// XEP-0030: Service Discovery
@@ -68,7 +69,7 @@ bool QXmppServerDiscovery::handleStanza(QXmppStream *incoming, const QDomElement
if (request.queryType() == QXmppDiscoveryIq::ItemsQuery)
{
QList<QXmppDiscoveryIq::Item> items;
- foreach (QXmppServerExtension *extension, m_server->loadedExtensions())
+ foreach (QXmppServerExtension *extension, server()->loadedExtensions())
{
foreach (const QString &jid, extension->discoveryItems())
{
@@ -79,8 +80,18 @@ bool QXmppServerDiscovery::handleStanza(QXmppStream *incoming, const QDomElement
}
response.setItems(items);
} else {
+ // identities
+ QList<QXmppDiscoveryIq::Identity> identities;
+ QXmppDiscoveryIq::Identity identity;
+ identity.setCategory("server");
+ identity.setType("im");
+ identity.setName(qApp->applicationName());
+ identities.append(identity);
+ response.setIdentities(identities);
+
+ // features
QStringList features;
- foreach (QXmppServerExtension *extension, m_server->loadedExtensions())
+ foreach (QXmppServerExtension *extension, server()->loadedExtensions())
features += extension->discoveryFeatures();
response.setFeatures(features);
}
@@ -90,12 +101,6 @@ bool QXmppServerDiscovery::handleStanza(QXmppStream *incoming, const QDomElement
return false;
}
-bool QXmppServerDiscovery::start(QXmppServer *server)
-{
- m_server = server;
- return true;
-}
-
// PLUGIN
class QXmppServerDiscoveryPlugin : public QXmppServerPlugin
diff --git a/src/server/mod_disco.h b/src/server/mod_disco.h
index d5640a5b..6816293a 100644
--- a/src/server/mod_disco.h
+++ b/src/server/mod_disco.h
@@ -36,14 +36,13 @@ class QXmppServerDiscovery : public QXmppServerExtension
public:
QStringList discoveryFeatures() const;
+
QStringList discoveryItems() const;
void setDiscoveryItems(const QStringList &items);
bool handleStanza(QXmppStream *incoming, const QDomElement &element);
- bool start(QXmppServer *server);
private:
- QXmppServer *m_server;
QStringList m_discoveryItems;
};
diff --git a/src/server/mod_ping.cpp b/src/server/mod_ping.cpp
index fcc4d259..82837123 100644
--- a/src/server/mod_ping.cpp
+++ b/src/server/mod_ping.cpp
@@ -38,7 +38,7 @@ QStringList QXmppServerPing::discoveryFeatures() const
bool QXmppServerPing::handleStanza(QXmppStream *stream, const QDomElement &element)
{
- if (element.attribute("to") != m_jid)
+ if (element.attribute("to") != server()->domain())
return false;
// XEP-0199: XMPP Ping
@@ -58,12 +58,6 @@ bool QXmppServerPing::handleStanza(QXmppStream *stream, const QDomElement &eleme
return false;
}
-bool QXmppServerPing::start(QXmppServer *server)
-{
- m_jid = server->domain();
- return true;
-}
-
// PLUGIN
class QXmppServerPingPlugin : public QXmppServerPlugin
diff --git a/src/server/mod_ping.h b/src/server/mod_ping.h
index 99f77a60..71d08801 100644
--- a/src/server/mod_ping.h
+++ b/src/server/mod_ping.h
@@ -37,10 +37,6 @@ class QXmppServerPing : public QXmppServerExtension
public:
QStringList discoveryFeatures() const;
bool handleStanza(QXmppStream *stream, const QDomElement &element);
- bool start(QXmppServer *server);
-
-private:
- QString m_jid;
};
#endif
diff --git a/src/server/mod_proxy65.cpp b/src/server/mod_proxy65.cpp
index 3eac9bfb..a5ce0744 100644
--- a/src/server/mod_proxy65.cpp
+++ b/src/server/mod_proxy65.cpp
@@ -144,7 +144,6 @@ struct TransferStats
class QXmppServerProxy65Private
{
public:
- QString domain;
QString jid;
QHostAddress host;
quint16 port;
@@ -167,17 +166,6 @@ QXmppServerProxy65::QXmppServerProxy65()
d->server = new QXmppSocksServer(this);
-#if 0
- // connect signals
- bool check = connect(client, SIGNAL(connected()),
- this, SLOT(slotConnected()));
- Q_ASSERT(check);
-
- check = connect(client, SIGNAL(disconnected()),
- this, SLOT(slotDisconnected()));
- Q_ASSERT(check);
-#endif
-
bool check = connect(d->server, SIGNAL(newConnection(QTcpSocket*, const QString&, quint16)),
this, SLOT(slotSocketConnected(QTcpSocket*, const QString &, quint16)));
Q_ASSERT(check);
@@ -207,7 +195,7 @@ bool QXmppServerProxy65::handleStanza(QXmppStream *stream, const QDomElement &el
QXmppDiscoveryIq discoIq;
discoIq.parse(element);
- if (discoIq.type() == QXmppIq::Get && discoIq.queryType() == QXmppDiscoveryIq::InfoQuery)
+ if (discoIq.type() == QXmppIq::Get)
{
QXmppDiscoveryIq responseIq;
responseIq.setTo(discoIq.from());
@@ -216,17 +204,20 @@ bool QXmppServerProxy65::handleStanza(QXmppStream *stream, const QDomElement &el
responseIq.setType(QXmppIq::Result);
responseIq.setQueryType(discoIq.queryType());
- QStringList features = QStringList() << ns_disco_info << ns_disco_items << ns_bytestreams;
+ if (discoIq.queryType() == QXmppDiscoveryIq::InfoQuery)
+ {
+ QStringList features = QStringList() << ns_disco_info << ns_disco_items << ns_bytestreams;
- QList<QXmppDiscoveryIq::Identity> identities;
- QXmppDiscoveryIq::Identity identity;
- identity.setCategory("proxy");
- identity.setType("bytestreams");
- identity.setName("SOCKS5 Bytestreams");
- identities.append(identity);
+ QList<QXmppDiscoveryIq::Identity> identities;
+ QXmppDiscoveryIq::Identity identity;
+ identity.setCategory("proxy");
+ identity.setType("bytestreams");
+ identity.setName("SOCKS5 Bytestreams");
+ identities.append(identity);
- responseIq.setFeatures(features);
- responseIq.setIdentities(identities);
+ responseIq.setFeatures(features);
+ responseIq.setIdentities(identities);
+ }
stream->sendPacket(responseIq);
return true;
@@ -268,7 +259,7 @@ bool QXmppServerProxy65::handleStanza(QXmppStream *stream, const QDomElement &el
// FIXME : make it possible to specify permissions
if (pair &&
- jidToDomain(bsIq.from()) == d->domain)
+ jidToDomain(bsIq.from()) == server()->domain())
{
qDebug() << "Activating connection" << hash << "by" << bsIq.from();
pair->activate();
@@ -314,16 +305,14 @@ void QXmppServerProxy65::setStatisticsFile(const QString &statisticsFile)
}
}
-bool QXmppServerProxy65::start(QXmppServer *server)
+bool QXmppServerProxy65::start()
{
- d->domain = server->domain();
-
// determine jid
if (d->jid.isEmpty())
- d->jid = "proxy." + server->domain();
+ d->jid = "proxy." + server()->domain();
// determine address
- const QString hostName = server->domain();
+ const QString hostName = server()->domain();
QHostAddress hostAddress;
if (!hostAddress.setAddress(hostName))
{
@@ -347,6 +336,10 @@ bool QXmppServerProxy65::start(QXmppServer *server)
void QXmppServerProxy65::stop()
{
+ d->server->close();
+ foreach (QTcpSocketPair *pair, d->pairs)
+ delete pair;
+ d->pairs.clear();
}
void QXmppServerProxy65::slotSocketConnected(QTcpSocket *socket, const QString &hostName, quint16 port)
@@ -355,7 +348,6 @@ void QXmppServerProxy65::slotSocketConnected(QTcpSocket *socket, const QString &
QTcpSocketPair *pair = d->pairs.value(hostName);
if (!pair)
{
- qDebug() << "SOCKET CONNECTED" << hostName << port;
pair = new QTcpSocketPair(hostName);
check = connect(pair, SIGNAL(finished()), this, SLOT(slotPairFinished()));
Q_ASSERT(check);
diff --git a/src/server/mod_proxy65.h b/src/server/mod_proxy65.h
index 32d15cf4..e9557383 100644
--- a/src/server/mod_proxy65.h
+++ b/src/server/mod_proxy65.h
@@ -80,7 +80,7 @@ public:
QStringList discoveryItems() const;
bool handleStanza(QXmppStream *stream, const QDomElement &element);
- bool start(QXmppServer *server);
+ bool start();
void stop();
private slots: