diff --git a/Makefile b/Makefile index 6b652ad..f698db8 100755 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ PKG= luaxmlrpc-$(VERSION) TAR_FILE= $(PKG).tar.gz ZIP_FILE= $(PKG).zip SRCS= README Makefile \ - xmlrpc.lua xrh.lua xrc.lua test.lua \ + xmlrpc.lua xmlrpc.http.lua xmlrpc.cgi.lua test.lua \ index.html manual.html license.html luaxmlrpc.png dist: diff --git a/README b/README index b717e59..5d1aac1 100755 --- a/README +++ b/README @@ -5,15 +5,15 @@ The standalone server depends on LuaSocket for Lua 5.0 also. Here goes a small description of the files in the distribution - index.html -- Home page - license.html -- Copyright & License - luaxmlrpc.png -- LuaXMLRPC Logo - Makefile -- Makefile for Unix systems - manual.html -- Reference manual - README -- This file - test.lua -- Overall API test script - xmlrpc.lua -- Source file - xrc.lua -- Extension server library over CGI - xrh.lua -- Extension server library over HTTP + index.html -- Home page + license.html -- Copyright & License + luaxmlrpc.png -- LuaXMLRPC Logo + Makefile -- Makefile for Unix systems + manual.html -- Reference manual + README -- This file + test.lua -- Overall API test script + xmlrpc.lua -- Source file + xmlrpc.http.lua -- Extension library over HTTP + xmlrpc.cgi.lua -- Server implementation over CGI $Id$ diff --git a/doc/manual.html b/doc/manual.html index f8e1469..b5ddf1f 100755 --- a/doc/manual.html +++ b/doc/manual.html @@ -53,31 +53,15 @@ It enables a Lua program to:

LuaXMLRPC provides a simple API and an abstraction layer over XML avoiding manipulation of string representation of data structures. -It also offers ways to express everything when needed. +

