aboutsummaryrefslogtreecommitdiff
path: root/src/server/mod_proxy65.cpp
diff options
context:
space:
mode:
authorJeremy Lainé <jeremy.laine@m4x.org>2011-09-13 12:08:15 +0000
committerJeremy Lainé <jeremy.laine@m4x.org>2011-09-13 12:08:15 +0000
commit8eaf6c3def32f1aa07fe863d5eab69f44672b3a5 (patch)
treee6950f5dbceeb0e34ac98f7639a63049f8cf7c44 /src/server/mod_proxy65.cpp
parent5d6e2cabfb730fa6b537397db342bed8eec15de1 (diff)
downloadqxmpp-8eaf6c3def32f1aa07fe863d5eab69f44672b3a5.tar.gz
* hide some QXmppServer internals
* improve QXmppServer performance
Diffstat (limited to 'src/server/mod_proxy65.cpp')
-rw-r--r--src/server/mod_proxy65.cpp56
1 files changed, 46 insertions, 10 deletions
diff --git a/src/server/mod_proxy65.cpp b/src/server/mod_proxy65.cpp
index 9562eae4..374adc79 100644
--- a/src/server/mod_proxy65.cpp
+++ b/src/server/mod_proxy65.cpp
@@ -160,14 +160,15 @@ class QXmppServerProxy65Private
{
public:
// configuration
+ QString advertisedName;
+ QHostAddress advertisedAddress;
QStringList allowedDomains;
QString jid;
- QHostAddress hostAddress;
QString hostName;
quint16 port;
// state
- QMap<QString, QTcpSocketPair*> pairs;
+ QHash<QString, QTcpSocketPair*> pairs;
QXmppSocksServer *server;
// statistics
@@ -205,6 +206,26 @@ QXmppServerProxy65::~QXmppServerProxy65()
delete d;
}
+/// Returns the host which is advertised to clients for SOCKS5 connections.
+///
+/// You should only care about this if the host which the clients will see is
+/// different from \a host().
+
+QString QXmppServerProxy65::advertisedHost() const
+{
+ return d->advertisedName;
+}
+
+/// Sets the host which is advertised to clients for SOCKS5 connections.
+///
+/// You should only care about this if the host which the clients will see is
+/// different from \a host().
+
+void QXmppServerProxy65::setAdvertisedHost(const QString &advertisedHost)
+{
+ d->advertisedName = advertisedHost;
+}
+
/// Returns the XMPP domains which are allowed to use the proxy.
///
@@ -284,10 +305,8 @@ QStringList QXmppServerProxy65::discoveryItems() const
return QStringList() << d->jid;
}
-bool QXmppServerProxy65::handleStanza(QXmppStream *stream, const QDomElement &element)
+bool QXmppServerProxy65::handleStanza(const QDomElement &element)
{
- Q_UNUSED(stream);
-
if (element.attribute("to") != d->jid)
return false;
@@ -341,7 +360,7 @@ bool QXmppServerProxy65::handleStanza(QXmppStream *stream, const QDomElement &el
QXmppByteStreamIq::StreamHost streamHost;
streamHost.setJid(d->jid);
- streamHost.setHost(d->hostAddress);
+ streamHost.setHost(d->advertisedAddress);
streamHost.setPort(d->port);
streamHosts.append(streamHost);
@@ -389,10 +408,11 @@ bool QXmppServerProxy65::start()
if (d->jid.isEmpty())
d->jid = "proxy." + server()->domain();
- // determine address
+ // determine bind address
if (d->hostName.isEmpty())
d->hostName = server()->domain();
- if (!d->hostAddress.setAddress(d->hostName))
+ QHostAddress bindAddress;
+ if (!bindAddress.setAddress(d->hostName))
{
QHostInfo hostInfo = QHostInfo::fromName(d->hostName);
if (hostInfo.addresses().isEmpty())
@@ -400,11 +420,27 @@ bool QXmppServerProxy65::start()
warning(QString("Could not lookup host %1").arg(d->hostName));
return false;
}
- d->hostAddress = hostInfo.addresses().first();
+ bindAddress = hostInfo.addresses().first();
+ }
+
+ // determine advertised address
+ if (d->advertisedName.isEmpty()) {
+ d->advertisedName = d->hostName;
+ d->advertisedAddress = bindAddress;
+ }
+ else if (!d->advertisedAddress.setAddress(d->advertisedName))
+ {
+ QHostInfo hostInfo = QHostInfo::fromName(d->advertisedName);
+ if (hostInfo.addresses().isEmpty())
+ {
+ warning(QString("Could not lookup host %1").arg(d->hostName));
+ return false;
+ }
+ d->advertisedAddress = hostInfo.addresses().first();
}
// start listening
- if (!d->server->listen(d->hostAddress, d->port))
+ if (!d->server->listen(bindAddress, d->port))
return false;
// start statistics update