Commit Graph

37 Commits

Author SHA1 Message Date
Simon McVittie
07a6541f06 common: Use g_info() for messages that will be shown by flatpak -v
This brings us one step closer to being able to stop using the flatpak2
log domain for messages that are exclusive to `flatpak -v -v`.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-12-15 16:45:35 +00:00
git-bruh
83b881cdc2 flatpak-utils-http: check for HTTP2 support before trying to use it 2022-09-06 12:47:16 +02:00
Phaedrus Leeds
600e18567c Add a vim modeline and .editorconfig
To make indentation work with less effort. The modeline was copied from
libostree with minor modification and the .editorconfig from GLib.

The advantage of having both a modeline and an editorconfig is we can
work out of the box on more editor setups, and the modeline allows us to
specify the style with a lot more fine grained control.
2022-08-22 19:48:10 -07:00
Milan Crha
dc82a19dc5 common: Add thread safety on libcurl usage
There can happen a race condition between internal libcurl structure
content when two threads set the `data` structure for the callbacks
from two threads, which can cause access of already freed stack-allocated
`data`, resulting in a memory corruption.

Closes https://github.com/flatpak/flatpak/issues/3701
2022-08-22 10:36:30 +02:00
Alexander Larsson
aea92f3909 http: Support curl
If build with curl (--with-curl, which is default) then we use libcurl
instead of libsoup as the http backend.
2022-06-16 13:49:45 +02:00
Alexander Larsson
0c6bb85cb6 flatpak-http: Restructure the soup http implementation
This miniminzes the soup implementation by moving it out of the
highlevel multiple-retry entry points and simplifying the
lower level part to use only one shared helper.

This will also make it easier to replace the soup specific
parts.
2022-06-16 13:49:45 +02:00
Alexander Larsson
1c9e65d5e4 Move all use of soup APIs into flatpak-utils-http
This will allow us to make the soup dependency optional.
2022-06-16 13:49:45 +02:00
Alexander Larsson
618d0c8fae http: Add flatpak_load_uri_full with some more complete features
This allows:
 * getting http status
 * getting www-authenticate header
 * Doing HEAD instead of get

This is needed by the OCI registry code for authentication
2022-06-16 13:49:45 +02:00
Alexander Larsson
b1083a4c41 http utils: Make a generic FlatpakHttpSession instead of SoupSession
Its still just a SoupSession, but now the implementation is more
centralized and can be something else down the line.
2022-06-16 13:49:45 +02:00
Alexander Larsson
0b4f1dadbf Bump glib requirement to 2.46 (from 2.44)
Since we switched to libappstream we really have an implicit dependency
on this, as there are no versions of it building with glib earlier
than 2.46.

This isn't dropping a lot of old code, but at least it is more truthful
about our actual dependencies.
2022-06-14 08:54:18 +02:00
Simon McVittie
c68f31d86a build: Consistently include libglnx header as "libglnx.h"
Recent Meson versions have warnings if you add the subprojects
directory as an include path, because the way Meson wants to consume
subprojects is by the subproject's build system producing a Meson
dependency object that encapsulates its include directory. Flatpak
doesn't have a Meson build system yet, but I'm working on that.

libglnx seems to be set up to have the libglnx directory be its include
path instead: for example, ostree (by the author of libglnx) already
uses "libglnx.h" or <libglnx.h> everywhere. Do the same here.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-04-11 10:32:34 +02:00
Patrick Griffis
cda4967a9e Re-enable HTTP compression
The original commit (9865ed8989) disabling
it claimed it fixed OCI downloads. This no longer seems to be a problem.

This has also exposed new bugs as some servers will send
gzip compressed data when the client does not send Accept-Encoding.
If we leave this enabled that issue goes away.
2021-11-15 11:12:01 +01:00
Philip Withnall
8ff02c0e5b flatpak-utils-http: Ensure to wake up the main context on error
All the other code paths which set `data->done` or `data->error` ensure
to wake up the main context so its loop exit conditions can be checked
again — this code path was missing a wakeup though.

Spotted by code inspection; I haven’t hit this in the wild.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-10-26 23:24:52 +01:00
Alexander Larsson
1b130c5cc3 http utils: push custom thread local main context
We're calling async soup APIs with SOUP_SESSION_USE_THREAD_CONTEXT
set, which means that libsoup async APIs will run async callbacks on
the loop of the thread-default main context. We then manually spin
this main context, because we're supposed to look like a sync call and
the async stuff is just internally.

