Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/ftp Separate no_proxy handling.



details:   https://anonhg.NetBSD.org/src/rev/a0891e097554
branches:  trunk
changeset: 812443:a0891e097554
user:      christos <christos%NetBSD.org@localhost>
date:      Tue Dec 15 21:01:27 2015 +0000

description:
Separate no_proxy handling.

diffstat:

 usr.bin/ftp/fetch.c |  84 +++++++++++++++++++++++++++++-----------------------
 1 files changed, 46 insertions(+), 38 deletions(-)

diffs (115 lines):

diff -r 26ca802d4e39 -r a0891e097554 usr.bin/ftp/fetch.c
--- a/usr.bin/ftp/fetch.c       Tue Dec 15 20:49:49 2015 +0000
+++ b/usr.bin/ftp/fetch.c       Tue Dec 15 21:01:27 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: fetch.c,v 1.210 2015/12/15 20:49:49 christos Exp $     */
+/*     $NetBSD: fetch.c,v 1.211 2015/12/15 21:01:27 christos Exp $     */
 
 /*-
  * Copyright (c) 1997-2015 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: fetch.c,v 1.210 2015/12/15 20:49:49 christos Exp $");
+__RCSID("$NetBSD: fetch.c,v 1.211 2015/12/15 21:01:27 christos Exp $");
 #endif /* not lint */
 
 /*
@@ -566,6 +566,45 @@
        return s;
 }
 
+static int
+handle_noproxy(const char *host, in_port_t portnum)
+{
+
+       char *cp, *ep, *np, *np_copy, *np_iter, *no_proxy;
+       unsigned long np_port;
+       size_t hlen, plen;
+       int isproxy = 1;
+
+       /* check URL against list of no_proxied sites */
+       no_proxy = getoptionvalue("no_proxy");
+       if (EMPTYSTRING(no_proxy))
+               return isproxy;
+
+       np_iter = np_copy = ftp_strdup(no_proxy);
+       hlen = strlen(host);
+       while ((cp = strsep(&np_iter, " ,")) != NULL) {
+               if (*cp == '\0')
+                       continue;
+               if ((np = strrchr(cp, ':')) != NULL) {
+                       *np++ =  '\0';
+                       np_port = strtoul(np, &ep, 10);
+                       if (*np == '\0' || *ep != '\0')
+                               continue;
+                       if (np_port != portnum)
+                               continue;
+               }
+               plen = strlen(cp);
+               if (hlen < plen)
+                       continue;
+               if (strncasecmp(host + hlen - plen, cp, plen) == 0) {
+                       isproxy = 0;
+                       break;
+               }
+       }
+       FREEPTR(np_copy);
+       return isproxy;
+}
+
 /*
  * Retrieve URL, via a proxy if necessary, using HTTP.
  * If proxyenv is set, use that for the proxy, otherwise try ftp_proxy or
@@ -726,45 +765,14 @@
                if (! EMPTYSTRING(penv)) {                      /* use proxy */
                        url_t purltype;
                        char *phost, *ppath;
-                       char *pport, *no_proxy;
+                       char *pport;
                        in_port_t pportnum;
 
-                       isproxy = 1;
-
-                               /* check URL against list of no_proxied sites */
-                       no_proxy = getoptionvalue("no_proxy");
-                       if (! EMPTYSTRING(no_proxy)) {
-                               char *np, *np_copy, *np_iter;
-                               unsigned long np_port;
-                               size_t hlen, plen;
+                       isproxy = handle_noproxy(host, portnum);
 
-                               np_iter = np_copy = ftp_strdup(no_proxy);
-                               hlen = strlen(host);
-                               while ((cp = strsep(&np_iter, " ,")) != NULL) {
-                                       if (*cp == '\0')
-                                               continue;
-                                       if ((np = strrchr(cp, ':')) != NULL) {
-                                               *np++ =  '\0';
-                                               np_port = strtoul(np, &ep, 10);
-                                               if (*np == '\0' || *ep != '\0')
-                                                       continue;
-                                               if (np_port != portnum)
-                                                       continue;
-                                       }
-                                       plen = strlen(cp);
-                                       if (hlen < plen)
-                                               continue;
-                                       if (strncasecmp(host + hlen - plen,
-                                           cp, plen) == 0) {
-                                               isproxy = 0;
-                                               break;
-                                       }
-                               }
-                               FREEPTR(np_copy);
-                               if (isproxy == 0 && urltype == FTP_URL_T) {
-                                       rval = fetch_ftp(url);
-                                       goto cleanup_fetch_url;
-                               }
+                       if (isproxy == 0 && urltype == FTP_URL_T) {
+                               rval = fetch_ftp(url);
+                               goto cleanup_fetch_url;
                        }
 
                        if (isproxy) {



Home | Main Index | Thread Index | Old Index