Software /
code /
prosody
Annotate
tools/ejabberdsql2prosody.lua @ 1592:a7c140fc672b
ejabberdsql2prosody: Initial commit
- full parser
- only exports account data at the moment
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Sat, 25 Jul 2009 23:19:39 +0500 |
child | 1593:4e44aa858a4c |
rev | line source |
---|---|
1592
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
1 #!/usr/bin/env lua |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
2 -- Prosody IM |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
3 -- Copyright (C) 2008-2009 Matthew Wild |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
4 -- Copyright (C) 2008-2009 Waqas Hussain |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
5 -- |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
6 -- This project is MIT/X11 licensed. Please see the |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
7 -- COPYING file in the source package for more information. |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
8 -- |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
9 |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
10 package.path = package.path ..";../?.lua"; |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
11 local serialize = require "util.serialization".serialize; |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
12 local st = require "util.stanza"; |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
13 package.loaded["util.logger"] = {init = function() return function() end; end} |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
14 local dm = require "util.datamanager" |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
15 dm.set_data_path("data"); |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
16 |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
17 function parseFile(filename) |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
18 ------ |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
19 |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
20 local file = nil; |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
21 local last = nil; |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
22 local function read(expected) |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
23 local ch; |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
24 if last then |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
25 ch = last; last = nil; |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
26 else ch = file:read(1); end |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
27 if expected and ch ~= expected then error("expected: "..expected.."; got: "..(ch or "nil")); end |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
28 return ch; |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
29 end |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
30 local function pushback(ch) |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
31 if last then error(); end |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
32 last = ch; |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
33 end |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
34 local function peek() |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
35 if not last then last = read(); end |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
36 return last; |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
37 end |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
38 |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
39 local function unescape(s) |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
40 if s == "\\'" then return "'"; end |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
41 if s == "\\n" then return "\n"; end |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
42 error("Unknown escape sequence: "..s); |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
43 end |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
44 local function readString() |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
45 read("'"); |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
46 local s = ""; |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
47 while true do |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
48 local ch = peek(); |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
49 if ch == "\\" then |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
50 s = s..unescape(read()..read()); |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
51 elseif ch == "'" then |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
52 break; |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
53 else |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
54 s = s..read(); |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
55 end |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
56 end |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
57 read("'"); |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
58 return s; |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
59 end |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
60 local function readNonString() |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
61 local s = ""; |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
62 while true do |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
63 if peek() == "," or peek() == ")" then |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
64 break; |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
65 else |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
66 s = s..read(); |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
67 end |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
68 end |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
69 return tonumber(s); |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
70 end |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
71 local function readItem() |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
72 if peek() == "'" then |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
73 return readString(); |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
74 else |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
75 return readNonString(); |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
76 end |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
77 end |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
78 local function readTuple() |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
79 local items = {} |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
80 read("("); |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
81 while peek() ~= ")" do |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
82 table.insert(items, readItem()); |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
83 if peek() == ")" then break; end |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
84 read(","); |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
85 end |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
86 read(")"); |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
87 return items; |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
88 end |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
89 local function readTuples() |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
90 if peek() ~= "(" then read("("); end |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
91 local tuples = {}; |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
92 while true do |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
93 table.insert(tuples, readTuple()); |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
94 if peek() == "," then read() end |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
95 if peek() == ";" then break; end |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
96 end |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
97 return tuples; |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
98 end |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
99 local function readTableName() |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
100 local tname = ""; |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
101 while peek() ~= "`" do tname = tname..read(); end |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
102 return tname; |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
103 end |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
104 local function readInsert() |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
105 if peek() == nil then return nil; end |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
106 for ch in ("INSERT INTO `"):gmatch(".") do -- find line starting with this |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
107 if peek() == ch then |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
108 read(); -- found |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
109 else -- match failed, skip line |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
110 while peek() and read() ~= "\n" do end |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
111 return nil; |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
112 end |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
113 end |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
114 local tname = readTableName(); |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
115 for ch in ("` VALUES "):gmatch(".") do read(ch); end -- expect this |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
116 local tuples = readTuples(); |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
117 read(";"); read("\n"); |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
118 return tname, tuples; |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
119 end |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
120 |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
121 local function readFile(filename) |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
122 file = io.open(filename); |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
123 if not file then error("File not found: "..filename); os.exit(0); end |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
124 local t = {}; |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
125 while true do |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
126 local tname, tuples = readInsert(); |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
127 if tname then |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
128 t[tname] = tuples; |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
129 elseif peek() == nil then |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
130 break; |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
131 end |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
132 end |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
133 return t; |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
134 end |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
135 |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
136 return readFile(filename); |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
137 |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
138 ------ |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
139 end |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
140 |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
141 local arg = ...; |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
142 local help = "/? -? ? /h -h /help -help --help"; |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
143 if not arg or help:find(arg, 1, true) then |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
144 print([[ejabberd SQL db dump importer for Prosody |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
145 |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
146 Usage: ejabberdsql2prosody.lua filename.txt |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
147 |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
148 The file can be generated from ejabberd using: |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
149 sudo ./bin/ejabberdctl dump filename.txt |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
150 |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
151 Note: The path of ejabberdctl depends on your ejabberd installation, and ejabberd needs to be running for ejabberdctl to work.]]); |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
152 os.exit(1); |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
153 end |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
154 local map = { |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
155 ["last"] = {"username", "seconds", "state"}; |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
156 ["privacy_default_list"] = {"username", "name"}; |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
157 ["privacy_list"] = {"username", "name", "id"}; |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
158 ["privacy_list_data"] = {"id", "t", "value", "action", "ord", "match_all", "match_iq", "match_message", "match_presence_in", "match_presence_out"}; |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
159 ["private_storage"] = {"username", "namespace", "data"}; |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
160 ["rostergroups"] = {"username", "jid", "grp"}; |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
161 ["rosterusers"] = {"username", "jid", "nick", "subscription", "ask", "askmessage", "server", "subscribe", "type"}; |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
162 ["spool"] = {"username", "xml", "seq"}; |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
163 ["users"] = {"username", "password"}; |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
164 ["vcard"] = {"username", "vcard"}; |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
165 --["vcard_search"] = {}; |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
166 } |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
167 local NULL = {}; |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
168 local t = parseFile(arg); |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
169 for name, data in pairs(t) do |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
170 local m = map[name]; |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
171 if m then |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
172 for i=1,#data do |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
173 local row = data[i]; |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
174 for j=1,#row do |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
175 row[m[j]] = row[j]; |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
176 row[j] = nil; |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
177 end |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
178 end |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
179 end |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
180 end |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
181 |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
182 local host = "ayena.de"; |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
183 |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
184 for i, row in ipairs(t["users"] or NULL) do |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
185 local node, password = row.username, row.password; |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
186 local ret, err = dm.store(node, host, "accounts", {password = password}); |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
187 --print("["..(err or "success").."] accounts: "..node.."@"..host.." = "..password); |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
188 end |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
189 for i, row in ipairs(t["private_storage"] or NULL) do |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
190 --local node, password = row.username, row.password; |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
191 --local ret, err = dm.store(node, host, "accounts", {password = password}); |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
192 --print("["..(err or "success").."] accounts: "..node.."@"..host.." = "..password); |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
193 end |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
194 |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
195 |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
196 |
a7c140fc672b
ejabberdsql2prosody: Initial commit
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
197 print(serialize(t)); |