43 lines
1.0 KiB
Lua
43 lines
1.0 KiB
Lua
local serial = require "serialization"
|
|
local minitel = require "minitel"
|
|
local buffer = require "buffer"
|
|
local lz16 = require "liblz16"
|
|
local rpc = require "rpc"
|
|
|
|
local server
|
|
local port = 15
|
|
|
|
local f = io.open("/etc/invsrv","rb")
|
|
if not f then error("no server configured") end
|
|
server=f:read()
|
|
port=tonumber(f:read()) or port
|
|
f:close()
|
|
|
|
local inv = setmetatable({}, {__index=rpc.proxy(server, "inv_")})
|
|
|
|
function inv.matchAll(criteria, fuzzy)
|
|
local socket = minitel.open(server,port)
|
|
if not socket then return false end
|
|
local cstr = "compress=true\tfuzzy="..tostring(fuzzy)
|
|
for k,v in pairs(criteria) do
|
|
cstr=string.format("%s\t%s=%s", cstr, k, v)
|
|
end
|
|
socket:write(cstr.."\n")
|
|
socket.mode = {r=true}
|
|
local function cread()
|
|
if socket.state ~= "open" then
|
|
return nil
|
|
end
|
|
os.sleep(0.05)
|
|
return socket:read("*a")
|
|
end
|
|
local lsock = lz16.buffer(buffer.new("rb",{read = cread,close=function() end}))
|
|
local rt = {}
|
|
for line in lsock:lines() do
|
|
rt[#rt+1] = serial.unserialize(line)
|
|
end
|
|
lsock:close()
|
|
return rt
|
|
end
|
|
|
|
return inv |