Initial commit

This commit is contained in:
Case Duckworth 2020-11-12 08:08:18 -06:00
commit 4ae5373f11
1 changed files with 67 additions and 0 deletions

67
james.awk Executable file
View File

@ -0,0 +1,67 @@
#!/bin/awk -f
# james -- a gemini browser in awk
# it just shells out to openssl for the connection bit
function usplit(url, uarr) {
# clear out the url
for (p in uarr) delete uarr[p];
# scheme - scheme:
if (match(url, /^[^:\/\?#]+:/)) {
uarr["scheme"] = substr(url, RSTART, RLENGTH - 1);
url = substr(url, RSTART + RLENGTH);
}
# authority - //authority
if (match(url, /^\/\/[^\/\?#]*/)) {
uarr["authority"] = substr(url, RSTART+2, RLENGTH-2);
url = substr(url, RSTART + RLENGTH);
}
# path - path
if (match(url, /^[^\?#]*/)) {
uarr["path"] = substr(url, RSTART, RLENGTH);
url = substr(url, RSTART + RLENGTH);
}
# query - ?query
if (match(url, /^\?[^#]*/)) {
uarr["query"] = substr(url, RSTART+1, RLENGTH-1);
url = substr(url, RSTART + RLENGTH);
}
# fragment - #fragment
if (match(url, /^#.*/)) {
uarr["fragment"] = substr(url, RSTART+1);
url = substr(url, RSTART + RLENGTH);
}
# sanity checks
if (!uarr["path"]) uarr["path"] = "/";
}
function fetch(url) {
if (url !~ /.*:\/\/.*/) url="gemini://" url
usplit(url, u);
port = 1965; # TODO: allow different
cmd = "printf '%s\r\n' '" url "' | openssl s_client -crlf -quiet -connect " u["authority"] ":" port " -servername " u["authority"] " -no_ssl3 -no_tls1 -no_tls1_1"
while (cmd | getline) {
print
}
close(cmd);
}
BEGIN {
print "Welcome to JAMES, a Gemini browser in POSIX awk.";
print "Type your request and I'll fetch it for you.";
print "Type 'q' to quit."
}
/^q$/ {
exit 0;
}
{
fetch($0);
}
END {
print "Thanks for flying with James.";
}