Comparison

plugins/mod_roster.lua @ 928:92288c13d7bc

Fixed: mod_roster: Prep JIDs being added to roster (part of issue #57)
author Waqas Hussain <waqas20@gmail.com>
date Mon, 30 Mar 2009 02:38:51 +0500
parent 916:f0743928ef7e
child 1133:b293d7dc6a45
comparison
equal deleted inserted replaced
927:cc180d25dbeb 928:92288c13d7bc
9 9
10 10
11 local st = require "util.stanza" 11 local st = require "util.stanza"
12 12
13 local jid_split = require "util.jid".split; 13 local jid_split = require "util.jid".split;
14 local jid_prep = require "util.jid".prep;
14 local t_concat = table.concat; 15 local t_concat = table.concat;
15 local tostring = tostring; 16 local tostring = tostring;
16 17
17 local handle_presence = require "core.presencemanager".handle_presence; 18 local handle_presence = require "core.presencemanager".handle_presence;
18 local rm_remove_from_roster = require "core.rostermanager".remove_from_roster; 19 local rm_remove_from_roster = require "core.rostermanager".remove_from_roster;
59 -- Protection against overwriting roster.pending, until we move it 60 -- Protection against overwriting roster.pending, until we move it
60 and query.tags[1].attr.jid ~= "pending" then 61 and query.tags[1].attr.jid ~= "pending" then
61 local item = query.tags[1]; 62 local item = query.tags[1];
62 local from_node, from_host = jid_split(stanza.attr.from); 63 local from_node, from_host = jid_split(stanza.attr.from);
63 local from_bare = from_node and (from_node.."@"..from_host) or from_host; -- bare JID 64 local from_bare = from_node and (from_node.."@"..from_host) or from_host; -- bare JID
64 local node, host, resource = jid_split(item.attr.jid); 65 local jid = jid_prep(item.attr.jid);
65 local to_bare = node and (node.."@"..host) or host; -- bare JID 66 local node, host, resource = jid_split(jid);
66 if not resource and host then 67 if not resource and host then
67 if item.attr.jid ~= from_node.."@"..from_host then 68 if jid ~= from_node.."@"..from_host then
68 if item.attr.subscription == "remove" then 69 if item.attr.subscription == "remove" then
69 local r_item = session.roster[item.attr.jid]; 70 local r_item = session.roster[jid];
70 if r_item then 71 if r_item then
71 local success, err_type, err_cond, err_msg = rm_remove_from_roster(session, item.attr.jid); 72 local success, err_type, err_cond, err_msg = rm_remove_from_roster(session, jid);
72 if success then 73 if success then
73 session.send(st.reply(stanza)); 74 session.send(st.reply(stanza));
74 rm_roster_push(from_node, from_host, item.attr.jid); 75 rm_roster_push(from_node, from_host, jid);
76 local to_bare = node and (node.."@"..host) or host; -- bare JID
75 if r_item.subscription == "both" or r_item.subscription == "from" then 77 if r_item.subscription == "both" or r_item.subscription == "from" then
76 handle_presence(session, st.presence({type="unsubscribed"}), from_bare, to_bare, 78 handle_presence(session, st.presence({type="unsubscribed"}), from_bare, to_bare,
77 core_route_stanza, false); 79 core_route_stanza, false);
78 elseif r_item.subscription == "both" or r_item.subscription == "to" then 80 elseif r_item.subscription == "both" or r_item.subscription == "to" then
79 handle_presence(session, st.presence({type="unsubscribe"}), from_bare, to_bare, 81 handle_presence(session, st.presence({type="unsubscribe"}), from_bare, to_bare,
86 session.send(st.error_reply(stanza, "modify", "item-not-found")); 88 session.send(st.error_reply(stanza, "modify", "item-not-found"));
87 end 89 end
88 else 90 else
89 local r_item = {name = item.attr.name, groups = {}}; 91 local r_item = {name = item.attr.name, groups = {}};
90 if r_item.name == "" then r_item.name = nil; end 92 if r_item.name == "" then r_item.name = nil; end
91 if session.roster[item.attr.jid] then 93 if session.roster[jid] then
92 r_item.subscription = session.roster[item.attr.jid].subscription; 94 r_item.subscription = session.roster[jid].subscription;
93 r_item.ask = session.roster[item.attr.jid].ask; 95 r_item.ask = session.roster[jid].ask;
94 else 96 else
95 r_item.subscription = "none"; 97 r_item.subscription = "none";
96 end 98 end
97 for _, child in ipairs(item) do 99 for _, child in ipairs(item) do
98 if child.name == "group" then 100 if child.name == "group" then
100 if text and text ~= "" then 102 if text and text ~= "" then
101 r_item.groups[text] = true; 103 r_item.groups[text] = true;
102 end 104 end
103 end 105 end
104 end 106 end
105 local success, err_type, err_cond, err_msg = rm_add_to_roster(session, item.attr.jid, r_item); 107 local success, err_type, err_cond, err_msg = rm_add_to_roster(session, jid, r_item);
106 if success then 108 if success then
107 session.send(st.reply(stanza)); 109 session.send(st.reply(stanza));
108 rm_roster_push(from_node, from_host, item.attr.jid); 110 rm_roster_push(from_node, from_host, jid);
109 else 111 else
110 session.send(st.error_reply(stanza, err_type, err_cond, err_msg)); 112 session.send(st.error_reply(stanza, err_type, err_cond, err_msg));
111 end 113 end
112 end 114 end
113 else 115 else