url-mode: support for custom prefix

Allow for the protocol configuration to be:

 prefix:some_string

The url-mode then matches anything starting with this 'some_prefix'
prefix.

This, combined with a custom launch command able to handle these "URL"
allow for opening application specific references (e.g. gitlab short
references).

Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
This commit is contained in:
Marc Poulhiès 2023-07-11 10:26:56 +02:00
parent 4a73828911
commit eaaf1ad3a4

View file

@ -1159,11 +1159,24 @@ parse_section_url(struct context *ctx)
conf->url.prot_count * sizeof(conf->url.protocols[0])); conf->url.prot_count * sizeof(conf->url.protocols[0]));
size_t idx = conf->url.prot_count - 1; size_t idx = conf->url.prot_count - 1;
conf->url.protocols[idx] = xmalloc((chars + 1 + 3) * sizeof(char32_t)); bool is_custom_prefix = str_has_prefix(prot, "prefix:");
mbsntoc32(conf->url.protocols[idx], prot, len, chars + 1); size_t prot_suffix_len = 3; // the '://'
c32cpy(&conf->url.protocols[idx][chars], U"://"); if (is_custom_prefix) {
prot += 7;
len -= 7;
chars -= 7;
prot_suffix_len = 0;
}
conf->url.protocols[idx] = xmalloc((chars + 1 + prot_suffix_len) * sizeof(char32_t));
mbsntoc32(conf->url.protocols[idx], prot, len, chars + 1);
if (!is_custom_prefix) {
c32cpy(&conf->url.protocols[idx][chars], U"://");
} else {
c32cpy(&conf->url.protocols[idx][chars], U"");
}
chars += prot_suffix_len;
chars += 3; /* Include the "://" */
if (chars > conf->url.max_prot_len) if (chars > conf->url.max_prot_len)
conf->url.max_prot_len = chars; conf->url.max_prot_len = chars;
} }