From 6776117801de68eddc5da5f793300e5919dbbca3 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Wed, 8 Jul 2009 15:23:07 +0100 Subject: util.xmlrpc: Support for multiple parameters in requests --- util/xmlrpc.lua | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/util/xmlrpc.lua b/util/xmlrpc.lua index 2c256aa1..d326e677 100644 --- a/util/xmlrpc.lua +++ b/util/xmlrpc.lua @@ -14,6 +14,7 @@ local t_concat = table.concat; local t_insert = table.insert; local tostring = tostring; local tonumber = tonumber; +local select = select; local st = require "util.stanza"; module "xmlrpc" @@ -45,12 +46,17 @@ local map = { stanza:tag("nil"):up(); end; }; -_lua_to_xmlrpc = function(stanza, object) - local h = map[type(object)]; - if h then - h(stanza, object); - else - error("Type not supported by XML-RPC: " .. type(object)); +_lua_to_xmlrpc = function(stanza, ...) + for i=1,select('#', ...) do + stanza:tag("param"):tag("value"); + local object = select(i, ...); + local h = map[type(object)]; + if h then + h(stanza, object); + else + error("Type not supported by XML-RPC: " .. type(object)); + end + stanza:up():up(); end end function create_response(object) @@ -66,11 +72,11 @@ function create_error_response(faultCode, faultString) return stanza; end -function create_request(method_name, object) +function create_request(method_name, ...) local stanza = st.stanza("methodCall") :tag("methodName"):text(method_name):up() - :tag("params"):tag("param"):tag("value"); - _lua_to_xmlrpc(stanza, object); + :tag("params"); + _lua_to_xmlrpc(stanza, ...); stanza:up():up():up(); return stanza; end -- cgit v1.2.3