Merge branch 'js/partial-urlmatch'
The same as js/partial-urlmatch-2.17, built on more recent codebase to avoid unnecessary merge conflicts. * js/partial-urlmatch: credential: handle `credential.<partial-URL>.<key>` again credential: optionally allow partial URLs in credential_from_url_gently()
This commit is contained in:
commit
568324f31b
17
credential.c
17
credential.c
@ -86,6 +86,22 @@ static int select_all(const struct urlmatch_item *a,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int match_partial_url(const char *url, void *cb)
|
||||||
|
{
|
||||||
|
struct credential *c = cb;
|
||||||
|
struct credential want = CREDENTIAL_INIT;
|
||||||
|
int matches = 0;
|
||||||
|
|
||||||
|
if (credential_from_potentially_partial_url(&want, url) < 0)
|
||||||
|
warning(_("skipping credential lookup for key: credential.%s"),
|
||||||
|
url);
|
||||||
|
else
|
||||||
|
matches = credential_match(&want, c);
|
||||||
|
credential_clear(&want);
|
||||||
|
|
||||||
|
return matches;
|
||||||
|
}
|
||||||
|
|
||||||
static void credential_apply_config(struct credential *c)
|
static void credential_apply_config(struct credential *c)
|
||||||
{
|
{
|
||||||
char *normalized_url;
|
char *normalized_url;
|
||||||
@ -105,6 +121,7 @@ static void credential_apply_config(struct credential *c)
|
|||||||
config.collect_fn = credential_config_callback;
|
config.collect_fn = credential_config_callback;
|
||||||
config.cascade_fn = NULL;
|
config.cascade_fn = NULL;
|
||||||
config.select_fn = select_all;
|
config.select_fn = select_all;
|
||||||
|
config.fallback_match_fn = match_partial_url;
|
||||||
config.cb = c;
|
config.cb = c;
|
||||||
|
|
||||||
credential_format(c, &url);
|
credential_format(c, &url);
|
||||||
|
10
urlmatch.c
10
urlmatch.c
@ -572,10 +572,14 @@ int urlmatch_config_entry(const char *var, const char *value, void *cb)
|
|||||||
|
|
||||||
config_url = xmemdupz(key, dot - key);
|
config_url = xmemdupz(key, dot - key);
|
||||||
norm_url = url_normalize_1(config_url, &norm_info, 1);
|
norm_url = url_normalize_1(config_url, &norm_info, 1);
|
||||||
free(config_url);
|
if (norm_url)
|
||||||
if (!norm_url)
|
|
||||||
return 0;
|
|
||||||
retval = match_urls(url, &norm_info, &matched);
|
retval = match_urls(url, &norm_info, &matched);
|
||||||
|
else if (collect->fallback_match_fn)
|
||||||
|
retval = collect->fallback_match_fn(config_url,
|
||||||
|
collect->cb);
|
||||||
|
else
|
||||||
|
retval = 0;
|
||||||
|
free(config_url);
|
||||||
free(norm_url);
|
free(norm_url);
|
||||||
if (!retval)
|
if (!retval)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -59,6 +59,11 @@ struct urlmatch_config {
|
|||||||
* specificity rules) than existing.
|
* specificity rules) than existing.
|
||||||
*/
|
*/
|
||||||
int (*select_fn)(const struct urlmatch_item *found, const struct urlmatch_item *existing);
|
int (*select_fn)(const struct urlmatch_item *found, const struct urlmatch_item *existing);
|
||||||
|
/*
|
||||||
|
* An optional callback to allow e.g. for partial URLs; it shall
|
||||||
|
* return 1 or 0 depending whether `url` matches or not.
|
||||||
|
*/
|
||||||
|
int (*fallback_match_fn)(const char *url, void *cb);
|
||||||
};
|
};
|
||||||
|
|
||||||
int urlmatch_config_entry(const char *var, const char *value, void *cb);
|
int urlmatch_config_entry(const char *var, const char *value, void *cb);
|
||||||
|
Loading…
Reference in New Issue
Block a user