Merge from waqas
[prosody.git] / tools / ejabberd2prosody.lua
old mode 100644 (file)
new mode 100755 (executable)
index 60cb8b1..3c3ce94
@@ -1,17 +1,39 @@
+#!/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
 local data_path = "data";\r
 dm.set_data_path(data_path);\r
 \r
+local path_separator = "/"; if os.getenv("WINDIR") then path_separator = "\\" end\r
 local _mkdir = {}\r
 function mkdir(path)\r
-       path = path:gsub("/", "\\");\r
+       path = path:gsub("/", path_separator);\r
        --print("mkdir",path);\r
        local x = io.popen("mkdir "..path.." 2>&1"):read("*a");\r
 end\r
@@ -52,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
@@ -102,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
@@ -168,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