0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-16 23:10: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 // Utilities
bool is_error(const json::object &rr); bool is_error(const json::object &rr);
bool is_error(const json::array &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); 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, const time_t &min_ttl);
bool expired(const json::object &rr, const time_t &rr_ts); 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); 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 bool
ircd::net::dns::is_error(const json::array &rrs) ircd::net::dns::is_error(const json::array &rrs)
{ {

View file

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