lay it out a bit better
[ghsmtp.git] / DNS.hpp
blobc41cbd7ca71044047d98c822276616781e8f95ca
1 #ifndef DNS_DOT_HPP
2 #define DNS_DOT_HPP
4 #include <memory>
6 #include "DNS-message.hpp"
7 #include "DNS-rrs.hpp"
8 #include "Sock.hpp"
9 #include "iobuffer.hpp"
11 #include <glog/logging.h>
13 namespace DNS {
15 class Resolver {
16 public:
17 Resolver(Resolver const&) = delete;
18 Resolver& operator=(Resolver const&) = delete;
20 Resolver(fs::path config_path);
22 RR_collection get_records(RR_type typ, char const* name);
23 RR_collection get_records(RR_type typ, std::string const& name)
25 return get_records(typ, name.c_str());
28 std::vector<std::string> get_strings(RR_type typ, char const* name);
29 std::vector<std::string> get_strings(RR_type typ, std::string const& name)
31 return get_strings(typ, name.c_str());
34 message xchg(message const& q);
36 private:
37 std::unique_ptr<Sock> ns_sock_;
38 int ns_;
39 int ns_fd_;
42 class Query {
43 public:
44 Query(Query const&) = delete;
45 Query& operator=(Query const&) = delete;
47 Query(Resolver& res, RR_type type, char const* name);
48 Query(Resolver& res, RR_type type, std::string const& name)
49 : Query(res, type, name.c_str())
53 bool authentic_data() const { return authentic_data_; }
54 bool bogus_or_indeterminate() const { return bogus_or_indeterminate_; }
55 bool nx_domain() const { return nx_domain_; }
57 bool has_record() const { return has_record_; }
58 RR_collection get_records();
59 std::vector<std::string> get_strings();
61 uint16_t rcode() const { return rcode_; }
62 uint16_t extended_rcode() const { return extended_rcode_; }
64 private:
65 bool xchg_(Resolver& res, uint16_t id);
66 void check_answer_(Resolver& res, RR_type type, char const* name);
68 uint16_t rcode_{0};
69 uint16_t extended_rcode_{0};
71 RR_type type_;
73 message q_;
74 message a_;
76 bool authentic_data_{false};
77 bool bogus_or_indeterminate_{false};
78 bool nx_domain_{false};
79 bool has_record_{false};
82 inline std::vector<std::string>
83 get_strings(Resolver& res, RR_type type, char const* name)
85 return res.get_strings(type, name);
88 inline std::vector<std::string>
89 get_strings(Resolver& res, RR_type type, std::string const& name)
91 return res.get_strings(type, name.c_str());
94 inline bool has_record(Resolver& res, RR_type type, char const* name)
96 Query q(res, type, name);
97 return q.has_record();
100 inline bool has_record(Resolver& res, RR_type type, std::string const& name)
102 return has_record(res, type, name.c_str());
104 } // namespace DNS
106 #endif // DNS_DOT_HPP