Commit Graph

6872 Commits

Author SHA1 Message Date
Philip Withnall
e446c3487b guri: Change type of g_uri_escape_bytes() to use guint8
`guint8` is the conventional way in modern GLib APIs to represent ‘a byte
which could contain arbitrary binary’. `guchar` is not advised for that
(even though it’s equivalent) because it could be misread as `gchar`.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2020-08-07 14:02:18 +01:00
Philip Withnall
ceda9755de guri: Clear return values on error from g_uri_params_iter_next()
This reduces the chance of the caller accidentally double-freeing or
use-after-free-ing something.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2020-08-07 14:02:18 +01:00
Philip Withnall
83597b9e57 guri: Use NONE values of flags rather than 0
This introduces no functional changes, but makes the code a little
easier to read.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2020-08-07 14:02:18 +01:00
Philip Withnall
41a21c3566 guri: Add links to RFC 3986 in code comments
This should make the RFC easier to refer to in future.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2020-08-07 14:02:18 +01:00
Philip Withnall
f873b88f89 guri: Add G_URI_HIDE_QUERY
Sometimes there are sensitive details in URI query components, so we
should provide the option for hiding them too.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2020-08-07 14:02:18 +01:00
Philip Withnall
ae6a0ef8b8 guri: Tweak quotes in error strings
Use nice curly Unicode quotes.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2020-08-07 14:02:18 +01:00
Philip Withnall
40873f8452 guri: Use g_steal_pointer() to make ownership transfer clearer
This introduces no functional changes, just makes the code a bit easier
to read.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2020-08-07 14:02:18 +01:00
Philip Withnall
de0ebf8a5f guri: Minor code formatting fixes
Signed-off-by: Philip Withnall <withnall@endlessm.com>
2020-08-07 14:02:18 +01:00
Philip Withnall
1f1efbbb05 guri: Rename G_URI_ERROR_MISC to G_URI_ERROR_FAILED
This brings its naming in line with the ‘generic’ error codes in other
error domains.

This is not an API break since `GUriError` hasn’t been in a release yet.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2020-08-07 14:02:18 +01:00
Philip Withnall
ff60d2ebf5 guri: Various minor documentation tweaks and improvements
Signed-off-by: Philip Withnall <withnall@endlessm.com>
2020-08-07 14:02:17 +01:00
Sebastian Dröge
602b7cca33 Merge branch 'uri-path-slashes' into 'master'
guri: Document and check restrictions on path prefixes

See merge request GNOME/glib!1612
2020-08-07 12:57:17 +00:00
Philip Withnall
89cf298b19 guri: Document and check restrictions on path prefixes
RFC 3986, section 3 says:
> The scheme and path components are required, though the path may be
> empty (no characters).  When authority is present, the path must
> either be empty or begin with a slash ("/") character.  When
> authority is not present, the path cannot begin with two slash
> characters ("//").  These restrictions result in five different ABNF
> rules for a path (Section 3.3), only one of which will match any
> given URI reference.

