summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2021-08-31 22:01:34 -0400
committerEdward Thomson <ethomson@edwardthomson.com>2021-09-01 20:40:19 -0400
commit9e98e443ca5e95bfb570536187c6e155bc126e59 (patch)
treed1eccc035814b3628a795c4d0fcc058fd76f60ab /src
parente5ba0a3c37a5a1a24f1904d56ebf8d30df9df75f (diff)
downloadlibgit2-9e98e443ca5e95bfb570536187c6e155bc126e59.tar.gz
url: introduce `git_net_url_matches_pattern_list`
Provide a utility method on a url to determine if it matches any pattern in a comma-separated list, similar to what one would find in `NO_PROXY` environment variables.
Diffstat (limited to 'src')
-rw-r--r--src/net.c19
-rw-r--r--src/net.h3
2 files changed, 22 insertions, 0 deletions
diff --git a/src/net.c b/src/net.c
index f3cca5da7..3322f68c2 100644
--- a/src/net.c
+++ b/src/net.c
@@ -459,6 +459,25 @@ bool git_net_url_matches_pattern(git_net_url *url, const char *pattern)
return matches_pattern(url, pattern, strlen(pattern));
}
+bool git_net_url_matches_pattern_list(
+ git_net_url *url,
+ const char *pattern_list)
+{
+ const char *pattern, *pattern_end, *sep;
+
+ for (pattern = pattern_list;
+ pattern && *pattern;
+ pattern = sep ? sep + 1 : NULL) {
+ sep = strchr(pattern, ',');
+ pattern_end = sep ? sep : strchr(pattern, '\0');
+
+ if (matches_pattern(url, pattern, (pattern_end - pattern)))
+ return true;
+ }
+
+ return false;
+}
+
void git_net_url_dispose(git_net_url *url)
{
if (url->username)
diff --git a/src/net.h b/src/net.h
index 4d4c7c7fe..971e002b6 100644
--- a/src/net.h
+++ b/src/net.h
@@ -58,6 +58,9 @@ extern int git_net_url_fmt_path(git_buf *buf, git_net_url *url);
extern bool git_net_url_matches_pattern(
git_net_url *url,
const char *pattern);
+extern bool git_net_url_matches_pattern_list(
+ git_net_url *url,
+ const char *pattern_list);
/** Disposes the contents of the structure. */
extern void git_net_url_dispose(git_net_url *url);