0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-19 16:30:52 +01:00

ircd::net::hostport: Add non-canonicalizing constructor.

This commit is contained in:
Jason Volk 2019-03-18 17:40:16 -07:00
parent 7db86a58c2
commit d03d2c1944

View file

@ -54,6 +54,8 @@ namespace ircd
/// ///
struct ircd::net::hostport struct ircd::net::hostport
{ {
IRCD_OVERLOAD(verbatim)
string_view host {"0.0.0.0"}; string_view host {"0.0.0.0"};
string_view service {canon_service}; string_view service {canon_service};
uint16_t port {canon_port}; uint16_t port {canon_port};
@ -64,6 +66,7 @@ struct ircd::net::hostport
hostport(const string_view &host, const string_view &service, const uint16_t &port = canon_port); hostport(const string_view &host, const string_view &service, const uint16_t &port = canon_port);
hostport(const string_view &host, const uint16_t &port); hostport(const string_view &host, const uint16_t &port);
hostport(const string_view &amalgam); hostport(const string_view &amalgam);
hostport(const string_view &amalgam, verbatim_t);
hostport() = default; hostport() = default;
}; };
@ -76,12 +79,10 @@ inline
ircd::net::hostport::hostport(const string_view &host, ircd::net::hostport::hostport(const string_view &host,
const string_view &service, const string_view &service,
const uint16_t &port) const uint16_t &port)
:host{host} :host{rfc3986::host(host)}
,service{service} ,service{service}
,port{port} ,port{port}
{ {}
rfc3986::valid_host(host);
}
/// Creates a host:port pair from a hostname and a port number. When /// Creates a host:port pair from a hostname and a port number. When
/// passed to net::dns() no SRV resolution will be done because no /// passed to net::dns() no SRV resolution will be done because no
@ -136,6 +137,25 @@ ircd::net::hostport::hostport(const string_view &amalgam)
this->port = canon_port; this->port = canon_port;
} }
inline
ircd::net::hostport::hostport(const string_view &amalgam,
verbatim_t)
:host
{
rfc3986::host(amalgam)
}
,service
{
amalgam != host && !rfc3986::port(amalgam)?
rsplit(amalgam, ':').second:
string_view{}
}
,port
{
rfc3986::port(amalgam)
}
{}
inline inline
ircd::net::hostport::operator ircd::net::hostport::operator
bool() bool()