From 3604dc5aa5d623740263dd077f5b7d209cf1d486 Mon Sep 17 00:00:00 2001 From: Jan-Michael Brummer Date: Wed, 29 Mar 2023 17:15:33 +0200 Subject: Remove d-bus support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We tried hard to make the D-Bus service a thing, but we failed. Beside all the advantages we do have problems which couldn't be solved reliable: - Dependency impact in containers (which adds D-Bus) - Environment Variables couldn't be used anymore - Two services had to be created (session/system) for users without a desktop environment - ... Alternatives like using private d-bus connections would lead to additional processes per app/lib using libproxy. Even with a timeout this looks akward. Let's remove it. ¯\_(ツ)_/¯ --- .github/workflows/build.yml | 29 +--- docs/architecture.md | 18 -- meson.build | 2 - meson_options.txt | 14 -- src/backend/dbus/dbus.c | 190 --------------------- src/backend/dbus/meson.build | 92 ---------- .../dbus/org.libproxy.proxy-system.service.in | 4 - src/backend/dbus/org.libproxy.proxy.conf.in | 28 --- src/backend/dbus/org.libproxy.proxy.service.in | 3 - src/backend/dbus/org.libproxy.proxy.xml | 16 -- src/backend/meson.build | 7 +- src/libproxy/meson.build | 29 +--- src/libproxy/proxy-dbus.c | 136 --------------- tests/meson.build | 2 +- 14 files changed, 4 insertions(+), 566 deletions(-) delete mode 100644 src/backend/dbus/dbus.c delete mode 100644 src/backend/dbus/meson.build delete mode 100644 src/backend/dbus/org.libproxy.proxy-system.service.in delete mode 100644 src/backend/dbus/org.libproxy.proxy.conf.in delete mode 100644 src/backend/dbus/org.libproxy.proxy.service.in delete mode 100644 src/backend/dbus/org.libproxy.proxy.xml delete mode 100644 src/libproxy/proxy-dbus.c diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 236a783..431ff2d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -23,7 +23,7 @@ jobs: libcurl4-openssl-dev \ valac - name: Build setup - run: meson setup build -Db_coverage=true -Ddbus=disabled + run: meson setup build -Db_coverage=true - name: Build run: ninja -C build - name: Tests and Coverage @@ -37,33 +37,6 @@ jobs: - name: CodeCov uses: codecov/codecov-action@v3 - build-linux-dbus: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: Dependencies - run: | - sudo apt-get update - sudo apt install \ - libglib2.0-dev \ - libgirepository1.0-dev \ - duktape-dev \ - libsoup-3.0-dev \ - meson \ - gcovr \ - gi-docgen \ - libpeas-dev \ - gsettings-desktop-schemas-dev \ - libcurl4-openssl-dev \ - valac - - name: Build setup - run: meson setup build -Db_coverage=true -Ddbus=enabled - - name: Build - run: ninja -C build - - name: Tests - run: | - ninja test -C build - build-osx: runs-on: macos-latest steps: diff --git a/docs/architecture.md b/docs/architecture.md index 9da4938..35c3596 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -12,22 +12,4 @@ previous versions of Libproxy. To name a few advantages: - Make use of existing plugin loader - Automatic documentation out of code - Gobject Introspection bindings for almost every programming language -- D-Bus Service -Using D-Bus as a service on Linux we can elimnate the previous ABI clashes we -have had in the past. mozjs in different versions on one system could lead to -crashes in cases where the application using libproxy favours a different mozjs -version. - -## Building Libproxy as simple library - -On non D-Bus system you still have the option to build Libproxy as a self -contained library using `-Ddbus=disabled`. In this case you can still run into -an ABI issue, but with it's current plugins it is unlikely at the moment. - -## Building Libproxy as D-Bus Service -On D-Bus system Libproxy will be build using a D-Bus service and a simple -helper library. The main logic part (previous simple library) is done in the -D-Bus service and so can never crash an application. -The application itself will be linked with the helper library which does the -necessary D-Bus calls and wait's for answer. diff --git a/meson.build b/meson.build index 924a0c7..3543d12 100644 --- a/meson.build +++ b/meson.build @@ -112,8 +112,6 @@ curl_dep = dependency('libcurl', required: get_option('curl')) ws2_32_dep = cc.find_library('ws2_32', required : with_platform_windows) gsettings_desktop_schema = dependency('gsettings-desktop-schemas', required: get_option('config-gnome')) -build_dbus = get_option('dbus').disable_auto_if(['window', 'darwin'].contains(host_system)).allowed() - config_h = configuration_data() config_h.set_quoted('PACKAGE_VERSION', meson.project_version()) config_h.set_quoted('PX_PLUGINS_DIR', px_plugins_dir) diff --git a/meson_options.txt b/meson_options.txt index 0e7a7e9..b04ed96 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -12,20 +12,6 @@ option( description: 'Whether to compile test cases for libproxy' ) -option( - 'dbus', - type: 'feature', - value: 'auto', - description: 'Whether to build D-Bus service' -) - -option( - 'dbus-system-user', - type: 'string', - value: 'libproxy', - description: 'Which user should be used on D-Bus system session' -) - option( 'config-env', type: 'boolean', diff --git a/src/backend/dbus/dbus.c b/src/backend/dbus/dbus.c deleted file mode 100644 index 0b30ccf..0000000 --- a/src/backend/dbus/dbus.c +++ /dev/null @@ -1,190 +0,0 @@ -/* dbus.c - * - * Copyright 2022-2023 The Libproxy Team - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -#include "px-manager.h" -#include "px-interface.h" - -#include - -static gboolean replace; -static gboolean use_system; - -static GApplication *app; - -const GOptionEntry options[] = { - { "replace", 'r', 0, G_OPTION_ARG_NONE, &replace, "Replace running daemon.", NULL }, - { "system", 's', 0, G_OPTION_ARG_NONE, &use_system, "Use system bus.", NULL }, - { NULL } -}; - -static void -handle_method_call (GDBusConnection *connection, - const gchar *sender, - const gchar *object_path, - const gchar *interface_name, - const gchar *method_name, - GVariant *parameters, - GDBusMethodInvocation *invocation, - gpointer user_data) -{ - PxManager *manager = PX_MANAGER (user_data); - GVariantBuilder *result; - g_auto (GStrv) proxies = NULL; - g_autoptr (GError) error = NULL; - const gchar *url; - int idx; - - g_application_hold (app); - if (g_strcmp0 (method_name, "GetProxiesFor") != 0) { - g_warning ("Invalid method name '%s', aborting.", method_name); - g_dbus_method_invocation_return_error (invocation, - PX_MANAGER_ERROR, - PX_MANAGER_ERROR_UNKNOWN_METHOD, - "Unknown method"); - g_application_release (app); - return; - } - - g_variant_get (parameters, "(&s)", &url); - - proxies = px_manager_get_proxies_sync (manager, url, &error); - if (error) { - g_warning ("Could not query proxy servers: %s", error->message); - g_dbus_method_invocation_return_gerror (invocation, error); - g_application_release (app); - return; - } - - result = g_variant_builder_new (G_VARIANT_TYPE ("as")); - if (proxies) { - for (idx = 0; proxies[idx]; idx++) { - g_variant_builder_add (result, "s", proxies[idx]); - } - } - - g_dbus_method_invocation_return_value (invocation, - g_variant_new ("(as)", result)); - g_application_release (app); -} - -static const GDBusInterfaceVTable interface_vtable = { - handle_method_call, -}; - -static void -on_bus_acquired (GDBusConnection *connection, - const gchar *name, - gpointer user_data) -{ - g_autoptr (GError) error = NULL; - PxManager *manager = NULL; - - manager = px_manager_new (); - g_dbus_connection_register_object (connection, - "/org/libproxy/proxy", - (GDBusInterfaceInfo *)&org_libproxy_proxy_interface, - &interface_vtable, - manager, - g_object_unref, - &error); - g_application_release (user_data); - - if (error) { - g_warning ("Could not register dbus object: %s", error->message); - g_application_quit (user_data); - return; - } -} - -static void -on_name_lost (GDBusConnection *connection, - const gchar *name, - gpointer user_data) -{ - if (!connection) { - g_warning ("Can't connect proxy bus"); - g_application_quit (user_data); - } else { - g_warning ("Unknown name lost error"); - g_application_quit (user_data); - } -} - -static void -activate (GApplication *application) -{ - GBusNameOwnerFlags flags; - - flags = G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT; - if (replace) - flags |= G_BUS_NAME_OWNER_FLAGS_REPLACE; - - g_bus_own_name (use_system ? G_BUS_TYPE_SYSTEM : G_BUS_TYPE_SESSION, - "org.libproxy.proxy", - flags, - on_bus_acquired, - NULL, - on_name_lost, - app, - NULL); - - g_application_hold (app); -} - -int -main (int argc, - char **argv) -{ - GOptionContext *context; - g_autoptr (GError) error = NULL; - - replace = FALSE; - use_system = FALSE; - - context = g_option_context_new (""); - g_option_context_set_summary (context, "Libproxy D-Bus Service"); - g_option_context_add_main_entries (context, options, "libproxy"); - - if (!g_option_context_parse (context, &argc, &argv, &error)) { - g_printerr ("%s: %s", g_get_application_name (), error->message); - g_printerr ("\n"); - g_printerr ("Try \"%s --help\" for more information.", - g_get_prgname ()); - g_printerr ("\n"); - g_option_context_free (context); - return 1; - } - - app = g_application_new ("org.libproxy.proxy-service", -#if GLIB_CHECK_VERSION (2, 73, 0) - G_APPLICATION_DEFAULT_FLAGS -#else - G_APPLICATION_FLAGS_NONE -#endif - ); - - g_signal_connect (app, "activate", G_CALLBACK (activate), NULL); - - /* Set application timeout to 60 seconds */ - g_application_set_inactivity_timeout (app, 60000); - - return g_application_run (app, argc, argv); -} diff --git a/src/backend/dbus/meson.build b/src/backend/dbus/meson.build deleted file mode 100644 index 107e401..0000000 --- a/src/backend/dbus/meson.build +++ /dev/null @@ -1,92 +0,0 @@ -if build_dbus - gdbus_codegen = find_program('gdbus-codegen') - - unitdir = '' - dbus_data_dir = join_paths(get_option('prefix'), get_option('datadir'), 'dbus-1') - dbus_interfaces_dir = join_paths(dbus_data_dir, 'interfaces') - dbus_user_services_dir = join_paths(dbus_data_dir, 'services') - dbus_system_services_dir = join_paths(dbus_data_dir, 'system-services') - dbus_system_conf_dir = join_paths(dbus_data_dir, 'system.d') - - px_interface = [ - 'org.libproxy.proxy.xml' - ] - - px_interface_h = custom_target( - 'px-interface.h', - input: px_interface, - output: ['px-interface.h'], - command: [ - gdbus_codegen, - '--interface-info-header', - '--output', '@OUTPUT@', - '@INPUT@' - ] - ) - - px_interface_c = custom_target( - 'libproxy-iface.c', - input: px_interface, - output: ['px-interface.c'], - command: [ - gdbus_codegen, - '--interface-info-body', - '--output', '@OUTPUT@', - '@INPUT@' - ], - ) - - proxyd_sources = [ - px_interface_c, - px_interface_h, - 'dbus.c', - ] - - proxyd_deps = [ - px_backend_dep - ] - - executable( - 'proxyd', - proxyd_sources, - c_args: px_backend_c_args, - dependencies: proxyd_deps, - install_dir: join_paths(px_prefix, get_option('libexecdir')), - install: true, - ) - - # D-Bus Interface - install_data('org.libproxy.proxy.xml', install_dir : dbus_interfaces_dir) - - # D-Bus User Service - user_service_data = configuration_data() - user_service_data.set('LIBEXECDIR', join_paths(px_prefix, get_option('libexecdir'))) - configure_file( - input: 'org.libproxy.proxy.service.in', - output: 'org.libproxy.proxy.service', - configuration: user_service_data, - install: true, - install_dir: dbus_user_services_dir - ) - - # D-Bus System Service - system_service_data = configuration_data() - system_service_data.set('LIBEXECDIR', join_paths(px_prefix, get_option('libexecdir'))) - system_service_data.set('USER', get_option('dbus-system-user')) - dbus_system_service = configure_file( - input: 'org.libproxy.proxy-system.service.in', - output: 'org.libproxy.proxy-system.service', - configuration: system_service_data - ) - install_data(dbus_system_service, rename : 'org.libproxy.proxy.service', install_dir : dbus_system_services_dir) - - dbus_config_data = configuration_data() - dbus_config_data.set('daemon_user', get_option('dbus-system-user')) - configure_file( - input: 'org.libproxy.proxy.conf.in', - output: 'org.libproxy.proxy.conf', - configuration: dbus_config_data, - install: true, - install_dir: dbus_system_conf_dir - ) -endif diff --git a/src/backend/dbus/org.libproxy.proxy-system.service.in b/src/backend/dbus/org.libproxy.proxy-system.service.in deleted file mode 100644 index 2af960b..0000000 --- a/src/backend/dbus/org.libproxy.proxy-system.service.in +++ /dev/null @@ -1,4 +0,0 @@ -[D-BUS Service] -Name=org.libproxy.proxy -Exec=@LIBEXECDIR@/proxyd --system -User=@USER@ diff --git a/src/backend/dbus/org.libproxy.proxy.conf.in b/src/backend/dbus/org.libproxy.proxy.conf.in deleted file mode 100644 index daa79f5..0000000 --- a/src/backend/dbus/org.libproxy.proxy.conf.in +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/backend/dbus/org.libproxy.proxy.service.in b/src/backend/dbus/org.libproxy.proxy.service.in deleted file mode 100644 index d1ac5f4..0000000 --- a/src/backend/dbus/org.libproxy.proxy.service.in +++ /dev/null @@ -1,3 +0,0 @@ -[D-BUS Service] -Name=org.libproxy.proxy -Exec=@LIBEXECDIR@/proxyd diff --git a/src/backend/dbus/org.libproxy.proxy.xml b/src/backend/dbus/org.libproxy.proxy.xml deleted file mode 100644 index bba9251..0000000 --- a/src/backend/dbus/org.libproxy.proxy.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - Get proxy servers for given url. - - - - - - diff --git a/src/backend/meson.build b/src/backend/meson.build index b0b8de9..b25453a 100644 --- a/src/backend/meson.build +++ b/src/backend/meson.build @@ -34,9 +34,4 @@ px_backend_dep = declare_dependency( dependencies: px_backend_deps ) -subdir('dbus') -subdir('plugins') - -summary({ - 'D-Bus Service' : build_dbus, -}, section: 'Architecture') \ No newline at end of file +subdir('plugins') \ No newline at end of file diff --git a/src/libproxy/meson.build b/src/libproxy/meson.build index ce50e85..3a9aa87 100644 --- a/src/libproxy/meson.build +++ b/src/libproxy/meson.build @@ -2,20 +2,10 @@ libproxy_inc = include_directories('.') libproxy_sources = [] -libproxy_dbus_sources = [ - 'proxy-dbus.c', -] - -libproxy_non_dbus_sources = [ +libproxy_sources = [ 'proxy.c', ] -if build_dbus - libproxy_sources += libproxy_dbus_sources -else - libproxy_sources += libproxy_non_dbus_sources -endif - libproxy_headers = [ 'proxy.h', ] @@ -48,23 +38,6 @@ libproxy_dep = declare_dependency ( dependencies: libproxy_deps ) -libproxy_test = shared_library( - 'proxy_test', - libproxy_non_dbus_sources, - include_directories: px_backend_inc, - dependencies: libproxy_deps, - link_args : vflag, - link_depends : mapfile, - soversion: '1', - install: false, -) - -libproxy_test_dep = declare_dependency ( - include_directories: libproxy_inc, - link_with: libproxy_test, - dependencies: libproxy_deps -) - install_headers(libproxy_headers, subdir: 'libproxy') pkg = import('pkgconfig') diff --git a/src/libproxy/proxy-dbus.c b/src/libproxy/proxy-dbus.c deleted file mode 100644 index fe03789..0000000 --- a/src/libproxy/proxy-dbus.c +++ /dev/null @@ -1,136 +0,0 @@ -/* proxy-dbus.c - * - * Copyright 2022-2023 The Libproxy Team - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * SPDX-License-Identifier: LGPL-2.1-or-later - */ - -#include - -#include "proxy.h" - -struct _pxProxyFactory { - GDBusConnection *connection; - GCancellable *cancellable; -}; - -pxProxyFactory *px_proxy_factory_copy (pxProxyFactory *self); - -G_DEFINE_BOXED_TYPE (pxProxyFactory, - px_proxy_factory, - (GBoxedCopyFunc)px_proxy_factory_copy, - (GFreeFunc)px_proxy_factory_new); - -pxProxyFactory * -px_proxy_factory_copy (pxProxyFactory *self) -{ - return g_memdup2 (self, sizeof (pxProxyFactory)); -} - -pxProxyFactory * -px_proxy_factory_new (void) -{ - g_autoptr (GError) error = NULL; - pxProxyFactory *self = g_new0 (pxProxyFactory, 1); - - self->cancellable = g_cancellable_new (); - - self->connection = g_bus_get_sync (G_BUS_TYPE_SESSION, self->cancellable, &error); - if (!self->connection) { - g_clear_error (&error); - self->connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, self->cancellable, &error); - } - - if (!self->connection) - g_warning ("Could not create dbus connection: %s", error->message); - - return self; -} - -char ** -px_proxy_factory_get_proxies (pxProxyFactory *self, - const char *url) -{ - g_autoptr (GError) error = NULL; - g_autoptr (GVariantIter) iter = NULL; - g_autoptr (GList) list = NULL; - g_autoptr (GDBusMessage) msg = NULL; - g_autoptr (GDBusMessage) reply = NULL; - GVariant *result; - GList *tmp; - char *str; - char **retval; - gsize len; - gsize idx; - - if (!self->connection) - return NULL; - - msg = g_dbus_message_new_method_call ("org.libproxy.proxy", - "/org/libproxy/proxy", - "org.libproxy.proxy", - "GetProxiesFor"); - - g_dbus_message_set_body (msg, g_variant_new ("(s)", url)); - - reply = g_dbus_connection_send_message_with_reply_sync (self->connection, msg, G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1, NULL, self->cancellable, &error); - if (!reply) { - g_warning ("Could not query proxy: %s", error->message); - return NULL; - } - - if (g_dbus_message_get_message_type (reply) != G_DBUS_MESSAGE_TYPE_METHOD_RETURN) - return NULL; - - result = g_dbus_message_get_body (reply); - g_variant_get (result, "(as)", &iter); - - while (g_variant_iter_loop (iter, "&s", &str)) { - list = g_list_prepend (list, str); - } - - len = g_list_length (list); - if (len == 0) { - retval = g_malloc0 (sizeof (char *) * 2); - retval[0] = g_strdup ("direct://"); - - return retval; - } - - retval = g_malloc0_n (len + 1, sizeof (char *)); - for (tmp = list, idx = 0; tmp && tmp->data; tmp = tmp->next, idx++) { - char *value = tmp->data; - retval[idx] = g_strdup (value); - } - - return retval; -} - -void -px_proxy_factory_free_proxies (char **proxies) -{ - g_clear_pointer (&proxies, g_strfreev); -} - -void -px_proxy_factory_free (pxProxyFactory *self) -{ - g_cancellable_cancel (self->cancellable); - g_clear_object (&self->cancellable); - g_clear_object (&self->connection); - g_clear_pointer (&self, g_free); -} diff --git a/tests/meson.build b/tests/meson.build index cd268f2..b5ca084 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -10,7 +10,7 @@ if get_option('tests') libproxy_test = executable('test-libproxy', ['libproxy-test.c'], include_directories: libproxy_inc, - dependencies: [libproxy_test_dep], + dependencies: [libproxy_dep], ) test('Libproxy test', libproxy_test, -- cgit v1.2.1