summaryrefslogtreecommitdiffstats
blob: cd0b167333b6478fd2d2fc8ff64ac554335e04e0 (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
53
54
/*
 * Copyright (c) 2012 Tobias Markmann
 * Licensed under the simplified BSD license.
 * See Documentation/Licenses/BSD-simplified.txt for more information.
 */

#pragma once

#include <Swiften/Network/DomainNameResolver.h>
#include <Swiften/Network/Timer.h>

#include <boost/shared_ptr.hpp>

#include <unbound.h>

namespace Swift {
	class EventLoop;
	class TimerFactory;

	class UnboundDomainNameResolver;

	class UnboundQuery {
		public:
			UnboundQuery(UnboundDomainNameResolver* resolver, ub_ctx* context) : resolver(resolver), ubContext(context) {}
			virtual ~UnboundQuery() {}
			virtual void handleResult(int err, ub_result* result) = 0;
		protected:
			UnboundDomainNameResolver* resolver;
			ub_ctx* ubContext;
	};

	class UnboundDomainNameResolver : public DomainNameResolver {
		public:
			UnboundDomainNameResolver(EventLoop* eventLoop, TimerFactory* timerFactory);
			virtual ~UnboundDomainNameResolver();

			virtual boost::shared_ptr<DomainNameServiceQuery> createServiceQuery(const std::string& name);
			virtual boost::shared_ptr<DomainNameAddressQuery> createAddressQuery(const std::string& name);

			static void unbound_callback_wrapper(void* data, int err, ub_result* result);

		private:
			void unbound_callback(boost::shared_ptr<UnboundQuery> query, int err, ub_result* result);

			void processData();

		private:
			EventLoop* eventLoop;
			TimerFactory* timerFactory;
			ub_ctx* ubContext;
			Timer::ref timer;
	};

}