Software /
code /
prosody
Comparison
tools/ejabberd2prosody.lua @ 6280:ce1a20bd2053
tools/ejabberd2prosody.lua: Fix JID building, node-less jids became @hostname in some cases
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Tue, 17 Jun 2014 11:01:51 +0200 |
parent | 6024:c352d97cf137 |
child | 6284:b49540983320 |
child | 6797:509b70437035 |
comparison
equal
deleted
inserted
replaced
6279:16d5b55c8d8d | 6280:ce1a20bd2053 |
---|---|
53 end | 53 end |
54 end | 54 end |
55 function build_time(tuple) | 55 function build_time(tuple) |
56 local Megaseconds,Seconds,Microseconds = unpack(tuple); | 56 local Megaseconds,Seconds,Microseconds = unpack(tuple); |
57 return Megaseconds * 1000000 + Seconds; | 57 return Megaseconds * 1000000 + Seconds; |
58 end | |
59 function build_jid(tuple, full) | |
60 local node, jid, resource = tuple[1], tuple[2], tuple[3] | |
61 if type(node) == "string" and node ~= "" then | |
62 jid = tuple[1] .. "@" .. jid; | |
63 end | |
64 if full and type(resource) == "string" and resource ~= "" then | |
65 jid = jid .. "/" .. resource; | |
66 end | |
67 return jid; | |
58 end | 68 end |
59 | 69 |
60 function vcard(node, host, stanza) | 70 function vcard(node, host, stanza) |
61 local ret, err = dm.store(node, host, "vcard", st.preserialize(stanza)); | 71 local ret, err = dm.store(node, host, "vcard", st.preserialize(stanza)); |
62 print("["..(err or "success").."] vCard: "..node.."@"..host); | 72 print("["..(err or "success").."] vCard: "..node.."@"..host); |
103 if item[1] ~= "listitem" then print("[error] privacy: unhandled item: "..tostring(item[1])); break; end | 113 if item[1] ~= "listitem" then print("[error] privacy: unhandled item: "..tostring(item[1])); break; end |
104 local _type, value = item[2], item[3]; | 114 local _type, value = item[2], item[3]; |
105 if _type == "jid" then | 115 if _type == "jid" then |
106 if type(value) ~= "table" then print("[error] privacy: jid value is not valid: "..tostring(value)); break; end | 116 if type(value) ~= "table" then print("[error] privacy: jid value is not valid: "..tostring(value)); break; end |
107 local _node, _host, _resource = value[1], value[2], value[3]; | 117 local _node, _host, _resource = value[1], value[2], value[3]; |
108 if (type(_node) == "table") then _node = nil; end | 118 value = build_jid(value, true) |
109 if (type(_host) == "table") then _host = nil; end | |
110 if (type(_resource) == "table") then _resource = nil; end | |
111 value = (_node and _node.."@".._host or _host)..(_resource and "/".._resource or ""); | |
112 elseif _type == "none" then | 119 elseif _type == "none" then |
113 _type = nil; | 120 _type = nil; |
114 value = nil; | 121 value = nil; |
115 elseif _type == "group" then | 122 elseif _type == "group" then |
116 if type(value) ~= "string" then print("[error] privacy: group value is not string: "..tostring(value)); break; end | 123 if type(value) ~= "string" then print("[error] privacy: group value is not string: "..tostring(value)); break; end |
152 else print("[warn] default privacy list doesn't exist: "..tostring(default)); end | 159 else print("[warn] default privacy list doesn't exist: "..tostring(default)); end |
153 end | 160 end |
154 local ret, err = dm.store(node, host, "privacy", privacy); | 161 local ret, err = dm.store(node, host, "privacy", privacy); |
155 print("["..(err or "success").."] privacy: " ..node.."@"..host.." - "..count.." list(s)"); | 162 print("["..(err or "success").."] privacy: " ..node.."@"..host.." - "..count.." list(s)"); |
156 end | 163 end |
157 local function _table_to_jid(t) | |
158 if type(t[2]) == "string" then | |
159 local jid = t[2]; | |
160 if type(t[1]) == "string" then jid = t[1].."@"..jid; end | |
161 if type(t[3]) == "string" then jid = jid.."/"..t[3]; end | |
162 return jid; | |
163 end | |
164 end | |
165 function muc_room(node, host, properties) | 164 function muc_room(node, host, properties) |
166 local store = { jid = node.."@"..host, _data = {}, _affiliations = {} }; | 165 local store = { jid = node.."@"..host, _data = {}, _affiliations = {} }; |
167 for _,aff in ipairs(properties.affiliations) do | 166 for _,aff in ipairs(properties.affiliations) do |
168 store._affiliations[_table_to_jid(aff[1])] = aff[2][1] or aff[2]; | 167 store._affiliations[build_jid(aff[1])] = aff[2][1] or aff[2]; |
169 end | 168 end |
170 store._data.subject = properties.subject; | 169 store._data.subject = properties.subject; |
171 if properties.subject_author then | 170 if properties.subject_author then |
172 store._data.subject_from = store.jid .. "/" .. properties.subject_author; | 171 store._data.subject_from = store.jid .. "/" .. properties.subject_author; |
173 end | 172 end |
205 vcard = function(tuple) | 204 vcard = function(tuple) |
206 vcard(tuple[2][1], tuple[2][2], build_stanza(tuple[3])); | 205 vcard(tuple[2][1], tuple[2][2], build_stanza(tuple[3])); |
207 end; | 206 end; |
208 roster = function(tuple) | 207 roster = function(tuple) |
209 local node = tuple[3][1]; local host = tuple[3][2]; | 208 local node = tuple[3][1]; local host = tuple[3][2]; |
210 local contact = (type(tuple[4][1]) == "table") and tuple[4][2] or tuple[4][1].."@"..tuple[4][2]; | 209 local contact = build_jid(tuple[4]); |
211 local name = tuple[5]; local subscription = tuple[6]; | 210 local name = tuple[5]; local subscription = tuple[6]; |
212 local ask = tuple[7]; local groups = tuple[8]; | 211 local ask = tuple[7]; local groups = tuple[8]; |
213 if type(name) ~= type("") then name = nil; end | 212 if type(name) ~= type("") then name = nil; end |
214 if ask == "none" then | 213 if ask == "none" then |
215 ask = nil; | 214 ask = nil; |