Merge from waqas
[prosody.git] / tools / ejabberd2prosody.lua
index e36a6943062a65231de0ea1454d4493a8b4127d3..3c3ce9459fca2167b4175bc2788bee0dab3ab3b3 100755 (executable)
@@ -1,9 +1,29 @@
 #!/usr/bin/env lua
+-- Prosody IM v0.2
+-- Copyright (C) 2008 Matthew Wild
+-- Copyright (C) 2008 Waqas Hussain
+-- 
+-- This program is free software; you can redistribute it and/or
+-- modify it under the terms of the GNU General Public License
+-- as published by the Free Software Foundation; either version 2
+-- of the License, or (at your option) any later version.
+-- 
+-- This program is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+-- GNU General Public License for more details.
+-- 
+-- You should have received a copy of the GNU General Public License
+-- along with this program; if not, write to the Free Software
+-- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+--
+
+
 \r
 require "erlparse";\r
-require "serialize";\r
 \r
 package.path = package.path ..";../?.lua";\r
+local serialize = require "util.serialization".serialize;
 local st = require "util.stanza";\r
 package.loaded["util.logger"] = {init = function() return function() end; end}\r
 local dm = require "util.datamanager"\r
@@ -54,7 +74,7 @@ function build_stanza(tuple, stanza)
        elseif tuple[1] == "xmlcdata" then\r
                stanza:text(tuple[2]);\r
        else\r
-               error("unknown element type: "..serialize.serialize(tuple));\r
+               error("unknown element type: "..serialize(tuple));\r
        end\r
 end\r
 function build_time(tuple)\r
@@ -104,7 +124,7 @@ local filters = {
        end;\r
        roster = function(tuple)\r
                local node = tuple[3][1]; local host = tuple[3][2];\r
-               local contact = tuple[4][1].."@"..tuple[4][2];\r
+               local contact = (type(tuple[4][1]) == "table") and tuple[4][2] or tuple[4][1].."@"..tuple[4][2];\r
                local name = tuple[5]; local subscription = tuple[6];\r
                local ask = tuple[7]; local groups = tuple[8];\r
                if type(name) ~= type("") then name = nil; end\r
@@ -170,7 +190,7 @@ for item in erlparse.parseFile(arg) do
        count = count + 1;\r
        local name = item[1];\r
        t[name] = (t[name] or 0) + 1;\r
-       --print(count, serialize.serialize(item));\r
+       --print(count, serialize(item));\r
        if filters[name] then filters[name](item); end\r
 end\r
---print(serialize.serialize(t));\r
+--print(serialize(t));\r