~moody/rc-gemd

89c9f20250438c4768fc3186d9d83b45d2997c03 — Moody 10 months ago 0de05ae
Parse query options properly
Add require input script for prompting client
Add example of require-input use in select-handler
3 files changed, 20 insertions(+), 1 deletions(-)

A handlers/require-input
M rc-gemd
M select-handler
A handlers/require-input => handlers/require-input +5 -0
@@ 0,0 1,5 @@
#!/bin/rc
if(~ $query ''){
	echo 10^' '^$1^$cr
	exit
}

M rc-gemd => rc-gemd +3 -0
@@ 14,6 14,9 @@ if not
server_name=`{echo $url | sed 's,/.*,,'}
location=`{echo $url | sed 's,[a-zA-Z0-9.:]+/?,/,'}

query=`{echo $location | sed 's,[^?]*\??,,'}
location=`{echo $location | sed 's,\?.*,,'}

echo request from `{sed 's/!.*//' $net/remote} to $url >[1=2]

. $rc_gemd_dir/select-handler

M select-handler => select-handler +12 -1
@@ 1,5 1,16 @@
#!/bin/rc
fs_root=/lib/gem
if(~ $location /)
	location=/index.gem
fs_root=/lib/gem

if(~ $location /search){
	. $rc_gemd_dir/handlers/require-input 'Input a search query'
	echo 20^' '^'text/gemini'^$cr
	sq=`{echo $query | urlencode -d}
	ls $fs_root | grep $"sq | sed '
		s,^'$fs_root'/,,g
		s,^,=> ,g'
	exit
}

exec serve-static