From c15ba89112efd780f8434c605fcb216aed355bd9 Mon Sep 17 00:00:00 2001 From: Soumya Ranjan Patnaik Date: Sun, 31 Dec 2023 19:52:01 +0530 Subject: [PATCH] portal-impl: fallback implementation is used if preferred value is none Don't use fallback portal implementations in the following cases: - the preferred portals for an interface contains `none` - no preference is set for the interface but the default preference contains `none` --- src/portal-impl.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/src/portal-impl.c b/src/portal-impl.c index 85b3a23f0..f2bbda203 100644 --- a/src/portal-impl.c +++ b/src/portal-impl.c @@ -488,6 +488,51 @@ load_portal_configuration (gboolean opt_verbose) return; } +PortalInterface * +find_matching_iface_config (const char *interface) +{ + if (config == NULL) + return NULL; + + for (size_t i = 0; i < config->n_ifaces; i++) + { + PortalInterface *iface = config->interfaces[i]; + + if (g_strcmp0 (iface->dbus_name, interface) == 0) + return iface; + } + + return NULL; +} + +static gboolean +portal_default_prefers_none (void) +{ + if (config != NULL && g_strv_contains ((const char * const *) config->default_portal->portals, "none")) + { + g_debug ("Found 'none' in configuration for default"); + return TRUE; + } + + return FALSE; +} + +static gboolean +portal_interface_prefers_none (const char *interface) +{ + const PortalInterface *iface = find_matching_iface_config (interface); + if (iface == NULL) + return portal_default_prefers_none (); + + if (g_strv_contains ((const char * const *) iface->portals, "none")) + { + g_debug ("Found 'none' in configuration for %s", iface->dbus_name); + return TRUE; + } + + return FALSE; +} + static gboolean portal_impl_name_matches (const PortalImplementation *impl, const PortalInterface *iface) @@ -507,7 +552,7 @@ portal_impl_name_matches (const PortalImplementation *impl, } /* No portal */ - if (g_strv_contains ((const char * const *) iface->portals, "none")) + if (portal_interface_prefers_none (iface->dbus_name)) { g_debug ("Found 'none' in configuration for %s", iface->dbus_name); return FALSE; @@ -555,6 +600,9 @@ find_portal_implementation (const char *interface) GList *l; int i; + if (portal_interface_prefers_none (interface)) + return NULL; + for (l = implementations; l != NULL; l = l->next) { PortalImplementation *impl = l->data; @@ -625,6 +673,9 @@ find_all_portal_implementations (const char *interface) impls = g_ptr_array_new (); + if (portal_interface_prefers_none (interface)) + return impls; + for (l = implementations; l != NULL; l = l->next) { PortalImplementation *impl = l->data;