Diff

mod_remote_roster/mod_remote_roster.lua @ 315:dead242beee3

mod_remote_roster: Implement section 2.5 of <http://jkaluza.fedorapeople.org/remote-roster.html>.
author Waqas Hussain <waqas20@gmail.com>
date Mon, 10 Jan 2011 17:20:34 +0500
parent 314:df212e1fa576
child 316:c86fc337d56f
line wrap: on
line diff
--- a/mod_remote_roster/mod_remote_roster.lua	Mon Jan 10 16:35:43 2011 +0500
+++ b/mod_remote_roster/mod_remote_roster.lua	Mon Jan 10 17:20:34 2011 +0500
@@ -13,6 +13,7 @@
 local hosts = hosts;
 
 local load_roster = require "core.rostermanager".load_roster;
+local save_roster = require "core.rostermanager".save_roster;
 local rm_remove_from_roster = require "core.rostermanager".remove_from_roster;
 local rm_add_to_roster = require "core.rostermanager".add_to_roster;
 local rm_roster_push = require "core.rostermanager".roster_push;
@@ -68,24 +69,25 @@
 		local item = query.tags[1];
 		local jid = jid_prep(item.attr.jid);
 		local node, host, resource = jid_split(jid);
-		if not resource and host then
-			if jid ~= stanza.attr.to then
+		if not resource and host == session.host then
+			if jid ~= stanza.attr.to then -- not self-jid
 				if item.attr.subscription == "remove" then
 					local r_item = roster[jid];
 					if r_item then
 						local to_bare = node and (node.."@"..host) or host; -- bare JID
-						if r_item.subscription == "both" or r_item.subscription == "from" or (roster.pending and roster.pending[jid]) then
-							core_post_stanza(session, st.presence({type="unsubscribed", from=session.full_jid, to=to_bare}));
-						end
-						if r_item.subscription == "both" or r_item.subscription == "to" or r_item.ask then
-							core_post_stanza(session, st.presence({type="unsubscribe", from=session.full_jid, to=to_bare}));
-						end
-						local success, err_type, err_cond, err_msg = rm_remove_from_roster(session, jid);
-						if success then
+						--if r_item.subscription == "both" or r_item.subscription == "from" or (roster.pending and roster.pending[jid]) then
+						--	core_post_stanza(hosts[module.host], st.presence({type="unsubscribed", from=stanza.attr.to, to=to_bare}));
+						--end
+						--if r_item.subscription == "both" or r_item.subscription == "to" or r_item.ask then
+						--	core_post_stanza(hosts[module.host], st.presence({type="unsubscribe", from=stanza.attr.to, to=to_bare}));
+						--end
+						roster[jid] = nil;
+						if save_roster(from_node, from_host, roster) then
 							session.send(st.reply(stanza));
 							rm_roster_push(from_node, from_host, jid);
 						else
-							session.send(st.error_reply(stanza, err_type, err_cond, err_msg));
+							roster[jid] = item;
+							session.send(st.error_reply(stanza, "wait", "internal-server-error", "Unable to save roster"));
 						end
 					else
 						session.send(st.error_reply(stanza, "modify", "item-not-found"));
@@ -93,9 +95,9 @@
 				else
 					local r_item = {name = item.attr.name, groups = {}};
 					if r_item.name == "" then r_item.name = nil; end
-					if session.roster[jid] then
-						r_item.subscription = session.roster[jid].subscription;
-						r_item.ask = session.roster[jid].ask;
+					if roster[jid] then
+						r_item.subscription = roster[jid].subscription;
+						r_item.ask = roster[jid].ask;
 					else
 						r_item.subscription = "none";
 					end
@@ -107,13 +109,15 @@
 							end
 						end
 					end
-					local success, err_type, err_cond, err_msg = rm_add_to_roster(session, jid, r_item);
-					if success then -- Ok, send success
+					local olditem = roster[jid];
+					roster[jid] = r_item;
+					if save_roster(from_node, from_host, roster) then -- Ok, send success
 						session.send(st.reply(stanza));
 						-- and push change to all resources
 						rm_roster_push(from_node, from_host, jid);
 					else -- Adding to roster failed
-						session.send(st.error_reply(stanza, err_type, err_cond, err_msg));
+						roster[jid] = olditem;
+						session.send(st.error_reply(stanza, "wait", "internal-server-error", "Unable to save roster"));
 					end
 				end
 			else -- Trying to add self to roster