Compare commits
5 Commits
6a0087d1ae
...
eb6fabadaa
Author | SHA1 | Date |
---|---|---|
Ciaran Gultnieks | eb6fabadaa | |
Tim Niemueller | b12ac249d6 | |
Tim Niemueller | 23a0455500 | |
Tim Niemueller | 47710d9be8 | |
Tim Niemueller | 777f825cab |
|
@ -0,0 +1 @@
|
|||
*~
|
Before Width: | Height: | Size: 8.1 KiB After Width: | Height: | Size: 8.1 KiB |
|
@ -0,0 +1,7 @@
|
|||
require("xmlrpc.http")
|
||||
|
||||
local ok, res = xmlrpc.http.call("http://localhost:12345", "hello_world")
|
||||
assert(ok, string.format("XML-RPC call failed on client: %s", tostring(res)))
|
||||
|
||||
print("Result: " .. tostring(res))
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
require("xavante")
|
||||
require("xavante.httpd")
|
||||
require("wsapi.xavante")
|
||||
require("wsapi.request")
|
||||
require("xmlrpc")
|
||||
|
||||
--- XML-RPC WSAPI handler
|
||||
-- @param wsapi_env WSAPI environment
|
||||
function wsapi_handler(wsapi_env)
|
||||
local headers = { ["Content-type"] = "text/xml" }
|
||||
local req = wsapi.request.new(wsapi_env)
|
||||
local method, arg_table = xmlrpc.srvDecode(req.POST.post_data)
|
||||
local func = xmlrpc.dispatch(method)
|
||||
local result = { pcall(func, unpack(arg_table or {})) }
|
||||
local ok = result[1]
|
||||
if not ok then
|
||||
result = { code = 3, message = result[2] }
|
||||
else
|
||||
table.remove(result, 1)
|
||||
if table.getn(result) == 1 then
|
||||
result = result[1]
|
||||
end
|
||||
end
|
||||
|
||||
local r = xmlrpc.srvEncode(result, not ok)
|
||||
headers["Content-length"] = tostring(#r)
|
||||
|
||||
local function xmlrpc_reply(wsapienv)
|
||||
coroutine.yield(r)
|
||||
end
|
||||
|
||||
return 200, headers, coroutine.wrap(xmlrpc_reply)
|
||||
end
|
||||
|
||||
-- XML-RPC exported functions
|
||||
xmlrpc_exports = {}
|
||||
|
||||
--- Get simple string.
|
||||
-- @return simple string
|
||||
function xmlrpc_exports.hello_world()
|
||||
return "Hello World"
|
||||
end
|
||||
|
||||
local rules = {{ match = ".", with = wsapi.xavante.makeHandler(wsapi_handler) }}
|
||||
local config = { server = {host = "*", port = 12345}, defaultHost = { rules = rules} }
|
||||
|
||||
xmlrpc.srvMethods(xmlrpc_exports)
|
||||
xavante.HTTP(config)
|
||||
xavante.start()
|
|
@ -4,6 +4,7 @@
|
|||
---------------------------------------------------------------------
|
||||
|
||||
local error, tonumber, tostring, unpack = error, tonumber, tostring, unpack
|
||||
local pairs = pairs
|
||||
|
||||
local ltn12 = require"ltn12"
|
||||
local request = require"socket.http".request
|
||||
|
@ -20,20 +21,37 @@ module("xmlrpc.http")
|
|||
-- @return Table with the response (could be a `fault' or a `params'
|
||||
-- XML-RPC element).
|
||||
---------------------------------------------------------------------
|
||||
function call (url, method, ...)
|
||||
function call (cookies, url, method, ...)
|
||||
local request_sink, tbody = ltn12.sink.table()
|
||||
local request_body = xmlrpc.clEncode(method, ...)
|
||||
local reqheaders = { ["User-agent"] = xmlrpc._PKGNAME .. " " .. xmlrpc._VERSION,
|
||||
["Content-type"] = "text/xml",
|
||||
["content-length"] = tostring (string.len (request_body)),
|
||||
};
|
||||
|
||||
cooks = ""
|
||||
for key,value in pairs(cookies) do
|
||||
if cooks ~= "" then cooks = cooks .."," end
|
||||
cooks = cooks .. key .. "=" .. value .. "; "
|
||||
end
|
||||
if cooks ~= "" then reqheaders["Cookie"] = cooks end
|
||||
|
||||
local err, code, headers, status = request {
|
||||
url = url,
|
||||
method = "POST",
|
||||
source = ltn12.source.string (request_body),
|
||||
sink = request_sink,
|
||||
headers = {
|
||||
["User-agent"] = xmlrpc._PKGNAME .. " " .. xmlrpc._VERSION,
|
||||
["Content-type"] = "text/xml",
|
||||
["content-length"] = tostring (string.len (request_body)),
|
||||
},
|
||||
headers = reqheaders,
|
||||
}
|
||||
|
||||
if headers["set-cookie"] ~= nil then
|
||||
for s in string.gmatch(headers["set-cookie"], "[^,]+[,$]") do
|
||||
for k, v in string.gmatch(s, "([^=]+)=([^;]+);.+") do
|
||||
cookies[string.gsub(k, "^%s*(.-)%s*$", "%1")] = v
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local body = table.concat (tbody)
|
||||
if tonumber (code) == 200 then
|
||||
return xmlrpc.clDecode (body)
|
||||
|
|
|
@ -19,7 +19,7 @@ _DESCRIPTION = "LuaXMLRPC is a library to make remote procedure calls using XML-
|
|||
_PKGNAME = "LuaXMLRPC"
|
||||
_VERSION_MAJOR = 1
|
||||
_VERSION_MINOR = 2
|
||||
_VERSION_MICRO = 0
|
||||
_VERSION_MICRO = 1
|
||||
_VERSION = _VERSION_MAJOR .. "." .. _VERSION_MINOR .. "." .. _VERSION_MICRO
|
||||
|
||||
---------------------------------------------------------------------
|
||||
|
|
Loading…
Reference in New Issue