Deleted Added
full compact
http.subr (257788) http.subr (257795)
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:

--- 10 unchanged lines hidden (view full) ---

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#
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:

--- 10 unchanged lines hidden (view full) ---

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# $FreeBSD: head/usr.sbin/bsdconfig/share/media/http.subr 257788 2013-11-07 10:40:19Z dteske $
27# $FreeBSD: head/usr.sbin/bsdconfig/share/media/http.subr 257795 2013-11-07 12:40:42Z dteske $
28#
29############################################################ INCLUDES
30
31BSDCFG_SHARE="/usr/share/bsdconfig"
32. $BSDCFG_SHARE/common.subr || exit 1
33f_dprintf "%s: loading includes..." media/http.subr
34f_include $BSDCFG_SHARE/device.subr
35f_include $BSDCFG_SHARE/dialog.subr

--- 36 unchanged lines hidden (view full) ---

72#
73f_dialog_menu_media_http()
74{
75 f_dialog_title "$msg_please_select_a_freebsd_http_distribution_site"
76 local title="$DIALOG_TITLE" btitle="$DIALOG_BACKTITLE"
77 f_dialog_title_restore
78 local prompt="$msg_please_select_the_site_closest_to_you_or_other"
79 local menu_list="
28#
29############################################################ INCLUDES
30
31BSDCFG_SHARE="/usr/share/bsdconfig"
32. $BSDCFG_SHARE/common.subr || exit 1
33f_dprintf "%s: loading includes..." media/http.subr
34f_include $BSDCFG_SHARE/device.subr
35f_include $BSDCFG_SHARE/dialog.subr

--- 36 unchanged lines hidden (view full) ---

72#
73f_dialog_menu_media_http()
74{
75 f_dialog_title "$msg_please_select_a_freebsd_http_distribution_site"
76 local title="$DIALOG_TITLE" btitle="$DIALOG_BACKTITLE"
77 f_dialog_title_restore
78 local prompt="$msg_please_select_the_site_closest_to_you_or_other"
79 local menu_list="
80 '$msg_main_site' 'ftp.freebsd.org'
80 'dist $msg_main_site' 'ftp.freebsd.org'
81 'pkg $msg_main_site' 'pkg.freebsd.org'
81 'URL' '$msg_specify_some_other_http_site'
82 " # END-QUOTE
83 local hline="$msg_select_a_site_thats_close"
84
85 local height width rows
86 eval f_dialog_menu_size height width rows \
87 \"\$title\" \
88 \"\$btitle\" \

--- 227 unchanged lines hidden (view full) ---

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
82 'URL' '$msg_specify_some_other_http_site'
83 " # END-QUOTE
84 local hline="$msg_select_a_site_thats_close"
85
86 local height width rows
87 eval f_dialog_menu_size height width rows \
88 \"\$title\" \
89 \"\$btitle\" \

--- 227 unchanged lines hidden (view full) ---

317
318 setvar $VAR_HTTP_HOST "$hostname"
319 setvar $VAR_HTTP_PORT "$port"
320 setvar $VAR_HTTP_DIR "$dir"
321
322 device_http set type $DEVICE_TYPE_HTTP
323 device_http set init f_media_init_http
324 device_http set get f_media_get_http
324 device_http set shutdown :
325 device_http set shutdown f_media_shutdown_http
325 device_http set private 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]

--- 114 unchanged lines hidden (view full) ---

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
326 device_http set private network
327 f_struct_copy device_http device_media
328 f_struct_free device_http
329
330 return $SUCCESS
331}
332
333# f_http_check_access [$connect_only]

--- 114 unchanged lines hidden (view full) ---

448# The [possibly] adjusted VAR_HTTP_PATH that was found to contain
449# a valid FreeBSD repository.
450#
451f_media_init_http()
452{
453 local dev="$1"
454 f_dprintf "Init routine called for HTTP device. dev=[%s]" "$dev"
455
456 if [ "$HTTP_INITIALIZED" ]; then
457 f_dprintf "HTTP device already initialized."
458 return $SUCCESS
459 fi
460
455 #
456 # First verify access
457 #
458 local connect_only=1
459 f_http_check_access $connect_only
460
461 local http_host
462 f_getvar $VAR_HTTP_HOST http_host

--- 25 unchanged lines hidden (view full) ---

488 *)
489 #
490 # Ok, since we have a release variable, let's walk
491 # through the list of directories looking for a release
492 # directory. First successful path wins.
493 #
494 local fdir hp
495 f_getvar $VAR_HTTP_PATH%/ hp
461 #
462 # First verify access
463 #
464 local connect_only=1
465 f_http_check_access $connect_only
466
467 local http_host
468 f_getvar $VAR_HTTP_HOST http_host

--- 25 unchanged lines hidden (view full) ---

