Initial commit
This commit is contained in:
commit
4ae5373f11
|
@ -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.";
|
||||
}
|
Loading…
Reference in New Issue