Add routines for handling stupid URI formatting to Plumber.
This commit is contained in:
parent
effb7907a1
commit
88ebb40c38
73
plumber
73
plumber
@ -32,36 +32,80 @@ edgecase()
|
||||
err()
|
||||
{
|
||||
printf "Plumber wasn't able to find a way to handle the following URI.\n%s\nError code: %s\nProbable reason: %s\n" "${1}" "${2}" "${3}"|xmessage -file - &
|
||||
exit 1
|
||||
}
|
||||
|
||||
case "${2}" in
|
||||
0) set -- "${1}" "${2}" "Some other error." ;;
|
||||
1) set -- "${1}" "${2}" "It doesn't exist on the local filesystem." ;;
|
||||
2) set -- "${1}" "${2}" "There was a parsing error."
|
||||
esac
|
||||
|
||||
err "${@}"
|
||||
}
|
||||
|
||||
cleanse_prefix()
|
||||
{
|
||||
if [ "$(printf "%s" "${1}")" = 'f' ]
|
||||
then
|
||||
printf "%s\n" "$(printf "%s" "${1}"|sed -ne 's&file://\(.*\)&\1&p')"
|
||||
else
|
||||
printf "%s" "${1}"
|
||||
fi
|
||||
}
|
||||
|
||||
cleanse_spaces()
|
||||
{
|
||||
if [ "$(echo "${1}"|grep -c '%20')" = '1' ]
|
||||
then
|
||||
printf "%s\n" "${1}"|sed -e 's&%20& *&g'
|
||||
else
|
||||
printf "%s\n" "${1}"
|
||||
fi
|
||||
}
|
||||
|
||||
cleanse_leftparen()
|
||||
{
|
||||
if [ "$(echo "${1}"|grep -c '%28')" = '1' ]
|
||||
then
|
||||
printf "%s\n" "${1}"|sed -e 's&%28&(&g'
|
||||
else
|
||||
printf "%s\n" "${1}"
|
||||
fi
|
||||
}
|
||||
|
||||
cleanse_rightparen()
|
||||
{
|
||||
if [ "$(echo "${1}"|grep -c '%29')" = '1' ]
|
||||
then
|
||||
printf "%s\n" "${1}"|sed -e 's&%29&)&g'
|
||||
else
|
||||
printf "%s\n" "${1}"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
local_handler()
|
||||
{
|
||||
cleanse_prefix()
|
||||
{
|
||||
printf "%s" "$(printf "%s" "${1}" | sed -ne 's&file://&&p')"
|
||||
}
|
||||
|
||||
target="$(cleanse_prefix "${1}")"
|
||||
if [ -e "${target}" ]
|
||||
|
||||
set -- "$(cleanse_prefix "${1}")"
|
||||
set -- "$(cleanse_leftparen "${1}")"
|
||||
set -- "$(cleanse_rightparen "${1}")"
|
||||
|
||||
|
||||
if [ -e "${1}" ]
|
||||
then
|
||||
mime="$(file --mime-type -b "${target}")"
|
||||
mime="$(file --mime-type -b "${1}")"
|
||||
|
||||
case ${mime} in
|
||||
*html*) exec Links "${target}" & ;;
|
||||
text*) exec xless "${target}" & ;;
|
||||
video*) exec fpv "${target}" & ;;
|
||||
audio*) exec fpm "${target}" & ;;
|
||||
image*) exec iview "${target}" & ;;
|
||||
*pdf) exec gv "${target}" & ;;
|
||||
*) exec exit 1 ;; #Abort. This should never be reached.
|
||||
*html*) exec Links "${1}" & ;;
|
||||
text*) exec xless "${1}" & ;;
|
||||
video*) exec fpv "${1}" & ;;
|
||||
audio*) exec fpm "${1}" & ;;
|
||||
image*) exec iview "${1}" & ;;
|
||||
*pdf) exec gv "${1}" & ;;
|
||||
*) set -- "${1}" "2" ;; #Abort.
|
||||
esac
|
||||
else
|
||||
# Set the error code and throw an error.
|
||||
@ -82,6 +126,7 @@ case "$(printf "%s" "${1}"|cut -b 1,2,3,4)" in
|
||||
then
|
||||
local_handler "${@}"
|
||||
else
|
||||
set -- "${1}" "2"
|
||||
edgecase "${@}"
|
||||
fi
|
||||
esac
|
||||
|
Loading…
Reference in New Issue
Block a user