avf: move ff_http_match_no_proxy to network
It is only used by network protocols.
This commit is contained in:
parent
afc8685395
commit
ec7c51c786
5 changed files with 57 additions and 57 deletions
|
@ -277,3 +277,57 @@ int ff_listen_connect(int fd, const struct sockaddr *addr,
|
|||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue