about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--.gitignore2
-rw-r--r--Makefile18
-rw-r--r--README.md1
-rwxr-xr-xadapter/finger/cha-finger (renamed from bonus/finger/cha-finger)26
-rw-r--r--res/config.toml2
-rw-r--r--src/config/config.nim6
-rw-r--r--src/types/urimethodmap.nim4
7 files changed, 47 insertions, 12 deletions
diff --git a/.gitignore b/.gitignore
index 1cd8f875..462f41a3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,6 @@
 a
 cha
-cha.exe
+target/
 test/
 profile_results.txt
 .obj/
diff --git a/Makefile b/Makefile
index 16478c1a..826c51a3 100644
--- a/Makefile
+++ b/Makefile
@@ -7,6 +7,11 @@ MANPREFIX1 ?= $(MANPREFIX)/man1
 MANPREFIX5 ?= $(MANPREFIX)/man5
 TARGET ?= release
 
+TARGETDIR = $(OUTDIR)/$(TARGET)
+BIN = $(TARGETDIR)/bin
+LIBEXEC = $(TARGETDIR)/libexec/chawan
+CGI_BIN = $(LIBEXEC)/cgi-bin
+
 ifeq ($(TARGET),debug)
 FLAGS += --debugger:native
 else ifeq ($(TARGET),release)
@@ -17,13 +22,20 @@ else ifeq ($(TARGET),release1)
 FLAGS += -d:release --debugger:native
 endif
 
-$(OUTDIR)/$(TARGET)/bin/cha: lib/libquickjs.a src/*.nim src/**/*.nim res/* res/**/*
+.PHONY: all
+all: $(BIN)/cha $(CGI_BIN)/cha-finger
+
+$(BIN)/cha: lib/libquickjs.a src/*.nim src/**/*.nim res/* res/**/*
 	@mkdir -p "$(OUTDIR)/$(TARGET)/bin"
 	$(NIMC) -d:curlLibName:$(CURLLIBNAME) -o:"$(OUTDIR)/$(TARGET)/bin/cha" \
 		--nimcache:"$(OBJDIR)/$(TARGET)" -d:$(TARGET) $(FLAGS) \
 		src/main.nim
 	ln -sf "$(OUTDIR)/$(TARGET)/bin/cha" cha
 
+$(CGI_BIN)/cha-finger: adapter/finger/cha-finger
+	@mkdir -p $(CGI_BIN)
+	cp adapter/finger/cha-finger $(CGI_BIN)
+
 CFLAGS = -g -Wall -O2 -DCONFIG_VERSION=\"$(shell cat lib/quickjs/VERSION)\"
 QJSOBJ = $(OBJDIR)/quickjs
 
@@ -75,7 +87,9 @@ manpage: $(OBJDIR)/man/cha-config.5 $(OBJDIR)/man/cha-mailcap.5 \
 .PHONY: install
 install:
 	mkdir -p "$(DESTDIR)$(PREFIX)/bin"
-	install -m755 "$(OUTDIR)/$(TARGET)/bin/cha" "$(DESTDIR)$(PREFIX)/bin"
+	install -m755 "$(BIN)/cha" "$(DESTDIR)$(PREFIX)/bin"
+	mkdir -p "$(DESTDIR)$(PREFIX)/libexec/chawan/cgi-bin"
+	install -m755 "$(CGI_BIN)/cha-finger" "$(DESTDIR)$(PREFIX)/libexec/chawan/cgi-bin"
 	if test -d "$(OBJDIR)/man"; then \
 	mkdir -p "$(DESTDIR)$(MANPREFIX5)"; \
 	mkdir -p "$(DESTDIR)$(MANPREFIX1)"; \
diff --git a/README.md b/README.md
index 88b142cb..29e7e4fe 100644
--- a/README.md
+++ b/README.md
@@ -63,6 +63,7 @@ Currently implemented features are:
 * cookies
 * FTP support
 * Gopher support
+* Finger support
 * [local CGI](doc/localcgi.md) support
 * [urimethodmap](doc/urimethodmap.md) support
 
diff --git a/bonus/finger/cha-finger b/adapter/finger/cha-finger
index a0f68ef5..ea40e0ab 100755
--- a/bonus/finger/cha-finger
+++ b/adapter/finger/cha-finger
@@ -5,19 +5,28 @@
 # Usage: put this script in your cgi-bin folder, then add the following line to
 # your urimethodmap:
 #
-# finger: file:/cgi-bin/cha-finger?%s
+# finger: /cgi-bin/cha-finger?%s
+#
+# Note: the Chawan default configuration already does this, so normally you
+# don't need to do anything to use the finger protocol.
 
-printf 'Content-Type: text/plain\r\n\r\n'
-if test -z "$QUERY_STRING"
-then	echo "URL expected"
+die() {
+	echo "$1"
 	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'
+
 if printf '%s\n' "$URL" | grep -q '^\([^[]/]*\)\|\(\[[^]]*\]\):[0-9]'
-then	echo "Invalid port"
-	exit 1
+then	die "Invalid port"
 fi
 
 case "$URL" in
@@ -34,4 +43,7 @@ case "$URL" in
 	;;
 esac
 
-printf '%s\r\n' "$USER" | curl -- "telnet://$HOST:79" 2>/dev/null
+printf '%s\r\n' "$USER" | if test -n "$ALL_PROXY"
+then	curl -x "$ALL_PROXY" -- "telnet://$HOST:79"
+else	curl -- "telnet://$HOST:79"
+fi 2>/dev/null
diff --git a/res/config.toml b/res/config.toml
index de5652a3..ae1192bc 100644
--- a/res/config.toml
+++ b/res/config.toml
@@ -33,7 +33,7 @@ urimethodmap = [
 tmpdir = "/tmp/cha"
 editor = "vi %s +%d"
 w3m-cgi-compat = false
-cgi-dir = "${%CHA_BIN_DIR}/../libexec/cgi-bin"
+cgi-dir = "${%CHA_BIN_DIR}/../libexec/chawan/cgi-bin"
 
 [network]
 max-redirect = 10
diff --git a/src/config/config.nim b/src/config/config.nim
index 5f8e9c17..1274e731 100644
--- a/src/config/config.nim
+++ b/src/config/config.nim
@@ -385,9 +385,13 @@ proc getMimeTypes*(config: Config): MimeTypes =
     return DefaultGuess
   return mimeTypes
 
+const DefaultURIMethodMap = parseURIMethodMap("""
+finger:		cgi-bin:cha-finger?%s
+""")
+
 proc getURIMethodMap*(config: Config): URIMethodMap =
   let configDir = getConfigDir() / "chawan" #TODO store this in config?
-  var urimethodmap: URIMethodMap
+  var urimethodmap = DefaultURIMethodMap
   for p in config.external.urimethodmap:
     let f = openFileExpand(configDir, p)
     if f != nil:
diff --git a/src/types/urimethodmap.nim b/src/types/urimethodmap.nim
index 283564a2..f9331cfd 100644
--- a/src/types/urimethodmap.nim
+++ b/src/types/urimethodmap.nim
@@ -69,3 +69,7 @@ proc parseURIMethodMap*(this: var URIMethodMap, s: string) =
     elif v.startsWith("/cgi-bin/"):
       v = "cgi-bin:" & v.substr("/cgi-bin/".len)
     discard this.map.hasKeyOrPut(k, v)
+
+proc parseURIMethodMap*(s: string): URIMethodMap =
+  result = URIMethodMap()
+  result.parseURIMethodMap(s)