summaryrefslogtreecommitdiffstats
blob: 275ec787995477810b2f0420ea3406714cd514e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "Swiften/Network/StaticDomainNameResolver.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 {

void StaticDomainNameResolver::addAddress(const String& domain, const HostAddress& address) {
	addresses[domain] = address;
}

void StaticDomainNameResolver::addService(const String& service, const DomainNameServiceQuery::Result& result) {
	services.push_back(std::make_pair(service, 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));
}

boost::shared_ptr<DomainNameAddressQuery> StaticDomainNameResolver::createAddressQuery(const String& name) {
	return boost::shared_ptr<DomainNameAddressQuery>(new AddressQuery(name, this));
}

}