xref: /freebsd/usr.sbin/bsdconfig/share/media/http.subr (revision 5ca8e32633c4ffbbcd6762e5888b6a4ba0708c6c)
1if [ ! "$_MEDIA_HTTP_SUBR" ]; then _MEDIA_HTTP_SUBR=1
2#
3# Copyright (c) 2012-2013 Devin Teske
4# All rights reserved.
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions
8# are met:
9# 1. Redistributions of source code must retain the above copyright
10#    notice, this list of conditions and the following disclaimer.
11# 2. Redistributions in binary form must reproduce the above copyright
12#    notice, this list of conditions and the following disclaimer in the
13#    documentation and/or other materials provided with the distribution.
14#
15# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25# SUCH DAMAGE.
26#
27#
28############################################################ INCLUDES
29
30BSDCFG_SHARE="/usr/share/bsdconfig"
31. $BSDCFG_SHARE/common.subr || exit 1
32f_dprintf "%s: loading includes..." media/http.subr
33f_include $BSDCFG_SHARE/device.subr
34f_include $BSDCFG_SHARE/dialog.subr
35f_include $BSDCFG_SHARE/media/common.subr
36f_include $BSDCFG_SHARE/media/tcpip.subr
37f_include $BSDCFG_SHARE/strings.subr
38f_include $BSDCFG_SHARE/struct.subr
39f_include $BSDCFG_SHARE/variable.subr
40
41BSDCFG_LIBE="/usr/libexec/bsdconfig"
42f_include_lang $BSDCFG_LIBE/include/messages.subr
43
44############################################################ GLOBALS
45
46HTTP_SKIP_RESOLV=
47
48URL_MAX=261261
49	# NOTE: This is according to actual fetch(1) test-results. We actually
50	# use nc(1) to retrieve files, but it's still a good idea to keep the
51	# URLs short enough that fetch(1) won't complain.
52
53HTTP_DIRS="
54	.
55	releases/$UNAME_P
56	snapshots/$UNAME_P
57	pub/FreeBSD
58	pub/FreeBSD/releases/$UNAME_P
59	pub/FreeBSD/snapshots/$UNAME_P
60	pub/FreeBSD-Archive/old-releases/$UNAME_P
61" # END-QUOTE
62
63############################################################ FUNCTIONS
64
65# f_dialog_menu_media_http
66#
67# Prompt the user to select from a range of ``built-in'' HTTP servers or
68# specify their own. If the user makes a choice and doesn't cancel or press
69# Esc, stores the user's choice in VAR_FTP_PATH (see variable.subr) and returns
70# success.
71#
72f_dialog_menu_media_http()
73{
74	f_dialog_title "$msg_please_select_a_freebsd_http_distribution_site"
75	local title="$DIALOG_TITLE" btitle="$DIALOG_BACKTITLE"
76	f_dialog_title_restore
77	local prompt="$msg_please_select_the_site_closest_to_you_or_other"
78	local menu_list="
79		'pkg $msg_main_site'  'pkg.freebsd.org'
80		'URL'                 '$msg_specify_some_other_http_site'
81	" # END-QUOTE
82	local hline="$msg_select_a_site_thats_close"
83
84	local height width rows
85	eval f_dialog_menu_size height width rows \
86	                        \"\$title\"  \
87	                        \"\$btitle\" \
88	                        \"\$prompt\" \
89	                        \"\$hline\"  \
90	                        $menu_list
91
92	local mtag
93	mtag=$( eval $DIALOG \
94		--title \"\$title\"             \
95		--backtitle \"\$btitle\"        \
96		--hline \"\$hline\"             \
97		--ok-label \"\$msg_ok\"         \
98		--cancel-label \"\$msg_cancel\" \
99		--menu \"\$prompt\"             \
100		$height $width $rows            \
101		$menu_list                      \
102		2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
103	) || return $DIALOG_CANCEL
104	f_dialog_data_sanitize mtag
105
106	case "$mtag" in
107	URL) setvar $VAR_HTTP_PATH "other" ;;
108	*)
109		local value
110		value=$( eval f_dialog_menutag2item \"\$mtag\" $menu_list )
111		setvar $VAR_HTTP_PATH "http://$value"
112	esac
113
114	return $DIALOG_OK
115}
116
117# f_media_set_http
118#
119# Return success if we both found and set the media type to be an HTTP server.
120#
121# Variables from variable.subr that can be used to script user input:
122#
123# 	VAR_HTTP_PATH
124# 		URL containing host and optionally a target path to the release
125# 		repository on the HTTP server. Valid examples include:
126# 			http://myhost
127# 			http://somename:80/pub/
128# 			http://192.168.2.3/pub/
129# 			http://[::1]:8000/
130# 		The default port if not specified is 80.
131# 	VAR_NAMESERVER [Optional]
132# 		If set, overrides resolv.conf(5) and sets the nameserver that
133# 		is used to convert names into addresses (when a name converts
134# 		into multiple addresses, the first address to successfully
135# 		connect is used).
136#
137# Meanwhile, the following variables from variable.subr are set after
138# successful execution:
139#
140# 	VAR_HTTP_HOST
141# 		The HTTP host to connect to, parsed from VAR_HTTP_PATH. In the
142# 		example case of IPv6 where VAR_HTTP_PATH is "http://[::1]" this
143# 		variable will be set to "::1" (the outer brackets are removed).
144# 	VAR_HTTP_PORT
145# 		The TCP port to connect to, parsed from VAR_HTTP_PATH. Usually
146# 		80 unless VAR_HTTP_PATH was one of the following forms:
147# 			http://hostname:OTHER_PORT
148# 			http://hostname:OTHER_PORT/*
149# 			http://ip:OTHER_PORT
150# 			http://ip:OTHER_PORT/*
151# 			http://[ip6]:OTHER_PORT
152# 			http://[ip6]:OTHER_PORT/*
153# 	VAR_HTTP_DIR
154# 		If VAR_HTTP_PATH contained a directory element (e.g.,
155# 		"http://localhost/pub") this variable contains only the
156# 		directory element (e.g., "/pub").
157#
158f_media_set_http()
159{
160	f_media_close
161
162	local url
163	f_getvar $VAR_HTTP_PATH url
164
165	# If we've been through here before ...
166	if f_struct device_network && [ "${url#$msg_other}" ]; then
167		f_dialog_yesno "$msg_reuse_old_http_site_settings" || url=
168	fi
169
170	if [ ! "$url" ]; then
171		f_dialog_menu_media_http || return $FAILURE
172		f_getvar $VAR_HTTP_PATH url
173	fi
174	[ "$url" ] || return $FAILURE
175
176	case "$url" in
177	other)
178		setvar $VAR_HTTP_PATH "http://"
179		f_variable_get_value $VAR_HTTP_PATH \
180			"$msg_please_specify_url_of_freebsd_http_distribution"
181		f_getvar $VAR_HTTP_PATH url
182		if [ ! "${url#http://}" ]; then
183			unset $VAR_HTTP_PATH
184			return $FAILURE
185		fi
186		if [ ${#url} -gt ${URL_MAX:-261261} ]; then
187			f_show_msg "$msg_length_of_specified_url_is_too_long" \
188			           ${#url} ${URL_MAX:-261261}
189			unset $VAR_HTTP_PATH
190			return $FAILURE
191		fi
192		case "$url" in
193		http://*) : valid URL ;;
194		*)
195			f_show_msg "$msg_sorry_invalid_url" "$url"
196			unset $VAR_HTTP_PATH
197			return $FAILURE
198		esac
199	esac
200	case "$url" in
201	http://*) : valid URL ;;
202	*)
203		f_show_msg "$msg_sorry_invalid_url" "$url"
204		unset $VAR_HTTP_PATH
205		return $FAILURE
206	esac
207
208	# Set the name of the HTTP device to the URL
209	f_struct_new DEVICE device_http
210	device_http set name "$url"
211
212	if ! f_struct device_network ||
213	   ! f_dialog_yesno "$msg_youve_already_done_the_network_configuration"
214	then
215		f_struct device_network &&
216			f_device_shutdown device_network
217		if ! f_device_select_tcp; then
218			unset $VAR_HTTP_PATH
219			return $FAILURE
220		fi
221		local dev if
222		f_getvar $VAR_NETWORK_DEVICE if
223		f_device_find -1 "$if" $DEVICE_TYPE_NETWORK dev
224		f_struct_copy "$dev" device_network
225	fi
226	if ! f_device_init device_network; then
227		f_dprintf "f_media_set_http: %s" "$msg_net_device_init_failed"
228		unset $VAR_HTTP_PATH
229		return $FAILURE
230	fi
231
232	local hostname="${url#*://}" port=80 dir=/
233	case "$hostname" in
234	#
235	# The order in-which the below individual cases appear is important!
236	#
237	"["*"]":*/*) # IPv6 address with port and directory
238		f_dprintf "Looks like an IPv6 addr with port/dir: %s" \
239		          "$hostname"
240		hostname="${hostname#\[}"
241		port="${hostname#*\]:}"
242		port="${port%%[!0-9]*}"
243		dir="/${hostname#*/}"
244		hostname="${hostname%%\]:*}"
245		;;
246	"["*"]":*) # IPv6 address with port
247		f_dprintf "Looks like an IPv6 addr with port: %s" "$hostname"
248		hostname="${hostname#\[}"
249		port="${hostname#*\]:}"
250		port="${port%%[!0-9]*}"
251		hostname="${hostname%%\]:*}"
252		;;
253	"["*"]"/*) # IPv6 address with directory
254		f_dprintf "Looks like an IPv6 addr with dir: %s" "$hostname"
255		hostname="${hostname#\[}"
256		dir="/${hostname#*/}"
257		hostname="${hostname%%\]*}"
258		;;
259	"["*"]") # IPv6 address
260		f_dprintf "Looks like an IPv6 addr: %s" "$hostname"
261		hostname="${hostname#\[}"
262		hostname="${hostname%\]}"
263		;;
264	#
265	# ^^^ IPv6 above / DNS Name or IPv4 below vvv
266	#
267	*:*/*) # DNS name or IPv4 address with port and directory
268		f_dprintf "Looks like a %s with port/dir: %s" \
269		          "DNS name or IPv4 addr" "$hostname"
270		port="${hostname#*:}"
271		port="${port%%[!0-9]*}"
272		dir="/${hostname#*/}"
273		hostname="${hostname%%:*}"
274		;;
275	*:*) # DNS name or IPv4 address with port
276		f_dprintf "Looks like a DNS name or IPv4 addr with port: %s" \
277		          "$hostname"
278		port="${hostname#*:}"
279		hostname="${hostname%%:*}"
280		;;
281	*/*) # DNS name or IPv4 address with directory
282		f_dprintf "Looks like a DNS name or IPv4 addr with dir: %s" \
283		          "$hostname"
284		dir="/${hostname#*/}"
285		hostname="${hostname%%/*}"
286		;;
287	*) # DNS name or IPv4 address
288		f_dprintf "Looks like a DNS name or IPv4 addr: %s" "$hostname"
289		: leave hostname as-is
290	esac
291
292	f_dprintf "hostname = \`%s'" "$hostname"
293	f_dprintf "dir = \`%s'" "$dir"
294	f_dprintf "port \# = \`%d'" "$port"
295
296	local ns
297	f_getvar $VAR_NAMESERVER ns
298	[ "$ns" ] || f_resolv_conf_nameservers ns
299	if [ "$ns" -a ! "$HTTP_SKIP_RESOLV" ] && ! {
300		f_validate_ipaddr "$hostname" ||
301		f_validate_ipaddr6 "$hostname"
302	}; then
303		f_show_info "$msg_looking_up_host" "$hostname"
304		f_dprintf "%s: Looking up hostname, %s, using host(1)" \
305		          "f_media_set_http" "$hostname"
306		if ! f_quietly f_host_lookup "$hostname"; then
307			f_show_msg "$msg_cannot_resolve_hostname" "$hostname"
308			f_struct device_network &&
309				f_device_shutdown device_network
310			f_struct_free device_network
311			unset $VAR_HTTP_PATH
312			return $FAILURE
313		fi
314		f_dprintf "Found DNS entry for %s successfully." "$hostname"
315	fi
316
317	setvar $VAR_HTTP_HOST "$hostname"
318	setvar $VAR_HTTP_PORT "$port"
319	setvar $VAR_HTTP_DIR  "$dir"
320
321	device_http set type     $DEVICE_TYPE_HTTP
322	device_http set init     f_media_init_http
323	device_http set get      f_media_get_http
324	device_http set shutdown f_media_shutdown_http
325	device_http set private  device_network
326	f_struct_copy device_http device_media
327	f_struct_free device_http
328
329	return $SUCCESS
330}
331
332# f_http_check_access [$connect_only]
333#
334# Return success if able list a remote HTTP directory. If $connect_only is
335# present and non-null, then returns success if a connection can be made.
336# Variables from variable.subr that can be used to script user input:
337#
338# 	VAR_HTTP_HOST
339# 		The HTTP server host name, IPv4 address or IPv6 address.
340# 		Valid examples include:
341# 			myhost
342# 			192.168.2.3
343# 			::1
344# 	VAR_HTTP_PORT
345# 		The TCP port to connect to when communicating with the server.
346# 	VAR_HTTP_PATH
347# 		The HTTP path sent to the server. Unused if $connect_only is
348# 		present and non-NULL.
349#
350f_http_check_access()
351{
352	local connect_only="$1" hosts=
353
354	local http_host http_port
355	f_getvar $VAR_HTTP_HOST http_host
356	f_getvar $VAR_HTTP_PORT http_port
357
358	if ! {
359		f_validate_ipaddr "$http_host" ||
360		f_validate_ipaddr6 "$http_host" ||
361		{
362		  f_dprintf "%s: Looking up hostname, %s, using host(1)" \
363		            "f_http_check_access" "$http_host"
364		  f_host_lookup "$http_host" hosts
365		}
366	}; then
367		# All the above validations failed
368		[ "$hosts" ] && f_dialog_msgbox "$hosts"
369		unset $VAR_HTTP_HOST
370		return $FAILURE
371	elif [ ! "$hosts" ]; then
372		# One of the first two validations passed
373		hosts="$http_host"
374	fi
375
376	local host connected=
377	for host in $hosts; do
378		f_quietly nc -nz "$host" "$http_port" || continue
379		connected=1; break
380	done
381	if [ ! "$connected" ]; then
382		f_show_msg "$msg_couldnt_connect_to_server http://%s:%s/" \
383		           "$http_host" "$http_port"
384		unset $VAR_HTTP_HOST
385		return $FAILURE
386	fi
387	[ "$connect_only" ] && return $SUCCESS
388
389	local http_path
390	f_getvar $VAR_HTTP_PATH http_path
391	f_show_info "$msg_checking_access_to" "$http_path"
392
393	local rx
394	case "$http_path" in
395	http://*|/*) : valid request ;;
396	*) http_path="/$http_path" # full URI requests only
397	esac
398	if ! rx=$(
399		printf "GET %s/ HTTP/1.0\r\n\r\n" "${http_path%/}" |
400			nc -n "$host" "$http_port"
401	); then
402		f_show_msg "$msg_couldnt_connect_to_server http://%s:%s/" \
403		           "$http_host" "$http_port"
404		unset $VAR_HTTP_HOST
405		return $FAILURE
406	fi
407
408	local hdr
409	hdr=$( echo "$rx" | awk '/^\r$/{exit}{print}' )
410
411	local http_found=$FAILURE
412	if echo "$hdr" | awk '
413		BEGIN { found = 0 }
414		/^HTTP.... 200 / {
415			found = 1
416			exit
417		}
418		END { exit ! found }
419	'; then
420		http_found=$SUCCESS
421	fi
422
423	return $http_found
424}
425
426# f_media_init_http $device
427#
428# Initializes the HTTP media device. Returns success if able to confirm the
429# existence of at least one known HTTP server release path directly via HTTP
430# using f_http_check_access(), above.
431#
432# Variables from variable.subr that can be used to script user input:
433#
434# 	VAR_HTTP_HOST
435#		The HTTP server to connect to. Must be set. Also see
436# 		f_http_check_access() for additional variables.
437# 	VAR_RELNAME
438# 		Usually set to `uname -r' but can be overridden.
439# 	VAR_HTTP_PATH
440# 		The HTTP path sent to the server. Usually set by calling
441# 		f_media_set_http().
442#
443# Meanwhile, after successful execution, the following variables (also from
444# variable.subr) are set:
445#
446# 	VAR_HTTP_PATH
447# 		The [possibly] adjusted VAR_HTTP_PATH that was found to contain
448# 		a valid FreeBSD repository.
449#
450f_media_init_http()
451{
452	local dev="$1"
453	f_dprintf "Init routine called for HTTP device. dev=[%s]" "$dev"
454
455	if [ "$HTTP_INITIALIZED" ]; then
456		f_dprintf "HTTP device already initialized."
457		return $SUCCESS
458	fi
459
460	#
461	# First verify access
462	#
463	local connect_only=1
464	f_http_check_access $connect_only
465
466	local http_host
467	f_getvar $VAR_HTTP_HOST http_host
468	while [ ! "$http_host" ]; do
469		f_media_set_http || return $FAILURE
470		f_http_check_access $connect_only
471		f_getvar $VAR_HTTP_HOST http_host
472	done
473
474	local http_path http_found=$FAILURE
475	while :; do
476		#
477		# Now that we've verified that the path we're given is ok,
478		# let's try to be a bit intelligent in locating the release we
479		# are looking for.  First off, if the release is specified as
480		# "__RELEASE" or "any", then just assume that the current
481		# directory is the one we want and give up.
482		#
483		local rel
484		f_getvar $VAR_RELNAME rel
485		f_dprintf "f_media_init_http: rel=[%s]" "$rel"
486
487		case "$rel" in
488		__RELEASE|any)
489			f_getvar $VAR_HTTP_DIR $VAR_HTTP_PATH
490			f_http_check_access
491			http_found=$?
492			;;
493		*)
494			#
495			# Ok, since we have a release variable, let's walk
496			# through the list of directories looking for a release
497			# directory. First successful path wins.
498			#
499			local fdir hp
500			f_getvar $VAR_HTTP_PATH%/ hp
501			setvar $VAR_HTTP_PATH "$hp/$PKG_ABI/latest"
502			if [ "$PKG_ABI" ] && f_http_check_access; then
503				http_found=$SUCCESS
504				setvar $VAR_HTTP_PATH "$hp"
505			else
506				for fdir in $HTTP_DIRS; do
507					setvar $VAR_HTTP_PATH "$hp/$fdir/$rel"
508					if f_http_check_access; then
509						http_found=$SUCCESS
510						break
511					fi
512				done
513			fi
514		esac
515
516		[ $http_found -eq $SUCCESS ] && HTTP_INITIALIZED=YES break
517
518		f_getvar $VAR_HTTP_PATH http_path
519		f_show_msg "$msg_please_check_the_url_and_try_again" \
520		           "$http_path"
521
522		unset HTTP_INITIALIZED $VAR_HTTP_PATH
523		f_media_set_http || break
524	done
525
526	return $http_found
527}
528
529# f_media_get_http $device $file [$probe_type]
530#
531# Returns data from $file on an HTTP server using nc(1). Please note that
532# $device is unused but must be present (even if null). Information is instead
533# gathered from the environment. If $probe_type is both present and non-NULL,
534# this function exits after receiving the HTTP header response from the server
535# (if the HTTP response code is 200, success is returned; otherwise failure).
536# If $probe_type is equal to $PROBE_SIZE, prints the content-length in bytes
537# from the response (or -1 if not found) to standard-out.
538#
539# The variables used to configure the connection are as follows (all of which
540# are configured by f_media_set_http above):
541#
542# 	VAR_HTTP_HOST
543# 		HTTP server which to connect. Can be an IPv4 address, IPv6
544# 		address, or DNS hostname of your choice.
545# 	VAR_HTTP_PORT
546# 		TCP port to connect on; see f_media_set_http above.
547# 	VAR_HTTP_PATH
548# 		Directory prefix to use when requesting $file. Default is `/'
549# 		unless f_media_init_http was able to use f_http_check_access
550# 		to validate one of the defaults in $HTTP_DIRS (see GLOBALS at
551# 		the top of this file); assuming VAR_RELNAME was not set to
552# 		either `__RELEASE' or `any' (indicating that the global set of
553# 		$HTTP_DIRS should be ignored).
554#
555# See variable.subr for additional information.
556#
557# Example usage:
558# 	f_media_set_http
559# 	f_media_get_http media $file
560#
561f_media_get_http()
562{
563	local dev="$1" file="$2" probe_type="$3" hosts=
564	local name
565
566	$dev get name name
567	f_dprintf "f_media_get_http: dev=[%s] file=[%s] probe_type=%s" \
568	          "$name" "$file" "$probe_type"
569
570	local http_host http_port
571	f_getvar $VAR_HTTP_HOST http_host
572	f_getvar $VAR_HTTP_PORT http_port
573
574	if [ ! "$HTTP_INITIALIZED" ]; then
575		f_dprintf "No HTTP connection open, can't get file %s" "$file"
576		return $FAILURE
577	fi
578
579	if ! {
580		f_validate_ipaddr "$http_host" ||
581		f_validate_ipaddr6 "$http_host" ||
582		{
583		  f_dprintf "%s: Looking up hostname, %s, using host(1)" \
584		            "f_media_get_http" "$http_host"
585		  f_host_lookup "$http_host" hosts
586		}
587	}; then
588		# All the above validations failed
589		[ "$hosts" ] && f_dialog_msgbox "$hosts"
590		return $FAILURE
591	elif [ ! "$hosts" ]; then
592		# One of the first two validations passed
593		hosts="$http_host"
594	fi
595
596	local host connected=
597	for host in $hosts; do
598		f_quietly nc -nz "$host" "$http_port" || continue
599		connected=1; break
600	done
601	if [ ! "$connected" ]; then
602		f_show_msg "$msg_couldnt_connect_to_server http://%s:%s/" \
603		           "$http_host" "$http_port"
604		return $FAILURE
605	fi
606
607	local http_path
608	f_getvar $VAR_HTTP_PATH%/ http_path
609	case "$http_path" in
610	http://*|/*) : valid request ;;
611	*) http_path="/$http_path" # full URI requests only
612	esac
613
614	local url="$http_path/$file" rx
615	f_dprintf "sending http request for: %s" "$url"
616	f_dprintf "using nc to connect to: %s:%s" "$host" "$http_port"
617	printf "GET %s HTTP/1.0\r\n\r\n" "$url" | nc -n "$host" "$http_port" |
618	(
619		#
620		# scan the headers of the response
621		# this is extremely quick'n dirty
622		#
623
624		rv=0 length=-1
625		while read LINE; do
626			case "$LINE" in
627			HTTP*)
628				f_dprintf "received response: %s" "$LINE"
629				set -- $LINE; rv=$2
630				f_isinteger "$rv" || rv=0
631				;;
632			"Content-Length: "*)
633				length="${LINE%
634}"
635				length="${length#Content-Length: }"
636				f_dprintf "received content-length: %s" \
637				          "$length"
638				;;
639			*)
640				[ "${LINE%
641}" ] || break # End of headers
642			esac
643		done
644
645		[ $rv -ge 500 ] && exit 5
646		[ $rv -eq 404 ] && exit 44
647		[ $rv -ge 400 ] && exit 4
648		[ $rv -ge 300 ] && exit 3
649		[ $rv -eq 200 ] || exit $FAILURE
650
651		if [ ! "$probe_type" ]; then
652			cat # output the rest ``as-is''
653		elif [ "$probe_type" = "$PROBE_SIZE" ]; then
654			f_isinteger "$length" || length=-1
655			echo "$length"
656		fi
657		exit 200
658	)
659	local retval=$?
660	[ $retval -eq 200 ] && return $SUCCESS
661	[ "$probe_type" ] && return $FAILURE
662
663	case "$retval" in
664	  5) f_show_msg "$msg_server_error_when_requesting_url" "$url" ;;
665	 44) f_show_msg "$msg_url_was_not_found" "$url" ;;
666	  4) f_show_msg "$msg_client_error" ;;
667	  *) f_show_msg "$msg_error_when_requesting_url" "$url" ;;
668	esac 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
669	return $FAILURE
670}
671
672# f_media_shutdown_http $device
673#
674# Shuts down the HTTP device. Return status should be ignored. Note that since
675# we don't maintain an open connection to the HTTP server, nothing to do.
676#
677f_media_shutdown_http()
678{
679	[ "$HTTP_INITIALIZED" ] || return $SUCCESS
680
681	unset HTTP_INITIALIZED
682}
683
684############################################################ MAIN
685
686f_dprintf "%s: Successfully loaded." media/http.subr
687
688fi # ! $_MEDIA_HTTP_SUBR
689