From 55325a6e780b121f93d35076e4226521ca13ef12 Mon Sep 17 00:00:00 2001 From: "A. Wilcox" <AWilcox@Wilcox-Tech.com> Date: Sat, 19 Oct 2019 17:23:00 -0500 Subject: hscript: Implement UserIcon parsing --- util/net.hh | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 util/net.hh (limited to 'util') diff --git a/util/net.hh b/util/net.hh new file mode 100644 index 0000000..89e5303 --- /dev/null +++ b/util/net.hh @@ -0,0 +1,36 @@ +/* + * net.hh - Miscellaneous networking routines + * util, the utility library for + * Project Horizon + * + * Copyright (c) 2019 Adélie Linux and contributors. All rights reserved. + * This code is licensed under the AGPL 3.0 license, as noted in the + * LICENSE-code file in the root directory of this repository. + * + * SPDX-License-Identifier: AGPL-3.0-only + */ + +#ifndef __HORIZON_NET_HH_ +#define __HORIZON_NET_HH_ + +#include <algorithm> +#include <string> + +/*! Determine if a string starts with a valid, supported protocol + * @param url The URL. + * @returns true if +url+ is a URL for a supported protocol, false otherwise. + */ +static bool is_valid_url(const std::string &url) { + std::string::size_type colon = url.find("://"); + /* If there's no ://, it's definitely not a URL */ + if(colon == std::string::npos) return false; + std::string proto = url.substr(0, colon); + std::transform(proto.cbegin(), proto.cend(), proto.begin(), ::tolower); + if(proto == "http" || proto == "https" || proto == "tftp" || proto == "smb" + || proto == "cifs") { + return true; + } + return false; +} + +#endif /* !__HORIZON_NET_HH */ -- cgit v1.2.3-70-g09d2