0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-26 15:33:54 +01:00

ircd::net::dns: Add utils to properly check for empty records in JSON.

This commit is contained in:
Jason Volk 2019-03-24 20:12:15 -07:00
parent 8e15e5d09b
commit 7f5f07509a
3 changed files with 19 additions and 1 deletions

View file

@ -33,6 +33,8 @@ namespace ircd::net::dns
// Utilities
bool is_error(const json::object &rr);
bool is_error(const json::array &rr);
bool is_empty(const json::object &rr);
bool is_empty(const json::array &rr);
time_t get_ttl(const json::object &rr);
bool expired(const json::object &rr, const time_t &rr_ts, const time_t &min_ttl);
bool expired(const json::object &rr, const time_t &rr_ts);

View file

@ -3456,6 +3456,22 @@ ircd::net::dns::get_ttl(const json::object &rr)
return rr.get<time_t>("ttl", 0L);
}
bool
ircd::net::dns::is_empty(const json::array &rrs)
{
return std::all_of(begin(rrs), end(rrs), []
(const json::object &rr)
{
return is_empty(rr);
});
}
bool
ircd::net::dns::is_empty(const json::object &rr)
{
return empty(rr) || (rr.has("ttl") && size(rr) == 1);
}
bool
ircd::net::dns::is_error(const json::array &rrs)
{

View file

@ -1080,7 +1080,7 @@ try
if(op_fini)
return;
if(empty(rrs))
if(net::dns::is_empty(rrs))
{
err_set(make_exception_ptr<unavailable>("Host has no address record."));
assert(this->e && this->e->eptr);