summaryrefslogtreecommitdiffstats
path: root/usr.sbin/bsdconfig/share/media/httpproxy.subr
diff options
context:
space:
mode:
authordteske <dteske@FreeBSD.org>2013-07-14 03:08:52 +0000
committerdteske <dteske@FreeBSD.org>2013-07-14 03:08:52 +0000
commite9ad9b489dd3d2b2dd4dd9f43ab1c04b9c00d98a (patch)
treea9511d0f643be26ac006b8084db35a955fc813f9 /usr.sbin/bsdconfig/share/media/httpproxy.subr
parentc6eaf899761fc14eab6497d13c5ac87c11300777 (diff)
downloadFreeBSD-src-e9ad9b489dd3d2b2dd4dd9f43ab1c04b9c00d98a.zip
FreeBSD-src-e9ad9b489dd3d2b2dd4dd9f43ab1c04b9c00d98a.tar.gz
Re-implement $probe_only aspect of f_media_get_TYPE() (where TYPE is cdrom,
nfs, ftp, http, httpproxy, etc.) and f_device_get() (abstract method for calling aforementioned f_media_get_TYPE()). Previously, if $probe_only was present and non-NULL, the TYPE functions would check for $file and exit with an appropriate error status (success if the file exists and readable, failure otherwise). While this has been retained, a pair of globals has been introduced: $PROBE_EXIST and $PROBE_SIZE (see `/usr/share/bsdconfig/media/common.subr') The $PROBE_EXIST global can be used where you need the functionality of simply testing for existence (previously the _only_ functionality). Meanwhile, the new $PROBE_SIZE global can be used to cause the TYPE function to print the size of the file (in bytes) on standard-out (or -1) if not found or an error occurs. NOTE: If an error occurs, it is logged with the dprintf function, which is visible with `-d' flag or debug=1. In many cases, where you need to get the size of a file _and_ check for its existence, you can use the return status of a $PROBE_SIZE call.
Diffstat (limited to 'usr.sbin/bsdconfig/share/media/httpproxy.subr')
-rw-r--r--usr.sbin/bsdconfig/share/media/httpproxy.subr29
1 files changed, 20 insertions, 9 deletions
diff --git a/usr.sbin/bsdconfig/share/media/httpproxy.subr b/usr.sbin/bsdconfig/share/media/httpproxy.subr
index 817cf0d..66e5be4 100644
--- a/usr.sbin/bsdconfig/share/media/httpproxy.subr
+++ b/usr.sbin/bsdconfig/share/media/httpproxy.subr
@@ -329,14 +329,16 @@ f_media_init_http_proxy()
return $http_found
}
-# f_media_get_http_proxy $device $file [$probe_only]
+# f_media_get_http_proxy $device $file [$probe_type]
#
# Returns data from $file on an FTP server via HTTP proxy using nc(1). Please
# note that $device is unused but must be present (even if null). Information
-# is instead gathered from the environment. If $probe_only is both present and
+# is instead gathered from the environment. If $probe_type is both present and
# non-NULL, this function exits after receiving the HTTP header response from
# the proxy server (if the HTTP response code is 200, success is returned;
-# otherwise failure).
+# otherwise failure). If $probe_type is equal to $PROBE_SIZE, prints the
+# content-length in bytes from the response (or -1 if not found) to standard-
+# out.
#
# The variables used to configure the connection are as follows (all of which
# are configured by f_media_set_http_proxy above):
@@ -358,10 +360,10 @@ f_media_init_http_proxy()
#
f_media_get_http_proxy()
{
- local dev="$1" file="$2" probe_only="$3" hosts=
+ local dev="$1" file="$2" probe_type="$3" hosts=
- f_dprintf "f_media_get_http_proxy: dev=[%s] file=[%s] probe_only=%s" \
- "$dev" "$file" "$probe_only"
+ f_dprintf "f_media_get_http_proxy: dev=[%s] file=[%s] probe_type=%s" \
+ "$dev" "$file" "$probe_type"
local proxy_host proxy_port
f_getvar $VAR_HTTP_PROXY_HOST proxy_host
@@ -408,7 +410,7 @@ f_media_get_http_proxy()
# this is extremely quick'n dirty
#
- rv=0
+ rv=0 length=-1
while read LINE; do
case "$LINE" in
HTTP*)
@@ -416,6 +418,12 @@ f_media_get_http_proxy()
set -- $LINE; rv=$2
f_isinteger "$rv" || rv=0
;;
+ "Content-Length: "*)
+ length="${LINE% }"
+ length="${length#Content-Length: }"
+ f_dprintf "received content-length: %s" \
+ "$length"
+ ;;
*)
[ "${LINE% }" ] || break # End of headers
esac
@@ -427,14 +435,17 @@ f_media_get_http_proxy()
[ $rv -ge 300 ] && exit 3
[ $rv -eq 200 ] || exit $FAILURE
- if [ ! "$probe_only" ]; then
+ if [ ! "$probe_type" ]; then
cat # output the rest ``as-is''
+ elif [ "$probe_type" = "$PROBE_SIZE" ]; then
+ f_isinteger "$length" || length=-1
+ echo "$length"
fi
exit 200
)
local retval=$?
[ $retval -eq 200 ] && return $SUCCESS
- [ "$probe_only" ] && return $FAILURE
+ [ "$probe_type" ] && return $FAILURE
case "$retval" in
5) f_show_msg "$msg_server_error_when_requesting_url" "$url" ;;
OpenPOWER on IntegriCloud