Deleted Added
full compact
http.subr (256281) http.subr (258420)
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: stable/10/usr.sbin/bsdconfig/share/media/http.subr 256181 2013-10-09 08:12:26Z dteske $
27# $FreeBSD: stable/10/usr.sbin/bsdconfig/share/media/http.subr 258420 2013-11-21 03:38:47Z 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\" \

--- 358 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
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\" \

--- 358 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

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

476 # directory is the one we want and give up.
477 #
478 local rel
479 f_getvar $VAR_RELNAME rel
480 f_dprintf "f_media_init_http: rel=[%s]" "$rel"
481
482 case "$rel" in
483 __RELEASE|any)
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

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

482 # directory is the one we want and give up.
483 #
484 local rel
485 f_getvar $VAR_RELNAME rel
486 f_dprintf "f_media_init_http: rel=[%s]" "$rel"
487
488 case "$rel" in
489 __RELEASE|any)
484 setvar $VAR_HTTP_PATH "$VAR_HTTP_DIR"
490 f_getvar $VAR_HTTP_DIR $VAR_HTTP_PATH
485 f_http_check_access
486 http_found=$?
487 ;;
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
491 f_http_check_access
492 http_found=$?
493 ;;
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 "$hp/$PKG_ABI/latest"
503 if [ "$PKG_ABI" ] && f_http_check_access; then
504 http_found=$SUCCESS
505 setvar $VAR_HTTP_PATH "$hp"
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 }

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

590 f_getvar $VAR_HTTP_PATH%/ http_path
591 case "$http_path" in
592 http://*|/*) : valid request ;;
593 *) http_path="/$http_path" # full URI requests only
594 esac
595
596 local url="$http_path/$file" rx
597 f_dprintf "sending http request for: %s" "$url"
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 }

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

610 f_getvar $VAR_HTTP_PATH%/ http_path
611 case "$http_path" in
612 http://*|/*) : valid request ;;
613 *) http_path="/$http_path" # full URI requests only
614 esac
615
616 local url="$http_path/$file" rx
617 f_dprintf "sending http request for: %s" "$url"
618 f_dprintf "using nc to connect to: %s:%s" "$host" "$http_port"
598 printf "GET %s HTTP/1.0\r\n\r\n" "$url" | nc -n "$host" "$http_port" |
599 (
600 #
601 # scan the headers of the response
602 # this is extremely quick'n dirty
603 #
604
605 rv=0 length=-1

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

645 5) f_show_msg "$msg_server_error_when_requesting_url" "$url" ;;
646 44) f_show_msg "$msg_url_was_not_found" "$url" ;;
647 4) f_show_msg "$msg_client_error" ;;
648 *) f_show_msg "$msg_error_when_requesting_url" "$url" ;;
649 esac
650 return $FAILURE
651}
652
619 printf "GET %s HTTP/1.0\r\n\r\n" "$url" | nc -n "$host" "$http_port" |
620 (
621 #
622 # scan the headers of the response
623 # this is extremely quick'n dirty
624 #
625
626 rv=0 length=-1

--- 39 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
653############################################################ MAIN
654
655f_dprintf "%s: Successfully loaded." media/http.subr
656
657fi # ! $_MEDIA_HTTP_SUBR
686############################################################ MAIN
687
688f_dprintf "%s: Successfully loaded." media/http.subr
689
690fi # ! $_MEDIA_HTTP_SUBR