#include "dns-storage.hh" #include using namespace std; bool DNSName::makeRelative(const DNSName& root) { auto us = d_name, them=root.d_name; while(!them.empty()) { if(us.empty()) return false; if(us.back() == them.back()) { us.pop_back(); them.pop_back(); } else return false; } d_name = us; return true; } DNSName operator+(const DNSName& a, const DNSName& b) { DNSName ret=a; for(const auto& l : b.d_name) ret.d_name.push_back(l); return ret; } DNSNode::~DNSNode() = default; const DNSNode* DNSNode::find(DNSName& name, DNSName& last, bool wildcard, const DNSNode** passedZonecut, DNSName* zonecutname) const { // cout<<"find called for '"< 1) { last.push_front(name.back()); name.pop_back(); } } } // cout<<" Had match at this node , continuing to child '"<first<<"'"<second.find(name, last, wildcard, passedZonecut, zonecutname); } DNSNode* DNSNode::add(DNSName name) { if(name.empty()) return this; auto back = name.back(); name.pop_back(); return children[back].add(name); // will make child node if needed } void DNSNode::visit(std::function visitor, DNSName name) const { visitor(name, this); for(const auto& c : children) c.second.visit(visitor, DNSName{c.first}+name); } void DNSNode::addRRs(std::unique_ptr&&a) { rrsets[a->getType()].add(std::move(a)); } std::ostream & operator<<(std::ostream &os, const DNSLabel& d) { for(uint8_t a : d.d_s) { if(a <= 0x20 || a >= 0x7f) { // RFC 4343 os<<'\\'<