From d8ee9e9a10accbe46403fd7cf8a8656622a906c2 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Wed, 13 Mar 2019 10:50:49 -0700 Subject: [PATCH] ircd::net: Use more grammars in net::hostport construction. --- include/ircd/net/hostport.h | 41 +++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/include/ircd/net/hostport.h b/include/ircd/net/hostport.h index c361314cf..709c0997d 100644 --- a/include/ircd/net/hostport.h +++ b/include/ircd/net/hostport.h @@ -105,30 +105,35 @@ inline ircd::net::hostport::hostport(const string_view &amalgam) :host { - //TODO: grammar - rsplit(amalgam, ':').first + rfc3986::host(amalgam) +} +,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 }; - if(amalgam == host || empty(port)) - { - rfc3986::valid_host(host); - return; - } - - if(try_lex_cast(port)) - { - this->service = {}; - this->port = lex_cast(port); - rfc3986::valid_remote(amalgam); - } else { - this->service = port; - rfc3986::valid_host(host); - } + if(service) + this->service = service; + else + this->port = canon_port; } inline