...
This commit is contained in:
@@ -28,6 +28,79 @@ namespace adc
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
class AdcEndpointParser
|
||||
{
|
||||
public:
|
||||
static constexpr std::string_view protoHostDelim = "://";
|
||||
static constexpr std::string_view hostPortDelim = ":";
|
||||
static constexpr std::string_view portPathDelim = "/";
|
||||
|
||||
enum proto_id_t : uint8_t {
|
||||
PROTO_ID_LOCAL,
|
||||
PROTO_ID_TCP,
|
||||
PROTO_ID_TLS,
|
||||
PROTO_ID_UDP,
|
||||
PROTO_ID_WS,
|
||||
PROTO_ID_WSS,
|
||||
PROTO_ID_UNKNOWN
|
||||
};
|
||||
|
||||
static constexpr std::string_view protoMarkLocal{"local"}; // UNIX domain
|
||||
static constexpr std::string_view protoMarkTCP{"tcp"}; // TCP
|
||||
static constexpr std::string_view protoMarkTLS{"tls"}; // TLS
|
||||
static constexpr std::string_view protoMarkUDP{"udp"}; // UDP
|
||||
static constexpr std::string_view protoMarkWS{"ws"}; // Websocket
|
||||
static constexpr std::string_view protoMarkWSS{"wss"}; // Secure Websocket
|
||||
|
||||
static constexpr std::array validProtoMarks{protoMarkLocal, protoMarkTCP, protoMarkTLS,
|
||||
protoMarkUDP, protoMarkWS, protoMarkWSS};
|
||||
|
||||
|
||||
template <traits::adc_input_char_range R>
|
||||
AdcEndpointParser(const R& ept)
|
||||
{
|
||||
}
|
||||
|
||||
protected:
|
||||
std::string _proto, _host, _path;
|
||||
int port;
|
||||
|
||||
template <traits::adc_input_char_range R>
|
||||
bool parse(const R& ept)
|
||||
{
|
||||
// at least 'ws://a' (proto, proto-host delimiter and at least a single character of hostname)
|
||||
if (std::ranges::size(ept) < 6) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto found = std::ranges::search(ept, protoHostDelim);
|
||||
if (found.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool ok = false;
|
||||
|
||||
std::string_view proto{ept.begin(), found.begin()};
|
||||
for (auto& valid_proto : validProtoMarks) {
|
||||
ok = proto == valid_proto;
|
||||
if (ok) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!ok) {
|
||||
return ok;
|
||||
}
|
||||
|
||||
_proto.clear();
|
||||
std::ranges::copy(proto, std::back_inserter(_proto));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
class AdcEndpoint
|
||||
{
|
||||
public:
|
||||
|
||||
Reference in New Issue
Block a user