diff options
-rw-r--r-- | .github/workflows/build.yml | 9 | ||||
-rw-r--r-- | meson.build | 1 | ||||
-rw-r--r-- | meson_options.txt | 7 | ||||
-rw-r--r-- | src/backend/plugins/download-curl/download-curl.c | 99 | ||||
-rw-r--r-- | src/backend/plugins/download-curl/download-curl.h | 40 | ||||
-rw-r--r-- | src/backend/plugins/download-curl/download-curl.plugin | 6 | ||||
-rw-r--r-- | src/backend/plugins/download-curl/meson.build | 33 | ||||
-rw-r--r-- | src/backend/plugins/meson.build | 2 |
8 files changed, 194 insertions, 3 deletions
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4f40a08..f3a1bb9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -18,7 +18,8 @@ jobs: gcovr \ gi-docgen \ libpeas-dev \ - gsettings-desktop-schemas-dev + gsettings-desktop-schemas-dev \ + libcurl4-openssl-dev - name: Build setup run: meson setup build -Db_coverage=true - name: Build @@ -49,7 +50,8 @@ jobs: gcovr \ gi-docgen \ libpeas-dev \ - gsettings-desktop-schemas-dev + gsettings-desktop-schemas-dev \ + libcurl4-openssl-dev - name: Build setup run: meson setup build -Db_coverage=true -Ddbus=true - name: Build @@ -69,7 +71,7 @@ jobs: - name: Setup run: | pip install meson ninja - brew install libsoup icu4c gobject-introspection duktape gcovr gi-docgen libpeas + brew install libsoup icu4c gobject-introspection duktape gcovr gi-docgen libpeas curl echo 'PKG_CONFIG_PATH=/usr/local/opt/icu4c/lib/pkgconfig:/usr/local/opt/gi-docgen/lib/pkgconfig' >> $GITHUB_ENV - name: Build and Test run: | @@ -101,6 +103,7 @@ jobs: mingw-w64-x86_64-gi-docgen mingw-w64-x86_64-libsoup3 mingw-w64-x86_64-libpeas + mingw-w64-x86_64-curl - uses: actions/checkout@v3 - uses: actions/setup-python@v4 with: diff --git a/meson.build b/meson.build index 27b99ff..0b28bba 100644 --- a/meson.build +++ b/meson.build @@ -110,6 +110,7 @@ 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')) 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 dcd8e5d..f35387a 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -67,3 +67,10 @@ option( 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/plugins/download-curl/download-curl.c b/src/backend/plugins/download-curl/download-curl.c new file mode 100644 index 0000000..5a531cb --- /dev/null +++ b/src/backend/plugins/download-curl/download-curl.c @@ -0,0 +1,99 @@ +/* download-curl.c + * + * Copyright 2022-2023 Jan-Michael Brummer + * + * 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); + +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) +{ + self->curl = curl_easy_init (); +} + +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) +{ + GString *string = user_pointer; + size_t real_size = size * nmemb; + + g_string_append_len (string, contents, real_size); + return real_size; +} + +static GBytes * +px_download_curl_download (PxDownload *download, const char *uri) +{ + PxDownloadCurl *self = PX_DOWNLOAD_CURL (download); + g_autoptr (GBytes) bytes = NULL; + CURLcode res; + g_autoptr (GString) data = g_string_new (""); + const char *url = uri; + + if (g_str_has_prefix (url, "pac+")) + url += 4; + + curl_easy_setopt (self->curl, CURLOPT_URL, url); + curl_easy_setopt (self->curl, CURLOPT_WRITEFUNCTION, store_data); + curl_easy_setopt (self->curl, CURLOPT_WRITEDATA, data); + + res = curl_easy_perform (self->curl); + if (res != CURLE_OK) { + g_warning ("Could not download data: %s", curl_easy_strerror (res)); + return NULL; + } + + return g_steal_pointer (&bytes); +} + +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 new file mode 100644 index 0000000..4b95140 --- /dev/null +++ b/src/backend/plugins/download-curl/download-curl.h @@ -0,0 +1,40 @@ +/* download-curl.h + * + * Copyright 2022-2023 Jan-Michael Brummer + * + * 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> +#include <libpeas/peas.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) + +struct _PxDownloadCurl { + GObject parent_instance; + CURL *curl; +}; + +G_END_DECLS + + diff --git a/src/backend/plugins/download-curl/download-curl.plugin b/src/backend/plugins/download-curl/download-curl.plugin new file mode 100644 index 0000000..7aa75d6 --- /dev/null +++ b/src/backend/plugins/download-curl/download-curl.plugin @@ -0,0 +1,6 @@ +[Plugin] +Authors=Jan-Michael Brummer <jan.brummer@tabos.org> +Copyright=Copyright © 2023 Jan-Michael Brummer +Description=Donwload data using cURL +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 new file mode 100644 index 0000000..29da33e --- /dev/null +++ b/src/backend/plugins/download-curl/meson.build @@ -0,0 +1,33 @@ +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, + 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/meson.build b/src/backend/plugins/meson.build index 8a14739..d7d7c4c 100644 --- a/src/backend/plugins/meson.build +++ b/src/backend/plugins/meson.build @@ -4,6 +4,7 @@ subdir('config-osx') subdir('config-sysconfig') subdir('config-windows') +subdir('download-curl') subdir('download-soup') subdir('pacrunner-duktape') @@ -14,6 +15,7 @@ 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 |