- LuaXMLRPC is based on LuaExpat and on Lua 5.0.
-The abstraction layer over HTTP (xrh.lua) depends on +The abstraction layer over HTTP depends on LuaSocket 2.0.
- @@ -169,8 +153,10 @@ the resulting struct will have the string representation of these numbers as keys (e.g. "1" instead of 1). The library tries to convert integral numbers to integer types, otherwise converting them to floating point numbers. + @@ -181,15 +167,15 @@ and decoding XML-RPC messages and for transforming data types between the two representations. Following is the list of functions.

  • Basic support
  • Client side diff --git a/src/xmlrpc.lua b/src/xmlrpc.lua index 729e383..c884f32 100755 --- a/src/xmlrpc.lua +++ b/src/xmlrpc.lua @@ -491,14 +491,14 @@ end --------------------------------------------------------------------- -- Create a representation of an array with the given element type. --------------------------------------------------------------------- -function createArray (elemtype) +function newArray (elemtype) return { type = "array", elemtype = elemtype, } end --------------------------------------------------------------------- -- Create a representation of a structure with the given members. --------------------------------------------------------------------- -function createStruct (members) +function newStruct (members) return { type = "struct", elemtype = members, } end @@ -507,7 +507,7 @@ end -- @param val Any Lua value. -- @param typ A XML-RPC type. --------------------------------------------------------------------- -function createTypedValue (val, typ) +function newTypedValue (val, typ) return { ["*type"] = typ, ["*value"] = val } end @@ -517,7 +517,7 @@ end -- @param ... Parameters to the call. -- @return String with the XML string/document. --------------------------------------------------------------------- -function client_encode (method, ...) +function clEncode (method, ...) return toxml.methodCall (method, arg) end @@ -527,7 +527,7 @@ end -- @return Boolean indicating whether the call was successful or not; -- and a Lua object with the converted response element. --------------------------------------------------------------------- -function client_decode (meth_resp) +function clDecode (meth_resp) local d = parse (meth_resp) if type(d) ~= "table" then error ("Not an XML document: "..meth_resp) @@ -541,7 +541,7 @@ end -- @param request String with XML document. -- @return String with method's name AND the table of arguments. --------------------------------------------------------------------- -function server_decode (request) +function srvDecode (request) local d = parse (request) if type(d) ~= "table" then error ("Not an XML document: "..request) @@ -556,7 +556,7 @@ end -- a `fault' element (default = false). -- @return String with XML-RPC response. --------------------------------------------------------------------- -function server_encode (obj, is_fault) +function srvEncode (obj, is_fault) local ok = not (is_fault or false) return toxml.methodResponse (ok, obj) end @@ -570,7 +570,7 @@ end -- The given function should return a Lua function that implements. --------------------------------------------------------------------- dispatch = error -function server_methods (tab_or_func) +function srvMethods (tab_or_func) local t = type (tab_or_func) if t == "function" then dispatch = tab_or_func diff --git a/tests/test.lua b/tests/test.lua index cb59ca6..f545233 100755 --- a/tests/test.lua +++ b/tests/test.lua @@ -2,7 +2,6 @@ -- See Copyright Notice in license.html require "xmlrpc" -require "xrh" function table._print (tab, indent, spacing) spacing = spacing or "" @@ -116,14 +115,14 @@ function call_test (xml_call, method, ...) arg.n = nil -- client enconding test - local meth_call = xmlrpc.client_encode (method, unpack (arg)) + local meth_call = xmlrpc.clEncode (method, unpack (arg)) meth_call = string.gsub (meth_call, "%s*", "") local s = string.gsub (meth_call, xc, "") s = string.gsub (s, "%s*", "") assert (s == "", s.."\n!!!\n"..xc) -- server decoding test - local meth_call, param = xmlrpc.server_decode (xml_call) + local meth_call, param = xmlrpc.srvDecode (xml_call) assert (meth_call == method, meth_call) arg = remove_type (arg) assert (table.equal (arg, param)) @@ -131,12 +130,12 @@ end function response_test (xml_resp, lua_obj) -- client decoding test - local ok, obj = xmlrpc.client_decode (xml_resp) + local ok, obj = xmlrpc.clDecode (xml_resp) -- server encoding test xml_resp = string.gsub (xml_resp, "(%p)", "%%%1") xml_resp = string.gsub (xml_resp, "\r?\n%s*", "%%s*") - local meth_resp = xmlrpc.server_encode (lua_obj) + local meth_resp = xmlrpc.srvEncode (lua_obj) if type (obj) == "table" then lua_obj = remove_type (lua_obj) @@ -151,14 +150,14 @@ end function fault_test (xml_resp, message, code) -- client decoding test - local ok, str, n = xmlrpc.client_decode (xml_resp) + local ok, str, n = xmlrpc.clDecode (xml_resp) assert (str == message) assert (n == code) -- server encoding test xml_resp = string.gsub (xml_resp, "(%p)", "%%%1") xml_resp = string.gsub (xml_resp, "\r?\n%s*", "%%s*") - local meth_resp = xmlrpc.server_encode ({ message = message, code = code }, true) + local meth_resp = xmlrpc.srvEncode ({ message = message, code = code }, true) local s = string.gsub (meth_resp, xml_resp, "") s = string.gsub (s, "%s*", "") assert (s == "", s) @@ -177,7 +176,7 @@ call_test ([[ ]], "examples.getStateName", 41) -local double_139 = xmlrpc.createTypedValue (139, "double") +local double_139 = xmlrpc.newTypedValue (139, "double") call_test ([[ examples.getSomething @@ -199,7 +198,7 @@ call_test ([[ ]], "examples.getSomething", { lowerBound = 18.2, upperBound = double_139 }) -local double_array = xmlrpc.createArray ("double") +local double_array = xmlrpc.newArray ("double") call_test ([[ test @@ -213,10 +212,10 @@ call_test ([[ ]], "test", - xmlrpc.createTypedValue ({ 1, 2, 3, 4, }, double_array) + xmlrpc.newTypedValue ({ 1, 2, 3, 4, }, double_array) ) -local double_array_array = xmlrpc.createArray (double_array) +local double_array_array = xmlrpc.newArray (double_array) call_test ([[ test @@ -244,7 +243,7 @@ call_test ([[ ]], "test", - xmlrpc.createTypedValue ( + xmlrpc.newTypedValue ( { { 1, 2, 3, 4, }, { 11, 12, 13, 14, }, @@ -304,13 +303,13 @@ call_test ([[ ]], "insertTable", "people", - xmlrpc.createTypedValue ( + xmlrpc.newTypedValue ( { { name = "Fulano", email = "fulano@nowhere.world", }, { name = "Beltrano", email = "beltrano@nowhere.world", }, { name = "Cicrano", email = "cicrano@nowhere.world", }, }, - xmlrpc.createArray ("struct") + xmlrpc.newArray ("struct") ) ) diff --git a/xrc.lua b/xmlrpc.cgi.lua similarity index 91% rename from xrc.lua rename to xmlrpc.cgi.lua index 1eb7ae0..9e3d275 100755 --- a/xrc.lua +++ b/xmlrpc.cgi.lua @@ -22,7 +22,7 @@ end local _assert = assert function assert (cond, msg) if not cond then - respond (xmlrpc.server_encode ( + respond (xmlrpc.srvEncode ( { code = 2, message = msg, }, true )) @@ -43,7 +43,7 @@ local kepler_sites = { luaxmlrpc = kepler_home.."/luaxmlrpc", } -xmlrpc.server_methods { +xmlrpc.srvMethods { system = { listMethods = function (self) return { "system.listMethods" } end, }, @@ -56,7 +56,7 @@ xmlrpc.server_methods { local doc = {} post.parsedata (doc) -local method, arg_table = xmlrpc.server_decode (doc[1]) +local method, arg_table = xmlrpc.srvDecode (doc[1]) 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") @@ -76,5 +76,5 @@ else end end -local r = xmlrpc.server_encode (result, not ok) +local r = xmlrpc.srvEncode (result, not ok) respond (r) diff --git a/xrh.lua b/xmlrpc.http.lua similarity index 85% rename from xrh.lua rename to xmlrpc.http.lua index 714c09b..e320acb 100755 --- a/xrh.lua +++ b/xmlrpc.http.lua @@ -9,7 +9,7 @@ require"xmlrpc" local post = socket.http.post -xrh = {} +xmlrpc.http = {} --------------------------------------------------------------------- -- Call a remote method. @@ -18,17 +18,17 @@ xrh = {} -- @return Table with the response (could be a `fault' or a `params' -- XML-RPC element). --------------------------------------------------------------------- -function xrh.call (url, method, ...) +function xmlrpc.http.call (url, method, ...) local body, headers, code, err = post { url = url, - body = xmlrpc.client_encode (method, unpack (arg)), + body = xmlrpc.clEncode (method, unpack (arg)), headers = { ["User-agent"] = "LuaXMLRPC", ["Content-type"] = "text/xml", }, } if tonumber (code) == 200 then - return xmlrpc.client_decode (body) + return xmlrpc.clDecode (body) else error (err or code) end