[lastbash-cvs] lastbash lastbash,1.73,1.74
Status: Beta
Brought to you by:
cstroie
|
From: Costin S. <cs...@us...> - 2006-12-04 16:57:40
|
Update of /cvsroot/lastbash/lastbash In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv19850 Modified Files: lastbash Log Message: Added support for curl as external http client. Index: lastbash =================================================================== RCS file: /cvsroot/lastbash/lastbash/lastbash,v retrieving revision 1.73 retrieving revision 1.74 diff -u -d -r1.73 -r1.74 --- lastbash 4 Dec 2006 16:32:33 -0000 1.73 +++ lastbash 4 Dec 2006 16:57:36 -0000 1.74 @@ -62,7 +62,7 @@ # Internal stuff PLAYERS="mplayer" -HTTP_CLIENTS="wget" +HTTP_CLIENTS="wget curl" REQ_PROGRAMS="rm date sleep tput md5sum dd chmod" declare -a HTTP_HEADERS HTTP_RESPONSE CR=$'\x0d' @@ -287,6 +287,7 @@ # Select the HTTP client function case "${HTTP_CLIENT}" in "wget") HTTP_CLIENT_FUNCTION="http_get_wget" ;; + "curl") HTTP_CLIENT_FUNCTION="http_get_curl" ;; *) HTTP_CLIENT_FUNCTION="http_get_builtin" ;; esac @@ -359,10 +360,10 @@ # $3 - port # $4 - path - local RET ERRCODE + local RET # Send the request - wget --quiet \ + if wget --quiet \ --tries="3" \ --timeout="5" \ --save-headers \ @@ -371,12 +372,39 @@ --output-file="/dev/null" \ --output-document="${1}" \ "http://${2}:${3}${4}" + then + RET="0" + else + RET="1" + fi - # Keep the error code - ERRCODE="$?" + # Return the status code + return "${RET}" +} - # Check error code - if [ "${ERRCODE}" == "0" ] +# Function: HTTP GET method: curl implementation {{{1 +#----------------------------------------------------------------------------- +function http_get_curl() +{ + # $1 - output file + # $2 - host + # $3 - port + # $4 - path + + local RET + + # Send the request + if curl --silent \ + --connect-timeout "5" \ + --max-time "8" \ + --retry "3" \ + --http1.0 \ + --user-agent "${PROG_TITLE}/${PROG_VER}" \ + --header "Connection: Close" \ + --dump-header - \ + --output - \ + --stderr "/dev/null" \ + "http://${2}:${3}${4}" > "${1}" then RET="0" else |