(See https://tools.ietf.org/html/rfc3986#section-3.)

Given that those conditions are almost always going to be true, and that
typically the number and form of arguments passed to g_uri_join() will
be known at compile time, it would be unnecessarily awkward to add a
`GError` argument to g_uri_join() to detect these situations.

Instead, add precondition checks and document the restrictions.
Developers are responsible for ensuring their paths are in the right
format themselves.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2020-08-07 13:24:12 +01:00
Philip Withnall
623cb10f55 guri: Always prepend // to the host when building a URI
This is needed to distinguish the host (‘authority’ in the terms of RFC
3986) from a path if a scheme is not present.

It can be seen from the grammar in RFC 3986
(https://tools.ietf.org/html/rfc3986#appendix-A) that `authority` only
ever appears after `"//"`.

Spotted by Simon McVittie in
https://gitlab.gnome.org/GNOME/glib/-/merge_requests/1606#note_884893.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2020-08-07 12:51:31 +01:00
Felix Yan
161168c672 Fix multiple typos in guri.c 2020-08-06 14:18:01 +00:00
Marc-André Lureau
0ba7ebfda9 uri: allow to join a partial URI, without scheme
Fixes: #2166

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2020-08-05 22:40:08 +04:00
Philip Withnall
bb1df0e515 Merge branch 'uri-params-iter' into 'master'
Add GUriParamsIter

See merge request GNOME/glib!1572
2020-08-05 16:07:42 +00:00
Philip Withnall
df8dc7fc38 Merge branch 'guri-gio' into 'master'
Replace _g_uri_parse_authority() with GUri

Closes #2156

See merge request GNOME/glib!1567
2020-08-05 16:06:02 +00:00
Marc-André Lureau
3bcc6fd39f guri: add a test to check ipv6 with zoneid URI to string
The test was failing since commit 20ae4b46d ("uri: do not add ipv6
brackets on non-ip host").

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2020-08-05 18:50:13 +04:00
Marc-André Lureau
03550ec097 hostutils: accept zoneid in IPv6 addresses
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2020-08-05 18:50:13 +04:00
Marc-André Lureau
5767eef895 uri: add GUriParamsIter
See also:
https://gitlab.gnome.org/GNOME/glib/-/merge_requests/1328#note_863735
2020-08-04 20:10:57 +04:00
Sebastian Dröge
50343afb6e Merge branch 'uri-userinfo-enc' into 'master'
uri: do not encode ':' and ';' from userinfo

See merge request GNOME/glib!1600
2020-08-04 13:33:18 +00:00
Marc-André Lureau
ef173e2e75 uri: do not encode ':' and ';' from userinfo
The g_uri_join_internal() function was making a simplification that
userinfo can be encoded with the same restricted character set as the
user field alone, fix this by allowing the correct character set.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2020-08-04 17:10:06 +04:00
Marc-André Lureau
c354c404c6 tests/uri: check user field is correctly encoded
Suggested-by: Dan Winship <danw@gnome.org>
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2020-08-04 17:10:06 +04:00
Marc-André Lureau
4c20ea477c uri: always add G_URI_FLAGS_HAS_PASSWORD with build_with_user()
Otherwise, the to_string() encoding will not be reversible. Furthermore,
if no distinction is needed in the first place, g_uri_build() with
userinfo should be used instead.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2020-08-04 17:10:06 +04:00
Marc-André Lureau
b0f9af0e1d uri: do not encode userinfo fields
g_uri_build_with_user() builds a userinfo, but it shouldn't encode it
itself, but let the user flags declare what's there. Otherwise,
to_string() code paths may encode a second time.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2020-08-04 17:03:30 +04:00
Marc-André Lureau
c9c349aeaa uri: add ENCODED_PATH & ENCODED_FRAGMENT flags
Add encoded flags, similar to what was done in commit 7bee36b4 ("uri:
add G_FLAGS_ENCODED_QUERY").

SoupURI has manual handling of encoded path & fragment, but it can rely
on GUri decoding for the rest.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2020-08-04 16:56:19 +04:00
Sebastian Dröge
a97fe4e863 Merge branch 'uri-ipv6-bkt' into 'master'
uri: do not add ipv6 brackets on non-ip host

See merge request GNOME/glib!1599
2020-08-04 12:44:12 +00:00
Matthias Clasen
0992978202 timezone: Fix an uninitialized use
GTK ci rightly complains about this when ti builds
GLib as a subproject with -Werror=maybe-uninitialized.

subkey_dynamic_w will be freed without being initialized
when the first goto is taken.
2020-07-31 14:04:21 -04:00
Marc-André Lureau
20ae4b46d4 uri: do not add ipv6 brackets on non-ip host
The heuristic is a bit too agressive, as we may have hostname with
%-encoded ':' (as shown in GVfs URI tests).

Add an extra test to check :-decoding as well.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2020-07-30 21:37:34 +04:00
Marc-André Lureau
0fea3d71e4 guri: add some IPv6 scope-id tests
Add a few ipv6 scope parsing corner test cases.

- checking incorrect scoped IPv6 ending with only %25 isn't decoded.
- checking valid scoped IPv6 is passing g_uri_is_valid()

As discussed in
https://gitlab.gnome.org/GNOME/glib/-/merge_requests/1567#note_860499,
for historical reasons, GUri accepts the % preceding the zone-id in the
unescaped form as well.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2020-07-28 16:48:01 +04:00
Marc-André Lureau
82ad7853ba uri: change g_uri_is_valid() to check absolute URI
g_uri_is_valid() should check the given URI is valid following RFC-3986,
and reject relative references.

Fixes: https://gitlab.gnome.org/GNOME/glib/-/issues/2169

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2020-07-28 15:44:43 +04:00
Marc-André Lureau
44d4640c47 uri: rename absolute & relative uri_string to uri_ref
Let's reserve the term URI for absolute URIs, following rfc3986
terminology.

See:
https://gitlab.gnome.org/GNOME/glib/-/issues/2169

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2020-07-28 15:07:08 +04:00
Marc-André Lureau
d625a29b28 uri: add a comment about temporary GUri construction
As pointed out in the discussion of:
https://gitlab.gnome.org/GNOME/glib/-/issues/2169

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2020-07-28 14:54:55 +04:00
Marc-André Lureau
19c0db3185 uri: improve some documentation about absolute URIs
As pointed out in the discussion
https://gitlab.gnome.org/GNOME/glib/-/issues/2169.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2020-07-28 14:54:55 +04:00
Marc-André Lureau
3521763532 uri: add some note about the API scope
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2020-07-28 14:54:42 +04:00
Sebastian Dröge
9577616622 Merge branch '272-thread-pool-docs' into 'master'
gthreadpool: Mention g_get_num_processors() in the thread pool docs

Closes #272

See merge request GNOME/glib!1588
2020-07-27 19:04:11 +00:00
Philip Withnall
1203e80f5f Merge branch '250-testcase-docs' into 'master'
gtestutils: Clarify the docs for g_test_create_case()

Closes #250

See merge request GNOME/glib!1587
2020-07-27 17:01:16 +00:00
Philip Withnall
b3c0c4804b gthreadpool: Mention g_get_num_processors() in the thread pool docs
Just to make it a little more obvious that a thread pool can be
initialised with one thread per logical CPU.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Fixes: #272
2020-07-27 17:28:43 +01:00
Philip Withnall
07278e73d4 gtestutils: Clarify the docs for g_test_create_case()
Improve formatting, and clarify that the same *type* of test fixture can
be reused, not the same specific instance of a test fixture.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Fixes: #250
2020-07-27 17:26:56 +01:00
Philip Withnall
9c6c546236 gosxutils: Include Foundation rather than Cocoa
Apparently, the function calls added in 11729cdc use Foundation, not
Cocoa. Cocoa is a massive superset of Foundation, and is not available
on iOS.

Patch contributed by Jay Freeman, but without providing an e-mail
address. So the git commit cannot be attributed to him.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Fixes: #1869
2020-07-27 13:21:20 +01:00
Sebastian Dröge
4bd74ac582 Merge branch 'wip/pwithnall/bsd-nofollow' into 'master'
gfileutils: Fix O_NOFOLLOW handling on BSD systems

See merge request GNOME/glib!1591
2020-07-27 12:01:19 +00:00
Philip Withnall
b4aa9d7858 gfileutils: Fix O_NOFOLLOW handling on BSD systems
Various different BSD systems use a different errno from `E_LOOP` (as
defined by POSIX and used on Linux) to indicate that a file is a symlink
when you try to `open()` it with `O_NOFOLLOW`.

Fix the code which detects this. This is a follow-up to #1302.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2020-07-27 12:24:20 +01:00
Philip Withnall
1ef6e84012 tests: Add some tests for expanding invalid escapes with g_strcompress()
This brings the branch coverage of `g_strcompress()` up to 100%. Yay.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2020-07-26 23:22:06 +01:00
Philip Withnall
59eb3c5bdb tests: Add missing cast to URI tests
This fixes a compiler warning.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2020-07-26 23:05:31 +01:00
Philip Withnall
437526675a tests: Test that UTF-8 is escaped correctly by g_strescape()
`g_strescape()` is documented as escaping UTF-8 characters, so test that
it does.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Fixes: #4
2020-07-26 23:04:37 +01:00
Philip Withnall
5bf3849099 tests: Add tests for g_file_set_contents_full()
These exercise all the code paths I can manage without adding a load of
machinery to inject faults into `write()`.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Helps: #1302
2020-07-26 21:38:17 +01:00
Philip Withnall
f35f9e918a tests: Use G_TEST_OPTION_ISOLATE_DIRS for fileutils tests
They all still pass.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2020-07-26 21:38:17 +01:00
Philip Withnall
cd02eac2d4 gstdio: Add macOS support to g_fsync()
Apparently, `fsync()` doesn’t actually sync to the spinning disk on
macOS. You need an `fcntl()` for that.

See: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/fsync.2.html

Spotted by Christoph Reiter in a comment on !369.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2020-07-26 21:38:17 +01:00
Philip Withnall
926dfe5925 gstdio: Handle EINTR in g_fsync()
Signed-off-by: Philip Withnall <withnall@endlessm.com>
2020-07-26 21:38:17 +01:00
Philip Withnall
84dd89242a gfileutils: Use g_fsync() for platform-independence
Signed-off-by: Philip Withnall <withnall@endlessm.com>
2020-07-26 21:38:17 +01:00