mirror of
https://github.com/matrix-construct/construct
synced 2024-11-16 15:00:51 +01:00
ircd::rfc3986: Add interface to extract host and port from remote via grammar.
This commit is contained in:
parent
f955f1d494
commit
50e7d81d36
2 changed files with 43 additions and 0 deletions
|
@ -35,6 +35,9 @@ namespace ircd::rfc3986
|
||||||
void valid_remote(const string_view &); // host + optional :port
|
void valid_remote(const string_view &); // host + optional :port
|
||||||
bool valid_remote(std::nothrow_t, const string_view &);
|
bool valid_remote(std::nothrow_t, const string_view &);
|
||||||
|
|
||||||
|
uint16_t port(const string_view &remote); // get portnum from valid remote
|
||||||
|
string_view host(const string_view &remote); // get host without portnum
|
||||||
|
|
||||||
string_view encode(const mutable_buffer &, const string_view &url);
|
string_view encode(const mutable_buffer &, const string_view &url);
|
||||||
string_view encode(const mutable_buffer &, const json::members &);
|
string_view encode(const mutable_buffer &, const json::members &);
|
||||||
string_view decode(const mutable_buffer &, const string_view &url);
|
string_view decode(const mutable_buffer &, const string_view &url);
|
||||||
|
|
|
@ -265,6 +265,46 @@ catch(const qi::expectation_failure<const char *> &e)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ircd::string_view
|
||||||
|
ircd::rfc3986::host(const string_view &str)
|
||||||
|
try
|
||||||
|
{
|
||||||
|
static const parser::rule<string_view> rule
|
||||||
|
{
|
||||||
|
raw[parser::host]
|
||||||
|
,"host"
|
||||||
|
};
|
||||||
|
|
||||||
|
string_view ret;
|
||||||
|
const char *start(str.data()), *const stop(start + str.size());
|
||||||
|
qi::parse(start, stop, eps > rule, ret);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
catch(const qi::expectation_failure<const char *> &e)
|
||||||
|
{
|
||||||
|
throw expectation_failure<error>{e};
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t
|
||||||
|
ircd::rfc3986::port(const string_view &str)
|
||||||
|
try
|
||||||
|
{
|
||||||
|
static const parser::rule<uint16_t> rule
|
||||||
|
{
|
||||||
|
(eps > parser::host) >> -(lit(':') >> parser::port)
|
||||||
|
,"port"
|
||||||
|
};
|
||||||
|
|
||||||
|
uint16_t ret(0);
|
||||||
|
const char *start(str.data()), *const stop(start + str.size());
|
||||||
|
qi::parse(start, stop, rule, ret);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
catch(const qi::expectation_failure<const char *> &e)
|
||||||
|
{
|
||||||
|
throw expectation_failure<error>{e};
|
||||||
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
ircd::rfc3986::valid_remote(std::nothrow_t,
|
ircd::rfc3986::valid_remote(std::nothrow_t,
|
||||||
const string_view &str)
|
const string_view &str)
|
||||||
|
|
Loading…
Reference in a new issue