summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2009-12-02 20:42:30 (GMT)
committerRemko Tronçon <git@el-tramo.be>2009-12-03 08:09:01 (GMT)
commit5608da36a3a319070494d5a70ff984e7c172186e (patch)
tree2c44df5a9f0ea0ab180763222e54aece5dc65c93 /Swiften/Network/StaticDomainNameResolver.cpp
parent6e50bd41dc3f11815a40dfef500dc0d61ea5d737 (diff)
downloadswift-contrib-5608da36a3a319070494d5a70ff984e7c172186e.zip
swift-contrib-5608da36a3a319070494d5a70ff984e7c172186e.tar.bz2
DNS querying is now asynchronous.
This means we can now move them to a separate thread.
Diffstat (limited to 'Swiften/Network/StaticDomainNameResolver.cpp')
-rw-r--r--Swiften/Network/StaticDomainNameResolver.cpp54
1 files changed, 39 insertions, 15 deletions
diff --git a/Swiften/Network/StaticDomainNameResolver.cpp b/Swiften/Network/StaticDomainNameResolver.cpp
index 8ca4062..275ec78 100644
--- a/Swiften/Network/StaticDomainNameResolver.cpp
+++ b/Swiften/Network/StaticDomainNameResolver.cpp
@@ -1,28 +1,52 @@
#include "Swiften/Network/StaticDomainNameResolver.h"
-#include "Swiften/Network/DomainNameResolveException.h"
+#include "Swiften/Network/DomainNameResolveError.h"
#include "Swiften/Base/String.h"
+using namespace Swift;
+
+namespace {
+ struct ServiceQuery : public DomainNameServiceQuery {
+ ServiceQuery(const String& service, Swift::StaticDomainNameResolver* resolver) : service(service), resolver(resolver) {}
+
+ virtual void run() {
+ }
+
+ String service;
+ StaticDomainNameResolver* resolver;
+ };
+
+ struct AddressQuery : public DomainNameAddressQuery {
+ AddressQuery(const String& host, StaticDomainNameResolver* resolver) : host(host), resolver(resolver) {}
+
+ virtual void run() {
+ }
+
+ String host;
+ StaticDomainNameResolver* resolver;
+ };
+}
+
namespace Swift {
-StaticDomainNameResolver::StaticDomainNameResolver() {
+void StaticDomainNameResolver::addAddress(const String& domain, const HostAddress& address) {
+ addresses[domain] = address;
}
-std::vector<HostAddressPort> StaticDomainNameResolver::resolve(const String& queriedDomain) {
- std::vector<HostAddressPort> result;
+void StaticDomainNameResolver::addService(const String& service, const DomainNameServiceQuery::Result& result) {
+ services.push_back(std::make_pair(service, result));
+}
- for(DomainCollection::const_iterator i = domains.begin(); i != domains.end(); ++i) {
- if (i->first == queriedDomain) {
- result.push_back(i->second);
- }
- }
- if (result.empty()) {
- throw DomainNameResolveException();
- }
- return result;
+void StaticDomainNameResolver::addXMPPClientService(const String& domain, const HostAddressPort& address) {
+ addService("_xmpp-client._tcp." + domain, ServiceQuery::Result(domain, 5222, 0, 0));
+ addAddress(domain, address.getAddress());
+}
+
+boost::shared_ptr<DomainNameServiceQuery> StaticDomainNameResolver::createServiceQuery(const String& name) {
+ return boost::shared_ptr<DomainNameServiceQuery>(new ServiceQuery(name, this));
}
-void StaticDomainNameResolver::addDomain(const String& domain, const HostAddressPort& addressPort) {
- domains.push_back(std::make_pair(domain, addressPort));
+boost::shared_ptr<DomainNameAddressQuery> StaticDomainNameResolver::createAddressQuery(const String& name) {
+ return boost::shared_ptr<DomainNameAddressQuery>(new AddressQuery(name, this));
}
}