This is not really right, because normally there isn't any custom
mainloop context registred, which means we're spinning the main thread
context on some other thread, as well as queuing soup sorces on
it. This can't be any good!

Rather than doing this we actually create and push our own main
context that we then spin isolated from the default mainloop.
2021-03-19 10:59:04 +01:00
Alexander Larsson
534cf643a6 Revert "Revert "flatpak-utils-http: Don’t use GMainLoop""
This reverts commit 14f062593f.
2021-03-19 10:59:04 +01:00
Simon McVittie
14f062593f Revert "flatpak-utils-http: Don’t use GMainLoop"
This reverts commit c1561b1ded,
which seems to trigger a hang in the
test-oci-registry@system.wrap test-case.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-03-17 15:35:34 +01:00
Philip Withnall
c1561b1ded flatpak-utils-http: Don’t use GMainLoop
Iterate the `GMainContext` manually instead. This makes the exit
condition from the loop much more obvious, and eliminates the potential
class of problems where `g_main_loop_quit()` is called before
`g_main_loop_run()` and has no effect.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2021-01-13 19:32:58 +00:00
Alexander Larsson
3ebcd200ca Remove should-retry debug spew
Every http operation (even when successfull) was spewing info about
whether to retry it which made it hard to read the logs.
2020-11-03 12:57:37 +01:00
Philip Withnall
6c79a57114 http: Return HOST_UNREACHABLE on error 500
Sometimes a server might return a HTTP error 500 (this seems to happen
sometimes with Microsoft’s VSCode server, for example). Map this to
`G_IO_ERROR_HOST_UNREACHABLE` for now, which is a bit more specific than
returning `G_IO_ERROR_FAILED`, but without the hassle of introducing a
new public error domain which could give more detail.

In particular, this should allow gnome-software to show an error message
to the user for such failed downloads, rather than hiding the error and
logging the following:
```
not handling error failed for action download: While downloading http://packages.microsoft.com/repos/vscode/pool/main/c/code/code_1.45.1-1589445302_amd64.deb: Server returned status 500: Internal Server Error
```

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2020-10-12 11:04:40 +02:00
Alexander Larsson
e0a25e7650 http: Also accept image indexes when FLATPAK_HTTP_FLAGS_ACCEPT_OCI 2020-06-05 09:35:30 +02:00
Alexander Larsson
7820057336 Add content_type output to flatpak_load_uri()
We want this to get the oci mimetypes
2020-06-05 09:35:30 +02:00
Alexander Larsson
f6a0fa41a1 Add FLATPAK_HTTP_ERROR_UNAUTHORIZED (i.e. http status 401) 2020-05-05 13:08:57 +02:00
Alexander Larsson
e3c31309a4 Rename internal error FLATPAK_OCI_ERROR to FLATPAK_HTTP_ERROR
This is what it is really, and I want to extend it with more http errors
that are not necessarily oci related.
2020-05-05 13:08:57 +02:00
Alexander Larsson
0ef69c96db http-utils: Rename flatpak_load_http_uri to flatpak_load_uri and support file:
Various places (like the new load-commit-for-extra-data-setup) needs to
support file: uris, lets make it available generically.
2020-03-30 15:00:51 +02:00
Matthew Leeds
5560132ba6 flatpak-utils-http.c: Add retry logic for transient failures
Currently if flatpak is installing an extra data app such as Spotify and
the server with the .deb file fails to complete the request, the
installation fails with a message like "Connection terminated
unexpectedly". This commit makes flatpak instead try 5 times to download
a given URI if the error returned seems like a transient one (so not,
for example, 404 not found). This is analogous to what was done in
libostree in commit 938055392fd455027a69398c441b992ae521aa87, and we use
some code from there.
2020-03-20 15:47:18 -07:00
Matthew Leeds
0b25455af1 flatpak-utils-http.c: Use more specific GIOError codes
Instead of defaulting to G_IO_ERROR_FAILED, use more specific codes when
we can. These were copied from libostree.
2020-03-20 13:46:36 -07:00
Alexander Larsson
976c88cf56 oci: Pass down token into OCI http operations
This is needed for pull operations to actually use the token if one
is given by an authenticator.
2019-12-12 12:16:53 +01:00
Matthias Clasen
e04263ca5c Fix a case of signed/unsigned confusion
G_input_stream_read_finish returns a gssize,
which we must not store in a gsize, since it
may be -1.

