/usr/share/lua/5.1/xmlrpc/server.lua is in liblua5.1-xmlrpc0 1.2.1-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | ---------------------------------------------------------------------
-- XML-RPC server
-- See Copyright Notice in license.html
---------------------------------------------------------------------
local assert, pcall, setmetatable, type, unpack = assert, pcall, setmetatable, type, unpack
local cgilua = require"cgilua"
local os = require"os"
local string = require"string"
local table = require"table"
local xmlrpc = require"xmlrpc"
module("xmlrpc.server")
---------------------------------------------------------------------
local function respond (resp)
cgilua.header ("Date", os.date())
cgilua.header ("Server", "Me")
cgilua.header ("Content-length", string.len (resp))
cgilua.header ("Connection", "close")
cgilua.contentheader ("text", "xml")
cgilua.put (resp)
end
---------------------------------------------------------------------
function assert (cond, msg)
if not cond then
respond (xmlrpc.srvEncode (
{ code = 2, message = msg, },
true
))
--os.exit() -- !!!!!!!!!!!
end
end
cgilua.seterroroutput (function (msg)
respond (xmlrpc.srvEncode ({ code = 2, message = msg, }, true))
end)
---------------------------------------------------------------------
local function decodedata (doc)
local method, arg_table = xmlrpc.srvDecode (doc)
assert (type(method) == "string", "Invalid `method': string expected")
local t = type(arg_table)
assert (t == "table" or t == "nil", "Invalid table of arguments: not a table nor nil")
local func = xmlrpc.dispatch (method)
assert (type(func) == "function", "Unavailable method")
return func, (arg_table or {})
end
---------------------------------------------------------------------
local function callfunc (func, arg_table)
local result = { pcall (func, unpack (arg_table)) }
local ok = result[1]
if not ok then
result = { code = 3, message = result[2], }
else
table.remove (result, 1)
if #result == 1 then
result = result[1]
end
end
return ok, result
end
---------------------------------------------------------------------
function xmlrpc.server:new()
local o = { methods = { } }
setmetatable (o, self)
self.__index = self
return o
end
---------------------------------------------------------------------
function xmlrpc.server:register(name, service)
assert (type(name) == "string", "Invalid `name': string expected")
self.methods[name] = service
end
---------------------------------------------------------------------
function xmlrpc.server:handle()
xmlrpc.srvMethods (self.methods)
local func, arg_table = decodedata (cgi[1])
local ok, result = callfunc (func, arg_table)
local r = xmlrpc.srvEncode (result, not ok)
respond (r)
end
|