# HG changeset patch # User Kim Alvefur # Date 1373455173 -7200 # Node ID 24f4e73645fefc789bfd3cacabcd5b25c2f4d560 # Parent 49f1fed6e25eb4c5c135c8b4b877ac32ce66b859 mod_storage_sql2: Support XML serialization for stanzas. diff -r 49f1fed6e25e -r 24f4e73645fe plugins/mod_storage_sql2.lua --- a/plugins/mod_storage_sql2.lua Wed Jul 10 13:18:10 2013 +0200 +++ b/plugins/mod_storage_sql2.lua Wed Jul 10 13:19:33 2013 +0200 @@ -1,7 +1,12 @@ local json = require "util.json"; +local xml_parse = require "util.xml".parse; local resolve_relative_path = require "core.configmanager".resolve_relative_path; +local stanza_mt = require"util.stanza".stanza_mt; +local getmetatable = getmetatable; +local function is_stanza(x) return getmetatable(x) == stanza_mt; end + local unpack = unpack local function iterator(result) return function(result) @@ -134,6 +139,8 @@ local t = type(value); if t == "string" or t == "boolean" or t == "number" then return t, tostring(value); + elseif is_stanza(value) then + return "xml", tostring(value); elseif t == "table" then local value,err = json.encode(value); if value then return "json", value; end @@ -149,6 +156,8 @@ elseif t == "number" then return tonumber(value); elseif t == "json" then return json.decode(value); + elseif t == "xml" then + return xml_parse(value); end end