about summary refs log tree commit diff stats
path: root/adapter/protocol/gopher.nim
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-11-04 22:00:55 +0100
committerbptato <nincsnevem662@gmail.com>2024-11-05 20:14:57 +0100
commit2234d19a52c37b74be1ed27a21d3f454496c3729 (patch)
tree9a19163a0090e6eea013f06d6f6da4087c9e49d4 /adapter/protocol/gopher.nim
parent74a130c90a97da3bdf1352a4f95f2f85be315923 (diff)
downloadchawan-2234d19a52c37b74be1ed27a21d3f454496c3729.tar.gz
gopher: rewrite in shell
also, make gopher2html more lenient, and add some functioning error
handling in our nc clone. (other scripts still have to be updated to
benefit from this)
Diffstat (limited to 'adapter/protocol/gopher.nim')
-rw-r--r--adapter/protocol/gopher.nim75
1 files changed, 0 insertions, 75 deletions
diff --git a/adapter/protocol/gopher.nim b/adapter/protocol/gopher.nim
deleted file mode 100644
index 42f2f898..00000000
--- a/adapter/protocol/gopher.nim
+++ /dev/null
@@ -1,75 +0,0 @@
-import std/os
-import std/posix
-import std/strutils
-
-import ../gophertypes
-import lcgi
-
-proc loadSearch(os: PosixStream; t: GopherType; surl: string) =
-  os.sendDataLoop("""
-Content-Type: text/html
-
-<!DOCTYPE HTML>
-<HTML>
-<HEAD>
-<BASE HREF="""" & surl & """">
-</HEAD>
-<BODY>
-<H1>Search """ & htmlEscape(surl) & """</H1>
-<FORM>
-<INPUT TYPE=SEARCH NAME="NAME">
-</FORM>
-</BODY>
-</HTML>
-""")
-
-proc loadRegular(os: PosixStream; t: GopherType; path: var string;
-    host, port, query: string) =
-  let ps = os.connectSocket(host, port)
-  enterNetworkSandbox()
-  if query != "":
-    path &= '\t'
-    path &= query
-  path &= '\n'
-  ps.sendDataLoop(percentDecode(path))
-  let s = case t
-  of gtDirectory, gtSearch: "Content-Type: text/gopher\n"
-  of gtHTML: "Content-Type: text/html\n"
-  of gtGif: "Content-Type: image/gif\n"
-  of gtPng: "Content-Type: image/png\n"
-  of gtTextFile, gtError: "Content-Type: text/plain\n"
-  else: ""
-  os.sendDataLoop(s & '\n')
-  var buffer: array[4096, uint8]
-  while true:
-    let n = ps.recvData(buffer)
-    if n == 0:
-      break
-    os.sendDataLoop(addr buffer[0], n)
-  ps.sclose()
-
-proc main() =
-  let os = newPosixStream(STDOUT_FILENO)
-  if getEnv("REQUEST_METHOD") != "GET":
-    os.die("InvalidMethod")
-  let scheme = getEnv("MAPPED_URI_SCHEME")
-  let host = getEnv("MAPPED_URI_HOST")
-  let port = getEnvEmpty("MAPPED_URI_PORT", "70")
-  let query = getEnv("MAPPED_URI_QUERY").after('=')
-  var path = getEnv("MAPPED_URI_PATH")
-  var i = 0
-  while i < path.len and path[i] == '/':
-    inc i
-  var t = gtDirectory
-  if i < path.len:
-    t = gopherType(path[i])
-    if t != gtUnknown:
-      path.delete(0 .. i)
-    else:
-      t = gtDirectory
-  if t == gtSearch and query == "":
-    os.loadSearch(t, scheme & "://" & host & ":" & port & '/')
-  else:
-    os.loadRegular(t, path, host, port, query)
-
-main()