Summary Files Commits Branches @commit @diff @stats
path: root / uri.c
blob: 7b97e4843b0e74857af0dd45d4f97a169a0d37f9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// BadWolf: Minimalist and privacy-oriented WebKitGTK+ browser
// Copyright © 2019 Haelwenn (lanodan) Monnier <contact@hacktivis.me>
// SPDX-License-Identifier: BSD-3-Clause

#include "uri.h"

#include <glib.h>         /* g_strcmp0() */
#include <glib/gprintf.h> /* g_fprintf() */
#include <libsoup/soup.h> /* soup* */
#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);
}