Comparison

tools/ejabberd2prosody.lua @ 4360:a993a4a2ea0a

ejabberd2prosody: Add support for privacy lists.
author Waqas Hussain <waqas20@gmail.com>
date Fri, 26 Aug 2011 16:02:08 +0500
parent 2943:9236a7856688
child 4380:9f1c61805817
comparison
equal deleted inserted replaced
4359:c69cbac4178f 4360:a993a4a2ea0a
75 function offline_msg(node, host, t, stanza) 75 function offline_msg(node, host, t, stanza)
76 stanza.attr.stamp = os.date("!%Y-%m-%dT%H:%M:%SZ", t); 76 stanza.attr.stamp = os.date("!%Y-%m-%dT%H:%M:%SZ", t);
77 stanza.attr.stamp_legacy = os.date("!%Y%m%dT%H:%M:%S", t); 77 stanza.attr.stamp_legacy = os.date("!%Y%m%dT%H:%M:%S", t);
78 local ret, err = dm.list_append(node, host, "offline", st.preserialize(stanza)); 78 local ret, err = dm.list_append(node, host, "offline", st.preserialize(stanza));
79 print("["..(err or "success").."] offline: " ..node.."@"..host.." - "..os.date("!%Y-%m-%dT%H:%M:%SZ", t)); 79 print("["..(err or "success").."] offline: " ..node.."@"..host.." - "..os.date("!%Y-%m-%dT%H:%M:%SZ", t));
80 end
81 function privacy(node, host, default, lists)
82 local privacy = { lists = {} };
83 local count = 0;
84 if default then privacy.default = default; end
85 for _, inlist in ipairs(lists) do
86 local name, items = inlist[1], inlist[2];
87 local list = { name = name; items = {}; };
88 local orders = {};
89 for _, item in pairs(items) do
90 repeat
91 if item[1] ~= "listitem" then print("[error] privacy: unhandled item: "..tostring(item[1])); break; end
92 local _type, value = item[2], item[3];
93 if _type == "jid" then
94 if type(value) ~= "table" then print("[error] privacy: jid value is not valid: "..tostring(value)); break; end
95 local _node, _host, _resource = value[1], value[2], value[3];
96 if (type(_node) == "table") then _node = nil; end
97 if (type(_host) == "table") then _host = nil; end
98 if (type(_resource) == "table") then _resource = nil; end
99 value = (_node and _node.."@".._host or _host)..(_resource and "/".._resource or "");
100 elseif _type == "none" then
101 _type = nil;
102 value = nil;
103 elseif _type == "group" then
104 if type(value) ~= "string" then print("[error] privacy: group value is not string: "..tostring(value)); break; end
105 elseif _type == "subscription" then
106 if value~="both" and value~="from" and value~="to" and value~="none" then
107 print("[error] privacy: subscription value is invalid: "..tostring(value)); break;
108 end
109 else print("[error] privacy: invalid item type: "..tostring(_type)); break; end
110 local action = item[4];
111 if action ~= "allow" and action ~= "deny" then print("[error] privacy: unhandled action: "..tostring(action)); break; end
112 local order = item[5];
113 if type(order) ~= "number" or order<0 then print("[error] privacy: order is not numeric: "..tostring(order)); break; end
114 if orders[order] then print("[error] privacy: duplicate order value: "..tostring(order)); break; end
115 orders[order] = true;
116 local match_all = item[6];
117 local match_iq = item[7];
118 local match_message = item[8];
119 local match_presence_in = item[9];
120 local match_presence_out = item[10];
121 list.items[#list.items+1] = {
122 type = _type;
123 value = value;
124 action = action;
125 order = order;
126 message = match_message == "true";
127 iq = match_iq == "true";
128 ["presence-in"] = match_presence_in == "true";
129 ["presence-out"] = match_presence_out == "true";
130 };
131 until true;
132 end
133 table.sort(list.items, function(a, b) return a.order < b.order; end);
134 if privacy.lists[list.name] then print("[warn] duplicate privacy list: "..tostring(list.name)); end
135 privacy.lists[list.name] = list;
136 count = count + 1;
137 end
138 if default and not privacy.lists[default] then
139 if default == "none" then privacy.default = nil;
140 else print("[warn] default privacy list doesn't exist: "..tostring(default)); end
141 end
142 local ret, err = dm.store(node, host, "privacy", privacy);
143 print("["..(err or "success").."] privacy: " ..node.."@"..host.." - "..count.." list(s)");
80 end 144 end
81 145
82 146
83 local filters = { 147 local filters = {
84 passwd = function(tuple) 148 passwd = function(tuple)
116 private_storage = function(tuple) 180 private_storage = function(tuple)
117 private_storage(tuple[2][1], tuple[2][2], tuple[2][3], build_stanza(tuple[3])); 181 private_storage(tuple[2][1], tuple[2][2], tuple[2][3], build_stanza(tuple[3]));
118 end; 182 end;
119 offline_msg = function(tuple) 183 offline_msg = function(tuple)
120 offline_msg(tuple[2][1], tuple[2][2], build_time(tuple[3]), build_stanza(tuple[7])); 184 offline_msg(tuple[2][1], tuple[2][2], build_time(tuple[3]), build_stanza(tuple[7]));
185 end;
186 privacy = function(tuple)
187 privacy(tuple[2][1], tuple[2][2], tuple[3], tuple[4]);
121 end; 188 end;
122 config = function(tuple) 189 config = function(tuple)
123 if tuple[2] == "hosts" then 190 if tuple[2] == "hosts" then
124 local output = io.output(); io.output("prosody.cfg.lua"); 191 local output = io.output(); io.output("prosody.cfg.lua");
125 io.write("-- Configuration imported from ejabberd --\n"); 192 io.write("-- Configuration imported from ejabberd --\n");