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

ircd:Ⓜ️🆔 Implement MXID interface suite with grammars.

This commit is contained in:
Jason Volk 2018-03-13 16:22:47 -07:00
parent 7deebfd344
commit 368b8c4516
2 changed files with 79 additions and 25 deletions

View file

@ -62,11 +62,11 @@ struct ircd::m::id
public: public:
// Extract elements // Extract elements
string_view local() const; string_view local() const; // The full localpart including sigil
string_view host() const; string_view host() const; // The full server part including port
string_view name() const; string_view localname() const; // The localpart not including sigil
string_view hostname() const; string_view hostname() const; // The server part not including port
uint16_t hostport() const; uint16_t port() const; // Just the port number or 8448 if none
IRCD_USING_OVERLOAD(generate, m::generate); IRCD_USING_OVERLOAD(generate, m::generate);

View file

@ -122,7 +122,7 @@ struct ircd::m::id::input
//TODO: ---- share grammar with rfc3986.cc //TODO: ---- share grammar with rfc3986.cc
const rule<> port const rule<uint16_t> port
{ {
ushort_ ushort_
,"port number" ,"port number"
@ -526,52 +526,106 @@ ircd::m::id::id(const enum sigil &sigil,
} }
uint16_t uint16_t
ircd::m::id::hostport() ircd::m::id::port()
const try const
{ {
//TODO: grammar static const parser::rule<uint16_t> rule
const auto port
{ {
split(host(), ':').second omit[parser.prefix >> ':' >> parser.dns_name >> ':'] >> parser.port
}; };
return port? lex_cast<uint16_t>(port) : 8448; uint16_t ret{8448};
} auto *start{data()};
catch(const std::exception &e) const auto res
{ {
return 8448; qi::parse(start, data() + size(), rule, ret)
};
assert(res || ret == 8448);
return ret;
} }
ircd::string_view ircd::string_view
ircd::m::id::hostname() ircd::m::id::hostname()
const const
{ {
//TODO: grammar static const parser::rule<string_view> dns_name
return rsplit(host(), ':').first; {
parser.dns_name
};
static const parser::rule<string_view> rule
{
omit[parser.prefix >> ':'] >> raw[dns_name]
};
string_view ret;
auto *start{data()};
const auto res
{
qi::parse(start, data() + size(), rule, ret)
};
assert(res == true);
assert(!ret.empty());
return ret;
} }
ircd::string_view ircd::string_view
ircd::m::id::name() ircd::m::id::localname()
const const
{ {
//TODO: grammar auto ret{local()};
return lstrip(local(), at(0)); assert(!ret.empty());
ret.pop_front();
return ret;
} }
ircd::string_view ircd::string_view
ircd::m::id::host() ircd::m::id::host()
const const
{ {
//TODO: grammar static const parser::rule<string_view> server_name
return split(*this, ':').second; {
parser.server_name
};
static const parser::rule<string_view> rule
{
omit[parser.prefix >> ':'] >> raw[server_name]
};
string_view ret;
auto *start{data()};
const auto res
{
qi::parse(start, data() + size(), rule, ret)
};
assert(res == true);
assert(!ret.empty());
return ret;
} }
ircd::string_view ircd::string_view
ircd::m::id::local() ircd::m::id::local()
const const
{ {
//TODO: grammar static const parser::rule<string_view> prefix
return split(*this, ':').first; {
parser.prefix
};
static const parser::rule<string_view> rule
{
eps > raw[prefix]
};
string_view ret;
auto *start{data()};
qi::parse(start, data() + size(), rule, ret);
assert(!ret.empty());
return ret;
} }
bool bool