Closes: https://github.com/flatpak/flatpak/issues/2885
2019-12-01 23:01:10 -05:00
Alexander Larsson
45e31735f1 OCI: Accept docker v2 manifests as well as OCI manifests
Closes: #2978
Approved by: alexlarsson
2019-09-06 12:49:40 +00:00
Matthew Leeds
807f2baa53 Move interpretation of OSTREE_DEBUG_HTTP
It makes more sense to have this in flatpak_create_soup_session() so
every caller of that interprets the env var.

Closes: #2740
Approved by: matthiasclasen
2019-03-06 23:44:50 +00:00
Matthew Leeds
e8816b7663 Remove extra newlines in variable definiton blocks
Uncrustify has an option "nl_func_var_def_blk" which is supposed to
ensure there's a newline character between the block of variable
definitions and the rest of the function body, but it gets confused and
thinks that the first instance of "g_autoptr" or "g_auto" being used on
a variable is the start of the function body. So this commit removes
those extra newline characters and removes that option in uncrustify.cfg
so they don't get re-added the next time uncrustify is run.

Here's the command I used:

perl -0777 -i -pe 's/\n(\n\s*g_auto\()/\1/g' `git ls-tree --name-only
-r HEAD | grep \\\.[ch]$ | grep -v common/valgrind-private.h |
grep -v app/flatpak-polkit-agent-text-listener\\\.[ch]`

I ran it again with "g_autoptr" in place of "g_auto", and made a few
manual edits to add back the newline when the g_auto* was in the middle
of a function body rather than at the top.

Closes: #2715
Approved by: matthiasclasen
2019-02-25 18:12:30 +00:00
Owen W. Taylor
05cc3c0f66 flatpak_cache_http_uri: save downloaded files with permission 0644
Previously, downloaded files were being saved with 0600 permissions,
which prevented OCI icons downloaded by the system helper at appstream
creation time from being read by users.

Closes: #2362
Approved by: matthiasclasen
2018-11-30 23:53:10 +00:00
Alexander Larsson
9cc0f0d404 Fix leak in flatpak_cache_http_uri
Need to free the return value of soup_header_parse_param_list

Closes: #1966
Approved by: alexlarsson
2018-08-17 08:13:15 +00:00
Owen W. Taylor
c4c06b7be4 Allow using a compressed cache for HTTP downloads
Add a new flag for flatpak_cache_http_uri() that adds Accept-Encoding: gzip
to the request, and if the result is returned compressed, stores the data
compressed. If the data result is return uncompressed, it's compressed.

Closes: #1910
Approved by: alexlarsson
2018-08-09 12:49:35 +00:00
Owen W. Taylor
4dfa7721bb Remove unused etag functionality
Checking the registry against a previous etag is now handled inside
flatpak_cache_http_uri(), so remove the etag parameters that were
previously passed around in various places for simplicity.

Closes: #1910
Approved by: alexlarsson
2018-08-09 12:49:35 +00:00
Owen W. Taylor
951aed561a Add flatpak_cache_http_uri: cache downloads based on HTTP headers
Add a new function, flatpak_cache_http_uri() that when passed an URL and
a local destination location, either a) downloads the content and stores
it at the destination location, storing HTTP cache header information
like Last-Modified, Etag into user xattrs (if available) or a separate
file or b) if the downloaded content is already present, checks the
header information to decide whether the downloaded content can be used
or needs to be revalidated witha conditional request.

Tests are added that use a special case test server that adds HTTP caching
headers and reacts to them based on query parameters. A small test binary
'httpcache' is added for the tests to use.

Closes: #1910
Approved by: alexlarsson
2018-08-09 12:49:35 +00:00
Owen W. Taylor
cd6a10cb66 flatpak-utils-http.c: Split HTTP functionality into a separate file
In preparation for extending the HTTP downloading function to include
caching, split HTTP related utilities into a separate file with a
separate header.

Closes: #1910
Approved by: alexlarsson
2018-08-09 12:49:35 +00:00