Summary Files Commits Branches @commit @diff @stats
path: root / uri.c
diff options
context:
space:
mode:
1 files changed, 22 insertions, 0 deletions
-rw-r--r--uri.c22
diff --git a/uri.c b/uri.c
new file mode 100644
index 0000000..6843e4a
--- /dev/null
+++ b/uri.c
@@ -0,0 +1,22 @@
+// BadWolf: Minimalist and privacy-oriented WebKitGTK+ browser
+// Copyright © 2019-2020 Badwolf Authors <https://hacktivis.me/projects/badwolf>
+// SPDX-License-Identifier: BSD-3-Clause
+
+#include "uri.h"
+
+#include <glib.h> /* g_strcmp0() */
+#include <unistd.h> /* access() */
+
+const gchar *
+badwolf_ensure_uri_scheme(const gchar *text, gboolean try_file)
+{
+ const gchar *fallback = "about:blank";
+
+ if(g_strcmp0(text, "") <= 0) return fallback;
+
+ if(g_uri_parse_scheme(text)) return text;
+
+ if(try_file && (access(text, R_OK) == 0)) return g_strdup_printf("file://%s", text);
+
+ return g_strdup_printf("http://%s", text);
+}