0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-26 07:23:53 +01:00

ircd::rfc1035: Add json::stack serializations for record types.

This commit is contained in:
Jason Volk 2019-03-18 12:46:27 -07:00
parent 29ba0d214b
commit dbc2ca3b64
2 changed files with 85 additions and 0 deletions

View file

@ -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();
};

View file

@ -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)
{