diff options
author | Jan-Michael Brummer <jan.brummer@tabos.org> | 2023-02-09 16:18:55 +0100 |
---|---|---|
committer | Jan-Michael Brummer <jan.brummer@tabos.org> | 2023-03-27 16:31:58 +0200 |
commit | 50464aa1d159e1804dbbb3891f206f8b84713c5f (patch) | |
tree | 55845a947c2a657df3ba7ad0d86e26767c82297d | |
parent | d7974aa73fe21a3f79ce715ca038e13c06d4bd58 (diff) | |
download | libproxy-git-50464aa1d159e1804dbbb3891f206f8b84713c5f.tar.gz |
Make use of curl only (#54)
Simplify libproxy and allow only one download lib: curl.
-rw-r--r-- | meson.build | 4 | ||||
-rw-r--r-- | meson_options.txt | 14 | ||||
-rw-r--r-- | src/backend/meson.build | 3 | ||||
-rw-r--r-- | src/backend/plugins/download-curl/download-curl.c | 116 | ||||
-rw-r--r-- | src/backend/plugins/download-curl/download-curl.h | 34 | ||||
-rw-r--r-- | src/backend/plugins/download-curl/download-curl.plugin | 3 | ||||
-rw-r--r-- | src/backend/plugins/download-curl/meson.build | 34 | ||||
-rw-r--r-- | src/backend/plugins/download-soup/download-soup.c | 89 | ||||
-rw-r--r-- | src/backend/plugins/download-soup/download-soup.h | 34 | ||||
-rw-r--r-- | src/backend/plugins/download-soup/download-soup.plugin | 3 | ||||
-rw-r--r-- | src/backend/plugins/download-soup/meson.build | 34 | ||||
-rw-r--r-- | src/backend/plugins/meson.build | 5 | ||||
-rw-r--r-- | src/backend/px-manager.c | 66 | ||||
-rw-r--r-- | src/backend/px-plugin-download.c | 30 | ||||
-rw-r--r-- | src/backend/px-plugin-download.h | 39 |
15 files changed, 44 insertions, 464 deletions
diff --git a/meson.build b/meson.build index 4a17bfe..52510a8 100644 --- a/meson.build +++ b/meson.build @@ -109,8 +109,8 @@ endif glib_dep = dependency('glib-2.0', version: '>= 2.71.3') gio_dep = dependency('gio-2.0', version: '>= 2.71.3') peas_dep = dependency('libpeas-1.0') -soup_dep = dependency('libsoup-3.0', required: get_option('download-soup')) -curl_dep = dependency('libcurl', required: get_option('download-curl')) +soup_dep = dependency('libsoup-3.0', required: get_option('tests')) +curl_dep = dependency('libcurl') ws2_32_dep = cc.find_library('ws2_32', required : with_platform_windows) gsettings_desktop_schema = dependency('gsettings-desktop-schemas', required: get_option('config-gnome')) diff --git a/meson_options.txt b/meson_options.txt index 89d05e1..8e703d7 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -66,18 +66,4 @@ option( type: 'boolean', value: true, description: 'Whether to build plugin for PAC Runner Duktape' -) - -option( - 'download-soup', - type: 'boolean', - value: true, - description: 'Whether to build plugin for downloading with SOUP' -) - -option( - 'download-curl', - type: 'boolean', - value: true, - description: 'Whether to build plugin for downloading with cURL' )
\ No newline at end of file diff --git a/src/backend/meson.build b/src/backend/meson.build index bdca0f1..4a9a1ab 100644 --- a/src/backend/meson.build +++ b/src/backend/meson.build @@ -7,11 +7,10 @@ px_backend_sources = [ 'px-plugin-config.h', 'px-plugin-pacrunner.c', 'px-plugin-pacrunner.h', - 'px-plugin-download.c', - 'px-plugin-download.h', ] px_backend_deps = [ + curl_dep, gio_dep, glib_dep, peas_dep, diff --git a/src/backend/plugins/download-curl/download-curl.c b/src/backend/plugins/download-curl/download-curl.c deleted file mode 100644 index d26d62b..0000000 --- a/src/backend/plugins/download-curl/download-curl.c +++ /dev/null @@ -1,116 +0,0 @@ -/* download-curl.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 <libpeas/peas.h> -#include <curl/curl.h> - -#include "download-curl.h" - -#include "px-plugin-download.h" -#include "px-manager.h" - -static void px_download_iface_init (PxDownloadInterface *iface); -G_MODULE_EXPORT void peas_register_types (PeasObjectModule *module); - -struct _PxDownloadCurl { - GObject parent_instance; - CURL *curl; -}; - -G_DEFINE_FINAL_TYPE_WITH_CODE (PxDownloadCurl, - px_download_curl, - G_TYPE_OBJECT, - G_IMPLEMENT_INTERFACE (PX_TYPE_DOWNLOAD, px_download_iface_init)) - -static void -px_download_curl_init (PxDownloadCurl *self) -{ -} - -static void -px_download_curl_class_init (PxDownloadCurlClass *klass) -{ -} - -static size_t -store_data (void *contents, - size_t size, - size_t nmemb, - void *user_pointer) -{ - GByteArray *byte_array = user_pointer; - size_t real_size = size * nmemb; - - g_byte_array_append (byte_array, contents, real_size); - - return real_size; -} - -static GBytes * -px_download_curl_download (PxDownload *download, - const char *uri) -{ - PxDownloadCurl *self = PX_DOWNLOAD_CURL (download); - GByteArray *byte_array = g_byte_array_new (); - CURLcode res; - const char *url = uri; - - if (!self->curl) - self->curl = curl_easy_init (); - - if (!self->curl) - return NULL; - - if (g_str_has_prefix (url, "pac+")) - url += 4; - - curl_easy_setopt (self->curl, CURLOPT_NOSIGNAL, 1); - curl_easy_setopt (self->curl, CURLOPT_FOLLOWLOCATION, 1); - curl_easy_setopt (self->curl, CURLOPT_NOPROXY, "*"); - curl_easy_setopt (self->curl, CURLOPT_CONNECTTIMEOUT, 30); - curl_easy_setopt (self->curl, CURLOPT_USERAGENT, "libproxy"); - - curl_easy_setopt (self->curl, CURLOPT_URL, url); - curl_easy_setopt (self->curl, CURLOPT_WRITEFUNCTION, store_data); - curl_easy_setopt (self->curl, CURLOPT_WRITEDATA, byte_array); - - res = curl_easy_perform (self->curl); - if (res != CURLE_OK) { - g_debug ("%s: Could not download data: %s", __FUNCTION__, curl_easy_strerror (res)); - return NULL; - } - - return g_byte_array_free_to_bytes (byte_array); -} - -static void -px_download_iface_init (PxDownloadInterface *iface) -{ - iface->download = px_download_curl_download; -} - -G_MODULE_EXPORT void -peas_register_types (PeasObjectModule *module) -{ - peas_object_module_register_extension_type (module, - PX_TYPE_DOWNLOAD, - PX_DOWNLOAD_TYPE_CURL); -} diff --git a/src/backend/plugins/download-curl/download-curl.h b/src/backend/plugins/download-curl/download-curl.h deleted file mode 100644 index 545222c..0000000 --- a/src/backend/plugins/download-curl/download-curl.h +++ /dev/null @@ -1,34 +0,0 @@ -/* download-curl.h - * - * 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 - */ - -#pragma once - -#include <glib.h> - -G_BEGIN_DECLS - -#define PX_DOWNLOAD_TYPE_CURL (px_download_curl_get_type ()) - -G_DECLARE_FINAL_TYPE (PxDownloadCurl, px_download_curl, PX, DOWNLOAD_CURL, GObject) - -G_END_DECLS - - diff --git a/src/backend/plugins/download-curl/download-curl.plugin b/src/backend/plugins/download-curl/download-curl.plugin deleted file mode 100644 index 1b10a83..0000000 --- a/src/backend/plugins/download-curl/download-curl.plugin +++ /dev/null @@ -1,3 +0,0 @@ -[Plugin] -Module=download-curl -Name=cURL
\ No newline at end of file diff --git a/src/backend/plugins/download-curl/meson.build b/src/backend/plugins/download-curl/meson.build deleted file mode 100644 index a1d8736..0000000 --- a/src/backend/plugins/download-curl/meson.build +++ /dev/null @@ -1,34 +0,0 @@ -plugin_name = 'download-curl' - -if get_option(plugin_name) - -plugin_src = [ - '@0@.c'.format(plugin_name), -] - -plugin_data = [ - '@0@.plugin'.format(plugin_name), -] - -plugin_lib = shared_module( - plugin_name, - sources: plugin_src, - include_directories: px_backend_inc, - c_args: px_backend_c_args, - dependencies: [px_backend_dep, curl_dep], - install_dir: join_paths(px_plugins_dir, plugin_name), - install: true, - name_suffix: module_suffix, -) - -# Starting with Meson 0.64 this can be replaced with fs.copyfile -custom_target( - '@0@-data'.format(plugin_name), - input: plugin_data, - output: plugin_data, - command: ['cp', '@INPUT@', '@OUTDIR@'], - install_dir: join_paths(px_plugins_dir, plugin_name), - install: true, -) - -endif
\ No newline at end of file diff --git a/src/backend/plugins/download-soup/download-soup.c b/src/backend/plugins/download-soup/download-soup.c deleted file mode 100644 index 4b4aa42..0000000 --- a/src/backend/plugins/download-soup/download-soup.c +++ /dev/null @@ -1,89 +0,0 @@ -/* download-soup.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 <libpeas/peas.h> -#include <libsoup/soup.h> - -#include "download-soup.h" - -#include "px-plugin-download.h" -#include "px-manager.h" - -static void px_download_iface_init (PxDownloadInterface *iface); -G_MODULE_EXPORT void peas_register_types (PeasObjectModule *module); - -struct _PxDownloadSoup { - GObject parent_instance; - - SoupSession *session; -}; - -G_DEFINE_FINAL_TYPE_WITH_CODE (PxDownloadSoup, - px_download_soup, - G_TYPE_OBJECT, - G_IMPLEMENT_INTERFACE (PX_TYPE_DOWNLOAD, px_download_iface_init)) - -static void -px_download_soup_init (PxDownloadSoup *self) -{ - self->session = soup_session_new (); -} - -static void -px_download_soup_class_init (PxDownloadSoupClass *klass) -{ -} - -static GBytes * -px_download_soup_download (PxDownload *download, - const char *uri) -{ - PxDownloadSoup *self = PX_DOWNLOAD_SOUP (download); - g_autoptr (SoupMessage) msg = soup_message_new (SOUP_METHOD_GET, uri); - g_autoptr (GError) error = NULL; - g_autoptr (GBytes) bytes = NULL; - - bytes = soup_session_send_and_read ( - self->session, - msg, - NULL, /* Pass a GCancellable here if you want to cancel a download */ - &error); - if (!bytes || soup_message_get_status (msg) != SOUP_STATUS_OK) { - g_debug ("%s: Failed to download: %s", __FUNCTION__, error ? error->message : ""); - return NULL; - } - - return g_steal_pointer (&bytes); -} - -static void -px_download_iface_init (PxDownloadInterface *iface) -{ - iface->download = px_download_soup_download; -} - -G_MODULE_EXPORT void -peas_register_types (PeasObjectModule *module) -{ - peas_object_module_register_extension_type (module, - PX_TYPE_DOWNLOAD, - PX_DOWNLOAD_TYPE_SOUP); -} diff --git a/src/backend/plugins/download-soup/download-soup.h b/src/backend/plugins/download-soup/download-soup.h deleted file mode 100644 index fa95c46..0000000 --- a/src/backend/plugins/download-soup/download-soup.h +++ /dev/null @@ -1,34 +0,0 @@ -/* download-soup.h - * - * 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 - */ - -#pragma once - -#include <glib.h> - -G_BEGIN_DECLS - -#define PX_DOWNLOAD_TYPE_SOUP (px_download_soup_get_type ()) - -G_DECLARE_FINAL_TYPE (PxDownloadSoup, px_download_soup, PX, DOWNLOAD_SOUP, GObject) - -G_END_DECLS - - diff --git a/src/backend/plugins/download-soup/download-soup.plugin b/src/backend/plugins/download-soup/download-soup.plugin deleted file mode 100644 index 294b957..0000000 --- a/src/backend/plugins/download-soup/download-soup.plugin +++ /dev/null @@ -1,3 +0,0 @@ -[Plugin] -Module=download-soup -Name=SOUP
\ No newline at end of file diff --git a/src/backend/plugins/download-soup/meson.build b/src/backend/plugins/download-soup/meson.build deleted file mode 100644 index db61aba..0000000 --- a/src/backend/plugins/download-soup/meson.build +++ /dev/null @@ -1,34 +0,0 @@ -plugin_name = 'download-soup' - -if get_option(plugin_name) - -plugin_src = [ - '@0@.c'.format(plugin_name), -] - -plugin_data = [ - '@0@.plugin'.format(plugin_name), -] - -plugin_lib = shared_module( - plugin_name, - sources: plugin_src, - include_directories: px_backend_inc, - c_args: px_backend_c_args, - dependencies: [px_backend_dep, soup_dep], - install_dir: join_paths(px_plugins_dir, plugin_name), - install: true, - name_suffix: module_suffix, -) - -# Starting with Meson 0.64 this can be replaced with fs.copyfile -custom_target( - '@0@-data'.format(plugin_name), - input: plugin_data, - output: plugin_data, - command: ['cp', '@INPUT@', '@OUTDIR@'], - install_dir: join_paths(px_plugins_dir, plugin_name), - install: true, -) - -endif
\ No newline at end of file diff --git a/src/backend/plugins/meson.build b/src/backend/plugins/meson.build index 09344f0..c7943d2 100644 --- a/src/backend/plugins/meson.build +++ b/src/backend/plugins/meson.build @@ -5,9 +5,6 @@ subdir('config-osx') subdir('config-sysconfig') subdir('config-windows') -subdir('download-curl') -subdir('download-soup') - subdir('pacrunner-duktape') summary({ @@ -17,7 +14,5 @@ summary({ 'Configuration Windows ' : get_option('config-windows'), 'Configuration sysconfig ' : get_option('config-sysconfig'), 'Configuration OS X ' : get_option('config-osx'), - 'Download cURL ' : get_option('download-curl'), - 'Download Soup ' : get_option('download-soup'), 'PAC Runner Duktape ' : get_option('pacrunner-duktape'), }, section: 'Plugins')
\ No newline at end of file diff --git a/src/backend/px-manager.c b/src/backend/px-manager.c index 6c63e93..223cf88 100644 --- a/src/backend/px-manager.c +++ b/src/backend/px-manager.c @@ -24,8 +24,8 @@ #include "px-manager.h" #include "px-plugin-config.h" #include "px-plugin-pacrunner.h" -#include "px-plugin-download.h" +#include <curl/curl.h> #include <libpeas/peas.h> enum { @@ -49,8 +49,8 @@ struct _PxManager { PeasEngine *engine; PeasExtensionSet *config_set; PeasExtensionSet *pacrunner_set; - PeasExtensionSet *download_set; GNetworkMonitor *network_monitor; + CURL *curl; char *plugins_dir; GCancellable *cancellable; @@ -108,7 +108,6 @@ px_manager_constructed (GObject *object) self->config_set = peas_extension_set_new (self->engine, PX_TYPE_CONFIG, NULL); self->pacrunner_set = peas_extension_set_new (self->engine, PX_TYPE_PACRUNNER, NULL); - self->download_set = peas_extension_set_new (self->engine, PX_TYPE_DOWNLOAD, NULL); list = peas_engine_get_plugin_list (self->engine); for (; list && list->data; list = list->next) { @@ -249,24 +248,18 @@ px_manager_new (void) return g_object_new (PX_TYPE_MANAGER, "plugins-dir", PX_PLUGINS_DIR, NULL); } -struct DownloadData { - const char *uri; - GBytes *bytes; - GError **error; -}; - -static void -download_pac (PeasExtensionSet *set, - PeasPluginInfo *info, - PeasExtension *extension, - gpointer data) +static size_t +store_data (void *contents, + size_t size, + size_t nmemb, + void *user_pointer) { - PxDownloadInterface *ifc = PX_DOWNLOAD_GET_IFACE (extension); - struct DownloadData *download_data = data; + GByteArray *byte_array = user_pointer; + size_t real_size = size * nmemb; + + g_byte_array_append (byte_array, contents, real_size); - g_debug ("%s: Download PAC '%s' using plugin '%s'", __FUNCTION__, download_data->uri, peas_plugin_info_get_module_name (info)); - if (!download_data->bytes) - download_data->bytes = ifc->download (PX_DOWNLOAD (extension), download_data->uri); + return real_size; } /** @@ -282,13 +275,36 @@ GBytes * px_manager_pac_download (PxManager *self, const char *uri) { - struct DownloadData download_data = { - .uri = uri, - .bytes = NULL, - }; + GByteArray *byte_array = g_byte_array_new (); + CURLcode res; + const char *url = uri; + + if (!self->curl) + self->curl = curl_easy_init (); + + if (!self->curl) + return NULL; + + if (g_str_has_prefix (url, "pac+")) + url += 4; + + curl_easy_setopt (self->curl, CURLOPT_NOSIGNAL, 1); + curl_easy_setopt (self->curl, CURLOPT_FOLLOWLOCATION, 1); + curl_easy_setopt (self->curl, CURLOPT_NOPROXY, "*"); + curl_easy_setopt (self->curl, CURLOPT_CONNECTTIMEOUT, 30); + curl_easy_setopt (self->curl, CURLOPT_USERAGENT, "libproxy"); + + curl_easy_setopt (self->curl, CURLOPT_URL, url); + curl_easy_setopt (self->curl, CURLOPT_WRITEFUNCTION, store_data); + curl_easy_setopt (self->curl, CURLOPT_WRITEDATA, byte_array); + + res = curl_easy_perform (self->curl); + if (res != CURLE_OK) { + g_debug ("%s: Could not download data: %s", __FUNCTION__, curl_easy_strerror (res)); + return NULL; + } - peas_extension_set_foreach (self->download_set, download_pac, &download_data); - return download_data.bytes; + return g_byte_array_free_to_bytes (byte_array); } struct ConfigData { diff --git a/src/backend/px-plugin-download.c b/src/backend/px-plugin-download.c deleted file mode 100644 index c552217..0000000 --- a/src/backend/px-plugin-download.c +++ /dev/null @@ -1,30 +0,0 @@ -/* px-plugin-download.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-plugin-download.h" - -G_DEFINE_INTERFACE (PxDownload, px_download, G_TYPE_OBJECT) - -static void -px_download_default_init (PxDownloadInterface *iface) -{ -} diff --git a/src/backend/px-plugin-download.h b/src/backend/px-plugin-download.h deleted file mode 100644 index f37c565..0000000 --- a/src/backend/px-plugin-download.h +++ /dev/null @@ -1,39 +0,0 @@ -/* px-plugin-download.h - * - * Copyright 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 - */ - -#pragma once - -#include <glib-object.h> - -G_BEGIN_DECLS - -#define PX_TYPE_DOWNLOAD (px_download_get_type ()) - -G_DECLARE_INTERFACE (PxDownload, px_download, PX, DOWNLOAD, GObject) - -struct _PxDownloadInterface -{ - GTypeInterface parent_iface; - - GBytes *(*download)(PxDownload *download, const char *uri); -}; - -G_END_DECLS |