From 9fe4353b46f298a65b2674e09a465b19bac1a4b5 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Sun, 3 Oct 2021 09:45:30 +0200 Subject: Fallback to libsoup2 for systems with glib-2.0 <2.66.0 This is the case on Ubuntu 20.04 for example. --- badwolf.c | 13 +++++++++++++ configure | 43 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/badwolf.c b/badwolf.c index a0a7d09..4c5a481 100644 --- a/badwolf.c +++ b/badwolf.c @@ -440,7 +440,11 @@ WebViewCb_load_failed_with_tls_errors(WebKitWebView *web_view, gchar *error_details = detail_tls_certificate_flags(errors); gint dialog_response; +#ifndef USE_LIBSOUP2 GUri *failing_uri = g_uri_parse(failing_text, G_URI_FLAGS_NONE, NULL); +#else + SoupURI *failing_uri = soup_uri_new(failing_text); +#endif GtkWidget *dialog = gtk_message_dialog_new(GTK_WINDOW(browser->window->main_window), GTK_DIALOG_MODAL & GTK_DIALOG_DESTROY_WITH_PARENT, @@ -461,12 +465,21 @@ WebViewCb_load_failed_with_tls_errors(WebKitWebView *web_view, if(dialog_response == 1) { +#ifndef USE_LIBSOUP2 webkit_web_context_allow_tls_certificate_for_host( webkit_web_view_get_context(browser->webView), certificate, g_uri_get_host(failing_uri)); +#else + webkit_web_context_allow_tls_certificate_for_host( + webkit_web_view_get_context(browser->webView), certificate, failing_uri->host); +#endif webkit_web_view_reload(browser->webView); } +#ifndef USE_LIBSOUP2 g_free(failing_uri); +#else + soup_uri_free(failing_uri); +#endif g_free(error_details); gtk_widget_destroy(dialog); diff --git a/configure b/configure index 3776bfa..bfb04b8 100755 --- a/configure +++ b/configure @@ -69,7 +69,7 @@ case "${WITH_WEBKITGTK}n" in DEPS="${DEPS} webkit2gtk-4.0" ;; n) - echo "warning: Packagers should specify the ABI version (4.0 or 4.1) in WITH_WEBKITGTK" >&2 + echo "notice: Packagers should consider setting the ABI version (4.0 or 4.1) in WITH_WEBKITGTK" >&2 if pkg_config_check --atleast-version=2.32.0 webkit2gtk-4.1 then DEPS="${DEPS} webkit2gtk-4.1" @@ -84,6 +84,47 @@ case "${WITH_WEBKITGTK}n" in ;; esac +case "${WITH_URI_PARSER}n" in + gurin) + echo "URI parser selected: GUri from glib-2.0" + pkg_config_check --atleast-version=2.66.0 glib-2.0 || exit 1 + DEPS="${DEPS} glib-2.0" + ;; + libsoup2n) + echo "URI parser selected: libsoup-2.4" + pkg_config_check libsoup-2.4 || exit 1 + DEPS="${DEPS} libsoup-2.4" + CFLAGS="${CFLAGS} -DUSE_LIBSOUP2" + + if echo "${DEPS}" | grep -q 'webkit2gtk-4.1' + then + echo 'warning: libsoup2 selected while WebKitGTK with libsoup3 API is used' >&2 + fi + ;; + n) + echo "notice: Packagers should consider setting the URI parsing library (guri or libsoup2) in WITH_URI_PARSER" >&2 + + if pkg_config_check --atleast-version=2.66.0 glib-2.0 + then + echo "URI parser selected: GUri from glib-2.0" + DEPS="${DEPS} glib-2.0" + else + pkg_config_check libsoup-2.4 || exit 1 + echo "URI parser selected: libsoup-2.4" + DEPS="${DEPS} libsoup-2.4" + CFLAGS="${CFLAGS} -DUSE_LIBSOUP2" + + if echo "${DEPS}" | grep -q 'webkit2gtk-4.1' + then + echo 'warning: libsoup2 selected while WebKitGTK with libsoup3 API is used' >&2 + fi + fi + ;; + *) + echo "error: invalid uri provider in WITH_URI_PARSER environment variable, must be guri or libsoup2" >&2 + ;; +esac + get_cflags() { "${PKGCONFIG}" --cflags "${DEPS}"; } DEPS_cflags="$(get_cflags)" get_libs() { "${PKGCONFIG}" --libs "${DEPS}"; } -- cgit v1.3.1-23-gd82d From eb30931ddcdfb63ef660d36e984a64ee02b5be5c Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Mon, 1 Nov 2021 13:18:54 +0100 Subject: Use g_uri_unref instead of g_free on g_uri_parse --- badwolf.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/badwolf.c b/badwolf.c index 4c5a481..8578404 100644 --- a/badwolf.c +++ b/badwolf.c @@ -476,7 +476,16 @@ WebViewCb_load_failed_with_tls_errors(WebKitWebView *web_view, } #ifndef USE_LIBSOUP2 - g_free(failing_uri); + /* Calling g_free(failing_uri) ought to be the correct way but this causes a segfault. + * + * - documentation describes it as something which should be free + * - implementation seems to make it a pointer that should be freed + * - epiphany doesn't seems to free/unref it but gnome code seems to frequently have memleaks + * + * Decided to at least continue to try with using g_uri_unref(failing_uri) instead. + * Related fediverse post: + */ + g_uri_unref(failing_uri); #else soup_uri_free(failing_uri); #endif -- cgit v1.3.1-23-gd82d From 1815d7a01c07f2cc69f406e343005e3e93c80123 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Mon, 1 Nov 2021 13:17:34 +0100 Subject: configure: Pick libsoup2 instead of GUri with webkit2gtk-4.0 As seen in the parent commit GUri seems rather unwieldy regarding memory management. Related: https://queer.hacktivis.me/objects/cec7c4e8-6a58-4358-85bf-b66f9bb21a98 --- configure | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/configure b/configure index bfb04b8..7f52579 100755 --- a/configure +++ b/configure @@ -104,20 +104,16 @@ case "${WITH_URI_PARSER}n" in n) echo "notice: Packagers should consider setting the URI parsing library (guri or libsoup2) in WITH_URI_PARSER" >&2 - if pkg_config_check --atleast-version=2.66.0 glib-2.0 + if echo "${DEPS}" | grep -q 'webkit2gtk-4.0' then - echo "URI parser selected: GUri from glib-2.0" - DEPS="${DEPS} glib-2.0" - else pkg_config_check libsoup-2.4 || exit 1 echo "URI parser selected: libsoup-2.4" DEPS="${DEPS} libsoup-2.4" CFLAGS="${CFLAGS} -DUSE_LIBSOUP2" - - if echo "${DEPS}" | grep -q 'webkit2gtk-4.1' - then - echo 'warning: libsoup2 selected while WebKitGTK with libsoup3 API is used' >&2 - fi + else + pkg_config_check --atleast-version="${min_glib_guri}" glib-2.0 || exit 1 + echo "URI parser selected: GUri from glib-2.0" + DEPS="${DEPS} glib-2.0" fi ;; *) -- cgit v1.3.1-23-gd82d