494 *)
495 #
496 # Ok, since we have a release variable, let's walk
497 # through the list of directories looking for a release
498 # directory. First successful path wins.
499 #
500 local fdir hp
501 f_getvar $VAR_HTTP_PATH%/ hp
496 for fdir in $HTTP_DIRS; do
497 setvar $VAR_HTTP_PATH "$hp/$fdir/$rel"
498 if f_http_check_access; then
499 http_found=$SUCCESS
500 break
501 fi
502 done
502 setvar $VAR_HTTP_PATH \
503 "$hp/freebsd:${UNAME_R%%.*}:$UNAME_PKG/latest"
504 if f_http_check_access; then
505 http_found=$SUCCESS
506 else
507 for fdir in $HTTP_DIRS; do
508 setvar $VAR_HTTP_PATH "$hp/$fdir/$rel"
509 if f_http_check_access; then
510 http_found=$SUCCESS
511 break
512 fi
513 done
514 fi
503 esac
504
515 esac
516
505 [ $http_found -eq $SUCCESS ] && break
517 if [ $http_found -eq $SUCCESS ]; then
518 HTTP_INITIALIZED=YES
519 break
520 fi
506
507 f_getvar $VAR_HTTP_PATH http_path
508 f_show_msg "$msg_please_check_the_url_and_try_again" \
509 "$http_path"
510
521
522 f_getvar $VAR_HTTP_PATH http_path
523 f_show_msg "$msg_please_check_the_url_and_try_again" \
524 "$http_path"
525
511 unset $VAR_HTTP_PATH
526 unset HTTP_INITIALIZED $VAR_HTTP_PATH
512 f_media_set_http || break
513 done
514
515 return $http_found
516}
517
518# f_media_get_http $device $file [$probe_type]
519#

--- 33 unchanged lines hidden (view full) ---

553
554 f_dprintf "f_media_get_http: dev=[%s] file=[%s] probe_type=%s" \
555 "$dev" "$file" "$probe_type"
556
557 local http_host http_port
558 f_getvar $VAR_HTTP_HOST http_host
559 f_getvar $VAR_HTTP_PORT http_port
560
527 f_media_set_http || break
528 done
529
530 return $http_found
531}
532
533# f_media_get_http $device $file [$probe_type]
534#

--- 33 unchanged lines hidden (view full) ---

568
569 f_dprintf "f_media_get_http: dev=[%s] file=[%s] probe_type=%s" \
570 "$dev" "$file" "$probe_type"
571
572 local http_host http_port
573 f_getvar $VAR_HTTP_HOST http_host
574 f_getvar $VAR_HTTP_PORT http_port
575
576 if [ ! "$HTTP_INITIALIZED" ]; then
577 f_dprintf "No HTTP connection open, can't get file %s" "$file"
578 return $FAILURE
579 fi
580
561 if ! {
562 f_validate_ipaddr "$http_host" ||
563 f_validate_ipaddr6 "$http_host" ||
564 {
565 f_dprintf "%s: Looking up hostname, %s, using host(1)" \
566 "f_media_get_http" "$http_host"
567 f_host_lookup "$http_host" hosts
568 }

--- 77 unchanged lines hidden (view full) ---

646 5) f_show_msg "$msg_server_error_when_requesting_url" "$url" ;;
647 44) f_show_msg "$msg_url_was_not_found" "$url" ;;
648 4) f_show_msg "$msg_client_error" ;;
649 *) f_show_msg "$msg_error_when_requesting_url" "$url" ;;
650 esac
651 return $FAILURE
652}
653
581 if ! {
582 f_validate_ipaddr "$http_host" ||
583 f_validate_ipaddr6 "$http_host" ||
584 {
585 f_dprintf "%s: Looking up hostname, %s, using host(1)" \
586 "f_media_get_http" "$http_host"
587 f_host_lookup "$http_host" hosts
588 }

--- 77 unchanged lines hidden (view full) ---

666 5) f_show_msg "$msg_server_error_when_requesting_url" "$url" ;;
667 44) f_show_msg "$msg_url_was_not_found" "$url" ;;
668 4) f_show_msg "$msg_client_error" ;;
669 *) f_show_msg "$msg_error_when_requesting_url" "$url" ;;
670 esac
671 return $FAILURE
672}
673
674# f_media_shutdown_http $device
675#
676# Shuts down the HTTP device. Return status should be ignored. Note that since
677# we don't maintain an open connection to the HTTP server, nothing to do.
678#
679f_media_shutdown_http()
680{
681 [ "$HTTP_INITIALIZED" ] || return $SUCCESS
682
683 unset HTTP_INITIALIZED
684}
685
654############################################################ MAIN
655
656f_dprintf "%s: Successfully loaded." media/http.subr
657
658fi # ! $_MEDIA_HTTP_SUBR
686############################################################ MAIN
687
688f_dprintf "%s: Successfully loaded." media/http.subr
689
690fi # ! $_MEDIA_HTTP_SUBR