Mercurial > prosody-hg
comparison util/xmlrpc.lua @ 1498:481dfc89047a
util.xmlrpc: Support for multiple parameters in requests
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Wed, 08 Jul 2009 15:23:07 +0100 |
| parents | 4c2c403ca04b |
| children | 841d61be198f |
comparison
equal
deleted
inserted
replaced
| 1497:4c2c403ca04b | 1498:481dfc89047a |
|---|---|
| 12 local error = error; | 12 local error = error; |
| 13 local t_concat = table.concat; | 13 local t_concat = table.concat; |
| 14 local t_insert = table.insert; | 14 local t_insert = table.insert; |
| 15 local tostring = tostring; | 15 local tostring = tostring; |
| 16 local tonumber = tonumber; | 16 local tonumber = tonumber; |
| 17 local select = select; | |
| 17 local st = require "util.stanza"; | 18 local st = require "util.stanza"; |
| 18 | 19 |
| 19 module "xmlrpc" | 20 module "xmlrpc" |
| 20 | 21 |
| 21 local _lua_to_xmlrpc; | 22 local _lua_to_xmlrpc; |
| 43 end; | 44 end; |
| 44 ["nil"]=function(stanza, object) -- nil extension | 45 ["nil"]=function(stanza, object) -- nil extension |
| 45 stanza:tag("nil"):up(); | 46 stanza:tag("nil"):up(); |
| 46 end; | 47 end; |
| 47 }; | 48 }; |
| 48 _lua_to_xmlrpc = function(stanza, object) | 49 _lua_to_xmlrpc = function(stanza, ...) |
| 49 local h = map[type(object)]; | 50 for i=1,select('#', ...) do |
| 50 if h then | 51 stanza:tag("param"):tag("value"); |
| 51 h(stanza, object); | 52 local object = select(i, ...); |
| 52 else | 53 local h = map[type(object)]; |
| 53 error("Type not supported by XML-RPC: " .. type(object)); | 54 if h then |
| 55 h(stanza, object); | |
| 56 else | |
| 57 error("Type not supported by XML-RPC: " .. type(object)); | |
| 58 end | |
| 59 stanza:up():up(); | |
| 54 end | 60 end |
| 55 end | 61 end |
| 56 function create_response(object) | 62 function create_response(object) |
| 57 local stanza = st.stanza("methodResponse"):tag("params"):tag("param"):tag("value"); | 63 local stanza = st.stanza("methodResponse"):tag("params"):tag("param"):tag("value"); |
| 58 _lua_to_xmlrpc(stanza, object); | 64 _lua_to_xmlrpc(stanza, object); |
| 64 _lua_to_xmlrpc(stanza, {faultCode=faultCode, faultString=faultString}); | 70 _lua_to_xmlrpc(stanza, {faultCode=faultCode, faultString=faultString}); |
| 65 stanza:up():up(); | 71 stanza:up():up(); |
| 66 return stanza; | 72 return stanza; |
| 67 end | 73 end |
| 68 | 74 |
| 69 function create_request(method_name, object) | 75 function create_request(method_name, ...) |
| 70 local stanza = st.stanza("methodCall") | 76 local stanza = st.stanza("methodCall") |
| 71 :tag("methodName"):text(method_name):up() | 77 :tag("methodName"):text(method_name):up() |
| 72 :tag("params"):tag("param"):tag("value"); | 78 :tag("params"); |
| 73 _lua_to_xmlrpc(stanza, object); | 79 _lua_to_xmlrpc(stanza, ...); |
| 74 stanza:up():up():up(); | 80 stanza:up():up():up(); |
| 75 return stanza; | 81 return stanza; |
| 76 end | 82 end |
| 77 | 83 |
| 78 local _xmlrpc_to_lua; | 84 local _xmlrpc_to_lua; |
