Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 21 Dec 2012 21:33:48 +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: r244565 - head/usr.sbin/bsdconfig/networking/share
Message-ID:  <201212212133.qBLLXmqT042431@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: dteske
Date: Fri Dec 21 21:33:47 2012
New Revision: 244565
URL: http://svnweb.freebsd.org/changeset/base/244565

Log:
  Split dialog(1)-based validators for hostname/netmask into two, providing
  transparent validators that can be used free of dialog(1) where needed.
  
  Syntax/return of the original dialog(1)-based validators remains unchanged.

Modified:
  head/usr.sbin/bsdconfig/networking/share/hostname.subr
  head/usr.sbin/bsdconfig/networking/share/netmask.subr

Modified: head/usr.sbin/bsdconfig/networking/share/hostname.subr
==============================================================================
--- head/usr.sbin/bsdconfig/networking/share/hostname.subr	Fri Dec 21 21:26:36 2012	(r244564)
+++ head/usr.sbin/bsdconfig/networking/share/hostname.subr	Fri Dec 21 21:33:47 2012	(r244565)
@@ -40,7 +40,7 @@ f_include_lang $BSDCFG_LIBE/$APP_DIR/inc
 
 ############################################################ FUNCTIONS
 
-# f_dialog_validate_hostname $hostname
+# f_validate_hostname $hostname
 #
 # Returns zero if the given argument (a fully-qualified hostname) is compliant
 # with standards set-forth in RFC's 952 and 1123 of the Network Working Group:
@@ -65,9 +65,9 @@ f_include_lang $BSDCFG_LIBE/$APP_DIR/inc
 # 	  3	One or more individual labels within the hostname are null.
 #
 # If the hostname is determined to be invalid, the appropriate error will be
-# displayed using the f_dialog_msgbox function.
+# displayed using the f_show_msg function.
 #
-f_dialog_validate_hostname()
+f_validate_hostname()
 {
 	local fqhn="$1"
 
@@ -95,18 +95,51 @@ f_dialog_validate_hostname()
 
 		done
 	)
+}
 
-	#
-	# Produce an appropriate error message if necessary.
-	#
-	local retval=$?
-	case $retval in
+# f_dialog_hnerror $error $hostname
+#
+# Display a msgbox with the appropriate error message for an error returned by
+# the f_validate_hostname function.
+#
+f_dialog_hnerror()
+{
+	local error="$1" fqhn="$2"
+
+	[ ${error:-0} -ne 0 ] || return $SUCCESS
+
+	case "$error" in
 	1) f_show_msg "$msg_hostname_label_contains_invalid_chars" "$fqhn";;
 	2) f_show_msg "$msg_hostname_label_starts_or_ends_with_hyphen" "$fqhn";;
 	3) f_show_msg "$msg_hostname_label_is_null" "$fqhn";;
 	63) f_show_msg "$msg_hostname_label_exceeds_max_length" "$fqhn";;
 	255) f_show_msg "$msg_hostname_exceeds_max_length" "$fqhn";;
 	esac
+}
+
+# f_dialog_validate_hostname $hostname
+#
+# Returns zero if the given argument (a fully-qualified hostname) is compliant
+# with standards set-forth in RFC's 952 and 1123 of the Network Working Group:
+#
+# RFC 952 - DoD Internet host table specification
+# http://tools.ietf.org/html/rfc952
+#
+# RFC 1123 - Requirements for Internet Hosts - Application and Support
+# http://tools.ietf.org/html/rfc1123
+#
+# If the hostname is determined to be invalid, the appropriate error will be
+# displayed using the f_dialog_hnerror function above.
+#
+f_dialog_validate_hostname()
+{
+	local fqhn="$1"
+
+	f_validate_hostname "$fqhn"
+	local retval=$?
+
+	# Produce an appropriate error message if necessary.
+	[ $retval -eq $SUCCESS ] || f_dialog_hnerror $retval "$fqhn"
 
 	return $retval
 }

Modified: head/usr.sbin/bsdconfig/networking/share/netmask.subr
==============================================================================
--- head/usr.sbin/bsdconfig/networking/share/netmask.subr	Fri Dec 21 21:26:36 2012	(r244564)
+++ head/usr.sbin/bsdconfig/networking/share/netmask.subr	Fri Dec 21 21:33:47 2012	(r244565)
@@ -69,7 +69,7 @@ f_ifconfig_netmask()
 	echo $netmask
 }
 
-# f_dialog_validate_netmask $netmask
+# f_validate_netmask $netmask
 #
 # Returns zero if the given argument (a subnet mask) is of the proper format.
 #
@@ -85,10 +85,7 @@ f_ifconfig_netmask()
 # 	 	invalid integer (only 0,128,192,224,240,248,252,254,255 are
 # 	 	valid integers).
 #
-# If the subnet mask is determined to be invalid, the appropriate error will be
-# displayed using the f_dialog_msgbox function.
-#
-f_dialog_validate_netmask()
+f_validate_netmask()
 {
 	local mask="$1"
 
@@ -121,18 +118,44 @@ f_dialog_validate_netmask()
 
 		[ $nfields -eq 4 ] || exit 4
 	)
+}
 
-	#
-	# Produce an appropriate error message if necessary.
-	#
-	local retval=$?
-	case $retval in
+# f_dialog_maskerror $error $netmask
+#
+# Display a msgbox with the appropriate error message for an error returned by
+# the f_validate_netmask function.
+#
+f_dialog_maskerror()
+{
+	local error="$1" netmask="$2"
+
+	[ ${error:-0} -ne 0 ] || return $SUCCESS
+
+	case "$error" in
 	1) f_show_msg "$msg_ipv4_mask_field_contains_invalid_chars" "$mask";;
 	2) f_show_msg "$msg_ipv4_mask_field_is_null" "$mask";;
 	3) f_show_msg "$msg_ipv4_mask_field_exceeds_max_value" "$mask";;
 	4) f_show_msg "$msg_ipv4_mask_field_missing_or_extra" "$mask";;
 	5) f_show_msg "$msg_ipv4_mask_field_invalid_value" "$mask";;
 	esac
+}
+
+# f_dialog_validate_netmask $netmask
+#
+# Returns zero if the given argument (a subnet mask) is of the proper format.
+#
+# If the subnet mask is determined to be invalid, the appropriate error will be
+# displayed using the f_dialog_maskerror function above.
+#
+f_dialog_validate_netmask()
+{
+	local netmask="$1"
+
+	f_validate_netmask "$netmask"
+	local retval=$?
+
+	# Produce an appropriate error message if necessary.
+	[ $retval -eq $SUCCESS ] || f_dialog_maskerror $retval "$netmask"
 
 	return $retval
 }



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