repo: geminiclient action: commit revision: path_from: revision_from: d674cb11588bb8976c0c842cd13cc7236c92cf29: path_to: revision_to:
commit d674cb11588bb8976c0c842cd13cc7236c92cf29 Author: epochDate: Sat Jun 20 08:23:22 2020 -0500 refactor of a lot of shit. more broken than before but might be "better" diff --git a/Makefile b/Makefile
--- a/Makefile +++ b/Makefile @@ -1,3 +1,8 @@ install: install -t $(PREFIX)/bin gemini2terminal - install -t $(PREFIX)/bin gemini + install -t $(PREFIX)/bin gemini-handler + install -t $(PREFIX)/bin gemini-get + install -t $(PREFIX)/bin gemini-message-handler + install -t $(PREFIX)/bin set_terminal_title + install -t $(PREFIX)/bin uri_write_cache + install -t $(PREFIX)/bin run_stdio_handler_by_mime_type diff --git a/README b/README
--- a/README
+++ b/README
@@ -1,3 +1,18 @@
+same uritools dep as old version.
+
+this time I split apart the handling of the requesting
+and the handling of the response.
+
+gemini-get will just send the network request to the right place
+and output the whole thing (header included) to stdout.
+
+gemini-message-handler reads a "message/gemini" from stdin
+and then attempts to launch a stream-handler if it can for the mime-type
+if it fails, it caches the response into a file and uses uristart
+to launch a program to handle the file:///?mime-type= URI
+
+----- old stuff below. some of it still useful. -----
+
gemini is some protocol that lies between gopher and http.
and also a file format that's somewhere between text/plain and markdown
diff --git a/gemini b/gemini
deleted file mode 100755
index f4b4629fae7fdf6c4310a7b071cf6edb4a361c2b..0000000000000000000000000000000000000000
--- a/gemini
+++ /dev/null
@@ -1,52 +0,0 @@
-#!/bin/sh
-
-if [ "$#" -lt 3 ];then
- printf "usage: URI domain port\n"
- exit 1
-fi
-
-export gemini_uri="$1"
-uri="$1"
-host="$2"
-port="$3"
-path="$4"
-
-echo "args: $@" >&2
-
-if [ "$3" = "" ];then
- port=1965
-else
- port=$3
-fi
-
-mkdir -p "${PREFIX}/var/cache/gemini"
-
-cachename="${PREFIX}/var/cache/gemini/$(printf "%s\n" "$uri" | tr '\n' '\0' | xargs -0 uriescape | sed 's|/|%2f|g' | sed 's|?|%3f|g')"
-
-#if [ ! -e "$cachename" ];then #if the cache doesn't exist, make it.
- printf '%s\r\n' "$uri" | ncat --no-shutdown --ssl "$host" "$port" > "$cachename"
-#fi
-#cat "$cachename"
-code="$(head -n1 "$cachename" | tr -d '\r' | tr '\t' ' ' | tr -s ' ' | cut '-d ' -f1)"
-meta="$(head -n1 "$cachename" | tr -d '\r' | tr '\t' ' ' | tr -s ' ' | cut '-d ' -f2-)"
-mimetype
-while [ "$code" = 10 ];do
- query="$(uriescape "$(echo | dmenu -p "$meta")" | sed 's|?|%3f|g')"
- if [ ! "$query" ];then #don't bother sending an empty query
- exit 1
- fi
- ## update the URI with the query string...
- uri="${uri}?${query}"
- cachename="${PREFIX}/var/cache/gemini/$(printf "%s\n" "$uri" | tr '\n' '\0' | xargs -0 uriescape | sed 's|/|%2f|g' | sed 's|?|%3f|g')"
- ## re-send the request...
- printf '%s\r\n' "$uri" | ncat --no-shutdown --ssl "$host" "$port" > "$cachename"
- code="$(head -n1 "$cachename" | tr '\t' ' ' | tr -s ' ' | cut '-d ' -f1)"
- mimetype="$(head -n1 "$cachename" | tr '\t' ' ' | tr -s ' ' | cut '-d ' -f2-)"
-done
-if [ "$code" != 20 ];then
- xmessage "gemini failed for some reason. file: $cachename code: $(head -n1 "$cachename") $code"
- exit 1
-fi
-mimetype="$(printf "%s\n" "$meta" | tr ';' ' ' | cut '-d ' -f1)"
-uristart "$(printf "file://%s?mime-type=%s\n" "$cachename" "$mimetype")"
-rm "$cachename" #ha. who needs cache?
diff --git a/gemini-get b/gemini-get
new file mode 100755
index 0000000000000000000000000000000000000000..ceb9dcf1cad64f5d81451eb2fa53ef430b7b496a
--- /dev/null
+++ b/gemini-get
@@ -0,0 +1,21 @@
+#!/bin/sh
+
+if [ ! "$1" ];then
+ printf "usage: gemini-get gemini:uri\n"
+ printf "the output is to stdout and is in raw message/gemini format.\n"
+ exit 1
+fi
+
+uri="$1"
+
+host="$(printf "%s\n" "$uri" | uricut -d)"
+port="$(printf "%s\n" "$uri" | uricut -P)"
+
+if [ ! "$port" ];then
+ port=1965
+fi
+
+printf '%s\r\n' "$uri" \
+ | openssl s_client -servername "$host" -quiet -connect "$host":"$port" \
+ 2>/dev/null
+echo $?
diff --git a/gemini-handler b/gemini-handler
new file mode 100755
index 0000000000000000000000000000000000000000..eb1419a2a810ed0d1b1bf284bf8e2037ffa92592
--- /dev/null
+++ b/gemini-handler
@@ -0,0 +1,3 @@
+#!/bin/sh
+export gemini_uri="$1" #this var is used by subprocesses of gemini-message-handler
+gemini-get "$gemini_uri" | gemini-message-handler "$gemini_uri"
diff --git a/gemini-message-handler b/gemini-message-handler
new file mode 100755
index 0000000000000000000000000000000000000000..f071242fd21597b8a1a01ca672c6ad5fb85cd4de
--- /dev/null
+++ b/gemini-message-handler
@@ -0,0 +1,25 @@
+#!/bin/bash
+### WE DO NOT KNOW WTF THE URI IS SUPPOSED TO BE.
+
+export gemini_uri="$1"
+
+read -r header meta
+meta="$(printf "%s\n" "$meta" | tr -d '\r')"
+case "$header" in
+10)
+ resp="$(echo | dmenu -p "$meta")"
+ exec uristart "$(printf "%s\n" "$gemini_uri" | cut -d? -f1)"'?'"${resp}"
+ ;;
+20)
+ printf "mime-type: %s\n" "$meta"
+ if run_stdio_handler_by_mime_type "$meta";then
+ exit 0 #this worked, we're done.
+ else
+ ### it didn't work. time to save and launch a file-based handler
+ uristart "$(uri_write_cache)?mime-type=${meta}"
+ fi
+ ;;
+*)
+ printf "wtf '%s'\n" "$header"
+ ;;
+esac
diff --git a/gemini2body b/gemini2body
new file mode 100755
index 0000000000000000000000000000000000000000..aee5b8dec1b611abf82958175dd89578a8aa7418
--- /dev/null
+++ b/gemini2body
@@ -0,0 +1,65 @@
+#!/bin/bash
+
+if [ "$#" -lt 3 ];then
+ printf "usage: URI domain port\n"
+ exit 1
+fi
+
+export gemini_uri="$1"
+uri="$1"
+host="$2"
+port="$3"
+path="$4"
+
+echo "args: $@" >&2
+
+if [ "$3" = "" ];then
+ port=1965
+else
+ port=$3
+fi
+
+mkdir -p "${PREFIX}/var/cache/gemini"
+
+cachename="${PREFIX}/var/cache/gemini/$(printf "%s\n" "$uri" | tr '\n' '\0' | xargs -0 uriescape | sed 's|/|%2f|g' | sed 's|?|%3f|g')"
+
+
+echo $uri $host $port
+#if [ ! -e "$cachename" ];then #if the cache doesn't exist, make it.
+ printf '%s\r\n' "$uri" | openssl s_client -servername "$host" -quiet -connect "$host":"$port" 2>/dev/null > "$cachename"
+#fi
+echo "after the ncat"
+#cat "$cachename"
+code="$(head -n1 "$cachename" | tr -d '\r' | tr '\t' ' ' | tr -s ' ' | cut '-d ' -f1)"
+meta="$(head -n1 "$cachename" | tr -d '\r' | tr '\t' ' ' | tr -s ' ' | cut '-d ' -f2-)"
+
+ while [ "$code" = 10 ];do
+ query="$(uriescape "$(echo | dmenu -p "$meta")" | sed 's|?|%3f|g')"
+ if [ ! "$query" ];then #don't bother sending an empty query
+ exit 1
+ fi
+ ## update the URI with the query string...
+ uri="$(printf "%s\n" "${uri}" | cut -d? -f1)" #strip off the old query string first.
+ uri="${uri}?${query}"
+ cachename="${PREFIX}/var/cache/gemini/$(printf "%s\n" "$uri" | tr '\n' '\0' | xargs -0 uriescape | sed 's|/|%2f|g' | sed 's|?|%3f|g')"
+ ## re-send the request...
+ printf '%s\r\n' "$uri" | openssl s_client -servername "$host" -quiet -connect "$host":"$port" 2>/dev/null > "$cachename"
+ code="$(head -n1 "$cachename" | tr '\t' ' ' | tr -s ' ' | cut '-d ' -f1)"
+ mimetype="$(head -n1 "$cachename" | tr '\t' ' ' | tr -s ' ' | cut '-d ' -f2-)"
+ done
+
+echo "code: $code"
+
+if [ "$code" != 20 ];then
+ if [ "${code::1}" = 3 ];then
+ copy_start_nevermind.sh "$meta"
+ exit 0
+ fi
+ xmessage "gemini failed for some reason. file: $cachename code: $(head -n1 "$cachename") $code"
+ exit 1
+fi
+#mimetype="$(printf "%s\n" "$meta" | tr ';' ' ' | cut '-d ' -f1)"
+#the mimetype is part of the message/gemini data, we don't need to give a fuck about it yet.
+mimetype=message/gemini
+uristart "$(printf "file://%s?mime-type=%s\n" "$cachename" "$mimetype")"
+rm "$cachename" #ha. who needs cache?
diff --git a/gemini2terminal b/gemini2terminal
--- a/gemini2terminal +++ b/gemini2terminal @@ -1,5 +1,5 @@ #!/bin/sh -printf "client side idea of our URI: <%s>. header: " "$gemini_uri" +set_terminal_title "$gemini_uri" domain="$(printf "%s\n" "$gemini_uri" | uricut -d)" scheme="$(printf "%s\n" "$gemini_uri" | uricut -s)" path="$(printf "%s\n" "$gemini_uri" | uricut -p)"
-----END OF PAGE-----