Skip to content

Commit

Permalink
open-uri: basic support for proposed intent Implements
Browse files Browse the repository at this point in the history
Add support for reading URI handlers from a proposed addendum to
the intents-spec in the form:

```ini
[Implements org.freedesktop.UriHandler]
Patterns=*.openstreetmap/node/*;*.openstreetmap/way/*;
```
  • Loading branch information
andyholmes committed May 2, 2024
1 parent fe0ee65 commit 11c6af7
Showing 1 changed file with 50 additions and 1 deletion.
51 changes: 50 additions & 1 deletion src/open-uri.c
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,47 @@ uri_handler_free (UriHandler *handler)
/*
* Temporary deserialization
*/
static GPtrArray *
uri_handler_deserialize_implements (GKeyFile *keyfile)
{
const char *group = "Implements org.freedesktop.UriHandler";
g_auto (GStrv) patterns = NULL;
GPtrArray *ret = NULL;

g_assert (keyfile != NULL);

patterns = g_key_file_get_string_list (keyfile, group, "Patterns", NULL, NULL);
if (patterns == NULL)
return NULL;

ret = g_ptr_array_new_with_free_func ((GDestroyNotify)uri_handler_free);
for (size_t i = 0; patterns[i] != NULL; i++)
{
UriHandler *handler = NULL;
g_auto (GStrv) pattern_parts = NULL;

pattern_parts = g_strsplit (patterns[i], "/", 2);
if (pattern_parts[0] == NULL)
continue;

handler = g_new0 (UriHandler, 1);
handler->hosts = g_new0 (char *, 2);
handler->hosts[0] = g_strdup (pattern_parts[0]);
if (pattern_parts[1] != NULL)
{
handler->paths = g_new0 (char *, 2);
handler->paths[0] = g_strconcat ("/", pattern_parts[1], NULL);
}

g_ptr_array_add (ret, g_steal_pointer (&handler));
}

if (ret->len == 0)
g_clear_pointer (&ret, g_ptr_array_unref);

return ret;
}

static GPtrArray *
uri_handler_deserialize_sections (GKeyFile *keyfile)
{
Expand Down Expand Up @@ -609,7 +650,15 @@ uri_handler_load_keyfiles (void)
if (!g_key_file_load_from_file (keyfile, filepath, G_KEY_FILE_NONE, NULL))
continue;

handlers = uri_handler_deserialize_sections (keyfile);
if (g_key_file_has_group (keyfile, "Implements org.freedesktop.UriHandler"))
{
handlers = uri_handler_deserialize_implements (keyfile);
}
else
{
handlers = uri_handler_deserialize_sections (keyfile);
}

if (handlers != NULL && handlers->len > 0)
{
g_autofree char *basename = NULL;
Expand Down

0 comments on commit 11c6af7

Please sign in to comment.