about summary refs log tree commit diff stats
path: root/adapter
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-12-12 10:58:46 +0100
committerbptato <nincsnevem662@gmail.com>2023-12-12 19:37:19 +0100
commit5efdc54db2d2c766d7ce7c6545207ce2ce805620 (patch)
tree88c9e029cb0de286df1ee20f4c57da63539d9272 /adapter
parent4eb57c2b88325d3963c6671a6f27bd08fc07cb59 (diff)
downloadchawan-5efdc54db2d2c766d7ce7c6545207ce2ce805620.tar.gz
cha-finger: use MAPPED_URI_*
Much simpler & more efficient than the ugly regex parsing we used
to have.
Diffstat (limited to 'adapter')
-rwxr-xr-xadapter/finger/cha-finger40
1 files changed, 15 insertions, 25 deletions
diff --git a/adapter/finger/cha-finger b/adapter/finger/cha-finger
index ea40e0ab..e963b339 100755
--- a/adapter/finger/cha-finger
+++ b/adapter/finger/cha-finger
@@ -1,6 +1,7 @@
 #!/bin/sh
 # Finger protocol adapter for Chawan. Requires curl.
-# (It also works with w3m.)
+# (It does *not* work without the environment variables MAPPED_URI_*, so no
+# w3m support.)
 #
 # Usage: put this script in your cgi-bin folder, then add the following line to
 # your urimethodmap:
@@ -15,35 +16,24 @@ die() {
 	exit 1
 }
 
-if test -z "$QUERY_STRING"
-then	die "URL expected"
-fi
 type curl >/dev/null || \
 	die "curl must be installed on your computer to use finger."
-URL="$(printf '%s\n' "$QUERY_STRING" | \
-	sed 's/^finger:\/\///;s/^\([^[]\/:]\|\[[^]:]*\]\):79/\1/')"
 
-printf 'Content-Type: text/plain\r\n\r\n'
+printf 'Content-Type: text/plain\n\n'
 
-if printf '%s\n' "$URL" | grep -q '^\([^[]/]*\)\|\(\[[^]]*\]\):[0-9]'
-then	die "Invalid port"
-fi
+PORT="${MAPPED_URI_PORT:-79}"
+test "$PORT" = 79 || die "Invalid port"
 
-case "$URL" in
-*@*)	USER="$(printf '%s\n' "$URL" | sed 's/@.*//')"
-	HOST="$(printf '%s\n' "$URL" | \
-		tail -c +$((${#USER} + 2)) | \
-		sed 's/\/.*//')"
-	;;
-*/w*)	HOST="$(printf '%s\n' "$URL" | sed 's/\/.*//')"
-	USER="/w $(printf '%s\n' "$URL" | tail -c +$((${#HOST} + 4)))"
-	;;
-*)	HOST="$(printf '%s\n' "$URL" | sed 's/\/.*//')"
-	USER="$(printf '%s\n' "$URL" | tail -c +$((${#HOST} + 2)))"
-	;;
-esac
+if test -n "$MAPPED_URI_USERNAME"
+then	USER="$MAPPED_URI_USERNAME"
+else	case "$MAPPED_URI_PATH" in
+	/w*) USER="/w ${MAPPED_URI_PATH#/w}" ;;
+	*) USER="$MAPPED_URI_PATH" ;;
+	esac
+fi
+URL="telnet://$MAPPED_URI_HOST:$PORT"
 
 printf '%s\r\n' "$USER" | if test -n "$ALL_PROXY"
-then	curl -x "$ALL_PROXY" -- "telnet://$HOST:79"
-else	curl -- "telnet://$HOST:79"
+then	curl -x "$ALL_PROXY" -- "$URL"
+else	curl -- "$URL"
 fi 2>/dev/null