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

ircd:Ⓜ️🆔 Reuse the rfc3986 grammar with the mxid grammar.

This commit is contained in:
Jason Volk 2019-02-26 13:07:52 -08:00
parent 581fcca2f7
commit 85cbaffca4

View file

@ -93,104 +93,6 @@ struct ircd::m::id::input
,"prefix"
};
//TODO: ---- share grammar with rfc3986.cc
const rule<uint16_t> port
{
ushort_
,"port number"
};
const rule<> ip4_octet
{
repeat(1,3)[char_("0-9")]
,"IPv4 octet"
};
const rule<> ip4_literal
{
repeat(3)[ip4_octet >> '.'] >> ip4_octet
,"IPv4 literal"
};
const rule<> ip6_char
{
char_("0-9a-fA-F")
,"IPv6 character"
};
const rule<> ip6_h16
{
repeat(1,4)[ip6_char]
,"IPv6 hexdigit"
};
const rule<> ip6_piece
{
ip6_h16 >> ':'
,"IPv6 address piece"
};
// This is reversed from the BNF in the RFC otherwise it requires
// backtracking during the repeat[]; grammars are adjusted accordingly.
const rule<> ip6_ipiece
{
':' >> ip6_h16
,"IPv6 address piece"
};
const rule<> ip6_ls32
{
(ip6_h16 >> ':' >> ip6_h16) | ip4_literal
};
/// https://tools.ietf.org/html/rfc3986 Appendix A
const rule<> ip6_addr[9]
{
{ repeat(6)[ip6_piece] >> ip6_ls32 },
{ lit("::") >> repeat(5)[ip6_piece] >> ip6_ls32 },
{ ip6_h16 >> lit("::") >> repeat(4)[ip6_piece] >> ip6_ls32 },
{ ip6_h16 >> repeat(0,1)[ip6_ipiece] >> lit("::") >> repeat(3)[ip6_piece] >> ip6_ls32 },
{ ip6_h16 >> repeat(0,2)[ip6_ipiece] >> lit("::") >> repeat(2)[ip6_piece] >> ip6_ls32 },
{ ip6_h16 >> repeat(0,3)[ip6_ipiece] >> lit("::") >> ip6_piece >> ip6_ls32 },
{ ip6_h16 >> repeat(0,4)[ip6_ipiece] >> lit("::") >> ip6_ls32 },
{ ip6_h16 >> repeat(0,5)[ip6_ipiece] >> lit("::") >> -ip6_h16 },
{ lit("::") >> -ip6_h16 },
};
const rule<> ip6_address
{
ip6_addr[0] | ip6_addr[1] | ip6_addr[2] |
ip6_addr[3] | ip6_addr[4] | ip6_addr[5] |
ip6_addr[6] | ip6_addr[7] | ip6_addr[8]
,"IPv6 address"
};
const rule<> ip6_literal
{
'[' >> ip6_address >> ']'
,"ip6 literal"
};
const rule<> hostlabel
{
char_("A-Za-z0-9") >> *(char_("A-Za-z0-9\x2D")) // x2D is '-'
};
const rule<> hostname
{
hostlabel % '.',
"hostname"
};
const rule<> dns_name
{
ip6_literal | ip4_literal | hostname
,"DNS name"
};
//TODO: /---- share grammar with rfc3986.cc
/// (Appendix 4.1) Server Name
/// A homeserver is uniquely identified by its server name. This value
/// is used in a number of identifiers, as described below. The server
@ -209,7 +111,7 @@ struct ircd::m::id::input
/// `[1234:5678::abcd]:5678` (IPv6 literal with explicit port)
const rule<> server_name
{
dns_name >> -(':' > port)
rfc3986::parser::remote
,"server name"
};
@ -505,7 +407,7 @@ ircd::m::id::id(const enum sigil &sigil,
{
//TODO: output grammar
char namebuf[64];
thread_local char namebuf[MAX_SIZE];
string_view name; switch(sigil)
{
case sigil::USER:
@ -558,9 +460,11 @@ uint16_t
ircd::m::id::port()
const
{
static const auto &host{rfc3986::parser::host};
static const auto &port{rfc3986::parser::port};
static const parser::rule<uint16_t> rule
{
omit[parser.prefix >> ':' >> parser.dns_name >> ':'] >> parser.port
omit[parser.prefix >> ':' >> host >> ':'] >> port
};
uint16_t ret{0};
@ -578,14 +482,14 @@ ircd::string_view
ircd::m::id::hostname()
const
{
static const parser::rule<string_view> dns_name
static const parser::rule<string_view> host
{
parser.dns_name
rfc3986::parser::host
};
static const parser::rule<string_view> rule
{
omit[parser.prefix >> ':'] >> raw[dns_name]
omit[parser.prefix >> ':'] >> raw[host]
};
string_view ret;