ejabberdsql2prosody: Added support for rosters

Sun, 26 Jul 2009 00:32:51 +0500

author
Waqas Hussain <waqas20@gmail.com>
date
Sun, 26 Jul 2009 00:32:51 +0500
changeset 1595
9551055b5344
parent 1594
6e639a34e503
child 1596
4fcb2df97141

ejabberdsql2prosody: Added support for rosters

tools/ejabberdsql2prosody.lua file | annotate | diff | comparison | revisions
--- a/tools/ejabberdsql2prosody.lua	Sat Jul 25 23:40:33 2009 +0500
+++ b/tools/ejabberdsql2prosody.lua	Sun Jul 26 00:32:51 2009 +0500
@@ -176,14 +176,61 @@
 		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

mercurial