util/xmlrpc.lua

changeset 1554
06030af44fad
parent 1523
841d61be198f
child 2923
b7049746bd29
equal deleted inserted replaced
1552:334b66f614a6 1554:06030af44fad
44 end; 44 end;
45 ["nil"]=function(stanza, object) -- nil extension 45 ["nil"]=function(stanza, object) -- nil extension
46 stanza:tag("nil"):up(); 46 stanza:tag("nil"):up();
47 end; 47 end;
48 }; 48 };
49 _lua_to_xmlrpc = function(stanza, ...) 49 _lua_to_xmlrpc = function(stanza, object)
50 for i=1,select('#', ...) do 50 local h = map[type(object)];
51 stanza:tag("param"):tag("value"); 51 if h then
52 local object = select(i, ...); 52 h(stanza, object);
53 local h = map[type(object)]; 53 else
54 if h then 54 error("Type not supported by XML-RPC: " .. type(object));
55 h(stanza, object);
56 else
57 error("Type not supported by XML-RPC: " .. type(object));
58 end
59 stanza:up():up();
60 end 55 end
61 end 56 end
62 function create_response(object) 57 function create_response(object)
63 local stanza = st.stanza("methodResponse"):tag("params"):tag("param"):tag("value"); 58 local stanza = st.stanza("methodResponse"):tag("params"):tag("param"):tag("value");
64 _lua_to_xmlrpc(stanza, object); 59 _lua_to_xmlrpc(stanza, object);
74 69
75 function create_request(method_name, ...) 70 function create_request(method_name, ...)
76 local stanza = st.stanza("methodCall") 71 local stanza = st.stanza("methodCall")
77 :tag("methodName"):text(method_name):up() 72 :tag("methodName"):text(method_name):up()
78 :tag("params"); 73 :tag("params");
79 _lua_to_xmlrpc(stanza, ...); 74 for i=1,select('#', ...) do
75 stanza:tag("param"):tag("value");
76 _lua_to_xmlrpc(stanza, select(i, ...));
77 stanza:up():up();
78 end
80 stanza:up():up():up(); 79 stanza:up():up():up();
81 return stanza; 80 return stanza;
82 end 81 end
83 82
84 local _xmlrpc_to_lua; 83 local _xmlrpc_to_lua;

mercurial