aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWaqas Hussain <waqas20@gmail.com>2009-07-26 00:32:51 +0500
committerWaqas Hussain <waqas20@gmail.com>2009-07-26 00:32:51 +0500
commit33fa4514f474cec4c377ac9d8f68ec090a06d555 (patch)
tree5c1ad331f30d02e224de1da245d134454568c05b
parentb481cd3ad7014ef7b91aa4b5d5db3a457cde887b (diff)
downloadprosody-33fa4514f474cec4c377ac9d8f68ec090a06d555.tar.gz
prosody-33fa4514f474cec4c377ac9d8f68ec090a06d555.zip
ejabberdsql2prosody: Added support for rosters
-rw-r--r--tools/ejabberdsql2prosody.lua55
1 files changed, 51 insertions, 4 deletions
diff --git a/tools/ejabberdsql2prosody.lua b/tools/ejabberdsql2prosody.lua
index b48f2b28..772f9214 100644
--- a/tools/ejabberdsql2prosody.lua
+++ b/tools/ejabberdsql2prosody.lua
@@ -176,14 +176,61 @@ for name, data in pairs(t) do
end
end
end
+--print(serialize(t));
for i, row in ipairs(t["users"] or NULL) do
local node, password = row.username, row.password;
local ret, err = dm.store(node, host, "accounts", {password = password});
print("["..(err or "success").."] accounts: "..node.."@"..host.." = "..password);
end
-for i, row in ipairs(t["private_storage"] or NULL) do
- --local node, password = row.username, row.password;
- --local ret, err = dm.store(node, host, "accounts", {password = password});
- --print("["..(err or "success").."] accounts: "..node.."@"..host.." = "..password);
+
+function roster(node, host, jid, item)
+ local roster = dm.load(node, host, "roster") or {};
+ roster[jid] = item;
+ local ret, err = dm.store(node, host, "roster", roster);
+ print("["..(err or "success").."] roster: " ..node.."@"..host.." - "..jid);
+end
+function roster_pending(node, host, jid)
+ local roster = dm.load(node, host, "roster") or {};
+ roster.pending = roster.pending or {};
+ roster.pending[jid] = true;
+ local ret, err = dm.store(node, host, "roster", roster);
+ print("["..(err or "success").."] roster: " ..node.."@"..host.." - "..jid);
+end
+function roster_group(node, host, jid, group)
+ local roster = dm.load(node, host, "roster") or {};
+ local item = roster[jid];
+ if not item then print("Warning: No roster item "..jid.." for user "..user..", can't put in group "..group); return; end
+ item.groups[group] = true;
+ local ret, err = dm.store(node, host, "roster", roster);
+ print("["..(err or "success").."] roster: " ..node.."@"..host.." - "..jid);
+end
+for i, row in ipairs(t["rosterusers"] or NULL) do
+ local node, contact = row.username, row.jid;
+ local name = row.nick;
+ if name == "" then name = nil; end
+ local subscription = row.subscription;
+ if subscription == "N" then
+ subscription = "none"
+ elseif subscription == "B" then
+ subscription = "both"
+ elseif subscription == "F" then
+ subscription = "from"
+ elseif subscription == "T" then
+ subscription = "to"
+ else error("Unknown subscription type: "..subscription) end;
+ local ask = row.ask;
+ if ask == "N" then
+ ask = nil;
+ elseif ask == "O" then
+ ask = "subscribe";
+ elseif ask == "I" then
+ roster_pending(node, host, contact);
+ return;
+ else error("Unknown ask type: "..ask); end
+ local item = {name = name, ask = ask, subscription = subscription, groups = {}};
+ roster(node, host, contact, item);
+end
+for i, row in ipairs(t["rostergroups"] or NULL) do
+ roster_group(row.username, host, row.jid, row.grp);
end