uri.c 625 B

1234567891011121314151617181920212223
  1. // BadWolf: Minimalist and privacy-oriented WebKitGTK+ browser
  2. // Copyright © 2019-2020 Badwolf Authors <https://hacktivis.me/projects/badwolf>
  3. // SPDX-License-Identifier: BSD-3-Clause
  4. #include "uri.h"
  5. #include <glib.h> /* g_strcmp0() */
  6. #include <unistd.h> /* access() */
  7. const gchar *
  8. badwolf_ensure_uri_scheme(const gchar *text, gboolean try_file)
  9. {
  10. const gchar *fallback = "about:blank";
  11. if(g_strcmp0(text, "") <= 0) return fallback;
  12. if(g_uri_parse_scheme(text)) return text;
  13. if(try_file && (access(text, R_OK) == 0)) return g_strdup_printf("file://%s", text);
  14. return g_strdup_printf("http://%s", text);
  15. }