aboutsummaryrefslogtreecommitdiffstats
path: root/libavformat/utils.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2013-02-28 13:12:04 +0100
committerMichael Niedermayer <michaelni@gmx.at>2013-02-28 13:13:04 +0100
commit03678a32bcb8e1ae5c213e02faf62df166cca05d (patch)
tree035a1b8ab38470337cf066aae3ab1cc60a03c48b /libavformat/utils.c
parent085bd039bb095cdf35ef41932eebbc428c5caa76 (diff)
parent5c8696555abd30a200d0d882e2913f66619fba68 (diff)
downloadffmpeg-03678a32bcb8e1ae5c213e02faf62df166cca05d.tar.gz
Merge remote-tracking branch 'qatar/master'
* qatar/master: lavf: Add a fate test for the noproxy pattern matching lavf: Handle the environment variable no_proxy more properly Conflicts: libavformat/Makefile libavformat/internal.h libavformat/tls.c libavformat/utils.c libavformat/version.h Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavformat/utils.c')
-rw-r--r--libavformat/utils.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/libavformat/utils.c b/libavformat/utils.c
index 9bd2d0c34b..3df8c51ddd 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -4379,3 +4379,57 @@ void ff_generate_avci_extradata(AVStream *st)
memcpy(st->codec->extradata, data, size);
st->codec->extradata_size = size;
}
+
+static int match_host_pattern(const char *pattern, const char *hostname)
+{
+ int len_p, len_h;
+ if (!strcmp(pattern, "*"))
+ return 1;
+ // Skip a possible *. at the start of the pattern
+ if (pattern[0] == '*')
+ pattern++;
+ if (pattern[0] == '.')
+ pattern++;
+ len_p = strlen(pattern);
+ len_h = strlen(hostname);
+ if (len_p > len_h)
+ return 0;
+ // Simply check if the end of hostname is equal to 'pattern'
+ if (!strcmp(pattern, &hostname[len_h - len_p])) {
+ if (len_h == len_p)
+ return 1; // Exact match
+ if (hostname[len_h - len_p - 1] == '.')
+ return 1; // The matched substring is a domain and not just a substring of a domain
+ }
+ return 0;
+}
+
+int ff_http_match_no_proxy(const char *no_proxy, const char *hostname)
+{
+ char *buf, *start;
+ int ret = 0;
+ if (!no_proxy)
+ return 0;
+ if (!hostname)
+ return 0;
+ buf = av_strdup(no_proxy);
+ if (!buf)
+ return 0;
+ start = buf;
+ while (start) {
+ char *sep, *next = NULL;
+ start += strspn(start, " ,");
+ sep = start + strcspn(start, " ,");
+ if (*sep) {
+ next = sep + 1;
+ *sep = '\0';
+ }
+ if (match_host_pattern(start, hostname)) {
+ ret = 1;
+ break;
+ }
+ start = next;
+ }
+ av_free(buf);
+ return ret;
+}