summaryrefslogtreecommitdiff
path: root/util/net.hh
diff options
context:
space:
mode:
authorA. Wilcox <AWilcox@Wilcox-Tech.com>2019-10-19 17:23:00 -0500
committerA. Wilcox <AWilcox@Wilcox-Tech.com>2019-10-19 17:23:00 -0500
commit55325a6e780b121f93d35076e4226521ca13ef12 (patch)
treeb3cf5fa6131fa966e7427b8837311c8dcdc9ceaa /util/net.hh
parentd3489c52d4ad1e5b17ce88e8b0e5142b30bb324e (diff)
downloadhorizon-55325a6e780b121f93d35076e4226521ca13ef12.tar.gz
horizon-55325a6e780b121f93d35076e4226521ca13ef12.tar.bz2
horizon-55325a6e780b121f93d35076e4226521ca13ef12.tar.xz
horizon-55325a6e780b121f93d35076e4226521ca13ef12.zip
hscript: Implement UserIcon parsing
Diffstat (limited to 'util/net.hh')
-rw-r--r--util/net.hh36
1 files changed, 36 insertions, 0 deletions
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 */