summaryrefslogtreecommitdiffstats
blob: afb21c89a615414af58947384a531f981821babc (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
55
56
57
58
59
/*
 * Copyright (c) 2013 Tobias Markmann
 * Licensed under the simplified BSD license.
 * See Documentation/Licenses/BSD-simplified.txt for more information.
 */

/*
 * Copyright (c) 2016 Isode Limited.
 * All rights reserved.
 * See the COPYING file for more information.
 */

#pragma once

#include <boost/asio.hpp>
#include <boost/enable_shared_from_this.hpp>
#include <boost/shared_ptr.hpp>

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

struct ub_ctx;
struct ub_result;

namespace Swift {
    class EventLoop;
    class IDNConverter;
    class TimerFactory;

    class UnboundDomainNameResolver;
    class UnboundQuery;

    class UnboundDomainNameResolver : public DomainNameResolver, public EventOwner, public boost::enable_shared_from_this<UnboundDomainNameResolver> {
        public:
            UnboundDomainNameResolver(IDNConverter* idnConverter, boost::shared_ptr<boost::asio::io_service> ioService, EventLoop* eventLoop);
            virtual ~UnboundDomainNameResolver();

            virtual boost::shared_ptr<DomainNameServiceQuery> createServiceQuery(const std::string& serviceLookupPrefix, const std::string& domain);
            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 handleUBSocketReadable(boost::system::error_code);
            void processData();

        private:
            IDNConverter* idnConverter;
            boost::shared_ptr<EventOwner> eventOwner;
            boost::shared_ptr<boost::asio::io_service> ioService;
            boost::asio::posix::stream_descriptor ubDescriptior;
            EventLoop* eventLoop;
            ub_ctx* ubContext;
    };

}