mirror of
https://github.com/matrix-construct/construct
synced 2024-12-31 18:04:06 +01:00
ircd::net: Use more grammars in net::hostport construction.
This commit is contained in:
parent
50e7d81d36
commit
d8ee9e9a10
1 changed files with 23 additions and 18 deletions
|
@ -105,30 +105,35 @@ inline
|
||||||
ircd::net::hostport::hostport(const string_view &amalgam)
|
ircd::net::hostport::hostport(const string_view &amalgam)
|
||||||
:host
|
:host
|
||||||
{
|
{
|
||||||
//TODO: grammar
|
rfc3986::host(amalgam)
|
||||||
rsplit(amalgam, ':').first
|
}
|
||||||
|
,port
|
||||||
|
{
|
||||||
|
rfc3986::port(amalgam)
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
const auto port
|
// When the amalgam has no port
|
||||||
|
if(amalgam == host)
|
||||||
|
{
|
||||||
|
// set the port to the canon_port; port=0 is bad
|
||||||
|
port = port?: canon_port;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// or a valid integer port
|
||||||
|
if(port)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// When the port is actually a service string
|
||||||
|
const auto service
|
||||||
{
|
{
|
||||||
rsplit(amalgam, ':').second
|
rsplit(amalgam, ':').second
|
||||||
};
|
};
|
||||||
|
|
||||||
if(amalgam == host || empty(port))
|
if(service)
|
||||||
{
|
this->service = service;
|
||||||
rfc3986::valid_host(host);
|
else
|
||||||
return;
|
this->port = canon_port;
|
||||||
}
|
|
||||||
|
|
||||||
if(try_lex_cast<uint16_t>(port))
|
|
||||||
{
|
|
||||||
this->service = {};
|
|
||||||
this->port = lex_cast<uint16_t>(port);
|
|
||||||
rfc3986::valid_remote(amalgam);
|
|
||||||
} else {
|
|
||||||
this->service = port;
|
|
||||||
rfc3986::valid_host(host);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline
|
inline
|
||||||
|
|
Loading…
Reference in a new issue