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:
parent
8e15e5d09b
commit
7f5f07509a
3 changed files with 19 additions and 1 deletions
|
@ -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);
|
||||
|
|
16
ircd/net.cc
16
ircd/net.cc
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue