tools/ejabberdsql2prosody.lua

changeset 1595
9551055b5344
parent 1594
6e639a34e503
child 1596
4fcb2df97141
equal deleted inserted replaced
1594:6e639a34e503 1595:9551055b5344
174 row[j] = nil; 174 row[j] = nil;
175 end 175 end
176 end 176 end
177 end 177 end
178 end 178 end
179 --print(serialize(t));
179 180
180 for i, row in ipairs(t["users"] or NULL) do 181 for i, row in ipairs(t["users"] or NULL) do
181 local node, password = row.username, row.password; 182 local node, password = row.username, row.password;
182 local ret, err = dm.store(node, host, "accounts", {password = password}); 183 local ret, err = dm.store(node, host, "accounts", {password = password});
183 print("["..(err or "success").."] accounts: "..node.."@"..host.." = "..password); 184 print("["..(err or "success").."] accounts: "..node.."@"..host.." = "..password);
184 end 185 end
185 for i, row in ipairs(t["private_storage"] or NULL) do 186
186 --local node, password = row.username, row.password; 187 function roster(node, host, jid, item)
187 --local ret, err = dm.store(node, host, "accounts", {password = password}); 188 local roster = dm.load(node, host, "roster") or {};
188 --print("["..(err or "success").."] accounts: "..node.."@"..host.." = "..password); 189 roster[jid] = item;
189 end 190 local ret, err = dm.store(node, host, "roster", roster);
191 print("["..(err or "success").."] roster: " ..node.."@"..host.." - "..jid);
192 end
193 function roster_pending(node, host, jid)
194 local roster = dm.load(node, host, "roster") or {};
195 roster.pending = roster.pending or {};
196 roster.pending[jid] = true;
197 local ret, err = dm.store(node, host, "roster", roster);
198 print("["..(err or "success").."] roster: " ..node.."@"..host.." - "..jid);
199 end
200 function roster_group(node, host, jid, group)
201 local roster = dm.load(node, host, "roster") or {};
202 local item = roster[jid];
203 if not item then print("Warning: No roster item "..jid.." for user "..user..", can't put in group "..group); return; end
204 item.groups[group] = true;
205 local ret, err = dm.store(node, host, "roster", roster);
206 print("["..(err or "success").."] roster: " ..node.."@"..host.." - "..jid);
207 end
208 for i, row in ipairs(t["rosterusers"] or NULL) do
209 local node, contact = row.username, row.jid;
210 local name = row.nick;
211 if name == "" then name = nil; end
212 local subscription = row.subscription;
213 if subscription == "N" then
214 subscription = "none"
215 elseif subscription == "B" then
216 subscription = "both"
217 elseif subscription == "F" then
218 subscription = "from"
219 elseif subscription == "T" then
220 subscription = "to"
221 else error("Unknown subscription type: "..subscription) end;
222 local ask = row.ask;
223 if ask == "N" then
224 ask = nil;
225 elseif ask == "O" then
226 ask = "subscribe";
227 elseif ask == "I" then
228 roster_pending(node, host, contact);
229 return;
230 else error("Unknown ask type: "..ask); end
231 local item = {name = name, ask = ask, subscription = subscription, groups = {}};
232 roster(node, host, contact, item);
233 end
234 for i, row in ipairs(t["rostergroups"] or NULL) do
235 roster_group(row.username, host, row.jid, row.grp);
236 end

mercurial