From 836b6fb5a56338dc28165284875b257ccfd6c224 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 31 Jul 2013 10:42:01 -0700 Subject: config: add generic callback wrapper to parse section..key Existing configuration parsing functions (e.g. http_options() in http.c) know how to parse two-level configuration variable names. We would like to exploit them and parse something like this: [http] sslVerify = true [http "https://weak.example.com"] sslVerify = false and pretend as if http.sslVerify were set to false when talking to "https://weak.example.com/path". Introduce `urlmatch_config_entry()` wrapper that: - is called with the target URL (e.g. "https://weak.example.com/path"), and the two-level variable parser (e.g. `http_options`); - uses `url_normalize()` and `match_urls()` to see if configuration data matches the target URL; and - calls the traditional two-level configuration variable parser only for the configuration data whose part matches the target URL (and if there are multiple matches, only do so if the current match is a better match than the ones previously seen). Signed-off-by: Junio C Hamano --- urlmatch.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'urlmatch.h') diff --git a/urlmatch.h b/urlmatch.h index b67f57f86f..b461dfd3df 100644 --- a/urlmatch.h +++ b/urlmatch.h @@ -33,4 +33,22 @@ struct url_info { extern char *url_normalize(const char *, struct url_info *); extern int match_urls(const struct url_info *url, const struct url_info *url_prefix, int *exactusermatch); +struct urlmatch_item { + size_t matched_len; + char user_matched; +}; + +struct urlmatch_config { + struct string_list vars; + struct url_info url; + const char *section; + const char *key; + + void *cb; + int (*collect_fn)(const char *var, const char *value, void *cb); + int (*cascade_fn)(const char *var, const char *value, void *cb); +}; + +extern int urlmatch_config_entry(const char *var, const char *value, void *cb); + #endif /* URL_MATCH_H */ -- cgit v1.2.3