util.pluginloader: Return full file path from internal file loader on success, not...
[prosody.git] / util / xmlrpc.lua
index 5a3917548e669dc48a4bf8d1e1ee165f6adb0bec..29815b0d94fc3a427642475fdc2185b486de0b5c 100644 (file)
@@ -1,6 +1,6 @@
--- Prosody IM v0.3
--- Copyright (C) 2008-2009 Matthew Wild
--- Copyright (C) 2008-2009 Waqas Hussain
+-- Prosody IM
+-- Copyright (C) 2008-2010 Matthew Wild
+-- Copyright (C) 2008-2010 Waqas Hussain
 -- 
 -- This project is MIT/X11 licensed. Please see the
 -- COPYING file in the source package for more information.
@@ -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"
@@ -41,6 +42,9 @@ local map = {
        number=function(stanza, object)
                stanza:tag("int"):text(tostring(object)):up();
        end;
+       ["nil"]=function(stanza, object) -- nil extension
+               stanza:tag("nil"):up();
+       end;
 };
 _lua_to_xmlrpc = function(stanza, object)
        local h = map[type(object)];
@@ -63,6 +67,18 @@ function create_error_response(faultCode, faultString)
        return stanza;
 end
 
+function create_request(method_name, ...)
+       local stanza = st.stanza("methodCall")
+               :tag("methodName"):text(method_name):up()
+               :tag("params");
+       for i=1,select('#', ...) do
+               stanza:tag("param"):tag("value");
+               _lua_to_xmlrpc(stanza, select(i, ...));
+               stanza:up():up();
+       end
+       stanza:up():up():up();
+       return stanza;
+end
 
 local _xmlrpc_to_lua;
 local int_parse = function(stanza)
@@ -146,6 +162,9 @@ local rmap = {
                if tostring(tonumber(n)) == n then n = tonumber(n); end
                return n;
        end;
+       ["nil"]=function(stanza) -- nil extension
+               return nil;
+       end;
 }
 _xmlrpc_to_lua = function(stanza)
        local h = rmap[stanza.name];