From 3d4573536119d41d62d4cd8679fa7aded662b296 Mon Sep 17 00:00:00 2001 From: Izaya Date: Mon, 19 Feb 2018 22:49:23 +1100 Subject: [PATCH] implemented the rev1 FRequest protocol in the bundled programs --- FRequest/OpenOS/etc/rc.d/fserv.lua | 43 ++++++++++++++++++++---------- FRequest/OpenOS/usr/bin/fget.lua | 14 +++++++++- 2 files changed, 42 insertions(+), 15 deletions(-) diff --git a/FRequest/OpenOS/etc/rc.d/fserv.lua b/FRequest/OpenOS/etc/rc.d/fserv.lua index 4e76657..c277755 100644 --- a/FRequest/OpenOS/etc/rc.d/fserv.lua +++ b/FRequest/OpenOS/etc/rc.d/fserv.lua @@ -20,29 +20,44 @@ function start() buffer=s:read(1024) local nl = buffer:find("\n") if nl then - local path=prefix .. "/" .. buffer:sub(1,nl-1) + local rt = buffer:sub(1,1) + local path=prefix .. "/" .. buffer:sub(2,nl-1) dprint(path) + if path:find("%.%./") then + s:write("f to pay respects") + s:close() + return + end if fs.exists(path) then - if fs.isDirectory(path) then - if fs.exists(path.."/index") then + if rt == "t" then + if fs.isDirectory(path) then + s:write("d") + if fs.exists(path.."/index") then + local f=io.open(path.."/index","rb") + s:write(f:read("*a")) + f:close() + end + local dbuffer = "" + for f in fs.list(path) do + dbuffer = dbuffer..f.."\n" + dprint(f) + end + s:write(dbuffer) + s:close() + else + s:write("y") + local f = io.open(path,"rb") s:write(f:read("*a")) + f:close() + s:close() end - local dbuffer = "" - for f in fs.list(path) do - dbuffer = dbuffer..f.."\n" - dprint(f) - end - s:write(dbuffer) - s:close() else - local f = io.open(path,"rb") - s:write(f:read("*a")) - f:close() + s:write(tostring(fs.size(path))) s:close() end else dprint("404") - s:write("file not found") + s:write("not found") s:close() end end diff --git a/FRequest/OpenOS/usr/bin/fget.lua b/FRequest/OpenOS/usr/bin/fget.lua index 49afdd2..3376276 100644 --- a/FRequest/OpenOS/usr/bin/fget.lua +++ b/FRequest/OpenOS/usr/bin/fget.lua @@ -12,7 +12,19 @@ if sep then end local socket = net.open(host,port) -socket:write(path.."\n") +socket:write("t"..path.."\n") +local c = socket:read(1) +repeat + c = socket:read(1) + os.sleep(0.5) +until c ~= "" +if c == "n" then + print(path..": Not found.") +elseif c == "f" then + print("Failure: ") +elseif c == "d" then + print("Directory listing for "..path) +end repeat l = socket:read(1024) io.write(l)