Compare commits

...

5 Commits

Author SHA1 Message Date
Ciaran Gultnieks eb6fabadaa Hacky, quick and dirty implementation of cookie support 2010-11-19 09:13:06 +00:00
Tim Niemueller b12ac249d6 Make files non-executable
Many files were executed which need not be, e.g. docs and source files.
2010-10-20 14:53:14 -04:00
Tim Niemueller 23a0455500 New version 1.2.1 with updated docs and examples 2010-10-18 17:54:22 -04:00
Tim Niemueller 47710d9be8 Add simple example scripts 2010-10-18 17:51:53 -04:00
Tim Niemueller 777f825cab .gitignore: ignore backup files 2010-10-18 17:51:44 -04:00
13 changed files with 82 additions and 7 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*~

0
Makefile Executable file → Normal file
View File

0
README Executable file → Normal file
View File

0
doc/examples.html Executable file → Normal file
View File

0
doc/index.html Executable file → Normal file
View File

0
doc/license.html Executable file → Normal file
View File

0
doc/luaxmlrpc.png Executable file → Normal file
View File

Before

Width:  |  Height:  |  Size: 8.1 KiB

After

Width:  |  Height:  |  Size: 8.1 KiB

0
doc/manual.html Executable file → Normal file
View File

7
examples/client.lua Normal file
View File

@ -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))

View File

@ -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()

30
src/http.lua Executable file → Normal file
View File

@ -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)

2
src/init.lua Executable file → Normal file
View File

@ -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
---------------------------------------------------------------------

0
src/server.lua Executable file → Normal file
View File