0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-09 05:29:00 +02:00

ircd:Ⓜ️🆔 Add test for whether hostname is an IP literal.

This commit is contained in:
Jason Volk 2019-02-26 13:24:46 -08:00
parent 85cbaffca4
commit 3e1157f043
2 changed files with 20 additions and 0 deletions

View file

@ -72,6 +72,7 @@ struct ircd::m::id
string_view localname() const; // The localpart not including sigil
string_view hostname() const; // The server part not including port
uint16_t port() const; // Just the port number or 0 if none
bool literal() const; // Whether the hostname() is IP literal
IRCD_USING_OVERLOAD(generate, m::generate);

View file

@ -456,6 +456,25 @@ ircd::m::id::id(const enum sigil &sigil,
{
}
bool
ircd::m::id::literal()
const
{
static const parser::rule<string_view> rule
{
rfc3986::parser::ip4_literal |
rfc3986::parser::ip6_literal
};
const auto &hostname
{
this->hostname()
};
const char *start(hostname.begin()), *const stop(hostname.end());
return qi::parse(start, stop, rule);
}
uint16_t
ircd::m::id::port()
const