test PRDR split result
[ghsmtp.git] / DNS.hpp
blob09e8ba9d8a34019d46bf7946b66e952d8c92b43f
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 truncation() const { return truncation_; }
56 bool nx_domain() const { return nx_domain_; }
58 bool has_record() const { return has_record_; }
59 RR_collection get_records();
60 std::vector<std::string> get_strings();
62 uint16_t rcode() const { return rcode_; }
63 uint16_t extended_rcode() const { return extended_rcode_; }
65 private:
66 bool xchg_(Resolver& res, uint16_t id);
67 void check_answer_(Resolver& res, RR_type type, char const* name);
69 uint16_t rcode_{0};
70 uint16_t extended_rcode_{0};
72 RR_type type_;
74 message q_;
75 message a_;
77 bool authentic_data_{false};
78 bool bogus_or_indeterminate_{false};
79 bool truncation_{false};
80 bool nx_domain_{false};
81 bool has_record_{false};
84 inline std::vector<std::string>
85 get_strings(Resolver& res, RR_type type, char const* name)
87 return res.get_strings(type, name);
90 inline std::vector<std::string>
91 get_strings(Resolver& res, RR_type type, std::string const& name)
93 return res.get_strings(type, name.c_str());
96 inline bool has_record(Resolver& res, RR_type type, char const* name)
98 Query q(res, type, name);
99 return q.has_record();
102 inline bool has_record(Resolver& res, RR_type type, std::string const& name)
104 return has_record(res, type, name.c_str());
106 } // namespace DNS
108 #endif // DNS_DOT_HPP