diff options
author | des <des@FreeBSD.org> | 2007-12-18 11:03:07 +0000 |
---|---|---|
committer | des <des@FreeBSD.org> | 2007-12-18 11:03:07 +0000 |
commit | f0e1aa6917a14f5641e43cf944cacb2e1aa83223 (patch) | |
tree | f5124fad1675d5be07f4721b1851e7bf4d8359a5 /lib/libfetch/common.c | |
parent | ddf13e4c294f0883bedec65186a9b10371ae7a87 (diff) | |
download | FreeBSD-src-f0e1aa6917a14f5641e43cf944cacb2e1aa83223.zip FreeBSD-src-f0e1aa6917a14f5641e43cf944cacb2e1aa83223.tar.gz |
Add support for the NO_PROXY / no_proxy environment variable as used by
lynx, curl etc. Note that this patch differs significantly from that
in the PR, as the submitter refined it after submitting the PR.
PR: 110388
Submitted by: Alexander Pohoyda <alexander.pohoyda@gmx.net>
MFC after: 3 weeks
Diffstat (limited to 'lib/libfetch/common.c')
-rw-r--r-- | lib/libfetch/common.c | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/lib/libfetch/common.c b/lib/libfetch/common.c index dc9eee0..936524f 100644 --- a/lib/libfetch/common.c +++ b/lib/libfetch/common.c @@ -33,8 +33,10 @@ __FBSDID("$FreeBSD$"); #include <sys/socket.h> #include <sys/time.h> #include <sys/uio.h> + #include <netinet/in.h> +#include <ctype.h> #include <errno.h> #include <netdb.h> #include <pwd.h> @@ -734,3 +736,51 @@ fetch_netrc_auth(struct url *url) fclose(f); return (-1); } + +/* + * The no_proxy environment variable specifies a set of domains for + * which the proxy should not be consulted; the contents is a comma-, + * or space-separated list of domain names. A single asterisk will + * override all proxy variables and no transactions will be proxied + * (for compatability with lynx and curl, see the discussion at + * <http://curl.haxx.se/mail/archive_pre_oct_99/0009.html>). + */ +int +fetch_no_proxy_match(const char *host) +{ + const char *no_proxy, *p, *q; + size_t h_len, d_len; + + if ((no_proxy = getenv("NO_PROXY")) == NULL && + (no_proxy = getenv("no_proxy")) == NULL) + return (0); + + /* asterisk matches any hostname */ + if (strcmp(no_proxy, "*") == 0) + return (1); + + h_len = strlen(host); + p = no_proxy; + do { + /* position p at the beginning of a domain suffix */ + while (*p == ',' || isspace((int)*p)) + p++; + + /* position q at the first separator character */ + for (q = p; *q; ++q) + if (*q == ',' || isspace((int)*q)) + break; + + d_len = q - p; + if (d_len > 0 && h_len > d_len && + strncasecmp(host + h_len - d_len, + p, d_len) == 0) { + /* domain name matches */ + return (1); + } + + p = q + 1; + } while (*q); + + return (0); +} |