summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2009-12-03 07:43:30 (GMT)
committerRemko Tronçon <git@el-tramo.be>2009-12-03 08:09:01 (GMT)
commite15c6fd319af1303db47f00e78e4ec42d0605279 (patch)
tree8e0c60809d7e7e16883168f8bee792d6418ae6d9 /Swiften
parente7e514d95e190a3a7d466740a4c3a1dfa9833ccc (diff)
downloadswift-contrib-e15c6fd319af1303db47f00e78e4ec42d0605279.zip
swift-contrib-e15c6fd319af1303db47f00e78e4ec42d0605279.tar.bz2
Fixed unit tests.
Diffstat (limited to 'Swiften')
-rw-r--r--Swiften/Network/SRVRecordPriorityComparator.h11
-rw-r--r--Swiften/Network/StaticDomainNameResolver.cpp32
-rw-r--r--Swiften/Network/StaticDomainNameResolver.h1
3 files changed, 29 insertions, 15 deletions
diff --git a/Swiften/Network/SRVRecordPriorityComparator.h b/Swiften/Network/SRVRecordPriorityComparator.h
deleted file mode 100644
index fc16597..0000000
--- a/Swiften/Network/SRVRecordPriorityComparator.h
+++ /dev/null
@@ -1,11 +0,0 @@
-#pragma once
-
-#include "Swiften/Network/SRVRecord.h"
-
-namespace Swift {
- struct SRVRecordPriorityComparator {
- bool operator()(const SRVRecord& a, const SRVRecord& b) const {
- return a.priority < b.priority;
- }
- };
-}
diff --git a/Swiften/Network/StaticDomainNameResolver.cpp b/Swiften/Network/StaticDomainNameResolver.cpp
index 275ec78..609bbdd 100644
--- a/Swiften/Network/StaticDomainNameResolver.cpp
+++ b/Swiften/Network/StaticDomainNameResolver.cpp
@@ -1,24 +1,44 @@
#include "Swiften/Network/StaticDomainNameResolver.h"
+
+#include <boost/bind.hpp>
+#include <boost/lexical_cast.hpp>
+
#include "Swiften/Network/DomainNameResolveError.h"
#include "Swiften/Base/String.h"
using namespace Swift;
namespace {
- struct ServiceQuery : public DomainNameServiceQuery {
+ struct ServiceQuery : public DomainNameServiceQuery, public EventOwner {
ServiceQuery(const String& service, Swift::StaticDomainNameResolver* resolver) : service(service), resolver(resolver) {}
virtual void run() {
+ std::vector<DomainNameServiceQuery::Result> results;
+ for(StaticDomainNameResolver::ServicesCollection::const_iterator i = resolver->getServices().begin(); i != resolver->getServices().end(); ++i) {
+ if (i->first == service) {
+ results.push_back(i->second);
+ }
+ }
+ MainEventLoop::postEvent(boost::bind(boost::ref(onResult), results));
}
String service;
StaticDomainNameResolver* resolver;
};
- struct AddressQuery : public DomainNameAddressQuery {
+ struct AddressQuery : public DomainNameAddressQuery, public EventOwner {
AddressQuery(const String& host, StaticDomainNameResolver* resolver) : host(host), resolver(resolver) {}
virtual void run() {
+ StaticDomainNameResolver::AddressesMap::const_iterator i = resolver->getAddresses().find(host);
+ if (i != resolver->getAddresses().end()) {
+ MainEventLoop::postEvent(
+ boost::bind(boost::ref(onResult), i->second, boost::optional<DomainNameResolveError>()));
+ }
+ else {
+ MainEventLoop::postEvent(boost::bind(boost::ref(onResult), HostAddress(), boost::optional<DomainNameResolveError>(DomainNameResolveError())));
+ }
+
}
String host;
@@ -37,8 +57,12 @@ void StaticDomainNameResolver::addService(const String& service, const DomainNam
}
void StaticDomainNameResolver::addXMPPClientService(const String& domain, const HostAddressPort& address) {
- addService("_xmpp-client._tcp." + domain, ServiceQuery::Result(domain, 5222, 0, 0));
- addAddress(domain, address.getAddress());
+ static int hostid = 0;
+ String hostname(std::string("host-") + boost::lexical_cast<std::string>(hostid));
+ hostid++;
+
+ addService("_xmpp-client._tcp." + domain, ServiceQuery::Result(hostname, address.getPort(), 0, 0));
+ addAddress(hostname, address.getAddress());
}
boost::shared_ptr<DomainNameServiceQuery> StaticDomainNameResolver::createServiceQuery(const String& name) {
diff --git a/Swiften/Network/StaticDomainNameResolver.h b/Swiften/Network/StaticDomainNameResolver.h
index ed8c613..0e877d3 100644
--- a/Swiften/Network/StaticDomainNameResolver.h
+++ b/Swiften/Network/StaticDomainNameResolver.h
@@ -8,6 +8,7 @@
#include "Swiften/Network/DomainNameResolver.h"
#include "Swiften/Network/DomainNameServiceQuery.h"
#include "Swiften/Network/DomainNameAddressQuery.h"
+#include "Swiften/EventLoop/MainEventLoop.h"
namespace Swift {
class String;