diff --git a/include/ircd/rfc1035.h b/include/ircd/rfc1035.h index df2fce461..dfd9c428e 100644 --- a/include/ircd/rfc1035.h +++ b/include/ircd/rfc1035.h @@ -209,6 +209,8 @@ struct ircd::rfc1035::record::A { uint32_t ip4 {0}; + void append(json::stack::object &) const; + A(const answer &); A(); }; @@ -220,6 +222,8 @@ struct ircd::rfc1035::record::AAAA { uint128_t ip6 {0}; + void append(json::stack::object &) const; + AAAA(const answer &); AAAA(); }; @@ -231,6 +235,8 @@ struct ircd::rfc1035::record::CNAME string_view name; char namebuf[NAME_BUF_SIZE]; + void append(json::stack::object &) const; + CNAME(const answer &); CNAME(); }; @@ -246,6 +252,8 @@ struct ircd::rfc1035::record::SRV string_view tgt; char tgtbuf[NAME_BUF_SIZE]; + void append(json::stack::object &) const; + SRV(const answer &); SRV(); }; diff --git a/ircd/rfc1035.cc b/ircd/rfc1035.cc index 5d3755f3c..a1a2c4024 100644 --- a/ircd/rfc1035.cc +++ b/ircd/rfc1035.cc @@ -217,6 +217,22 @@ ircd::rfc1035::record::A::A(const answer &answer) ip4 = bswap(*(const uint32_t *)data(rdata)); } +void +ircd::rfc1035::record::A::append(json::stack::object &out) +const +{ + thread_local char ipbuf[64]; + json::stack::member + { + out, "ip", net::string_ip4(ipbuf, ip4) + }; + + json::stack::member + { + out, "ttl", json::value(ttl) + }; +} + bool ircd::rfc1035::operator!=(const record::A &a, const record::A &b) { @@ -251,6 +267,22 @@ ircd::rfc1035::record::AAAA::AAAA(const answer &answer) ip6 = bswap(*(const uint128_t *)data(rdata)); } +void +ircd::rfc1035::record::AAAA::append(json::stack::object &out) +const +{ + thread_local char ipbuf[64]; + json::stack::member + { + out, "ip", net::string_ip6(ipbuf, ip6) + }; + + json::stack::member + { + out, "ttl", json::value(ttl) + }; +} + bool ircd::rfc1035::operator!=(const record::AAAA &a, const record::AAAA &b) { @@ -285,6 +317,21 @@ ircd::rfc1035::record::CNAME::CNAME(const answer &answer) name = string_view{namebuf, len - 1}; } +void +ircd::rfc1035::record::CNAME::append(json::stack::object &out) +const +{ + json::stack::member + { + out, "name", name + }; + + json::stack::member + { + out, "ttl", json::value(ttl) + }; +} + bool ircd::rfc1035::operator!=(const record::CNAME &a, const record::CNAME &b) { @@ -328,6 +375,36 @@ ircd::rfc1035::record::SRV::SRV(const answer &answer) assert(std::distance(pos, end(rdata)) >= 0); } +void +ircd::rfc1035::record::SRV::append(json::stack::object &out) +const +{ + json::stack::member + { + out, "port", json::value(port) + }; + + json::stack::member + { + out, "prio", json::value(priority) + }; + + json::stack::member + { + out, "tgt", tgt + }; + + json::stack::member + { + out, "ttl", json::value(ttl) + }; + + json::stack::member + { + out, "weight", json::value(weight) + }; +} + bool ircd::rfc1035::operator!=(const record::SRV &a, const record::SRV &b) {