Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 23 Jun 2013 09:41:47 +0000 (UTC)
From:      Devin Teske <dteske@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r252109 - head/usr.sbin/bsdconfig/share/media
Message-ID:  <201306230941.r5N9flsQ085016@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: dteske
Date: Sun Jun 23 09:41:47 2013
New Revision: 252109
URL: http://svnweb.freebsd.org/changeset/base/252109

Log:
  Fine-tune the parsing of the URL. Re-order, comment, and add debugging to
  each case of unique URL format.

Modified:
  head/usr.sbin/bsdconfig/share/media/ftp.subr
  head/usr.sbin/bsdconfig/share/media/httpproxy.subr

Modified: head/usr.sbin/bsdconfig/share/media/ftp.subr
==============================================================================
--- head/usr.sbin/bsdconfig/share/media/ftp.subr	Sun Jun 23 09:34:55 2013	(r252108)
+++ head/usr.sbin/bsdconfig/share/media/ftp.subr	Sun Jun 23 09:41:47 2013	(r252109)
@@ -378,27 +378,62 @@ f_media_set_ftp()
 
 	local hostname="${url#*://}" port=21 dir=/
 	case "$hostname" in
-	"["*"]")
+	#
+	# The order in-which the below individual cases appear is important!
+	#
+	"["*"]":*/*) # IPv6 address with port and directory
+		f_dprintf "Looks like an IPv6 addr with port/dir: %s" \
+		          "$hostname"
 		hostname="${hostname#\[}"
-		hostname="${hostname%%\]*}"
+		port="${hostname#*\]:}"
+		port="${port%%[!0-9]*}"
+		dir="/${hostname#*/}"
+		hostname="${hostname%%\]:*}"
 		;;
-	"["*"]/"*)
+	"["*"]":*) # IPv6 address with port
+		f_dprintf "Looks like an IPv6 addr with port: %s" "$hostname"
 		hostname="${hostname#\[}"
-		dir="/${hostname#*/}"
-		hostname="${hostname%%\]*}"
+		port="${hostname#*\]:}"
+		port="${port%%[!0-9]*}"
+		hostname="${hostname%%\]:*}"
 		;;
-	*"/"*)
+	"["*"]"/*) # IPv6 address with directory
+		f_dprintf "Looks like an IPv6 addr with dir: %s" "$hostname"
+		hostname="${hostname#\[}"
 		dir="/${hostname#*/}"
-		hostname="${hostname%%/*}"
+		hostname="${hostname%%\]*}"
 		;;
-	"["*"]:"*)
+	"["*"]") # IPv6 address
+		f_dprintf "Looks like an IPv6 addr: %s" "$hostname"
 		hostname="${hostname#\[}"
-		port="${hostname#*\]:}"
+		hostname="${hostname%\]}"
+		;;
+	#
+	# ^^^ IPv6 above / DNS Name or IPv4 below vvv
+	#
+	*:*/*) # DNS name or IPv4 address with port and directory
+		f_dprintf "Looks like a %s with port/dir: %s" \
+		          "DNS name or IPv4 addr" "$hostname"
+		port="${hostname#*:}"
 		port="${port%%[!0-9]*}"
-		hostname="${hostname%%\]:*}"
+		dir="/${hostname#*/}"
+		hostname="${hostname%%:*}"
+		;;
+	*:*) # DNS name or IPv4 address with port
+		f_dprintf "Looks like a DNS name or IPv4 addr with port: %s" \
+		          "$hostname"
+		port="${hostname#*:}"
+		hostname="${hostname%%:*}"
 		;;
-	*)
+	*/*) # DNS name or IPv4 address with directory
+		f_dprintf "Looks like a DNS name or IPv4 addr with dir: %s" \
+		          "$hostname"
+		dir="/${hostname#*/}"
 		hostname="${hostname%%/*}"
+		;;
+	*) # DNS name or IPv4 address
+		f_dprintf "Looks like a DNS name or IPv4 addr: %s" "$hostname"
+		: leave hostname as-is
 	esac
 
 	f_dprintf "hostname = \`%s'" "$hostname"

Modified: head/usr.sbin/bsdconfig/share/media/httpproxy.subr
==============================================================================
--- head/usr.sbin/bsdconfig/share/media/httpproxy.subr	Sun Jun 23 09:34:55 2013	(r252108)
+++ head/usr.sbin/bsdconfig/share/media/httpproxy.subr	Sun Jun 23 09:41:47 2013	(r252109)
@@ -77,19 +77,33 @@ f_media_set_http_proxy()
 
 	local hostname="$proxy" port=3128
 	case "$hostname" in
-	"["*"]")
-		hostname="${hostname#\[}"
-		hostname="${hostname%\]}"
-		;;
-	"["*"]:"*)
+	#
+	# The order in-which the below individual cases appear is important!
+	#
+	"["*"]":*) # IPv6 address with port
+		f_dprintf "Looks like an IPv6 addr with port: %s" "$hostname"
 		hostname="${hostname#\[}"
 		port="${hostname#*\]:}"
 		port="${port%%[!0-9]*}"
 		hostname="${hostname%%\]:*}"
 		;;
-	*":"*)
+	"["*"]") # IPv6 address
+		f_dprintf "Looks like an IPv6 addr: %s" "$hostname"
+		hostname="${hostname#\[}"
+		hostname="${hostname%\]}"
+		;;
+	#
+	# ^^^ IPv6 above / DNS Name or IPv4 below vvv
+	#
+	*:*) # DNS name or IPv4 address with port
+		f_dprintf "Looks like a DNS name or IPv4 addr with port: %s" \
+		          "$hostname"
 		port="${hostname#*:}"
 		hostname="${hostname%%:*}"
+		;;
+	*) # DNS name or IPv4 address
+		f_dprintf "Looks like a DNS name or IPv4 addr: %s" "$hostname"
+		: leave hostname as-is
 	esac
 
 	setvar $VAR_HTTP_PROXY_HOST "$hostname"



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201306230941.r5N9flsQ085016>